1: <?php
2: namespace Budovy;
3:
4: class ContactRepository extends Repository {
5: 6: 7: 8: 9:
10: function getPairData() {
11: return $this->getTable()->select('id, IF(company != \'\', CONCAT(company, \' - \', lastname, \' \', firstname), CONCAT(lastname, \' \', firstname)) AS name')->order('name ASC')->fetchPairs('id', 'name');
12: }
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: function getGridSelection($filter, $order, $page, $limit) {
24: $selection = $this->getTable()->select('*');
25:
26: if (isset($order[0])) {
27: $selection->order(implode(' ', $order));
28: }
29:
30: $selection->page($page, $limit);
31:
32: return $this->addGridFilter($selection, $filter);
33: }
34:
35: 36: 37: 38: 39: 40:
41: function getGridCount($filter) {
42: $selection = $this->getTable()->select('COUNT(*) AS cnt');
43:
44: $result = $this->addGridFilter($selection, $filter)->fetch();
45:
46: return $result->cnt;
47: }
48:
49: 50: 51: 52: 53: 54: 55:
56: private function addGridFilter(\Nette\Database\Table\Selection $selection, $filter) {
57: $filters = array();
58:
59: foreach ($filter as $k => $v) {
60: $filters[$k . ' LIKE ?'] = "%$v%";
61: }
62:
63: return $selection->where($filters);
64: }
65: }