Blame view

php/classes/CatalogCacheMgr.php 13.4 KB
d18b535d   elena   catalog draft + c...
1
2
3
4
5
6
7
8
9
<?php

/**
 * @class CatalogCacheMgr
 */
 
 
class CatIntervalCacheObject extends IntervalCacheObject
{
c865df36   Elena.Budnik   dateTime datatype...
10
	// for catalog   
d18b535d   elena   catalog draft + c...
11
12
	private $params      = array();
	
4a438b99   elena   catalog draft
13
14
	public function toArray() 
	{
d18b535d   elena   catalog draft + c...
15
16
17
18
19
20
21
		$result = array(
			"cacheId" => $this->id,
			"start"   => $this->getStartToISO(),
			"stop"    => $this->getStopToISO()
		);
		if ($this->isNew)
			$result["isNew"] = true;
c865df36   Elena.Budnik   dateTime datatype...
22
			
d18b535d   elena   catalog draft + c...
23
24
25
		if ($this->isModified)
			$result["isModified"] = true;
			
c865df36   Elena.Budnik   dateTime datatype...
26
27
28
29
30
		for ($i = 0; $i < count($this->params); $i++) 
		{
			$paramObject = array();
			$index = 'param'.sprintf("%d",$i+2);
			$result[$index] = $this->params[$i];		    
d18b535d   elena   catalog draft + c...
31
32
33
34
35
		}		 
		return $result; 
	}

	// for catalog 
4a438b99   elena   catalog draft
36
37
	public function setParams($params) 
	{
c865df36   Elena.Budnik   dateTime datatype...
38
		$this->params = $params;		
d18b535d   elena   catalog draft + c...
39
40
	}
	
4a438b99   elena   catalog draft
41
42
	public function getParams() 
	{		  	   
d18b535d   elena   catalog draft + c...
43
44
45
	   return $this->params;		
	}
			
c865df36   Elena.Budnik   dateTime datatype...
46
	public function writeBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) 
4a438b99   elena   catalog draft
47
	{
c865df36   Elena.Budnik   dateTime datatype...
48
49
		fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified));
		for ($i = 0; $i < $paramsNumber; $i++) 
7def71a5   Elena.Budnik   redmine #5380
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
		{
			if ($paramsTypes[$i] == '2') // string
			{
				fwrite($handle,pack('d', strlen($this->params[$i])));
				fwrite($handle, $this->params[$i],strlen($this->params[$i]));
			}
			else 
			{
				if ($paramsTypes[$i] == '1') 
						$paramString = CacheTools::iso2stamp($this->params[$i]);
				else
						$paramString = $this->params[$i];
		
				$paramArray =  explode(',',$paramString);
				for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j]));
			}
c865df36   Elena.Budnik   dateTime datatype...
66
		}	        
d18b535d   elena   catalog draft + c...
67
68
	}
	
c865df36   Elena.Budnik   dateTime datatype...
69
	public function loadBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) 
4a438b99   elena   catalog draft
70
	{
d18b535d   elena   catalog draft + c...
71
72
73
74
75
76
77
78
79
80
		$array = unpack('L6int',fread($handle,6*4));
		$this->id         = $array['int1'];
		$this->index      = $array['int2'];
		$this->start      = $array['int3'];
		$this->stop       = $array['int4'];
		$this->isNew      = $array['int5'];
		$this->isModified = $array['int6'];
		
		for ($i = 0; $i < $paramsNumber; $i++) {
		  $this->params[$i] = null;
7def71a5   Elena.Budnik   redmine #5380
81
		  
901ba3f3   Elena.Budnik   upload catalog
82
83
84
		  for ($j = 0; $j < $paramsSizes[$i]; $j++) 
		  {
				$val = unpack('dval',fread($handle,8));
c865df36   Elena.Budnik   dateTime datatype...
85
				
7def71a5   Elena.Budnik   redmine #5380
86
87
88
89
90
91
92
93
94
95
96
97
98
				if ($paramsTypes[$i] == '2') // string
				{
					$this->params[$i] = fread($handle,$val['val']);
				}
				else 
				{
					if ($paramsTypes[$i] == '1')
						$this->params[$i] .= CacheTools::stamp2iso($val['val']);
					else 
						$this->params[$i] .= $val['val'];
						
					if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ',';
				}
901ba3f3   Elena.Budnik   upload catalog
99
			}		       
d18b535d   elena   catalog draft + c...
100
101
102
103
		}
		 
	}
	
4a438b99   elena   catalog draft
104
105
	public function dump() 
	{
d18b535d   elena   catalog draft + c...
106
107
108
109
110
111
		echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL;
	}
} 
 
class CatalogCacheObject extends TimeTableCacheObject
{
c865df36   Elena.Budnik   dateTime datatype...
112
113
114
	private $paramsNumber;
	private $paramsSizes = array();
	private $paramsTypes = array();
d18b535d   elena   catalog draft + c...
115
        
4a438b99   elena   catalog draft
116
117
118
119
120
121
122
123
	public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) 
	{
		$interval = new CatIntervalCacheObject($this->lastId, count($this->intervals));
		++$this->lastId;
		$interval->setStartFromISO($startIso);
		$interval->setStopFromISO($stopIso);
		// for catalog
		$interval->setParams($params);
d18b535d   elena   catalog draft + c...
124

4a438b99   elena   catalog draft
125
126
		$interval->setIsNew($isNew);
		array_push($this->intervals, $interval);
c865df36   Elena.Budnik   dateTime datatype...
127