1 <?php
2
3 namespace PLus\Orders\Repositories\Entities;
4
5 6 7 8 9
10 class DepartmentRepository extends \PLus\Orders\Repositories\Repository {
11
12 function getPairData(){
13 return $this->getTable()->select('id, name')->order('name ASC')->fetchPairs('id', 'name');
14 }
15
16
17 function getGridSelection(){
18 return $this->getTable()
19 ->select('department.id, department.name AS dname, department.number, department.branch_id, branch.name AS bname');
20 }
21
22 23 24 25 26
27 public function findById($id) {
28 return $this->getTable()->select('department.*, branch.name AS bname')->wherePrimary($id)->fetch();
29 }
30
31 32 33 34 35 36
37 public function findAll4BossById($id) {
38 return $this->getTable()
39 ->select('department.*')
40 ->where(':department_user.user.id', $id)
41 ->fetchPairs('id', 'name');
42 }
43
44
45 46 47 48 49 50
51 public function findByUnitId($user_id) {
52 return $this->getTable()
53 ->select('department.id')
54 ->where(':unit:unit_user.user.id', $user_id)
55 ->fetch();
56 }
57
58
59 }
60