Blame view

php/classes/CatalogCacheMgr.php 5.91 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();
d18b535d   elena   catalog draft + c...
15
	}
5446b8f0   Benjamin Renard   Move CacheTools i...
16

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

ba9b1b7d   Benjamin Renard   Rework of TT and ...
24
	protected function resetCache($options = array()) {
0fea5567   Benjamin Renard   First step for re...
25
    $this->cache = new CatalogCacheObject();
ba9b1b7d   Benjamin Renard   Rework of TT and ...
26
27
		if (!empty($options['nparams'])) {
			for ($i = 0; $i < (int)$options['nparams']; $i++) {
21ff9173   Benjamin Renard   Merge FER_9660 in...
28
				$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 ...
29
			}
342b20ca   Benjamin Renard   Fix inheritence b...
30
		}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
31
32
33
34
35
36
37
38
39
40
41
42
		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
43
44
45
46
				$description = "";
				if (isset($parameter['description'])) {
					$description = $parameter['description'];
				}
21ff9173   Benjamin Renard   Merge FER_9660 in...
47
				$this->cache->addParameter($id, $parameter['name'], intval($parameter['size']), intval($parameter['type']), $description, FALSE);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
48
49
				++$index;
			}
342b20ca   Benjamin Renard   Fix inheritence b...
50
		}
ba9b1b7d   Benjamin Renard   Rework of TT and ...
51
52
		return array('parameters' => $this->cache->getParametersInfo());
  }
342b20ca   Benjamin Renard   Fix inheritence b...
53

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

e82af71b   elena   catalog draft
62

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

ba9b1b7d   Benjamin Renard   Rework of TT and ...
70
71
		$info = $this->objectMgr->getUploadedObject($name, $format,TRUE);
		foreach ($info['parameters'] as $parameter) {
af94e42d   Benjamin Renard   Fix catalog upload
72
73
74
75
			$description = "";
			if (isset($parameter['description'])) {
				$description = $parameter['description'];
			}
21ff9173   Benjamin Renard   Merge FER_9660 in...
76
			$this->cache->addParameter($parameter['id'], $parameter['name'], intval($parameter['size']), intval($parameter['type']), $parameter['description'], FALSE);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
77
78
		}

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

ceac8bd0   Hacene SI HADJ MOHAND   us ok
82
	public function initFromTimeTable($id, $nbParams, $type)
e1fdab74   Hacene SI HADJ MOHAND   starting
83
	{
19eca0a6   Hacene SI HADJ MOHAND   ok
84
85

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

e1fdab74   Hacene SI HADJ MOHAND   starting
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
          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
104
          return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(), 'parameters' => $this->cache->getParametersInfo());
e1fdab74   Hacene SI HADJ MOHAND   starting
105
 	}
342b20ca   Benjamin Renard   Fix inheritence b...
106

1a0151a5   Benjamin Renard   wip
107
	 public function getIntervalsForChart() {
738e0997   Benjamin Renard   Draw histogram
108
		 $result = $this->getIntervals(NULL, NULL, NULL, NULL);
1a0151a5   Benjamin Renard   wip
109
110
111
112
113
114
		 if (!$result['success']) {
			 return FALSE;
		 }

		 $parameters = $this->cache->getParametersInfo();
		 $parameters_to_split = array();
b0720b91   Benjamin Renard   Finalize catalog ...
115
		 $parameters_chart = array();
1a0151a5   Benjamin Renard   wip
116
117
118
		 foreach ($parameters as $parameter) {
			 if ($parameter['size'] > 1) {
				 $parameters_to_split[] = $parameter;
b0720b91   Benjamin Renard   Finalize catalog ...
119
120
121
122
123
124
125
126
127
128
129
130
				 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
131
132
133
134
			 }
		 }

		 if (empty($parameters_to_split)) {
b0720b91   Benjamin Renard   Finalize catalog ...
135
			 return $result + array('parameters' => $parameters_chart);
1a0151a5   Benjamin Renard   wip
136
137
138
139
140
		 }

		 //split parameters
		 foreach ($result[intervals] as &$interval) {
			 foreach ($parameters_to_split as $parameter) {
738e0997   Benjamin Renard   Draw histogram
141
142
				 $values = explode (',',$interval[$parameter['id']]);
				 unset($interval[$parameter['id']]);
1a0151a5   Benjamin Renard   wip
143
144
145
146
147
148
				 foreach ($values as $key => $value) {
					 $interval[$parameter['id'].'_COMPONENT_'.$key] = $value;
				 }
  		 }
		 }

b0720b91   Benjamin Renard   Finalize catalog ...
149
		 return $result + array('parameters' => $parameters_chart);
1a0151a5   Benjamin Renard   wip
150
   }
3d95b0a6   furkan   Adding the Delete...
151
152
153
154
155
156
157
158
159
160
161

   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
162

1fc076b5   Erdogan Furkan   #9660 - Adding de...
163
   public function addColumn($id,$name, $type,$size, $description){
42c4ccd3   Erdogan Furkan   #9660 - Done
164
165
166
		if (!$this->loadFromFile())
		return array('success' => false, 'message' => 'Cannot load cache file');
		$isNew=true;
1fc076b5   Erdogan Furkan   #9660 - Adding de...
167
		$this->cache->addParameter($id,$name, $size, $type, $description , $isNew);
42c4ccd3   Erdogan Furkan   #9660 - Done
168
169
170
171
172
173
174
175
176
177
178
		$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);
   }

1fc076b5   Erdogan Furkan   #9660 - Adding de...
179
   public function editColumn($id,$name, $type,$size,  $description){
42c4ccd3   Erdogan Furkan   #9660 - Done
180
181
182
		if (!$this->loadFromFile())
			return array('success' => false, 'message' => 'Cannot load cache file');

1fc076b5   Erdogan Furkan   #9660 - Adding de...
183
		$this->cache->editParameter($id,$name, $type, $size,  $description);
42c4ccd3   Erdogan Furkan   #9660 - Done
184
185
186
187

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