-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
200 lines (187 loc) · 4.75 KB
/
code.power
File metadata and controls
200 lines (187 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* Model
*
* @var Model
* @since 3.2.0
*/
protected Model $model;
/**
* Database
*
* @var Database
* @since 3.2.0
*/
protected Database $database;
/**
* Table Name
*
* @var string
* @since 3.2.1
*/
protected string $table;
/**
* Constructor
*
* @param Model $model The set model object.
* @param Database $database The insert database object.
* @param string|null $table The table name.
*
* @since 3.2.2
*/
public function __construct(Model $model, Database $database, ?string $table = null)
{
$this->model = $model;
$this->database = $database;
if ($table !== null)
{
$this->table = $table;
}
}
/**
* Get the auto-increment IDs generated by the most recent INSERT batch.
*
* This method returns the ordered list of auto-increment IDs calculated
* from the last executed multi-row INSERT operation.
*
* Behavioral notes:
* - IDs are only valid immediately after an INSERT operation.
* - The order of IDs matches the insertion order.
* - AUTO_INCREMENT values are assumed to be sequential within a single
* INSERT statement (as guaranteed by Joomla-supported databases).
* - When `$reset` is enabled, the internal ID bucket is cleared after
* the values are retrieved.
*
* @param bool $reset Whether to reset the internal insert ID bucket
* after retrieval.
*
* @return array<int|string> The generated auto-increment IDs.
*
* @since 5.1.4
*/
public function insertids(bool $reset = true): array
{
return $this->database->insertids($reset);
}
/**
* Set the current active table
*
* @param string|null $table The table that should be active
*
* @return self
* @since 3.2.2
*/
public function table(?string $table): self
{
if ($table !== null)
{
$this->table = $table;
}
return $this;
}
/**
* Insert a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
*
* @return bool
* @since 3.2.0
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
{
// build the array
$item = [];
$item[$key] = $keyValue;
$item[$field] = $value;
// Insert the column of this table
return $this->row($item);
}
/**
* Insert single row with multiple values to a given table
* Example: $this->item(Array);
*
* @param array $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function row(array $item): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, $this->getTable())) !== null)
{
// Insert the column of this table
return $this->database->row($item, $this->getTable());
}
return false;
}
/**
* Insert multiple rows to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of arrays)
*
* @return bool
* @since 3.2.0
*/
public function rows(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, $this->getTable())) !== null)
{
// Insert the column of this table
return $this->database->rows($items, $this->getTable());
}
return false;
}
/**
* Insert single item with multiple values to a given table
* Example: $this->item(Object);
*
* @param object $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function item(object $item): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, $this->getTable())) !== null)
{
// Insert the column of this table
return $this->database->item($item, $this->getTable());
}
return false;
}
/**
* Insert multiple items to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of objects)
*
* @return bool
* @since 3.2.0
*/
public function items(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, $this->getTable())) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, $this->getTable());
}
return false;
}
/**
* Get the current active table
*
* @return string
* @since 3.2.2
*/
public function getTable(): string
{
return $this->table;
}