1: <?php
2: namespace Budovy;
3:
4: class PriorityRepository extends Repository {
5: /**
6: * Vraci data v poli ID => nazev
7: *
8: * @return array
9: */
10: function getPairData() {
11: return $this->getTable()->order('name ASC')->fetchPairs('id', 'name');
12: }
13:
14: /**
15: * Vrati selection pro datagrid
16: *
17: * @param array $filter
18: * @param array $order
19: * @param int $page
20: * @param int $limit
21: * @return \Nette\Database\Table\Selection
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: $selection->page($page, $limit);
30:
31: return $this->addGridFilter($selection, $filter);
32: }
33:
34: /**
35: * Vrati pocet zaznamu pro datagrid
36: *
37: * @param array $filter
38: * @return int
39: */
40: function getGridCount($filter) {
41: $selection = $this->getTable()->select('COUNT(*) AS cnt');
42:
43: $result = $this->addGridFilter($selection, $filter)->fetch();
44:
45: return $result->cnt;
46: }
47:
48: /**
49: * Omezi selection na zaklade filtru pro datagrid
50: *
51: * @param Selection $selection
52: * @param Array $filter
53: * @return \Nette\Database\Table\Selection
54: */
55: private function addGridFilter(\Nette\Database\Table\Selection $selection, $filter) {
56: $filters = array();
57:
58: foreach ($filter as $k => $v) {
59: $filters[$k . ' LIKE ?'] = "%$v%";
60: }
61:
62: return $selection->where($filters);
63: }
64: }