| 20 | | /* return |
| 21 | | * |
| | 20 | |
| | 21 | public function inbox($user_id) |
| | 22 | { |
| | 23 | $this->unbindModel(array('belongsTo'=>array('User'))); |
| | 24 | |
| | 25 | $this->bindModel(array('belongsTo'=>array( |
| | 26 | 'User' => array( |
| | 27 | 'className' => 'User', |
| | 28 | 'foreignKey' => 'sender' |
| | 29 | ) |
| | 30 | ) |
| | 31 | ) ); |
| | 32 | |
| | 33 | $conditions = array("Message.user_id" => $user_id); |
| | 34 | $fields = array("Message.id", "Message.title", "Message.body", "Message.created", "Message.sender", "Message.status", "User.id", "User.username"); |
| | 35 | $order = "Message.id DESC"; |
| | 36 | $limit = 50; |
| | 37 | |
| | 38 | $data = $this->findAll($conditions, $fields, $order, $limit); |
| | 39 | |
| | 40 | return $data; |
| | 41 | } |
| | 42 | |
| | 43 | public function display($message_id, $user_id) |
| | 44 | { |
| | 45 | $this->unbindModel(array('belongsTo'=>array('User'))); |
| | 46 | |
| | 47 | $this->bindModel(array('belongsTo'=>array( |
| | 48 | 'User' => array( |
| | 49 | 'className' => 'User', |
| | 50 | 'foreignKey' => 'sender' |
| | 51 | ) |
| | 52 | ) |
| | 53 | ) ); |
| | 54 | |
| | 55 | $conditions = array("Message.user_id" => $user_id, "Message.id"=>$message_id); |
| | 56 | $fields = array("Message.id", "Message.title", "Message.body", "Message.created", "Message.sender", "Message.status", "User.id", "User.username"); |
| | 57 | |
| | 58 | $data = $this->find($conditions, $fields); |
| | 59 | |
| | 60 | if ( $data['Message']['status'] == 0 ): // change from new to readed |
| | 61 | $this->change($data['Message']['id'], 1); |
| | 62 | endif; |
| | 63 | |
| | 64 | return $data; |
| | 65 | } |
| | 66 | |
| | 67 | /* |
| | 68 | * Change message status |
| | 69 | * int |
| | 70 | * int |