Blame view

php/classes/CatalogCacheMgr.php 6.19 KB
19eca0a6   Hacene SI HADJ MOHAND   ok
1
<?php
d18b535d   elena   catalog draft + c...
2
3
4
5

/**
 * @class CatalogCacheMgr
 */
5446b8f0   Benjamin Renard   Move CacheTools i...
6

5446b8f0   Benjamin Renard   Move CacheTools i...
7
class CatalogCacheMgr extends TimeTableCacheMgr
d18b535d   elena   catalog draft + c...
8
{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
9
	const DEFAULT_PARAM_ID_PREFIX = 'cat_param_id_';
42c4ccd3   Erdogan Furkan   #9660 - Done
10
	const DEFAULT_NEW_PARAM_ID_PREFIX = 'added_param_id_'; 
1a0151a5   Benjamin Renard   wip
11
	private $isForVisu = FALSE;
d18b535d   elena   catalog draft + c...
12

1a0151a5   Benjamin Renard   wip
13
	function __construct($isForVisu = FALSE) {
0fea5567   Benjamin Renard   First step for re...
14
		$this->objectMgr  = new CatalogMgr();
0b40a169   Erdogan Furkan   #10690 - Fixed
15
		$this->isForVisu = $isForVisu;
d18b535d   elena   catalog draft + c...
16
	}
5446b8f0   Benjamin Renard   Move CacheTools i...
17

0fea5567   Benjamin Renard   First step for re...
18
	protected function getCacheFileName() {
1a0151a5   Benjamin Renard   wip
19
20
21
		if ($this->isForVisu) {
			return "cacheVisuCat";
		}
0fea5567   Benjamin Renard   First step for re...
22
23
24
	  return "cacheCat";
	}

ba9b1b7d   Benjamin Renard   Rework of TT and ...
25
	protected function resetCache($options = array()) {
0fea5567   Benjamin Renard   First step for re...
26
    $this->cache = new CatalogCacheObject();
ba9b1b7d   Benjamin Renard   Rework of TT and ...
27
28
		if (!empty($options['nparams'])) {
			for ($i = 0; $i < (int)$options['nparams']; $i++) {
ce347c54   Erdogan Furkan   Done.
29
				$this->cache->addParameter(CatalogCacheMgr::DEFAULT_PARAM_ID_PREFIX.(string)($i+1), 'column_'.(string)($i+1), 1, 0, "","", FALSE);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
30
			}
342b20ca   Benjamin Renard   Fix inheritence b...
31
		}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
32
33
34
35
36
37
38
39
40
41
42
43
		else if (!empty($options['parameters'])) {
			$index = 0;
			foreach ($options['parameters'] as $parameter) {
				if (array_key_exists('id',$parameter) && !empty($parameter['id'])) {
					$id = $parameter['id'];
				}
				else if (array_key_exists('ID',$parameter) && !empty($parameter['ID'])) {
					$id = $parameter['ID'];
				}
				else {
					$id = 'cat_param_id_'.$index;
				}
af94e42d   Benjamin Renard   Fix catalog upload
44
45
46
47
				$description = "";
				if (isset($parameter['description'])) {
					$description = $parameter['description'];
				}
ce347c54   Erdogan Furkan   Done.
48
49
50
51
52
				$status = "";
				if (isset($parameter['status'])) {
					$status = $parameter['status'];
				}
				$this->cache->addParameter($id, $parameter['name'], intval($parameter['size']), intval($parameter['type']), $description, $status, FALSE);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
53
54
				++$index;
			}
342b20ca   Benjamin Renard   Fix inheritence b...
55
		}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
56
57
		return array('parameters' => $this->cache->getParametersInfo());
  }
342b20ca   Benjamin Renard   Fix inheritence b...
58

42e2e019   Benjamin Renard   Next step for cac...
59
60
	protected function loadAdditionalDescription($options) {
		$params_desc = $this->objectMgr->getCatalogParamDescription($options);
342b20ca   Benjamin Renard   Fix inheritence b...
61
		if (!$params_desc['success']) {
ba9b1b7d   Benjamin Renard   Rework of TT and ...
62
			return array();
901ba3f3   Elena.Budnik   upload catalog
63
		}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
64
		return array('parameters' => $params_desc['parameters']);
d18b535d   elena   catalog draft + c...
65
	}
5446b8f0   Benjamin Renard   Move CacheTools i...
66

e82af71b   elena   catalog draft
67

342b20ca   Benjamin Renard   Fix inheritence b...
68
	public function initFromUploadedFile($name, $format)
5446b8f0   Benjamin Renard   Move CacheTools i...
69
	{
342b20ca   Benjamin Renard   Fix inheritence b...
70
71
72
		$result = parent::initFromUploadedFile($name, $format);
		if (!$result['success']) {
			return $result;
d18b535d   elena   catalog draft + c...
73
		}
5446b8f0   Benjamin Renard   Move CacheTools i...
74

ba9b1b7d   Benjamin Renard   Rework of TT and ...
75
76
		$info = $this->objectMgr->getUploadedObject($name, $format,TRUE);
		foreach ($info['parameters'] as $parameter) {
af94e42d   Benjamin Renard   Fix catalog upload
77
78
79
80
			$description = "";
			if (isset($parameter['description'])) {
				$description = $parameter['description'];
			}
ce347c54   Erdogan Furkan   Done.
81
82
83
84
85
			$status = "";
			if (isset($parameter['status'])) {
				$status = $parameter[''];
			}
			$this->cache->addParameter($parameter['id'], $parameter['name'], intval($parameter['size']), intval($parameter['type']), $parameter['description'],$parameter['status'], FALSE);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
86
87
		}

53048303   Benjamin Renard   Cleanup TimeTable...
88
		return $result+ array('parameters' => $info['parameters']);
f9c8b272   elena   edit catalog
89
	}
19eca0a6   Hacene SI HADJ MOHAND   ok
90

ceac8bd0   Hacene SI HADJ MOHAND   us ok
91
	public function initFromTimeTable($id, $nbParams, $type)
e1fdab74   Hacene SI HADJ MOHAND   starting
92
	{
19eca0a6   Hacene SI HADJ MOHAND   ok
93
94

          $params = $this->resetCache(array('nparams' => $nbParams));
e1fdab74   Hacene SI HADJ MOHAND   starting
95
          $ttMgr= new TimeTableMgr();
ceac8bd0   Hacene SI HADJ MOHAND   us ok
96
          $intervals_res = $ttMgr->loadIntervalsFromObject($id, $type);
19eca0a6   Hacene SI HADJ MOHAND   ok
97

e1fdab74   Hacene SI HADJ MOHAND   starting
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
          if (!$intervals_res['success'])
                        return $intervals_res;

          foreach ($intervals_res['intervals'] as $interval)
          {
                  //Add interval
                  $this->cache->addInterval($interval);
           }

          unset($intervals_res);

          //Update cache
          $this->cache->updateIndexes();

          //Save cache file
19eca0a6   Hacene SI HADJ MOHAND   ok
113
          return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(), 'parameters' => $this->cache->getParametersInfo());
e1fdab74   Hacene SI HADJ MOHAND   starting
114
 	}
