Blame view

php/classes/CatalogCacheObject.php 5.75 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
	}

21ff9173   Benjamin Renard   Merge FER_9660 in...
29
	public function addParameter($id, $name, $size, $type, $description, $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,
ba9b1b7d   Benjamin Renard   Rework of TT and ...
37
			);
42c4ccd3   Erdogan Furkan   #9660 - Done
38
39
40
		if($isNew){
			$this->isModified = $isNew;
		}
2a24088c   Benjamin Renard   Split some source...
41
42
	}

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

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

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

42c4ccd3   Erdogan Furkan   #9660 - Done
78
79
80
81
82
83
84
85
86
	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 ...
87
	public function writeAdditionalHeaderBin($handle)
2a24088c   Benjamin Renard   Split some source...
88
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
89
90
91
92
93
94
95
			//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
96
			//Param Size
ba9b1b7d   Benjamin Renard   Rework of TT and ...
97
			fwrite($handle,pack('L',$parameter['size']));
af94e42d   Benjamin Renard   Fix catalog upload
98
			//Param Type
ba9b1b7d   Benjamin Renard   Rework of TT and ...
99
			fwrite($handle,pack('L',$parameter['type']));
af94e42d   Benjamin Renard   Fix catalog upload
100
101
102
			//Description Size
			fwrite($handle,pack('L',strlen($parameter['description'])));
			//Param Id
ba9b1b7d   Benjamin Renard   Rework of TT and ...
103
			for ($i = 0; $i < strlen($parameter['id']); ++$i)
af94e42d   Benjamin Renard   Fix catalog upload
104
105
				fwrite($handle,pack('C',ord($parameter['id'][$i])));
			//Param name:
ba9b1b7d   Benjamin Renard   Rework of TT and ...
106
			for ($i = 0; $i < strlen($parameter['name']); ++$i)
af94e42d   Benjamin Renard   Fix catalog upload
107
108
109
110
				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])));
ba9b1b7d   Benjamin Renard   Rework of TT and ...
111
		}
2a24088c   Benjamin Renard   Split some source...
112
113
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
114
	protected function loadAdditionalHeaderBin($handle) {
af94e42d   Benjamin Renard   Fix catalog upload
115
			//Params Number
ba9b1b7d   Benjamin Renard   Rework of TT and ...
116
			if (!$res = unpack('Lnumber',fread($handle,4)))
2a24088c   Benjamin Renard   Split some source...
117
				return false;
ba9b1b7d   Benjamin Renard   Rework of TT and ...
118
			$nbParams = $res['number'];
2a24088c   Benjamin Renard   Split some source...
119

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

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

af94e42d   Benjamin Renard   Fix catalog upload
131
132
133
134
				//Param Size
			 	if (!$res = unpack('Lsize',fread($handle,4)))
					return false;
			 	$size = $res['size'];
ba9b1b7d   Benjamin Renard   Rework of TT and ...
135
136
137
138
139
140

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

af94e42d   Benjamin Renard   Fix catalog upload
141
142
143
144
145
				//Param Description lenfth
				if (!$res = unpack('Ldescriptionlength',fread($handle,4)))
					return false;
				$descriptionlength = $res['descriptionlength'];

ba9b1b7d   Benjamin Renard   Rework of TT and ...
146
147
148
149
150
151
152
153
				//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...
154

af94e42d   Benjamin Renard   Fix catalog upload
155
				//Param Name
ba9b1b7d   Benjamin Renard   Rework of TT and ...
156
157
158
159
160
161
162
				$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...
163

af94e42d   Benjamin Renard   Fix catalog upload
164
165
166
167
168
169
170
171
172
				//Param description
				$description = "";
				for ($j = 0; $j < $descriptionlength; ++$j)
				{
					if (!$res = unpack('Cdescription',fread($handle,1)))
						return false;
					$description .= chr($res['description']);
				}

21ff9173   Benjamin Renard   Merge FER_9660 in...
173
				$this->addParameter($id, $name, $size, $type, $description, FALSE);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
174
175
			}
			return true;
2a24088c   Benjamin Renard   Split some source...
176
177
	}

342b20ca   Benjamin Renard   Fix inheritence b...
178
179
	public function modifyIntervalFromId($cacheId, $data) {
		$result = parent::modifyIntervalFromId($cacheId, $data);
2a24088c   Benjamin Renard   Split some source...
180
181
182

		foreach ($this->intervals as $interval)
		{
342b20ca   Benjamin Renard   Fix inheritence b...
183
			if ($interval->getId() == $cacheId)
2a24088c   Benjamin Renard   Split some source...
184
			{
342b20ca   Benjamin Renard   Fix inheritence b...
185
				foreach($data as $key => $value) {
42e2e019   Benjamin Renard   Next step for cac...
186
187
188
					$interval->setParamValue($key, $value);
					$interval->setIsModified(true);
					$this->isModified = true;
2a24088c   Benjamin Renard   Split some source...
189
				}
42e2e019   Benjamin Renard   Next step for cac...
190
				return $this->isModified;
2a24088c   Benjamin Renard   Split some source...
191
192
193
194
195
			}
		}

		return false;
	}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
196
197
198
199
200
201
202

	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
203
			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 ...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
		}
		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...
224
225
226
}

 ?>