Next4Me
 All Classes Files Functions Variables
Cron.php
1 <?php
2 
3 class Application_Model_Cron extends Zend_Db_Table {
4 
5  function action($IdControlSession,$IdUserAccount,$Lat,$Long,$Device,$Activity,$Speed,$UserAccountType){
6  $entity['UserAccountType']=$UserAccountType;
7  $entity['IdUserAccount']=$IdUserAccount;
8  $entity['IdContext']=0;
9  $entity['IdStatus']=8;
10  $entity['UserAccountType']=0;
11  $this->Context = new Application_Model_Context;
12  $this->ContextCondition = new Application_Model_ContextCondition;
13  $this->ContextFactor = new Application_Model_ContextFactor;
14  $this->Trigger = new Application_Model_Trigger;
15 
16  $context = $this->Context->getContext($entity);
17  //echo "<pre>"; print_r($context); echo "</pre>";
18  if($context['resultId'] == "0"){
19  foreach($context['resultCode']['entity'] as $c){
20  $atemp = array();
21  $temp = array();
22  $entityCondition['IdContextCondition'] = 0;
23  $entityCondition['IdContext'] = $c['IdContext'];
24  $entityCondition['IdUserAccount'] = $IdUserAccount;
25  $entityCondition['UserAccountType'] = 0;
26 
27  $contextCondition = $this->ContextCondition->getContextCondition($entityCondition);
28  //echo "<pre>"; print_r($contextCondition); echo "</pre>";
29  $cCAtemporal = -3;
30  $cCTemporal = -3;
31  if($contextCondition['resultId']=="0"){
32 
33  foreach($contextCondition['resultCode']['entity'] as $cC)
34  {
35  $entityFactor['IdContextFactor']=0;
36  $entityFactor['IdContextCondition'] = $cC['IdContextCondition'];
37  $entityFactor['IdUserAccount'] = $IdUserAccount;
38  $entityFactor['UserAccountType']=0;
39 
40  $contextFactor = $this->ContextFactor->getContextFactor($entityFactor);
41  // echo "<pre>"; print_r($contextFactor); echo "</pre>";
42  // de aici incep factorii
43  if($contextFactor['resultId']=="0"){
44  $nrCF=0;
45  $cfTemporal=2;
46  $cfAtemporal=2;
47  foreach($contextFactor['resultCode']['entity'] as $cF)
48  {
49  $ef['Function'] = $cF['Function'];
50  $ef['Value'] = $cF['Value'];
51  $ef['IdUserAccount'] = $IdUserAccount;
52  $ef['IdControlSession'] = $IdControlSession;
53  $ef['IdUserAccount'] = $IdUserAccount;
54  $ef['LatCurrent'] = $Lat;
55  $ef['LongCurrent'] = $Long;
56  $ef['Device'] = $Device;
57  $ef['Activity'] = $Activity;
58  $ef['Speed'] = $Speed;
59  //echo "<pre>"; print_r($ef); echo "</pre>";
60  switch($cF['Type'])
61  {
62  case 'Speed':
63  $resTrigger = $this->Trigger->speed($ef);
64  $typeFactor = "Atemporal";
65  //echo "RezultTriger:".print_r($resTrigger)."-/-Type:".$typeFactor."-/-Function:".$cF['Type']."<br>";
66  break;
67  case 'Geofence':
68  $resTrigger = $this->Trigger->geofence($ef);
69  $typeFactor = "Atemporal";
70  //echo "RezultTriger:".print_r($resTrigger)."-/-Type:".$typeFactor."-/-Function:".$cF['Type']."<br>";
71  break;
72  case 'TimeStamp':
73  $resTrigger = $this->Trigger->timeStamp($ef);
74  $typeFactor = "Temporal";
75  // echo "RezultTriger:".print_r($resTrigger)."-/-Type:".$typeFactor."-/-Function:".$cF['Type']."<br>";
76  break;
77  case 'TimeRepeating':
78  $resTrigger = $this->Trigger->timeRepeating($ef);
79  $typeFactor = "Temporal";
80  //echo "RezultTriger:".print_r($resTrigger)."-/-Type:".$typeFactor."-/-Function:".$cF['Type']."<br>";
81  break;
82  case 'Device':
83  $resTrigger = $this->Trigger->device($ef);
84  $typeFactor = "Atemporal";
85  //echo "RezultTriger:".print_r($resTrigger)."-/-Type:".$typeFactor."-/-Function:".$cF['Type']."<br>";
86  break;
87  case 'Activity':
88  $resTrigger = $this->Trigger->activity($ef);
89  $typeFactor = "Atemporal";
90  //echo "RezultTriger:".print_r($resTrigger)."-/-Type:".$typeFactor."-/-Function:".$cF['Type']."<br>";
91  break;
92  }
93  if($typeFactor == "Atemporal"){if($cfAtemporal<(int)$resTrigger['resultCode']){$cfAtemporal=$resTrigger['resultCode'];}}
94  if($typeFactor == "Temporal"){if($cfTemporal<(int)$resTrigger['resultCode']){$cfTemporal=$resTrigger['resultCode'];}}
95  }
96  }
97  //pina aici au fost factorii
98  if($cfAtemporal<2){
99  if($cCAtemporal < $cfAtemporal){
100  $cCAtemporal = $cfAtemporal;
101  }
102  }
103  if($cfTemporal<2){
104  if($cCTemporal < $cfTemporal){
105  $cCTemporal = $cfTemporal;
106  }
107  }
108  }
109 
110  }
111  //pina aici au fost conditiile$cCAtemporal = -3;
112  if($cCAtemporal == -3 && $cCTemporal == -3){$IdStatus=1;}
113  if($cCAtemporal == 0 && $cCTemporal == -3){$IdStatus=1;}
114  if($cCAtemporal == -3 && $cCTemporal == -2){$IdStatus=2;}
115  if($cCAtemporal == 0 && $cCTemporal == -2){$IdStatus=2;}
116  if($cCAtemporal == -3 && $cCTemporal == -1){$IdStatus=3;}
117  if($cCAtemporal == -0 && $cCTemporal == -1){$IdStatus=4;}
118  if($cCAtemporal == -3 && $cCTemporal == 0){$IdStatus=5;}
119  if($cCAtemporal == 0 && $cCTemporal == 0){$IdStatus=6;}
120  if($cCAtemporal == -3 && $cCTemporal == 1){$IdStatus=7;}
121  if($cCAtemporal == 0 && $cCTemporal == 1){$IdStatus=8;}
122  $a=array("IdContext"=>$entityCondition['IdContext'], "IdUserAccount"=>$IdUserAccount, "IdStatus"=>$IdStatus, "UserAccountType"=>$entity['UserAccountType']);
123  //print_r($a);
124  $this->Context->addEditContext($a);
125  //echo "Max temp:".$max."->Max atemp:".$maxa."<br><br>";
126  //echo "<pre>".print_r($atemp)."</pre>";
127  //echo "<pre>".print_r($temp)."</pre>";
128  }
129  }
130  }
131 }