Blame view

php/classes/FilterResParam.php 14.2 KB
16035364   Benjamin Renard   First commit
1
2
3
<?php
/**
 * @class FilterResParam
722af6d4   Elena.Budnik   observatory level...
4
 * @version $Id: FilterResParam.php 3222 2016-04-27 14:44:55Z elena $
16035364   Benjamin Renard   First commit
5
6
7
8
9
10
11
12
13
14
15
 * @author benjamin
 */
  class FilterResParam extends FilterRes
    {
        protected $localXmlName, $localXml;
        protected $rootElement, $xp;
        
        function __construct() 
        {
                $this->localXmlName = USERWSDIR."LocalParams.xml";
                $this->localXml = new DomDocument("1.0");
e57cb025   Benjamin Renard   Fix most of error...
16
                @$this->localXml->load($this->localXmlName); 
16035364   Benjamin Renard   First commit
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
                $this->rootElement = $this->localXml->documentElement;
                
                $this->xp = new domxpath($this->localXml);
        }
  	
        function getTarget($value,$opId)
        {
                $result = array();	

                $missions = $this->xp->query("//mission[@xml:id]"); 	
                for ($i = 0; $i < $missions->length; $i++)
                {
                    $missionId  = $missions->item($i)->getAttribute('xml:id');

                    $missionTarget = ($missions->item($i)->hasAttribute('target') &&
                                        ($missions->item($i)->getAttribute('target') != ''));
                    if ($missionTarget)
                    {
                            $targetId = $missions->item($i)->getAttribute('target');
                            $missionTargetId = $targetId;
                    }
722af6d4   Elena.Budnik   observatory level...
38
39
40
41
42
43
44
45
46
	            // if there is observatory layer
                    $observatoryTargets = false;
                    $obsTarget = false;

                    $observatories = $this->xp->query("//mission[@xml:id='".$missionId."']/observatory");
 
                    if ($observatories->length > 1) {

                        $n_targets = 0;
c9343cf5   Elena.Budnik   bug in obs accumu...
47
48
                        $obsTargets = array();
                        $obsIds = array();
722af6d4   Elena.Budnik   observatory level...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                        
                        for ($i_obs = 0; $i_obs < $observatories->length; $i_obs++) {

                            $obs = $observatories->item($i_obs);
                            
                            if ( $obs->hasAttribute('target') && ($obs->getAttribute('target') !== '') ) {
                                $obsTargets[] = $obs->getAttribute('target'); 
                                $obsIds[] = $obs->getAttribute('xml:id');
                                $n_targets++;                            
                            }                         
                        } 
                        if ($n_targets > 0) {
                            $observatoryTargets = true;                            
                        }
                    }
16035364   Benjamin Renard   First commit
64
65
66
67
68
69

                    $instruments = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument");

  		    for ($j = 0; $j < $instruments->length; $j++)
  		    { 
  		    	$instrumentId =  $instruments->item($j)->getAttribute('xml:id');
722af6d4   Elena.Budnik   observatory level...
70
71
72
73
74
75
76
77
78
79
80
81
82

                        $obsTarget = false;

  		  	if ($observatoryTargets) {                          
                           for ($i_obs = 0; $i_obs < $n_targets; $i_obs++) { 
                                if ($instruments->item($j)->parentNode->getAttribute('xml:id') == $obsIds[$i_obs]) {
                                    $obsTarget = true;
                                    $obsTargetId = $obsTargets[$i_obs];
                                    break;
                                }       
                           }
                        }

16035364   Benjamin Renard   First commit
83
84
85
86
87
88
89
90
91
92
                        $datasets = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument[@xml:id='".$instrumentId."']//dataset");
                                                     
  		    	for ($k = 0; $k < $datasets->length; $k++)
  		    	{
  		    		 
                                $datasetId = $datasets->item($k)->getAttribute('xml:id');   
                        
  		    		$datasetTarget = ($datasets->item($k)->hasAttribute('target') &&
  		    		                  ($datasets->item($k)->getAttribute('target') != ''));
  		    		
722af6d4   Elena.Budnik   observatory level...
93
  		    		if (!$missionTarget && !$obsTarget && !$datasetTarget)
16035364   Benjamin Renard   First commit
94
95
  		    			$targetId = 'none';	    			
  		    		else if ($datasetTarget)
722af6d4   Elena.Budnik   observatory level...
96
97
98
99
  		    			$targetId = $datasets->item($k)->getAttribute('target'); 
                                else if ($obsTarget)
                                        $targetId = $obsTargetId; 
                                else if ($missionTarget && !$obsTarget)
16035364   Benjamin Renard   First commit
100
                                        $targetId = $missionTargetId; 
722af6d4   Elena.Budnik   observatory level...
101
102
                               
  		     			
16035364   Benjamin Renard   First commit
103
104
105
106
107
108
109
  		    		//fprintf($log,"%s\n",$targetId);
  		    			
  		    		$ok = ($value == $targetId);
  		    		if (!$ok)
  		    		  if (strlen($targetId) > strlen($value))
  		    		    $ok = ((substr($targetId,0,strlen($value)) == $value) && ($targetId[strlen($value)]=='.'));   
                               
e57cb025   Benjamin Renard   Fix most of error...
110
                                $id = $datasetId;
16035364   Benjamin Renard   First commit
111
112
113
114
115
116
117
                                $chain = $datasetId;
                                $node = $datasets->item($k);

                                while ($id !== $missionId) {
                                    $node = $node->parentNode;
                                    $id = $node->getAttribute('xml:id');
                                    $chain = $id.";".$chain;
722af6d4   Elena.Budnik   observatory level...
118
                                }  	  	    		
16035364   Benjamin Renard   First commit
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  		    		switch ($opId)
  		    		{
  		    			case 'eq' :
  		    				if ($ok)  
                                                    array_push($result,$chain);                                                         
  		    				break;
  		    			case 'ne' :
  		    				if (!$ok)                                     
                                                    array_push($result,$chain);
  		    				break;
  		    		}
  		    	}
  		    }
  		}
722af6d4   Elena.Budnik   observatory level...
133

16035364   Benjamin Renard   First commit
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  		return $result;
  	}
  	
        function getTime($kind,$value,$opId)
        {
                $result = array();	
                
                $missions = $this->xp->query("//mission[@xml:id]"); 	
                for ($i = 0; $i < $missions->length; $i++)  
                {
                    $missionId   = $missions->item($i)->getAttribute('xml:id');
 
  			
                    $instruments = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument");
	  
  		    for ($j = 0; $j < $instruments->length; $j++)
  		    {  	
                        $instrumentId =  $instruments->item($j)->getAttribute('xml:id');
  		  		
                        $datasets = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument[@xml:id='".$instrumentId."']//dataset");
  		    	
                        for ($k = 0; $k < $datasets->length; $k++)
  		    	{  		    		  
                                $datasetId = $datasets->item($k)->getAttribute('xml:id'); 
    		    		
  		    		switch($kind)
  		    		{
  		    			case 'sta' :
  		    				$dataTime = $datasets->item($k)->getAttribute('dataStart');
  		    				break;
  		    			case 'sto' :
  		    				$dataTime = $datasets->item($k)->getAttribute('dataStop');
  		    				break;
  		    		}
  		    		
  		    		list($day, $month, $year) = explode('-', $dataTime);
  		    		$date = mktime(0, 0, 0, $month, $day, $year);
  		    		list($year, $month, $day, $hour, $min, $sec) = split('[-T:]', $value);
  		    		$date_value = mktime($hour, $min, $sec, $month, $day, $year);
  		    		
                                $id = $datsetId;
                                $chain = $datasetId;
                                $node = $datasets->item($k);

                                while ($id !== $missionId) {
                                    $node = $node->parentNode;
                                    $id = $node->getAttribute('xml:id');
                                    $chain = $id.";".$chain;
                                }  

  		    		switch($opId)
  		    		{
  		    			case 'le' :
  		    				if ($date <= $date_value)                                                         
                                                        array_push($result,$chain);                                               
  		    				break;
  		    			case 'ge' :
  		    				if ($date >= $date_value)                                                           
                                                        array_push($result,$chain);                                                       		    					                                                  
  		    				break;
  		    		}
  		    	}
  		    }
  		}
  		
  		return $result;
  	}
  	
  	function getMissionName($value,$opId)
  	{
  		$result = array();	
  		
  		$missions = $this->xp->query("//mission[@name]"); 	
  		for ($i = 0; $i < $missions->length; $i++)  
  		{		
  		  $missionName = $missions->item($i)->getAttribute('name');
  		  $missionId   = $missions->item($i)->getAttribute('xml:id');

  		  if ((!fnmatch($value,$missionName,FNM_CASEFOLD) && ($opId == 'eq')) ||
  		      (fnmatch($value,$missionName,FNM_CASEFOLD) && ($opId == 'ne')))
  		    continue;

  		  $instruments = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument");	 
 
  		  for ($j = 0; $j < $instruments->length; $j++)
  		  {  	
  		    $instrumentId =  $instruments->item($j)->getAttribute('xml:id');   		
  		  	
                    $datasets = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument[@xml:id='".$instrumentId."']//dataset");
                                                    
                    for ($k = 0; $k < $datasets->length; $k++)
                    {                         
                        $datasetId = $datasets->item($k)->getAttribute('xml:id');

                        $id = $datsetId;
                        $chain = $datasetId;
                        $node = $datasets->item($k);

                        while ($id !== $missionId) {
                            $node = $node->parentNode;
                            $id = $node->getAttribute('xml:id');
                            $chain = $id.";".$chain;
                        }  
 
                     array_push($result,$chain);
                          
                    }
                    }
                }
 		return $result;
  	}
  	
  	function getDataType($value,$opId)
  	{
  		
  	}
  	
  	function getProvider($value,$opId)
  	{
  		$result = array();	
  		
  		$missions = $this->xp->query("//mission[@xml:id]"); 	
  		for ($i = 0; $i < $missions->length; $i++)  
  		{
                    $missionId   = $missions->item($i)->getAttribute('xml:id');

                    $instruments = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument");
	  
  		    for ($j = 0; $j < $instruments->length; $j++)
  		    {  	
                        $instrumentId =  $instruments->item($j)->getAttribute('xml:id');
  		  		
                        $datasets = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument[@xml:id='".$instrumentId."']//dataset");
                                                       
  		    	for ($k = 0; $k < $datasets->length; $k++)
  		    	{
                                $provider  = $datasets->item($k)->getAttribute('dataSource');
                                
                               
                                $datasetId = $datasets->item($k)->getAttribute('xml:id'); 
                                
                                if ((!preg_match("/".$value."/i",$provider) && ($opId == 'eq')) ||
                                        (preg_match("/".$value."/i",$provider) && ($opId == 'ne')))
                                        continue;

                                $id = $datsetId;
                                $chain = $datasetId;
                                $node = $datasets->item($k);

                                while ($id !== $missionId) {
                                    $node = $node->parentNode;
                                    $id = $node->getAttribute('xml:id');
                                    $chain = $id.";".$chain;
                                }    
                 
                                
                                array_push($result,$chain);
                                  
  		    	}
  		    }		
  		}
  		
  		return $result;
  	}
  	
    function getAll()
  	{
  		$result = array();	
  		 
  		$missions = $this->xp->query("//mission[@xml:id]"); 	
  		for ($i = 0; $i < $missions->length; $i++)
  		{
                    $missionId   = $missions->item($i)->getAttribute('xml:id');
                                                                                          
                    $instruments = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument");	
  
  		    for ($j = 0; $j < $instruments->length; $j++)
  		    {  	
                        $instrumentId =  $instruments->item($j)->getAttribute('xml:id');
                        
                        $datasets = $this->xp->query("//mission[@xml:id='".$missionId."']//instrument[@xml:id='".$instrumentId."']//dataset");
                                                       

  		    	for ($k = 0; $k < $datasets->length; $k++)
  		    	{
                                  
                                $datasetId = $datasets->item($k)->getAttribute('xml:id'); 
 
e57cb025   Benjamin Renard   Fix most of error...
322
                                $id = $datasetId;
16035364   Benjamin Renard   First commit
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
                                $chain = $datasetId;
                                $node = $datasets->item($k);

                                while ($id !== $missionId) {
                                    $node = $node->parentNode;
                                    $id = $node->getAttribute('xml:id');
                                    $chain = $id.";".$chain;
                                }  
                                
                                array_push($result,$chain);
                                   
  		    	}
  		    }
  		}
  		
  		return $result;
  	}
  	
  	function getCondResult($cond)
  	{
  		$condId = $cond['condId'];
  		switch($condId)
  		{
  			case 'tar' : //target
  				return $this->getTarget($cond['value'],$cond['opId']);
  			case 'sta' : //start time
  				return $this->getTime('sta',$cond['value'],$cond['opId']);
  			case 'sto' : //stop time
  				return $this->getTime('sto',$cond['value'],$cond['opId']);
  			case 'mis' : //mission name
  				return $this->getMissionName(trim($cond['value']),$cond['opId']);
  			case 'typ' : //dataset type
  				return $this->getAll();
  			case 'pro' : //provider
  				return $this->getProvider(trim($cond['value']),$cond['opId']);
  			default :
  				return array();
  		}
  	}
  }

e57cb025   Benjamin Renard   Fix most of error...
364
?>