1 <?php
2
3 namespace PLus\Orders\Repositories\Messages;
4
5
6
7 8 9 10 11
12 class ConsultationRepository extends \PLus\Orders\Repositories\Repository {
13
14
15 16 17 18 19 20
21 public function findConsultIds($user_id){
22 return $this->getTable()
23 ->select('DISTINCT order_id')
24 ->where('(from ? OR to ?)',$user_id,$user_id);
25 }
26
27
28
29 30 31 32 33 34 35
36 public function getConsultationHeader($user_id, $order_id) {
37 return $this->connection->query("SELECT c.*,CONCAT_WS(' ',f.firstname,f.lastname) AS fromname, CONCAT_WS(' ',t.firstname,t.lastname) AS toname, "
38 . "LEFT(p.message,150) AS message "
39 . "FROM consultation AS c LEFT JOIN post AS p ON c.id = p.consultation_id "
40 . "LEFT JOIN user AS f ON f.id = c.from "
41 . "LEFT JOIN user AS t ON t.id = c.to "
42 . "WHERE (c.from = $user_id OR c.to = $user_id) AND c.order_id = $order_id "
43 . "GROUP BY c.id");
44 }
45
46
47
48 49 50 51 52 53
54 public function getConsultationOrderHeadById($consultation_id,$order_id) {
55 return $this->getTable()->select('consultation.id, consultation.order_id, order.name')
56 ->where('order.id', $order_id)
57 ->where('consultation.id', $consultation_id)
58 ->fetch();
59 }
60
61
62
63 }
64