CatalogCacheIntervalObject.php
2.44 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
<?php
class CatalogCacheIntervalObject extends TimeTableCacheIntervalObject
{
// for catalog
private $params = array();
public function toArray()
{
$result = array(
"cacheId" => $this->id,
"start" => $this->getStartToISO(),
"stop" => $this->getStopToISO()
);
if ($this->isNew)
$result["isNew"] = true;
if ($this->isModified)
$result["isModified"] = true;
for ($i = 0; $i < count($this->params); $i++)
{
$paramObject = array();
$index = 'param'.sprintf("%d",$i+2);
$result[$index] = $this->params[$i];
}
return $result;
}
// for catalog
public function setParams($params)
{
$this->params = $params;
}
public function getParams()
{
return $this->params;
}
public function writeBin($handle, $paramsNumber, $paramsSizes, $paramsTypes)
{
fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified));
for ($i = 0; $i < $paramsNumber; $i++)
{
if ($paramsTypes[$i] == '2') // string
{
fwrite($handle,pack('d', strlen($this->params[$i])));
fwrite($handle, $this->params[$i],strlen($this->params[$i]));
}
else
{
if ($paramsTypes[$i] == '1')
$paramString = TimeUtils::iso2stamp($this->params[$i]);
else
$paramString = $this->params[$i];
$paramArray = explode(',',$paramString);
for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j]));
}
}
}
public function loadBin($handle, $paramsNumber, $paramsSizes, $paramsTypes)
{
$array = unpack('L6int',fread($handle,6*4));
$this->id = $array['int1'];
$this->index = $array['int2'];
$this->start = $array['int3'];
$this->stop = $array['int4'];
$this->isNew = $array['int5'];
$this->isModified = $array['int6'];
for ($i = 0; $i < $paramsNumber; $i++) {
$this->params[$i] = null;
for ($j = 0; $j < $paramsSizes[$i]; $j++)
{
$val = unpack('dval',fread($handle,8));
if ($paramsTypes[$i] == '2') // string
{
$this->params[$i] = fread($handle,$val['val']);
}
else
{
if ($paramsTypes[$i] == '1')
$this->params[$i] .= TimeUtils::stamp2iso($val['val']);
else
$this->params[$i] .= $val['val'];
if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ',';
}
}
}
}
public function dump()
{
parent::dump();
echo " parameters = ";
foreach ($this->params as $param) {
echo $param.", ";
}
echo PHP_EOL;
}
}
?>