| Conditions | 2 |
| Paths | 2 |
| Total Lines | 49 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | public function sidebar() |
||
| 14 | { |
||
| 15 | $this->loadModel('ConversationsUsers'); |
||
| 16 | $this->loadModel('Conversations'); |
||
| 17 | |||
| 18 | $id = isset($this->request->id) ? $this->request->id : null; |
||
| 19 | |||
| 20 | $participants = $this->ConversationsUsers |
||
|
|
|||
| 21 | ->find() |
||
| 22 | ->contain([ |
||
| 23 | 'Users' => function ($q) { |
||
| 24 | return $q->find('full'); |
||
| 25 | }, |
||
| 26 | 'Users.Groups' => function ($q) { |
||
| 27 | return $q->select(['id', 'name', 'css', 'is_staff', 'is_member']); |
||
| 28 | } |
||
| 29 | ]) |
||
| 30 | ->where([ |
||
| 31 | 'ConversationsUsers.conversation_id' => $id |
||
| 32 | ]) |
||
| 33 | ->toArray(); |
||
| 34 | |||
| 35 | $conversation = $this->Conversations |
||
| 36 | ->find() |
||
| 37 | ->contain([ |
||
| 38 | 'LastMessageUser' |
||
| 39 | ]) |
||
| 40 | ->where([ |
||
| 41 | 'Conversations.id' => $id |
||
| 42 | ]) |
||
| 43 | ->first(); |
||
| 44 | |||
| 45 | //Current user. |
||
| 46 | $this->loadModel('Users'); |
||
| 47 | $currentUser = $this->Users |
||
| 48 | ->find() |
||
| 49 | ->contain([ |
||
| 50 | 'Groups' => function ($q) { |
||
| 51 | return $q->select(['id', 'is_staff']); |
||
| 52 | } |
||
| 53 | ]) |
||
| 54 | ->where([ |
||
| 55 | 'Users.id' => $this->request->session()->read('Auth.User.id') |
||
| 56 | ]) |
||
| 57 | ->select(['id', 'group_id']) |
||
| 58 | ->first(); |
||
| 59 | |||
| 60 | $this->set(compact('conversation', 'participants', 'currentUser')); |
||
| 61 | } |
||
| 62 | } |
||
| 63 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: