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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 537 - (hide annotations)
Thu Oct 25 16:31:52 2012 UTC (12 years, 3 months ago) by mlimic
File size: 4746 byte(s)
created the function that updates the status on consultations that have a 'accord tacite' to 'Favorable'
1 mlimic 515 <?php
2    
3 mlimic 522 /*
4 mlimic 523 * Processes requests received via services which are meant to initiate a
5 mlimic 522 * synchronization.
6     *
7     * @author Mirna Limic <[email protected]>
8     * Date: 18/10/2012
9     *
10     * Follow-up:
11     * Bugs:
12     */
13    
14 mlimic 515 require_once ("./metier/metiermanager.php");
15 mlimic 529 //require_once('./REST/amqp_publisher.php');
16 mlimic 515
17     class MaintenanceManager extends MetierManager {
18    
19 mlimic 522 /*
20     * @var mixed Array containing function pointers (i.e. function names)
21     * that are (dereferenced and) called to perform the synchronization tasks.
22     */
23 mlimic 537 var $fptrs = array('user' => 'synchronizeUsers',
24     'consultation' => 'updateConsultationsStates'); // 'UserManager'
25 mlimic 515
26 mlimic 522
27     /*
28     * Constructor.
29     *
30     * Calls its parent's constructor.
31     */
32 mlimic 526 public function __construct() {
33 mlimic 515 parent::__construct();
34     }
35 mlimic 522
36 mlimic 515
37 mlimic 522 /*
38     * Destructor.
39     *
40     * Calls its parent's destructor.
41     */
42 mlimic 526 public function __destruct() {
43 mlimic 515 parent::__destruct();
44     }
45    
46 mlimic 522
47     /*
48     * Starts a synchronization process by calling
49     * one of the functions in the fptrs array.
50     *
51     * @param string $module The key to be used in order to retreive the name
52     * of the function that should be called.
53     * @param mixed $data The data that was received as a part of the request.
54     * @return string The result of processing.
55     */
56 mlimic 526 public function performMaintenance($module, $data) {
57 mlimic 515
58     // check that the known module is called
59     if (!in_array($module, array_keys($this->fptrs))) {
60     return 'Unknown module in request.';
61     }
62    
63     $ret = call_user_func(array($this, $this->fptrs[$module]), $data);
64     return $ret;
65     }
66    
67 mlimic 522
68     /*
69     * Synchronizes the users data in a DB with the user's data from the
70     * directory services that communicate via LDAP.
71     *
72     * @param mixed $data The data that was received as a part of the request.
73     * @return string The result of processing.
74     */
75 mlimic 526 public function synchronizeUsers($data) {
76 mlimic 515 // depending on what is in the data do the treatement
77     // currently only user synchronization with ldap is supported
78     $keys = array_keys($data);
79     if (in_array('userToAdd', $keys)
80     || in_array('userToDelete', $keys)
81     || in_array('userToUpdate', $keys)) {
82     //$this->f->synchronizeUsers($data);
83     }
84     return $this->OK;
85     }
86 mlimic 537
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 (database::isError($res, true)) {
103     //print ' ERROR in SELECTION ';
104     return $this->KO;
105     }
106    
107     $ids = array();
108     while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
109     //print '$row'.$row;
110     $ids[] = $row[0];
111     }
112     $res->free();
113    
114     // if there are no consultations that need to have
115     // their state set to Favorable, return OK
116     if (count($ids) == 0) {
117     return $this->OK;
118     }
119    
120     // get the idenfier of the evaluation: 'Favorable'
121     $sql = "SELECT avis_consultation FROM avis_consultation WHERE ".
122     "libelle = 'Favorable'";
123     $res = $this->db->query($sql);
124     if (database::isError($res, true)) {
125     $res->free();
126     return $this->KO;
127     }
128     $favorable = -1;
129     while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
130     $favorable = $row[0];
131     }
132     $res->free();
133    
134     // if we did not find the evaluation 'Favorable', return error
135     if ($favorable < 0) {
136     return $this->KO;
137     }
138    
139     // update the consultation table to set the 'Favorable' evaluation for
140     // the pertinent consultations
141     $fields = array('avis_consultation' => $favorable);
142     $res = $this->db->autoExecute($table_name, $fields, DB_AUTOQUERY_UPDATE,
143     'consultation IN ('.implode(',', $ids).')');
144     if (database::isError($res, true)) {
145     $res->free();
146     return $this->KO;
147     }
148    
149     return $this->OK;
150     }
151 mlimic 515 }
152    
153     ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26