342b20ca   Benjamin Renard   Fix inheritence b...
115

1a0151a5   Benjamin Renard   wip
116
	 public function getIntervalsForChart() {
738e0997   Benjamin Renard   Draw histogram
117
		 $result = $this->getIntervals(NULL, NULL, NULL, NULL);
1a0151a5   Benjamin Renard   wip
118
119
120
121
122
123
		 if (!$result['success']) {
			 return FALSE;
		 }

		 $parameters = $this->cache->getParametersInfo();
		 $parameters_to_split = array();
b0720b91   Benjamin Renard   Finalize catalog ...
124
		 $parameters_chart = array();
1a0151a5   Benjamin Renard   wip
125
126
127
		 foreach ($parameters as $parameter) {
			 if ($parameter['size'] > 1) {
				 $parameters_to_split[] = $parameter;
b0720b91   Benjamin Renard   Finalize catalog ...
128
129
130
131
132
133
134
135
136
137
138
139
				 for ($i = 0; $i < $parameter['size']; ++$i) {
					 $comp_param = $parameter;
					 $comp_param['id'] = $parameter['id'].'_COMPONENT_'.$i;
					 $comp_param['name'] = $parameter['name'].'['.$i.']';
					 unset ($comp_param['size']);
				 	$parameters_chart[] = $comp_param;
				}
			 }
			 else {
				 $comp_param = $parameter;
				 unset ($comp_param['size']);
				 $parameters_chart[] = $comp_param;
1a0151a5   Benjamin Renard   wip
140
141
142
143
			 }
		 }

		 if (empty($parameters_to_split)) {
b0720b91   Benjamin Renard   Finalize catalog ...
144
			 return $result + array('parameters' => $parameters_chart);
1a0151a5   Benjamin Renard   wip
145
146
147
148
149
		 }

		 //split parameters
		 foreach ($result[intervals] as &$interval) {
			 foreach ($parameters_to_split as $parameter) {
738e0997   Benjamin Renard   Draw histogram
150
151
				 $values = explode (',',$interval[$parameter['id']]);
				 unset($interval[$parameter['id']]);
1a0151a5   Benjamin Renard   wip
152
153
154
155
156
157
				 foreach ($values as $key => $value) {
					 $interval[$parameter['id'].'_COMPONENT_'.$key] = $value;
				 }
  		 }
		 }

b0720b91   Benjamin Renard   Finalize catalog ...
158
		 return $result + array('parameters' => $parameters_chart);
1a0151a5   Benjamin Renard   wip
159
   }
