Blame view

php/classes/CatalogCacheObject.php 6.42 KB
2a24088c   Benjamin Renard   Split some source...
1
2
3
4
<?php

class CatalogCacheObject extends TimeTableCacheObject
{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
5
6
7
8
9
	private $parameters = array();

	public function reset() {
		parent::reset();
		$this->parameters = array();
e022e5b5   Benjamin Renard   Filter parameter ...
10
11
		unset($this->filter);
		$this->filter = new CatalogCacheFilterObject($this);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
12
		unset($this->sort);
ab7c3c63   Benjamin Renard   Sort parameter co...
13
		$this->sort = new CatalogCacheSortObject($this);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
14
	}
2a24088c   Benjamin Renard   Split some source...
15

ba9b1b7d   Benjamin Renard   Rework of TT and ...
16
17
	protected function createNewIntervalObject($id, $index = -1) {
		return new CatalogCacheIntervalObject($this, $id, $index);
2a24088c   Benjamin Renard   Split some source...
18
19
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
20
	public function addInterval($interval, $isNew = false, $index = -1)
2a24088c   Benjamin Renard   Split some source...
21
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
22
23
24
25
26
		$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;
2a24088c   Benjamin Renard   Split some source...
27
28
	}

ce347c54   Erdogan Furkan   Done.
29
	public function addParameter($id, $name, $size, $type, $description, $status, $isNew = false)
2a24088c   Benjamin Renard   Split some source...
30
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
31
32
33
34
35
	    $this->parameters[] = array(
				'id' => $id,
				'name' => $name,
				'size' => $size,
				'type' => $type,
af94e42d   Benjamin Renard   Fix catalog upload
36
				'description' => $description,
ce347c54   Erdogan Furkan   Done.
37
				'status' => $status
ba9b1b7d   Benjamin Renard   Rework of TT and ...
38
			);
42c4ccd3   Erdogan Furkan   #9660 - Done
39
40
41
		if($isNew){
			$this->isModified = $isNew;
		}
2a24088c   Benjamin Renard   Split some source...
42
43
	}

3d95b0a6   furkan   Adding the Delete...
44
45
46
47
48
49
50
51
52
53
54
55
	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;
	}

ce347c54   Erdogan Furkan   Done.
56
	public function editParameter($id, $name, $type, $size, $description, $status)
42c4ccd3   Erdogan Furkan   #9660 - Done
57
58
59
60
61
62
63
64
65
	{
		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;
1fc076b5   Erdogan Furkan   #9660 - Adding de...
66
67
				if(isset($description))
					$this->parameters[$index]['description'] = $description;
ce347c54   Erdogan Furkan   Done.
68
69
				if(isset($status))
					$this->parameters[$index]['status'] = $status;
42c4ccd3   Erdogan Furkan   #9660 - Done
70
71
72
73
74
				$this->isModified = TRUE;
				return true;
			}
		}
		return false;
2a24088c   Benjamin Renard   Split some source...
75
76
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
77
78
	public function getParametersInfo() {
		return $this->parameters;
2a24088c   Benjamin Renard   Split some source...
79
80
	}

42c4ccd3   Erdogan Furkan   #9660 - Done
81
82
83
84
85
86
87
88
89
	public function getParameterInfo($id){
		foreach ($this->parameters as $index=>$param){
			if($id == $param['id']){
				return $param;
			}
		}
		return false;
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
90
	public function writeAdditionalHeaderBin($handle)
2a24088c   Benjamin Renard   Split some source...
91
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
92
93
94
95
96
97
98
			//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'])));
af94e42d   Benjamin Renard   Fix catalog upload
99
			//Param Size
ba9b1b7d   Benjamin Renard   Rework of TT and ...
100
			fwrite($handle,pack('L',$parameter['size']));
af94e42d   Benjamin Renard   Fix catalog upload
101
			//Param Type
ba9b1b7d   Benjamin Renard   Rework of TT and ...
102
			fwrite($handle,pack('L',$parameter['type']));
af94e42d   Benjamin Renard   Fix catalog upload
103
104
			//Description Size
			fwrite($handle,pack('L',strlen($parameter['description'])));
ce347c54   Erdogan Furkan   Done.
105
106
			//Status Size
			fwrite($handle,pack('L',strlen($parameter['status'])));
af94e42d   Benjamin Renard   Fix catalog upload
107
			//Param Id
ba9b1b7d   Benjamin Renard   Rework of TT and ...
108
			for ($i = 0; $i < strlen($parameter['id']); ++$i)
af94e42d   Benjamin Renard   Fix catalog upload
109
110
				fwrite($handle,pack('C',ord($parameter['id'][$i])));
			//Param name:
ba9b1b7d   Benjamin Renard   Rework of TT and ...
111
			for ($i = 0; $i < strlen($parameter['name']); ++$i)
af94e42d   Benjamin Renard   Fix catalog upload
112
113
114
115
				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])));
ce347c54   Erdogan Furkan   Done.
116
117
118
			//Param status
			for ($i = 0; $i < strlen($parameter['status']); ++$i)
				fwrite($handle,pack('C',ord($parameter['status'][$i])));
ba9b1b7d   Benjamin Renard   Rework of TT and ...
119
		}
