Blame view

php/classes/CatalogCacheMgr.php 4.37 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_';
1a0151a5   Benjamin Renard   wip
10
	private $isForVisu = FALSE;
d18b535d   elena   catalog draft + c...
11

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

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

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

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

e82af71b   elena   catalog draft
61

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

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

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

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

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

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

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

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

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

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

b0720b91   Benjamin Renard   Finalize catalog ...
148
		 return $result + array('parameters' => $parameters_chart);
1a0151a5   Benjamin Renard   wip
149
   }
342b20ca   Benjamin Renard   Fix inheritence b...
150
}
5446b8f0   Benjamin Renard   Move CacheTools i...
151
?>