1: | <?php |
2: | |
3: | namespace ZCL\DB; |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | class EntityDataSource implements \Zippy\Interfaces\DataSource |
11: | { |
12: | |
13: | private $class; |
14: | private $where; |
15: | private $order; |
16: | private $count; |
17: | |
18: | |
19: | |
20: | public function __construct($class, $where = "", $order = "", $count = 0) { |
21: | $this->class = $class; |
22: | $this->where = $where; |
23: | $this->order = $order; |
24: | $this->count = $count; |
25: | } |
26: | |
27: | public function getItemCount() { |
28: | $class = $this->class; |
29: | return $class::findCnt($this->where); |
30: | } |
31: | |
32: | public function getItems($start = -1, $count = -1, $sortfield = null, $desc = null) { |
33: | if ($this->count > 0) { |
34: | $count = $this->count; |
35: | $start = 0; |
36: | } |
37: | $orderby = strlen($sortfield) > 0 ? $sortfield . ' ' . $desc : ""; |
38: | |
39: | if (strlen($this->order) > 0 && strlen($sortfield) == 0) { |
40: | $orderby = $this->order; |
41: | } |
42: | $class = $this->class; |
43: | return $class::find($this->where, $orderby, $count, $start); |
44: | } |
45: | |
46: | public function getItem($id) { |
47: | $class = $this->class; |
48: | return $class::load($id); |
49: | } |
50: | |
51: | public function setWhere($where = '') { |
52: | $this->where = $where; |
53: | } |
54: | |
55: | public function setOrder($order) { |
56: | $this->order = $order; |
57: | } |
58: | |
59: | } |
60: | |