2a24088c   Benjamin Renard   Split some source...
120
121
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
122
	protected function loadAdditionalHeaderBin($handle) {
af94e42d   Benjamin Renard   Fix catalog upload
123
			//Params Number
ba9b1b7d   Benjamin Renard   Rework of TT and ...
124
			if (!$res = unpack('Lnumber',fread($handle,4)))
2a24088c   Benjamin Renard   Split some source...
125
				return false;
ba9b1b7d   Benjamin Renard   Rework of TT and ...
126
			$nbParams = $res['number'];
2a24088c   Benjamin Renard   Split some source...
127

ba9b1b7d   Benjamin Renard   Rework of TT and ...
128
			for ($i = 0; $i < $nbParams; ++$i) {
af94e42d   Benjamin Renard   Fix catalog upload
129
				//Param Id length
ba9b1b7d   Benjamin Renard   Rework of TT and ...
130
131
132
		 		if (!$res = unpack('Lidlength',fread($handle,4)))
					return false;
				$idlength = $res['idlength'];
2a24088c   Benjamin Renard   Split some source...
133

af94e42d   Benjamin Renard   Fix catalog upload
134
135
				//Param Name length
			  	if (!$res = unpack('Lnamelength',fread($handle,4)))
ba9b1b7d   Benjamin Renard   Rework of TT and ...
136
137
					return false;
				$namelength = $res['namelength'];
2a24088c   Benjamin Renard   Split some source...
138

af94e42d   Benjamin Renard   Fix catalog upload
139
140
141
142
				//Param Size
			 	if (!$res = unpack('Lsize',fread($handle,4)))
					return false;
			 	$size = $res['size'];
ba9b1b7d   Benjamin Renard   Rework of TT and ...
143
144
145
146
147
148

				 //Param Type
				if (!$res = unpack('Ltype',fread($handle,4)))
					return false;
				$type = $res['type'];

af94e42d   Benjamin Renard   Fix catalog upload
149
150
151
152
153
				//Param Description lenfth
				if (!$res = unpack('Ldescriptionlength',fread($handle,4)))
					return false;
				$descriptionlength = $res['descriptionlength'];

ce347c54   Erdogan Furkan   Done.
154
155
156
157
158
				//Param status length
				if (!$res = unpack('Lstatuslength',fread($handle,4)))
					return false;
				$statuslength = $res['statuslength'];

ba9b1b7d   Benjamin Renard   Rework of TT and ...
159
160
161
162
163
164
165
166
				//Param Id
				$id = "";
				for ($j = 0; $j < $idlength; ++$j)
				{
						if (!$res = unpack('Cid',fread($handle,1)))
							return false;
						$id .= chr($res['id']);
					}
2a24088c   Benjamin Renard   Split some source...
167

af94e42d   Benjamin Renard   Fix catalog upload
168
				//Param Name
ba9b1b7d   Benjamin Renard   Rework of TT and ...
169
170
171
172
173
174
175
				$name = "";
				for ($j = 0; $j < $namelength; ++$j)
				{
					if (!$res = unpack('Cname',fread($handle,1)))
						return false;
					$name .= chr($res['name']);
				}
2a24088c   Benjamin Renard   Split some source...
176

af94e42d   Benjamin Renard   Fix catalog upload
177
178
179
180
181
182
183
184
185
				//Param description
				$description = "";
				for ($j = 0; $j < $descriptionlength; ++$j)
				{
					if (!$res = unpack('Cdescription',fread($handle,1)))
						return false;
					$description .= chr($res['description']);
				}

ce347c54   Erdogan Furkan   Done.
186
187
188
189
190
191
192
193
194
195
				//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);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
196
197
			}
			return true;
2a24088c   Benjamin Renard   Split some source...
198
199
	}

342b20ca   Benjamin Renard   Fix inheritence b...
200
201
	public function modifyIntervalFromId($cacheId, $data) {
		$result = parent::modifyIntervalFromId($cacheId, $data);
2a24088c   Benjamin Renard   Split some source...
202
203
204

		foreach ($this->intervals as $interval)
		{
342b20ca   Benjamin Renard   Fix inheritence b...
205
			if ($interval->getId() == $cacheId)
2a24088c   Benjamin Renard   Split some source...
206
			{
342b20ca   Benjamin Renard   Fix inheritence b...
207
				foreach($data as $key => $value) {
42e2e019   Benjamin Renard   Next step for cac...
208
209
210
					$interval->setParamValue($key, $value);
					$interval->setIsModified(true);
					$this->isModified = true;
2a24088c   Benjamin Renard   Split some source...
211
				}
42e2e019   Benjamin Renard   Next step for cac...
212
				return $this->isModified;
2a24088c   Benjamin Renard   Split some source...
213
214
215
216
217
			}
		}

		return false;
	}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
218
219
220
221
222
223
224

	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) {
af94e42d   Benjamin Renard   Fix catalog upload
225
			echo "    * id = ".$parameter['id'].", name = ".$parameter['name'].", size = ".$parameter['size'].", type = ".$parameter['type'].", description = ".$parameter['description'].PHP_EOL;
ba9b1b7d   Benjamin Renard   Rework of TT and ...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
		}
		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;
	}
2a24088c   Benjamin Renard   Split some source...
246
247
248
}

 ?>