Blame view

php/classes/IntervalCacheObject.php 2.36 KB
d18b535d   elena   catalog draft + c...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
class IntervalCacheObject
{
	protected $id         = -1;
	protected $index      = -1;
	protected $start      = 0;
	protected $stop       = 0;
	protected $isNew      = false;
	protected $isModified = false;

	function __construct($id, $index) {
		$this->id = $id;
		$this->index = $index;
	}

	public function getId() {
		return $this->id;
	}
	
	public function getIndex() {
		return $this->index;
	}
	
	public function setIndex($index) {
		$this->index = $index;
	}

	public function getStartToStamp() {
		return $this->start;
	}
	
	public function getStartToISO() {
		return CacheTools::stamp2iso($this->start);
	}

	public function setStartFromStamp($stamp) {
		$this->start = $stamp;
	}
	
	public function setStartFromISO($iso) {
		$this->start = CacheTools::iso2stamp($iso);
	}

	public function getStopToStamp() {
		return $this->stop;
	}
	
	public function getStopToISO() {
		return CacheTools::stamp2iso($this->stop);
	}

	public function setStopFromStamp($stamp) {
		$this->stop = $stamp;
	}
	
	public function setStopFromISO($iso) {
		$this->stop = CacheTools::iso2stamp($iso);
	}
	
	public function getDuration() {
		return ($this->stop-$this->start);
	}

	public function isModified() {
		return $this->isModified;
	}

	public function setIsModified($isModified) {
		$this->isModified = $isModified;
	}

	public function isNew() {
		return $this->isNew;
	}

	public function setIsNew($isNew) {
		$this->isNew = $isNew;
	}
	
	public function toArray() {
		$result = array(
			"cacheId" => $this->id,
			"start"   => $this->getStartToISO(),
			"stop"    => $this->getStopToISO()
		);
		if ($this->isNew)
			$result["isNew"] = true;
		if ($this->isModified)
			$result["isModified"] = true;
		
		return $result;
	}

	
	
	public function writeBin($handle) {
		fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified));
	}
	
	public function loadBin($handle) {
		$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'];
	}
	
	public function dump() {
		echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL;
	}
}
?>