tailieunhanh - Tạo mạng xã hội với PHP - part 16

Friends and Relationships type_plural_name, as usera_name, as userb_name FROM relationships r, relationship_types t, profile uap, profile ubp WHERE AND AND AND {$approved}"; if( $usera != 0 ) { $sql .= " AND {$usera} "; } if( $userb != 0 ) { $sql .= " AND {$userb} "; } $cache = $this-registry-getObject('db')-cacheQuery( $sql ); return $cache; } New controller method The controller needs to check if the user is logged in, include our relationships model, get the pending requests, and display them to the user in the view. private function pendingRelationships() { if( $this-registry-getObject('authenticate')-isLoggedIn() ) { require_once( FRAMEWORK_PATH | Friends and Relationships type_plural_name as usera_name as userb_name FROM relationships r relationship_types t profile uap profile ubp WHERE AND AND AND approved if usera 0 Ssql . AND usera if userb 0 Ssql . AND userb cache Sthis- registry- getObject db - cacheQuery Ssql return cache New controller method The controller needs to check if the user is logged in include our relationships model get the pending requests and display them to the user in the view. private function pendingRelationships if Sthis- registry- getObject authenticate - isLoggedIn require_once FRAMEWORK_PATH . models Srelationships new Relationships this- registry Spending relationships- getRelationships 0 this- registry- getObject authenticate - getUser - getUserID 0 Sthis- registry- getObject template - buildFromTemplates friends Sthis- registry- getObject template - getPage - addTag pending array SQL Spending else Sthis- registry- errorPage Please login Please login to manage pending connections 132 Download from Chapter 4 The result Now if we navigate to http oursite relationships pending we see a list of pending requests Pending connections Michael Peacock wants to be Jogging buddies with you. Approve or Reject this re q u est. Accepting a pending request We simply check that we are logged in that we are permitted to accept the request then we call the accept method and save the relationship. This is within the relationship model. private function approveRelationship r if this- registry- getObject authenticate - isLoggedIn require_once FRAMEWORK_PATH . models relationship new Relationship this- registry r 0 0 0 0 if relationship- getUserB this- registry- getObject authenticate - getUser - getUserID we can approve this relationship- approveRelationship relationship- save this- registry- errorPage .

TỪ KHÓA LIÊN QUAN