Blame view

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

ba9b1b7d   Benjamin Renard   Rework of TT and ...
29
	public function addParameter($id, $name, $size, $type)
2a24088c   Benjamin Renard   Split some source...
30
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
31
32
33
34
35
36
	    $this->parameters[] = array(
				'id' => $id,
				'name' => $name,
				'size' => $size,
				'type' => $type,
			);
2a24088c   Benjamin Renard   Split some source...
37
38
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
39
40
	public function getParametersInfo() {
		return $this->parameters;
2a24088c   Benjamin Renard   Split some source...
41
42
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
43
	public function writeAdditionalHeaderBin($handle)
2a24088c   Benjamin Renard   Split some source...
44
	{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
			//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'])));
			  //Param Size
			fwrite($handle,pack('L',$parameter['size']));
				//Param Type
			fwrite($handle,pack('L',$parameter['type']));
				//Param Id
			for ($i = 0; $i < strlen($parameter['id']); ++$i)
					fwrite($handle,pack('C',ord($parameter['id'][$i])));
				//Param name:
			for ($i = 0; $i < strlen($parameter['name']); ++$i)
					fwrite($handle,pack('C',ord($parameter['name'][$i])));
		}
2a24088c   Benjamin Renard   Split some source...
63
64
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
65
66
67
	protected function loadAdditionalHeaderBin($handle) {
				//Params Number
			if (!$res = unpack('Lnumber',fread($handle,4)))
2a24088c   Benjamin Renard   Split some source...
68
				return false;
ba9b1b7d   Benjamin Renard   Rework of TT and ...
69
			$nbParams = $res['number'];
2a24088c   Benjamin Renard   Split some source...
70

ba9b1b7d   Benjamin Renard   Rework of TT and ...
71
72
73
74
75
			for ($i = 0; $i < $nbParams; ++$i) {
					//Param Id length
		 		if (!$res = unpack('Lidlength',fread($handle,4)))
					return false;
				$idlength = $res['idlength'];
2a24088c   Benjamin Renard   Split some source...
76

ba9b1b7d   Benjamin Renard   Rework of TT and ...
77
78
79
80
					//Param Name length
			  if (!$res = unpack('Lnamelength',fread($handle,4)))
					return false;
				$namelength = $res['namelength'];
2a24088c   Benjamin Renard   Split some source...
81

ba9b1b7d   Benjamin Renard   Rework of TT and ...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
					//Param Size
			 if (!$res = unpack('Lsize',fread($handle,4)))
				return false;
			 $size = $res['size'];

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

				//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...
100

ba9b1b7d   Benjamin Renard   Rework of TT and ...
101
102
103
104
105
106
107
108
					//Param Name
				$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...
109

ba9b1b7d   Benjamin Renard   Rework of TT and ...
110
111
112
				$this->addParameter($id, $name, $size, $type);
			}
			return true;
2a24088c   Benjamin Renard   Split some source...
113
114
	}

342b20ca   Benjamin Renard   Fix inheritence b...
115
116
	public function modifyIntervalFromId($cacheId, $data) {
		$result = parent::modifyIntervalFromId($cacheId, $data);
2a24088c   Benjamin Renard   Split some source...
117
118
119

		foreach ($this->intervals as $interval)
		{
342b20ca   Benjamin Renard   Fix inheritence b...
120
			if ($interval->getId() == $cacheId)
2a24088c   Benjamin Renard   Split some source...
121
			{
342b20ca   Benjamin Renard   Fix inheritence b...
122
				foreach($data as $key => $value) {
42e2e019   Benjamin Renard   Next step for cac...
123
124
125
					$interval->setParamValue($key, $value);
					$interval->setIsModified(true);
					$this->isModified = true;
2a24088c   Benjamin Renard   Split some source...
126
				}
42e2e019   Benjamin Renard   Next step for cac...
127
				return $this->isModified;
2a24088c   Benjamin Renard   Split some source...
128
129
130
131
132
			}
		}

		return false;
	}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

	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) {
			echo "    * id = ".$parameter['id'].", name = ".$parameter['name'].", size = ".$parameter['size'].", type = ".$parameter['type'].PHP_EOL;
		}
		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...
161
162
163
}

 ?>