CatalogCacheObject.php
4.01 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
<?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)
{
$this->parameters[] = array(
'id' => $id,
'name' => $name,
'size' => $size,
'type' => $type,
);
}
public function getParametersInfo() {
return $this->parameters;
}
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']));
//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])));
}
}
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 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']);
}
$this->addParameter($id, $name, $size, $type);
}
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'].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;
}
}
?>