CatalogCacheObject.php
6.42 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
class CatalogCacheObject extends TimeTableCacheObject
{
private $parameters = array();
public function reset() {
parent::reset();
$this->parameters = array();
unset($this->filter);
$this->filter = new CatalogCacheFilterObject($this);
unset($this->sort);
$this->sort = new CatalogCacheSortObject($this);
}
protected function createNewIntervalObject($id, $index = -1) {
return new CatalogCacheIntervalObject($this, $id, $index);
}
public function addInterval($interval, $isNew = false, $index = -1)
{
$intervalObj = parent::addInterval($interval, $isNew, $index);
for ($i = 0; $i < count($interval['paramTable']); ++$i) {
$intervalObj->setParamValue($this->parameters[$i]['id'], $interval['paramTable'][$i]);
}
return $intervalObj;
}
public function addParameter($id, $name, $size, $type, $description, $status, $isNew = false)
{
$this->parameters[] = array(
'id' => $id,
'name' => $name,
'size' => $size,
'type' => $type,
'description' => $description,
'status' => $status
);
if($isNew){
$this->isModified = $isNew;
}
}
public function deleteParameter($id){
foreach($this->parameters as $index=>$param){
if($id == $param['id']){
unset($this->parameters[$index]);
$this->parameters = array_values($this->parameters);
$this->isModified = TRUE;
return true;
}
}
return false;
}
public function editParameter($id, $name, $type, $size, $description, $status)
{
foreach ($this->parameters as $index=>$param){
if($id == $param['id']){
if(isset($name))
$this->parameters[$index]['name'] = $name;
if(isset($type))
$this->parameters[$index]['type'] = $type;
if(isset($size))
$this->parameters[$index]['size'] = $size;
if(isset($description))
$this->parameters[$index]['description'] = $description;
if(isset($status))
$this->parameters[$index]['status'] = $status;
$this->isModified = TRUE;
return true;
}
}
return false;
}
public function getParametersInfo() {
return $this->parameters;
}
public function getParameterInfo($id){
foreach ($this->parameters as $index=>$param){
if($id == $param['id']){
return $param;
}
}
return false;
}
public function writeAdditionalHeaderBin($handle)
{
//Params Number
fwrite($handle,pack('L',count($this->parameters)));
foreach ($this->parameters as $parameter) {
//Param Id length
fwrite($handle,pack('L',strlen($parameter['id'])));
//Param name length
fwrite($handle,pack('L',strlen($parameter['name'])));
//Param Size
fwrite($handle,pack('L',$parameter['size']));
//Param Type
fwrite($handle,pack('L',$parameter['type']));
//Description Size
fwrite($handle,pack('L',strlen($parameter['description'])));
//Status Size
fwrite($handle,pack('L',strlen($parameter['status'])));
//Param Id
for ($i = 0; $i < strlen($parameter['id']); ++$i)
fwrite($handle,pack('C',ord($parameter['id'][$i])));
//Param name:
for ($i = 0; $i < strlen($parameter['name']); ++$i)
fwrite($handle,pack('C',ord($parameter['name'][$i])));
//Param description
for ($i = 0; $i < strlen($parameter['description']); ++$i)
fwrite($handle,pack('C',ord($parameter['description'][$i])));
//Param status
for ($i = 0; $i < strlen($parameter['status']); ++$i)
fwrite($handle,pack('C',ord($parameter['status'][$i])));
}
}
protected function loadAdditionalHeaderBin($handle) {
//Params Number
if (!$res = unpack('Lnumber',fread($handle,4)))
return false;
$nbParams = $res['number'];
for ($i = 0; $i < $nbParams; ++$i) {
//Param Id length
if (!$res = unpack('Lidlength',fread($handle,4)))
return false;
$idlength = $res['idlength'];
//Param Name length
if (!$res = unpack('Lnamelength',fread($handle,4)))
return false;
$namelength = $res['namelength'];
//Param Size
if (!$res = unpack('Lsize',fread($handle,4)))
return false;
$size = $res['size'];
//Param Type
if (!$res = unpack('Ltype',fread($handle,4)))
return false;
$type = $res['type'];
//Param Description lenfth
if (!$res = unpack('Ldescriptionlength',fread($handle,4)))
return false;
$descriptionlength = $res['descriptionlength'];
//Param status length
if (!$res = unpack('Lstatuslength',fread($handle,4)))
return false;
$statuslength = $res['statuslength'];
//Param Id
$id = "";
for ($j = 0; $j < $idlength; ++$j)
{
if (!$res = unpack('Cid',fread($handle,1)))
return false;
$id .= chr($res['id']);
}
//Param Name
$name = "";
for ($j = 0; $j < $namelength; ++$j)
{
if (!$res = unpack('Cname',fread($handle,1)))
return false;
$name .= chr($res['name']);
}
//Param description
$description = "";
for ($j = 0; $j < $descriptionlength; ++$j)
{
if (!$res = unpack('Cdescription',fread($handle,1)))
return false;
$description .= chr($res['description']);
}
//Param description
$status = "";
for ($j = 0; $j < $statuslength; ++$j)
{
if (!$res = unpack('Cstatus',fread($handle,1)))
return false;
$status .= chr($res['status']);
}
$this->addParameter($id, $name, $size, $type, $description, $status, FALSE);
}
return true;
}
public function modifyIntervalFromId($cacheId, $data) {
$result = parent::modifyIntervalFromId($cacheId, $data);
foreach ($this->intervals as $interval)
{
if ($interval->getId() == $cacheId)
{
foreach($data as $key => $value) {
$interval->setParamValue($key, $value);
$interval->setIsModified(true);
$this->isModified = true;
}
return $this->isModified;
}
}
return false;
}
public function dump() {
echo " => CatalogCacheObject : token = ".$this->token.", nb intervals = ".count($this->intervals).", last id = ".$this->lastId.", nb indexes = ".count($this->indexes).PHP_EOL;
echo PHP_EOL;
echo " => Parameters : ".PHP_EOL;
foreach ($this->parameters as $parameter) {
echo " * id = ".$parameter['id'].", name = ".$parameter['name'].", size = ".$parameter['size'].", type = ".$parameter['type'].", description = ".$parameter['description'].PHP_EOL;
}
echo PHP_EOL;
$this->filter->dump();
echo PHP_EOL;
$this->sort->dump();
echo PHP_EOL;
foreach ($this->intervals as $interval)
$interval->dump();
echo PHP_EOL;
echo " => Indexes list : ";
foreach ($this->indexes as $index)
{
echo $index.", ";
}
echo PHP_EOL;
}
}
?>