Blame view

php/classes/CatalogCacheIntervalObject.php 3.6 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
59
60
61
62
63
64
65
66
67
68
69
70
			for ($i = 0; $i < $size; ++$i) {
				$value = ($i >= count($values_array)) ? "" : $values_array[$i];
				switch ($parameter['type']) {
					case 0: //double
						fwrite($handle,pack('d', floatval($value)));
					  break;
					case 1: //date (timestamp)
						fwrite($handle,pack('L', TimeUtils::iso2stamp($value)));
						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...
71
						fwrite($handle,pack('l', intval($value)));
ba9b1b7d   Benjamin Renard   Rework of TT and ...
72
73
74
75
76
77
78
					  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...
79
80
81
82
			}
		}
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
83
	public function loadBin($handle)
2a24088c   Benjamin Renard   Split some source...
84
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
85
		parent::loadBin($handle);
2a24088c   Benjamin Renard   Split some source...
86

ba9b1b7d   Benjamin Renard   Rework of TT and ...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
		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;
						}
						$val = $res['val'];
					  break;
					case 1: //date (timestamp)
						if (!$res = unpack('Lval',fread($handle,4))) {
							break;
						}
e022e5b5   Benjamin Renard   Filter parameter ...
107
						$val = TimeUtils::stamp2iso($res['val']);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
						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...
124
						if (!$res = unpack('lval',fread($handle,4))) {
ba9b1b7d   Benjamin Renard   Rework of TT and ...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
							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...
141
				}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
142
143

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

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

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

 ?>