1: <?php
2: namespace Budovy;
3:
4: class ContactBindingRepository extends Repository {
5: 6: 7: 8: 9: 10: 11: 12: 13:
14: function getGridSelection($filter, $order, $page, $limit) {
15: $selection = $this->getTable()
16: ->select('id_contact, id_unit, id_operation, unit.name AS unit, operation.name AS operation, CONCAT(contact.firstname, \' \', contact.lastname) AS contact')
17: ->select('unit.place.name AS place');
18:
19: if (isset($order[0])) {
20: $selection->order(implode(' ', $order));
21: }
22:
23: $selection->page($page, $limit);
24:
25: return $this->addGridFilter($selection, $filter);
26: }
27:
28: 29: 30: 31: 32: 33:
34: function getGridCount($filter) {
35: $selection = $this->getTable()->select('COUNT(*) AS cnt');
36:
37: $result = $this->addGridFilter($selection, $filter)->fetch();
38:
39: return $result->cnt;
40: }
41:
42: 43: 44: 45: 46: 47: 48:
49: private function addGridFilter($selection, $filter) {
50: $filters = array();
51:
52: foreach ($filter as $k => $v) {
53: if ($k == 'contact') {
54: $filters['id_contact=?'] = $v;
55: } else if ($k == 'unit') {
56: $filters['id_unit=?'] = $v;
57: } else if ($k == 'place') {
58: $filters['unit.id_place=?'] = $v;
59: } else if ($k == 'operation') {
60: $filters['id_operation=?'] = $v;
61: }
62: }
63:
64: return $selection->where($filters);
65: }
66:
67: 68: 69: 70: 71: 72: 73:
74: function getContact($id_unit, $id_operation) {
75: return $this->getTable()->select('contact.*')->where(array('id_unit' => $id_unit, 'id_operation' => $id_operation))->fetch();
76: }
77:
78: 79: 80: 81: 82: 83: 84:
85: public function delete($id_contact, $id_unit, $id_operation) {
86: $this->getTable()->where(array('id_unit' => $id_unit, 'id_operation' => $id_operation, 'id_contact' => $id_contact))->delete();
87: }
88: }