parameters = array(); unset($this->filter); $this->filter = new CatalogCacheFilterObject($this); unset($this->sort); $this->sort = new CatalogCacheSortObject($this); } protected function createNewIntervalObject($id, $index = -1) { return new CatalogCacheIntervalObject($this, $id, $index); } public function addInterval($interval, $isNew = false, $index = -1) { $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; } public function addParameter($id, $name, $size, $type) { $this->parameters[] = array( 'id' => $id, 'name' => $name, 'size' => $size, 'type' => $type, ); } public function getParametersInfo() { return $this->parameters; } public function writeAdditionalHeaderBin($handle) { //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]))); } } protected function loadAdditionalHeaderBin($handle) { //Params Number if (!$res = unpack('Lnumber',fread($handle,4))) return false; $nbParams = $res['number']; for ($i = 0; $i < $nbParams; ++$i) { //Param Id length if (!$res = unpack('Lidlength',fread($handle,4))) return false; $idlength = $res['idlength']; //Param Name length if (!$res = unpack('Lnamelength',fread($handle,4))) return false; $namelength = $res['namelength']; //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']); } //Param Name $name = ""; for ($j = 0; $j < $namelength; ++$j) { if (!$res = unpack('Cname',fread($handle,1))) return false; $name .= chr($res['name']); } $this->addParameter($id, $name, $size, $type); } return true; } public function modifyIntervalFromId($cacheId, $data) { $result = parent::modifyIntervalFromId($cacheId, $data); foreach ($this->intervals as $interval) { if ($interval->getId() == $cacheId) { foreach($data as $key => $value) { $interval->setParamValue($key, $value); $interval->setIsModified(true); $this->isModified = true; } return $this->isModified; } } return false; } 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; } } ?>