Commit a4da6a12b53b67d0d1ca1f06faa08e359ed66c63
1 parent
ab5aab56
Exists in
master
and in
109 other branches
temporary commit
Showing
1 changed file
with
31 additions
and
40 deletions
Show diff stats
php/classes/AmdaStats.php
... | ... | @@ -7,12 +7,13 @@ |
7 | 7 | class AmdaStats { |
8 | 8 | |
9 | 9 | public $statXml; |
10 | - public $tasks = array('mining', 'print', 'plot'); | |
10 | + public $tasks = array('plot', 'mining', 'print', 'statistics'); | |
11 | 11 | public $tasksAdd = array('ttoper', 'samp', 'upload', 'create', 'images'); |
12 | - public $usersToExclude = array( 'bouchemit', 'impex'); | |
12 | + public $usersToExclude = array('bouchemit', 'impex'); | |
13 | 13 | public $success = true; |
14 | 14 | private $user = null; |
15 | - | |
15 | + private $task = array('request'=>'plot','mining'=>'condition', 'print'=>'download','statistics'=>'statistics'); | |
16 | + | |
16 | 17 | public function __construct($user) { |
17 | 18 | |
18 | 19 | $this->statXml = new DomDocument('1.0','UTF-8'); |
... | ... | @@ -113,32 +114,44 @@ class AmdaStats { |
113 | 114 | return $this->statXml->save(StatsXml); |
114 | 115 | } |
115 | 116 | |
116 | - public function addTaskWithParams($user, $task, $vars) { | |
117 | + public function addTask($user, $task, $vars) { | |
117 | 118 | |
118 | 119 | // if (!$this->user) { |
119 | 120 | // error_log('User is null', 1, email); |
120 | 121 | // return; |
121 | 122 | // } |
123 | + if ($task == 'killplot') | |
124 | + return; | |
125 | + | |
126 | + if ($vars) | |
127 | + $realTask = $this->task[$task]; | |
128 | + else | |
129 | + $realTask = $task; | |
122 | 130 | |
123 | 131 | if (!in_array($user, $this->usersToExclude)) { |
124 | - $taskElement = $this->statXml->getElementsByTagName("$task")->item(0); | |
132 | + $taskElementNode = $this->statXml->getElementsByTagName("$realTask"); | |
133 | + if ($taskElementNode->length == 0) { | |
134 | + $taskElementNode = $this->statXml->createElement("$realTask"); | |
135 | + $this->statXml->documentElement->appendChild($taskElementNode); | |
136 | + } | |
137 | + $taskElement = $taskElementNode->item(0); | |
125 | 138 | if (is_object($taskElement)) { |
126 | 139 | $newTask = $this->statXml->createElement('item'); |
127 | 140 | $newTask->setAttribute('date', date('Y-m-d')); |
128 | 141 | $newTask->setAttribute('user', $user); |
129 | - | |
142 | + | |
130 | 143 | if ($vars) { |
131 | - $ID = array(); | |
132 | - | |
133 | - foreach ($vars as $var) { | |
134 | - if ((substr($var, 0, 7) == 'impex__') || (substr($var, 0, 13) == 'spase___IMPEX')){ | |
135 | - $ID[] = 'impex'; | |
136 | - } | |
137 | - elseif (substr($var, 0, 4) == 'wsd_') { | |
138 | - $ID[] = 'uploadedData'; | |
139 | - } | |
140 | - else | |
141 | - $ID[] = $var; | |
144 | + $ID = array(); | |
145 | + | |
146 | + foreach ($vars as $var) { | |
147 | + if (substr($var, 0, 13) == 'spase___IMPEX') { | |
148 | + $ID[] = 'impex'; | |
149 | + } | |
150 | + elseif (substr($var, 0, 4) == 'wsd_') { | |
151 | + $ID[] = 'uploadedData'; | |
152 | + } | |
153 | + else | |
154 | + $ID[] = $var; | |
142 | 155 | } |
143 | 156 | |
144 | 157 | $ID = array_unique($ID); |
... | ... | @@ -148,34 +161,13 @@ class AmdaStats { |
148 | 161 | $newTask->appendChild($datasetElement); |
149 | 162 | } |
150 | 163 | } |
151 | - } | |
164 | + | |
152 | 165 | $taskElement->appendChild($newTask); |
153 | 166 | $this->statXml->save(StatsXml); |
154 | 167 | } |
155 | 168 | else |
156 | 169 | error_log('Check Stats.xml - no task element '.$task, 1, email); |
157 | - } | |
158 | - | |
159 | - public function addTask($task){ | |
160 | - | |
161 | - if (!$this->user) { | |
162 | - error_log('User is null', 1, email); | |
163 | - return; | |
164 | 170 | } |
165 | - | |
166 | - if (!in_array($this->user, $this->usersToExclude)) { | |
167 | - $taskElement = $this->statXml->getElementsByTagName("$task")->item(0); | |
168 | - if (is_object($taskElement)) { | |
169 | - $newTask = $this->statXml->createElement('item'); | |
170 | - $newTask->setAttribute('date', date('Y-m-d')); | |
171 | - $newTask->setAttribute('user', $this->user); | |
172 | - | |
173 | - $taskElement->appendChild($newTask); | |
174 | - $this->statXml->save(StatsXml); | |
175 | - } | |
176 | - else | |
177 | - error_log('Check Stats.xml - no task element '.$task, 1, email); | |
178 | - } | |
179 | 171 | } |
180 | 172 | |
181 | 173 | /* |
... | ... | @@ -211,7 +203,6 @@ class AmdaStats { |
211 | 203 | */ |
212 | 204 | public function getDataStat($index, $start, $stop, $update){ |
213 | 205 | |
214 | - | |
215 | 206 | if (!$update && file_exists(DATAPATH.'Statistics/data.json')) { |
216 | 207 | $GENERALarray = json_decode(file_get_contents(DATAPATH.'Statistics/data.json')); |
217 | 208 | } |
... | ... |