-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
149 lines (136 loc) · 2.94 KB
/
code.power
File metadata and controls
149 lines (136 loc) · 2.94 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
/**
* Updated Values
*
* @var array
* @since 3.2.0
*/
protected array $updated = [];
/**
* Search Config
*
* @var Config
* @since 3.2.0
*/
protected Config $config;
/**
* Update
*
* @var Update
* @since 3.2.0
*/
protected Update $update;
/**
* Constructor
*
* @param Config|null $config The search config object.
* @param Update|null $update The update object.
*
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Update $update = null)
{
$this->config = $config ?: Factory::_('Config');
$this->update = $update ?: Factory::_('Agent.Update');
}
/**
* Get updated values
*
* @param string|null $table The table being searched
*
* @return array|null
* @since 3.2.0
*/
public function get(?string $table = null): ?array
{
// set the table name
if (empty($table))
{
$table = $this->config->table_name;
}
if (isset($this->updated[$table]))
{
return $this->updated[$table];
}
return null;
}
/**
* Search over an item fields
*
* @param object $item The item object of fields to search through
* @param int|null $id The item id
* @param string|null $table The table being searched
*
* @return void
* @since 3.2.0
*/
public function item(object $item, ?int $id =null, ?string $table = null)
{
// set the table name
if (empty($table))
{
$table = $this->config->table_name;
}
// set the item id
if (empty($id))
{
$id = $item->id;
}
if (ObjectHelper::check($item))
{
foreach ($item as $field => $value)
{
if ($field !== 'id' && ($_value = $this->update->value($value)) !== null)
{
if (empty($this->updated[$table][$id]))
{
$this->updated[$table][$id] = new \stdClass();
$this->updated[$table][$id]->id = $id;
}
// add updated value
$this->updated[$table][$id]->{$field} = $_value;
}
}
}
}
/**
* Search over an array of items
*
* @param array|null $items The array of items to search through
* @param string|null $table The table being searched
*
* @return void
* @since 3.2.0
*/
public function items(?array $items = null, ?string $table = null)
{
// set the table name
if (empty($table))
{
$table = $this->config->table_name;
}
if (ArrayHelper::check($items))
{
foreach ($items as $id => $item)
{
$this->item($item, $id, $table);
}
}
}
/**
* Reset all updated values of a table
*
* @param string|null $table The table being searched
*
* @return void
* @since 3.2.0
*/
public function reset(?string $table = null)
{
// set the table name
if (empty($table))
{
$table = $this->config->table_name;
}
// empty or unset the table active values
unset($this->updated[$table]);
}