|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class DbRowDirectOperator |
|
5
|
|
|
* |
|
6
|
|
|
* Handle Entity\EntityModel storing/loading operations |
|
7
|
|
|
*/ |
|
8
|
|
|
class DbRowDirectOperator { |
|
9
|
|
|
protected $db; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* DbRowDirectOperator constructor. |
|
13
|
|
|
* |
|
14
|
|
|
* @param db_mysql $db |
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct($db) { |
|
17
|
|
|
$this->db = $db; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param \Entity\KeyedModel $cModel |
|
22
|
|
|
* @param int|string $dbId |
|
23
|
|
|
* |
|
24
|
|
|
* @return array |
|
25
|
|
|
*/ |
|
26
|
|
|
public function getById($cModel, $dbId) { |
|
27
|
|
|
$stmt = classSupernova::$gc->query |
|
|
|
|
|
|
28
|
|
|
->setIdField($cModel->getIdFieldName()) |
|
29
|
|
|
->field('*') |
|
30
|
|
|
->from($cModel->getTableName()) |
|
31
|
|
|
->where($cModel->getIdFieldName() . ' = "' . $dbId . '"'); |
|
32
|
|
|
|
|
33
|
|
|
return $stmt->selectRow(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param \Entity\KeyedModel $cModel |
|
38
|
|
|
* @param int|string $dbId |
|
39
|
|
|
* |
|
40
|
|
|
* @return int |
|
41
|
|
|
*/ |
|
42
|
|
|
public function deleteById($cModel, $dbId) { |
|
43
|
|
|
$db = $this->db; |
|
44
|
|
|
|
|
45
|
|
|
$db->doDeleteRow( |
|
46
|
|
|
$cModel->getTableName(), |
|
47
|
|
|
array( |
|
48
|
|
|
$cModel->getIdFieldName() => $dbId, |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
return $db->db_affected_rows(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param \Entity\EntityModel $cModel |
|
57
|
|
|
* @param array $row |
|
58
|
|
|
* |
|
59
|
|
|
* @return int|string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function insert($cModel, $row) { |
|
62
|
|
|
if (empty($row)) { |
|
63
|
|
|
// TODO Exception |
|
64
|
|
|
return 0; |
|
65
|
|
|
} |
|
66
|
|
|
$db = $this->db; |
|
67
|
|
|
$db->doInsertSet($cModel->getTableName(), $row); |
|
68
|
|
|
|
|
69
|
|
|
// TODO Exception if db_insert_id() is empty |
|
70
|
|
|
return $db->db_insert_id(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function doSelectFetchValue($query) { |
|
74
|
|
|
return $this->db->doSelectFetchValue($query); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns iterator to iterate through mysqli_result |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $query |
|
81
|
|
|
* |
|
82
|
|
|
* @return DbEmptyIterator|DbMysqliResultIterator |
|
83
|
|
|
*/ |
|
84
|
|
|
public function doSelectIterator($query) { |
|
85
|
|
|
return $this->db->doSelectIterator($query); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function doUpdateRowSetAffected($table, $fieldsAndValues, $where) { |
|
89
|
|
|
$this->db->doUpdateRowSet($table, $fieldsAndValues, $where); |
|
90
|
|
|
return $this->db->db_affected_rows(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.