salepg Posted February 16, 2015 Share Posted February 16, 2015 Hi, I'm trying to achieve same thing as this. Here is how my DB desing look like: So far, I have one page called mailbox.php, and template which should call PHP class and render view depending of action type using URL segments (new message, read new messages, read all messages...). Now, I need some brainstorming: What I have to do? Create more pages? Use custom tables? Use repeaters for many-to-many relationships or just making fields? I'm really stuck here and don't know what to do... What would you do? Cheers Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 16, 2015 Share Posted February 16, 2015 I don't know if this does help you, but templates are kinda like your models in ProcessWire. So you'd probably need threads, messages, and users (the last one is alread there). States and participations could be managed independently or as fields of thread/message. You can read more on this here: https://processwire.com/talk/topic/3579-tutorial-approaches-to-categorising-site-content/. I would suggest taking the hierarchy of pages in consideration as well (messages as children of thread). Your template.php files are your views, which render the current data. If you're then still in need of some kind of controller structure, url segments and maybe some autoload modules are your friend. 2 Link to comment Share on other sites More sharing options...
salepg Posted February 16, 2015 Author Share Posted February 16, 2015 TY, LostKobrakai. I'm still confused about all... How can I "link" users with a threads using PW approach? Let say that I have these pages: - Home -- users ---- user1_profile ---- user2_profile -- mailbox ---- thread (with title field) ------ message (with body and sentDate fields) Now I have to read/write messages. It's oblivious that I need more fields. But I hit the wall and someone have to rescue me. How I can adapt db sheme from the 1st post to PW and get the best of PW? I can guess that I need (maybe) participant field on the thread page and store in there sender/receiver (or 2 separated fields for same purpose)? Note: I'm expecting for example 1-10k users. There can be A LOT of data and I have to find a solution which don't affect performance a lot. P.S. If I get this into my head, I think that my learning curve will explode. Just need to figure out how I can use relational shema in PW. I'm done for today. This was hard day on PW. Link to comment Share on other sites More sharing options...
mr-fan Posted February 16, 2015 Share Posted February 16, 2015 there are two main concepts... all are pages == models, objects and so on fields are your data with a pagefield you could combine all together an get your 1:n n:1 1:1 connection of your models... have a read: http://processwire.com/videos/page-fieldtype/ next hint: you have 3 models like LostKobrakai wrote: messages (messagetext, pagefield for the thread, pagefield for the user_profile) --m1 --m2 --m3 threads (simple pagefield for the connection to the messages of one thread) -t1 -t2 -t3 -user_profiles (would make this maybe separate from the existing usersystem - depends on the other things on this site/app) -u1 (refer to the $user and pagefield with saves all his messages) -u2 there is a module that helps you to get information about the pagefield relations: http://modules.processwire.com/modules/page-references-tab/ if all is configured right you could use the PW API to get your data and save your data right how do you like. For Frontend or Bakendusage (there is a module for custom admin pages). best regards mr-fan 3 Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 16, 2015 Share Posted February 16, 2015 As mr-fan stated the key here is the FieldtypePage. It lets you link those pages. For your performance concerns, I would say build your code well, use "limit" in selectors as much as possible and let ProcessWire handle the database stuff. It does it very well. 2 Link to comment Share on other sites More sharing options...
salepg Posted February 17, 2015 Author Share Posted February 17, 2015 You stretched my brain A LOT, I dunno how to appriciate for that! BIG THANK YOU!! I modified mr-fan's example, needed about 1 hour and half for that (after 4-5 hours of yesterday's journey to nowhere). I'll update this topic with my solution... It's look like a little rusty atm and will see if I would make more elegant solution. Again, thank you! 1 Link to comment Share on other sites More sharing options...
mr-fan Posted February 17, 2015 Share Posted February 17, 2015 Great to hear....if you strech your brain once in the right direction with PW there will be almost no limits.... 2 Link to comment Share on other sites More sharing options...
salepg Posted February 20, 2015 Author Share Posted February 20, 2015 I didn't forgot... Here is my solution: templates(fields): - mailbox (generate view and calls MailboxClass as controler) - threads (title, headline, userProfiles [FieldtypePage]), - messages (title, threads [FieldtypePage], msgBody, dateCreated) userProfiles contains 2 userinfo pages (sender and receiver) which title is equal to username page structure: - Mailbox (mailbox.php template) -- Threads (threads.php which purpose is only as selector) ---- salepg (messages.php which purpose is only as selector) ---- salepg-1 ---- mr-fan ---- lostkobrakai mailbox.php <?php include './functions/MailboxClass.php'; /** here some code to generate basic view */ ?> MailboxClass.php <?php $out = ''; /** locate threads page */ $p = $pages->get("/mailbox/threads/"); /** find threads that belong to logged user */ $threads = $p->find("userProfiles={$user->name}, template=threads, limit=10"); foreach($threads as $thread) { /** making thread object */ $t = new Mailbox($thread); /** output thread's info and last message in that thread */ $out .= "<a href='#'>".$t->receiver."</span> <span>".$t->subject."</span> <span>".$t->msgBody."</span> <span>".$t->dateCreated."</span> </a>"; } class Mailbox { public $thread = NULL; public function __construct($thread) { /** title contain only username of someone who start conversation */ $this->title = $this->title($thread); $this->subject = $this->headline($thread); /** * output receiver's name; user assume that he is in conversation * userProfiles contain 2 User Pages as persons involved in conversation * sender is person who start conversation * receiver is person who will be displayed to person who checks messages */ foreach ($thread->userProfiles as $up){ $this->sender = $this->title; if($this->title != $up->name)$this->receiver = $up->name; } foreach ($thread->children as $message){ $this->msgBody = $message->msgBody; $this->dateCreated = $message->dateCreated; } } private function title($thread) { return $thread->title; } private function headline($thread) { return $thread->headline; } } I ommited a lot of code to simplify this solution and showed just threads that belong to logged user. For starting new thread, reply or open specific thread or message, it's easy to upgrade this code. Also, I used PHP class as a part of maibox.php, again, for the sake of simplicity. powered by mr-fan and LostKobrakai Cheers! 4 Link to comment Share on other sites More sharing options...
mr-fan Posted February 20, 2015 Share Posted February 20, 2015 Great to read that you get one of the "pw" moments that shows that everything is possible... I am very glad to help and say thank you for sharing. Best regards mr-fan 2 Link to comment Share on other sites More sharing options...
marie.mdna Posted June 7, 2022 Share Posted June 7, 2022 (edited) [edit] I found my way in, thanks again for sharing! Quote It looks incredible! I would love to reuse this logic but I have some problem to visualise how the templates and fields should look like from the admin panel (especially when it comes to userProfiles). For example, how could I get 2 user info pages from the same repeater field? On 2/20/2015 at 12:49 PM, salepg said: templates(fields): - mailbox (generate view and calls MailboxClass as controler) - threads (title, headline, userProfiles [FieldtypePage]), - messages (title, threads [FieldtypePage], msgBody, dateCreated) userProfiles contains 2 userinfo pages (sender and receiver) which title is equal to username page structure: - Mailbox (mailbox.php template) -- Threads (threads.php which purpose is only as selector) ---- salepg (messages.php which purpose is only as selector) ---- salepg-1 ---- mr-fan ---- lostkobrakai I would be a great help to have some screenshots of how to set the fields and templates properly! Edited June 7, 2022 by marie.mdna Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now