/[openfoncier]/trunk/services/metier/maintenancemanager.php
ViewVC logotype

Diff of /trunk/services/metier/maintenancemanager.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 523 by mlimic, Fri Oct 19 11:59:44 2012 UTC revision 559 by mlimic, Tue Oct 30 17:05:34 2012 UTC
# Line 12  Line 12 
12   */   */
13    
14  require_once ("./metier/metiermanager.php");  require_once ("./metier/metiermanager.php");
15    //require_once('./REST/amqp_publisher.php');
16    
17  class MaintenanceManager extends MetierManager {  class MaintenanceManager extends MetierManager {
18            
# Line 19  class MaintenanceManager extends MetierM Line 20  class MaintenanceManager extends MetierM
20       * @var mixed Array containing function pointers (i.e. function names)       * @var mixed Array containing function pointers (i.e. function names)
21       * that are (dereferenced and) called to perform the synchronization tasks.       * that are (dereferenced and) called to perform the synchronization tasks.
22       */       */
23      var $fptrs = array('user' => 'synchronizeUsers'); // 'UserManager'      var $fptrs = array('user' => 'synchronizeUsers',
24                           'consultation' => 'updateConsultationsStates'); // 'UserManager'
25            
26            
27      /*      /*
# Line 27  class MaintenanceManager extends MetierM Line 29  class MaintenanceManager extends MetierM
29       *       *
30       * Calls its parent's constructor.       * Calls its parent's constructor.
31       */       */
32      function __construct() {      public function __construct() {
33          parent::__construct();          parent::__construct();
34      }      }
35    
# Line 37  class MaintenanceManager extends MetierM Line 39  class MaintenanceManager extends MetierM
39       *       *
40       * Calls its parent's destructor.       * Calls its parent's destructor.
41       */           */    
42      function __destruct() {      public function __destruct() {
43          parent::__destruct();          parent::__destruct();
44      }      }
45            
# Line 51  class MaintenanceManager extends MetierM Line 53  class MaintenanceManager extends MetierM
53       * @param mixed $data The data that was received as a part of the request.       * @param mixed $data The data that was received as a part of the request.
54       * @return string The result of processing.       * @return string The result of processing.
55       */       */
56      function performMaintenance($module, $data) {      public function performMaintenance($module, $data) {
57                    
58          // check that the known module is called          // check that the known module is called
59          if (!in_array($module, array_keys($this->fptrs))) {          if (!in_array($module, array_keys($this->fptrs))) {
# Line 70  class MaintenanceManager extends MetierM Line 72  class MaintenanceManager extends MetierM
72       * @param mixed $data The data that was received as a part of the request.       * @param mixed $data The data that was received as a part of the request.
73       * @return string The result of processing.       * @return string The result of processing.
74       */           */    
75      function synchronizeUsers($data) {      public function synchronizeUsers($data) {
76          // depending on what is in the data do the treatement          // depending on what is in the data do the treatement
77          // currently only user synchronization with ldap is supported          // currently only user synchronization with ldap is supported
78          $keys = array_keys($data);          $keys = array_keys($data);
# Line 81  class MaintenanceManager extends MetierM Line 83  class MaintenanceManager extends MetierM
83          }          }
84          return $this->OK;                  return $this->OK;        
85      }      }
86        
87        
88        /*
89         * Sets to favorable the avis (evaluation) of consultations whose limit
90         * date has passed without there being a return (from an external service).
91         * @param mixed $data The data passed in with the REST call
92         * @return OK on success or not applicable, KO on DB error
93         */
94        public function updateConsultationsStates($data) {
95            $table_name = 'consultation';
96            $sql = "SELECT consultation FROM $table_name WHERE ".
97                " date_limite < DATE '". date('Y-m-d', time()) .
98                "' AND date_retour IS NULL AND avis_consultation IS NULL";
99    
100            $res = $this->db->query($sql);
101            // In case of error
102            if ($this->checkDBError($res, 'Erreur lors de mise à jour')) {
103                return $this->KO;
104            }
105            
106            $ids = array();
107            while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
108                $ids[] = $row[0];
109            }
110            $res->free();
111    
112            // if there are no consultations that need to have
113            // their state set to Favorable, return OK
114            if (count($ids) == 0) {
115                $this->setMessage("Aucune mise à jour");
116                return $this->NA;
117            }
118            
119            // get the idenfier of the evaluation: 'Favorable'
120            $sql = "SELECT avis_consultation FROM avis_consultation WHERE ".
121                "libelle = 'Tacite'";
122            $res = $this->db->query($sql);
123            if ($this->checkDBError($res, 'Erreur lors de mise à jour')) {
124                return $this->KO;
125            }
126    
127            $favorable = -1;
128            while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
129                $favorable = $row[0];
130            }
131            $res->free();
132    
133            // if we did not find the evaluation 'Favorable', return error
134            if ($favorable < 0) {
135                $this->setMessage("'Favorable' n'est pas présent ".
136                             "dans la columne : avis_consultation.libelle");
137                return $this->KO;
138            }
139    
140            // update the consultation table to set the 'Favorable' evaluation for
141            // the pertinent consultations
142            $fields = array('avis_consultation' => $favorable);
143            $res = $this->db->autoExecute($table_name, $fields, DB_AUTOQUERY_UPDATE,
144                                    'consultation IN ('.implode(',', $ids).')');
145            if ($this->checkDBError($res, 'Erreur lors de mise à jour')) {
146                return $this->KO;
147            }
148    
149            // $res->getDebugInfo(), $res->getMessage()
150            $this->setMessage('Il y a eu '.count($ids).' demandes de consultations dont '.
151                              'l\'avis été passé à Tacite');
152            return $this->OK;
153        }
154    
155  }  }
156    
157    
158    
159  ?>  ?>

Legend:
Removed from v.523  
changed lines
  Added in v.559

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26