3d95b0a6   furkan   Adding the Delete...
160
161
162
163
164
165
166
167
168
169
170

   public function deleteColumn($id){
		if (!$this->loadFromFile())
		return array('success' => false, 'message' => 'Cannot load cache file');

		$result = $this->cache->deleteParameter($id);
		if ($result){
			$this->saveToFile();
		}
		return array('success' => $result , 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(),'parameters' => $this->cache->getParametersInfo());
   }
42c4ccd3   Erdogan Furkan   #9660 - Done
171

ce347c54   Erdogan Furkan   Done.
172
   public function addColumn($id,$name, $type,$size, $description, $status){
42c4ccd3   Erdogan Furkan   #9660 - Done
173
174
175
		if (!$this->loadFromFile())
		return array('success' => false, 'message' => 'Cannot load cache file');
		$isNew=true;
ce347c54   Erdogan Furkan   Done.
176
		$this->cache->addParameter($id,$name, $size, $type, $description, $status, $isNew);
42c4ccd3   Erdogan Furkan   #9660 - Done
177
178
179
180
181
182
183
184
185
186
187
		$this->saveToFile();
		return array('success' => true , 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(),'parameters' => $this->cache->getParametersInfo());
   }

   public function getCatColumnInfo($id){
	if (!$this->loadFromFile())
		return array('success' => false, 'message' => 'Cannot load cache file');
	
	return $this->cache->getParameterInfo($id);
   }

ce347c54   Erdogan Furkan   Done.
188
   public function editColumn($id,$name, $type,$size,  $description, $status){
42c4ccd3   Erdogan Furkan   #9660 - Done
189
190
191
		if (!$this->loadFromFile())
			return array('success' => false, 'message' => 'Cannot load cache file');

ce347c54   Erdogan Furkan   Done.
192
		$this->cache->editParameter($id,$name, $type, $size,  $description, $status);
42c4ccd3   Erdogan Furkan   #9660 - Done
193
194
195
196

		$this->saveToFile();
		return array('success' => true , 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(),'parameters' => $this->cache->getParametersInfo());
	}
342b20ca   Benjamin Renard   Fix inheritence b...
197
}
5446b8f0   Benjamin Renard   Move CacheTools i...
198
?>