Blame view

php/classes/CatalogCacheIntervalObject.php 3.72 KB
2a24088c   Benjamin Renard   Split some source...
1
2
<?php

2f1cd444   Benjamin Renard   Apply convention ...
3
class CatalogCacheIntervalObject extends TimeTableCacheIntervalObject
2a24088c   Benjamin Renard   Split some source...
4
5
6
7
8
9
{
	// for catalog
	private $params      = array();

	public function toArray()
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
10
11
12
		$result = parent::toArray();

		foreach ($this->cacheObject->getParametersInfo() as $parameter)
2a24088c   Benjamin Renard   Split some source...
13
		{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
14
			$result[$parameter['id']] = $this->params[$parameter['id']];
2a24088c   Benjamin Renard   Split some source...
15
16
17
18
19
		}
		return $result;
	}

	// for catalog
ba9b1b7d   Benjamin Renard   Rework of TT and ...
20
	public function setParamValue($param_id, $param_value)
2a24088c   Benjamin Renard   Split some source...
21
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
22
		$this->params[$param_id] = $param_value;
2a24088c   Benjamin Renard   Split some source...
23
24
25
26
27
28
29
	}

	public function getParams()
	{
	   return $this->params;
	}

42e2e019   Benjamin Renard   Next step for cac...
30
31
32
33
34
35
36
37
38
39
40
	public function modifyInterval($data) {
		parent::modifyInterval($data);
		foreach ($this->cacheObject->getParametersInfo() as $parameter) {
			if (array_key_exists($parameter['id'], $data)) {
				$this->setParamValue($parameter['id'], $data->{$parameter['id']});
				$this->setIsModified(true);
			}
		}
		return $this->isModified();
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
41
	public function writeBin($handle)
2a24088c   Benjamin Renard   Split some source...
42
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
43
44
45
		parent::writeBin($handle);

		foreach ($this->cacheObject->getParametersInfo() as $parameter)
2a24088c   Benjamin Renard   Split some source...
46
		{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
47
48
49
50
51
52
53
			$size = $parameter['size'];
			$values = $this->params[$parameter['id']];
			if ($size > 1) {
				$values_array = explode(',',$values);
			}
			else {
				$values_array = array($values);
2a24088c   Benjamin Renard   Split some source...
54
			}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
55
56
57
58
			for ($i = 0; $i < $size; ++$i) {
				$value = ($i >= count($values_array)) ? "" : $values_array[$i];
				switch ($parameter['type']) {
					case 0: //double
f6464410   Erdogan Furkan   #10765 - Done.
59
60
61
62
63
						if($value == "nan")
							$floatValue  = NAN;
						else
							$floatValue = floatval($value);
						fwrite($handle,pack('d', $floatValue));
ba9b1b7d   Benjamin Renard   Rework of TT and ...
64
65
					  break;
					case 1: //date (timestamp)
3a8eaaff   Hacene SI HADJ MOHAND   resolue
66
						fwrite($handle,pack('d', TimeUtils::iso2stamp($value)));
ba9b1b7d   Benjamin Renard   Rework of TT and ...
67
68
69
70
71
72
73
74
						break;
					case 2: //string
						fwrite($handle,pack('L', strlen($value)));
						for ($j = 0; $j < strlen($value); ++$j) {
							fwrite($handle,pack('C', ord($value[$j])));
						}
						break;
					case 3: //int
f3004c4a   Benjamin Renard   Fix bug with sign...
75
						fwrite($handle,pack('l', intval($value)));
ba9b1b7d   Benjamin Renard   Rework of TT and ...
76
77
78
79
80
81
82
					  break;
					default: // not defined => string
					fwrite($handle,pack('L', strlen($value)));
					for ($j = 0; $j < strlen($value); ++$j) {
						fwrite($handle,pack('C', ord($value[$j])));
					}
				}
2a24088c   Benjamin Renard   Split some source...
83
84
85
86
			}
		}
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
87
	public function loadBin($handle)
2a24088c   Benjamin Renard   Split some source...
88
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
89
		parent::loadBin($handle);
2a24088c   Benjamin Renard   Split some source...
90

ba9b1b7d   Benjamin Renard   Rework of TT and ...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
		foreach ($this->cacheObject->getParametersInfo() as $parameter) {
		  $size = $parameter['size'];
			$id = $parameter['id'];


			$values = array();
		  for ($i = 0; $i < $size; $i++)
		  {
				$val = "";
				switch ($parameter['type']) {
					case 0: //double
						if (!$res = unpack('dval',fread($handle,8))) {
							break;
						}
f6464410   Erdogan Furkan   #10765 - Done.
105
						$val = is_nan($res['val']) ? "nan" : $res['val'];
ba9b1b7d   Benjamin Renard   Rework of TT and ...
106
107
					  break;
					case 1: //date (timestamp)
3a8eaaff   Hacene SI HADJ MOHAND   resolue
108
						if (!$res = unpack('dval',fread($handle,8))) {
ba9b1b7d   Benjamin Renard   Rework of TT and ...
109
110
							break;
						}
e022e5b5   Benjamin Renard   Filter parameter ...
111
						$val = TimeUtils::stamp2iso($res['val']);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
						break;
					case 2: //string
						if (!$res = unpack('Llength',fread($handle,4))) {
							break;
						}
						$length = $res['length'];
						$val = "";
						for ($j = 0; $j < $length; ++$j) {
							if (!$res = unpack('Cval',fread($handle,1))) {
								break;
							}
							$val .= chr($res['val']);
						}

						break;
					case 3: //int
f3004c4a   Benjamin Renard   Fix bug with sign...
128
						if (!$res = unpack('lval',fread($handle,4))) {
ba9b1b7d   Benjamin Renard   Rework of TT and ...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
							break;
						}
						$val = $res['val'];
					  break;
					default: // not defined => string
						if (!$res = unpack('Llength',fread($handle,4))) {
							break;
						}
						$length = $res['length'];
						$val = "";
						for ($j = 0; $j < $length; ++$j) {
							if (!$res = unpack('Cval',fread($handle,1))) {
								break;
							}
							$val .= chr($res['val']);
						}
2a24088c   Benjamin Renard   Split some source...
145
				}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
146
147

				$values[] = $val;
2a24088c   Benjamin Renard   Split some source...
148
			}
2a24088c   Benjamin Renard   Split some source...
149

ba9b1b7d   Benjamin Renard   Rework of TT and ...
150
151
			$this->params[$id] = implode(',',$values);
		}
2a24088c   Benjamin Renard   Split some source...
152
153
154
155
	}

	public function dump()
	{
342b20ca   Benjamin Renard   Fix inheritence b...
156
157
158
		parent::dump();
		echo "               parameters = ";
		foreach ($this->params as $param) {
ba9b1b7d   Benjamin Renard   Rework of TT and ...
159
			echo $param." - ";
342b20ca   Benjamin Renard   Fix inheritence b...
160
161
		}
		echo PHP_EOL;
2a24088c   Benjamin Renard   Split some source...
162
163
164
165
	}
}

 ?>