Jump to content

salepg

Members
  • Posts

    12
  • Joined

  • Last visited

salepg's Achievements

Jr. Member

Jr. Member (3/6)

7

Reputation

  1. 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!
  2. 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!
  3. 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.
  4. 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
  5. TY netcarver! You gave me nice hint to google it... Here is link that is closest to my solution. Now I have the hook... It's a fishing time, will see if I can handle it...
  6. Hi, I'm developing mailbox and I wanna rather use single class then making pages. Here is the plan (or I think that its a good plan): - I have mailbox.php template and mailbox page - when user click on mailbox, on sidebar he have options to write/read massages to and from ppl Instead of making these pages, and to prevent "ugly URLs" I wanna offer user to call write msg like: http://www.domain.com/mailbox/?actionType=newMail. Also, I think that this will be useful for some other stuff which I wanna add to my project. I'm not skilful but wanna learn stuff. Cheers
  7. Solved Insteed of this code: $pui = $pages->get("/users/$display_name/UserInfo"); foreach($pui->userInfo as $info) { $info->of(false); $info->set("firstName", $first_name); $info->set("lastName", $last_name); $info->set("displayName", $display_name); $info->set("dateCreated", date("j F Y H:i:s")); $info->set("dateUpdated", date("j F Y H:i:s")); $info->set("email", $email); $info->save(); $info->of(true); } I put this: $p = $pages->get("/users/$display_name/UserInfo"); $p->of(false); $pui = $p->userInfo->getNew(); $pui->firstName = $first_name; $pui->lastName = $last_name; $pui->displayName = $display_name; $pui->dateCreated = date("j F Y H:i:s"); $pui->dateUpdated = date("j F Y H:i:s"); $pui->email = $email; $p->save(); Also, I added this code at the end of IF statement to auto login user after registration: if($session->login($display_name, $password)) $session->redirect("./"); I found out that if user put "eee@eee" as a email adress, form is passed successfully but email repeater field remain empty. I need to stop registration process with an error warning (user can change it during a reg. process) or accept that kind of email (so user can change it later). How to handle this? Cheers!
  8. Hi 3fingers, Thank you for the links, I'll check it now I created user page to be searchable by other users via URL directly. For example, if I wanna check your user page, i just put your nickname instead of mine at the end of URL. For example, if my user page URL is http://domain.com/users/salepg/ i can access your page replacing just my nickname with yours: http://domain.com/users/3fingers/ and check your stats or whatever is on user page. User Info is just one piece of infos that I wanna assing to an user as I'm working on interested project - creating browser game mainly for learning purpose and secondary to publish it some day eventually. So, the idea is to have "subpages" for different stuff related to user as I'm expecting very big DB... but, I'm still open for advice I didn't think a lot about whole user picture, am I wrong? Second solution that I had in my mind is usage od PHP classes that will be like controlers which will handle all user stuff but at this moment I don't have so much courage to jump in.
  9. This is my 3rd post here. I have to admit that I become highly addictive on PW after painful usage of Joomla which I almost mastered, and really need to thank to Ryan for this drug! During registration process, I wanna assign values on an automatic way. Well, I'm stucked and need your help. Successful registration: new user is created, new pageInfo page is created (let say, user profile) using user_info template which contain title, headline and userinfo repeater with fields like firstName, lastName, etc. user will be redirect to his userinfo page after successful registration. I can grab repeater values (which I typed directly via Admin panel) but I don't know how to add values automatically during registration proccess. I don't even know if I have to use repeater or not... :/ (plan was to track user info changes; this can be redesign later to track only email or username changes but atm let say that I wanna track all changes) register.php <?php $headline = "Registration form"; include "./register.inc"; $errorMessage = ""; if($input->post->register_submit) { // process submitted register form $first_name = $sanitizer->text($input->post->first_name); $last_name = $sanitizer->text($input->post->last_name); $display_name = $sanitizer->username($input->post->display_name); $email = $sanitizer->email($input->post->email); $password = $input->post->password; $password_confirmation = $input->post->password_confirmation; if($password!=$password_confirmation) $errorMessage = "<br><p class='alert alert-danger alert-error'><strong>Error!</strong> Register failed, please try again.</p>"; $p = new Page(); $p->of(false); // sets output formatting to false in order to change field values. $p->parent = $pages->get("/users"); $p->template = "users"; $p->title = $display_name; // sanitized your value from form and sets to title //$p->other_field = $sanitizer->text($input->post->other_field); $p->save(); // save the new page $p = new Page(); $p->of(false); // sets output formatting to false in order to change field values. $p->parent = $pages->get("/users/$display_name"); $p->template = "user_info"; $p->title = "UserInfo"; $p->save(); // save the new page $pui = $pages->get("/users/$display_name/UserInfo"); foreach($pui->userInfo as $info) { $info->of(false); $info->set("firstName", $first_name); $info->set("lastName", $last_name); $info->set("displayName", $display_name); $info->set("dateCreated", date("j F Y H:i:s")); $info->set("dateUpdated", date("j F Y H:i:s")); $info->set("email", $email); $info->save(); $info->of(true); } // now add the user $u = new User(); $u->of(false); $u->name = $display_name; $u->email = $email; $u->pass = $password; $u->save(); $u->of(true); } ?> That's all for now...
  10. Hi, What's the difference between $page->child and $page->child() and when I should use which one? I know, noob question... but I had a problem with other usages not just at $page... :/
  11. Insteed of (which isn't works for me): /_main.php <a href='?logout=1'>Logout</a> I'm using: /_main.php <a href='{$config->urls->admin}login/logout/'>Logout</a> I don't know why first doesn't work. Second have a little "bug". When I'm logged as a regular user, when I log off it redirect me at homepage (which is ok), but if I'm logged as admin it redirect me to Admin Panel login. I can guess that solution is to include login.php before echoing these lines.
×
×
  • Create New...