1
|
|
|
<?php |
2
|
|
|
namespace Data; |
3
|
|
|
|
4
|
|
|
class ObjectDataTable extends \Data\DataTable |
5
|
|
|
{ |
6
|
|
|
protected $dataTable; |
7
|
|
|
protected $className = 'SerializableObject'; |
8
|
|
|
|
9
|
|
|
public static function getInstance() |
10
|
|
|
{ |
11
|
|
|
static $instance = null; |
12
|
|
|
if(null === $instance) |
13
|
|
|
{ |
14
|
|
|
$instance = new static(); |
|
|
|
|
15
|
|
|
} |
16
|
|
|
return $instance; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function __construct($dataTable) |
20
|
|
|
{ |
21
|
|
|
$this->dataTable = $dataTable; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function create($data) |
25
|
|
|
{ |
26
|
|
|
if(is_array($data)) |
27
|
|
|
{ |
28
|
|
|
$data = new $this->className($data); |
29
|
|
|
} |
30
|
|
|
if(method_exists($data, 'preCreate')) |
31
|
|
|
{ |
32
|
|
|
$data = $data->preCreate(); |
33
|
|
|
} |
34
|
|
|
return $this->dataTable->create($data); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function read($filter=false, $select=false, $count=false, $skip=false, $sort=false, $params=false) |
38
|
|
|
{ |
39
|
|
|
$res = $this->dataTable->read($filter, $select, $count, $skip, $sort, $params); |
40
|
|
|
if($res === false) |
41
|
|
|
{ |
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
if(!is_array($res)) |
45
|
|
|
{ |
46
|
|
|
$res = array($res); |
47
|
|
|
} |
48
|
|
|
$objCount = count($res); |
49
|
|
|
for($i = 0; $i < $objCount; $i++) |
50
|
|
|
{ |
51
|
|
|
$res[$i] = new $this->className($res[$i]); |
52
|
|
|
} |
53
|
|
|
return $res; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function update($filter, $data) |
57
|
|
|
{ |
58
|
|
|
if(method_exists($data, 'preUpdate')) |
59
|
|
|
{ |
60
|
|
|
$data = $data->preUpdate(); |
61
|
|
|
} |
62
|
|
|
return $this->dataTable->update($filter, $data); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function delete($filter) |
66
|
|
|
{ |
67
|
|
|
if(method_exists($data, 'preDelete')) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$data = $data->preDelete(); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
return $dataTable->delete($filter); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function count($filter=false) |
75
|
|
|
{ |
76
|
|
|
return parent::count($filter); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks for function calls that miss required arguments.