1 | <?php |
||
4 | class SQLDataTable extends DataTable |
||
5 | { |
||
6 | protected $dataset; |
||
7 | protected $tablename; |
||
8 | |||
9 | /** |
||
10 | * @param SQLDataSet $dataset The dataset to create this datatable in |
||
11 | * @param string $tablename The name of the table in the dataset |
||
12 | */ |
||
13 | public function __construct($dataset, $tablename) |
||
14 | { |
||
15 | $this->dataset = $dataset; |
||
16 | $this->tablename = $tablename; |
||
17 | } |
||
18 | |||
19 | public function get_primary_key() |
||
28 | |||
29 | public function count($filter = false) |
||
30 | { |
||
31 | $where = false; |
||
32 | if($filter !== false) |
||
33 | { |
||
34 | $where = $filter->to_sql_string(); |
||
|
|||
35 | } |
||
36 | $ret = $this->dataset->read($this->tablename, $where, 'COUNT(*)'); |
||
37 | if($ret === false || !isset($ret[0]) || !isset($ret[0]['COUNT(*)'])) |
||
38 | { |
||
39 | return false; |
||
40 | } |
||
41 | else |
||
42 | { |
||
43 | return $ret[0]['COUNT(*)']; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | public function read($filter = false, $select = false, $count = false, $skip = false, $sort = false, $params = false) |
||
48 | { |
||
49 | $where = false; |
||
50 | if($filter !== false) |
||
51 | { |
||
52 | $where = $filter->to_sql_string(); |
||
53 | } |
||
54 | if($select !== false && is_array($select)) |
||
55 | { |
||
56 | $select = implode(',', $select); |
||
57 | } |
||
58 | return $this->dataset->read($this->tablename, $where, $select, $count, $skip, $sort); |
||
59 | } |
||
60 | |||
61 | public function update($filter, $data) |
||
62 | { |
||
63 | $where = $filter->to_sql_string(); |
||
64 | return $this->dataset->update($this->tablename, $where, $data); |
||
65 | } |
||
66 | |||
67 | public function create($data) |
||
71 | |||
72 | public function delete($filter) |
||
81 | |||
82 | public function raw_query($sql) |
||
83 | { |
||
84 | return $this->dataset->raw_query($sql); |
||
86 | } |
||
87 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
88 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.