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

Contents of /trunk/services/metier/consultationmanager.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 645 - (show annotations)
Fri Nov 9 14:16:58 2012 UTC (12 years, 2 months ago) by nhaye
File size: 8037 byte(s)
Modification de l'appel à la méthode d'enregistrement des retour d'avis.

1 <?php
2
3 /*
4 * Processes requests received via services which concern consultations (by
5 * ERP or other services).
6 *
7 * @author Mirna Limic <[email protected]>
8 * Date: 18/10/2012
9 *
10 * Follow-up:
11 * Bugs:
12 */
13
14
15 require_once ("./metier/metiermanager.php");
16 require_once("../obj/consultation.class.php");
17
18 class ConsultationManager extends MetierManager {
19
20
21 /*
22 * Constructor.
23 *
24 * Calls it's parent constructor to establish a DB connection
25 * and initializes the instance variables
26 */
27 public function __construct() {
28 parent::__construct();
29 /*$this->date_limite = null;
30 $this->date_retour = null;
31 $this->date_envoi = null;
32 $this->dossier_id = null;*/
33 $this->decisions = null;
34 $this->metier_instance = null;
35 $this->filename_prefix = null;
36 $this->filename = null;
37 }
38
39
40 /*
41 * Destructor
42 *
43 * Call's its parent's destructor.
44 */
45 public function __destruct() {
46 parent::__destruct();
47 }
48
49
50 /*
51 * Verifies that the date_retour received in the incomming data
52 * is in the (date_envoi, date_limite) interval. Also, check that
53 * there is no date_retour set for the consultation, as well as the
54 * validity of the date itself
55 * @param string $date_str The date_retour recived in the request
56 * @param string $id The discussion id
57 * @return string OK on success, BAD_DATA if the data sent is invalid,
58 * KO otherwise
59 */
60 private function checkDates($date_str, $id) {
61 // check that the consultation exists in DB
62 if (empty($this->metier_instance->valF['date_limite'])) {
63 $this->setMessage("La consultation ".$id." n'était pas trouvé");
64 return $this->BAD_DATA;
65 }
66
67 // check that the date_retour does not already exist
68 if (!empty($this->metier_instance->valF['date_retour'])) {
69 $this->setMessage("Le date de retour de la consultation ".$id.
70 " existe déjà");
71 return $this->BAD_DATA;
72 }
73
74 // check that the date is valid
75 $date = explode("/", $date_str);
76 if (!checkdate($date[1], $date[0], $date[2])) {
77 $this->setMessage("Le date de retour fourni pour la consultation ".
78 $id." n'est pas bon (en bon format)");
79 return $this->BAD_DATA;
80 }
81
82 if (!$this->dateInsideInterval($date_str,
83 $this->metier_instance->valF['date_envoi'],
84 $this->metier_instance->valF['date_limite'])) {
85 $this->setMessage("Le date de retour fourni pour la consultation ".
86 $id." n'est pas entre le date d'envoi ".
87 "et le date limite de la demande de consultation");
88 return $this->BAD_DATA;
89 }
90 return $this->OK;
91 }
92
93
94 /*
95 * Verifies that the avis received in the incomming data corresponds
96 * to one of the avis found in DB.
97 * @param string $avis The avis recived in the request
98 * @param string $id The discussion id
99 * @return string OK on success, KO otherwise
100 */
101 private function avisValid($avis, $id) {
102 // get all of the decisions possible from table avis_decision
103 $sql = "SELECT libelle, avis_consultation FROM avis_consultation";
104 $res = $this->db->query($sql);
105 if ($this->checkDBError($res, 'Erreur lors de recuperation des avis '.
106 'possibles pendant traitement de la consultation '.$id)) {
107 return $this->KO;
108 }
109
110 $this->decisions = array();
111 while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
112 $this->decisions[$row[0]] = $row[1];
113 }
114 $res->free();
115
116 // check that the decision received corresponds to a decision in DB
117 if (!in_array($avis, array_keys($this->decisions))) {
118 $this->setMessage(
119 "L'avis de consultation reçu n'est pas feasible");
120 return $this->KO;
121 }
122 return $this->OK;
123 }
124
125
126 /*
127 * Verifies that all the data concerning file to be stored (if any)
128 * are present in full or not present at all
129 * @param mixed $data The data recived in the request
130 * @param string $id The discussion id
131 * @return string OK on success, KO otherwise
132 */
133 private function fichierDataValid(&$data, $id) {
134 // do the check
135 if (!isset($data['nom_fichier']) && isset($data['fichier_base64'])
136 || isset($data['nom_fichier']) && !isset($data['fichier_base64'])) {
137 $this->setMessage(
138 "Les données de fichier d'avis de la consultation ".$id.
139 " ne sont pas complètes ");
140 return $this->KO;
141 }
142 return $this->OK;
143 }
144
145 /*
146 * Called when one of the external services sends its recommendation
147 * as a responde to a demand issued by openfoncier.
148 * @param mixed $data The array containing building number.
149 * @param string $id The ID of the dossier.
150 * @return bool 'OK'
151 */
152 public function consultationDecision($data, $id) {
153
154 // get all of the dates for the consultation from DB
155 // and check the date received is ok with respect to the
156 // time interval set by (date_envoi, date_limite)
157 // equally extract the dossier ID while at it
158 $this->metier_instance = new consultation($id, $this->db, 0);
159
160 // check that the consultation was found
161 if (isset($this->metier_instance->errors['db_debuginfo'])
162 && !empty($consultation->errors['db_debuginfo'])) {
163 $this->setMessage("Erreur lors de recuperation de la ".
164 "consultation $id");
165 return $this->KO;
166 }
167
168 // check that the date sent is applicable
169 $res = $this->checkDates($data['date_retour'], $id);
170 if ($res != $this->OK) {
171 return $res;
172 }
173
174 // set the prefix for the filename to use in case file data
175 // was received
176 $this->filename_prefix = "consultation_".$id."_";
177 // check that data regarding fichier is complete
178 $res = $this->fichierDataValid($data, $id);
179 if ($res != $this->OK) {
180 return $res;
181 }
182
183 // check that the decision sent is one of the decisions found in DB
184 // and store the possible decisions in $this->decisions
185 $res = $this->avisValid($data['avis'], $id);
186 if ($res != $this->OK) {
187 return $res;
188 }
189 // first store the file if needed
190 $res = $this->f->storeDecisionFile($data['fichier_base64'],
191 $data['nom_fichier'],
192 $this->metier_instance->valF['dossier'],
193 $this->filename_prefix);
194 if ($res !== true) {
195 return $res;
196 }
197 $this->metier_instance->valF['date_retour'] = $data['date_retour'];
198 $this->metier_instance->valF['avis_consultation'] = $this->decisions[$data['avis']];
199 $this->metier_instance->valF['lu'] = FALSE;
200 if (isset($data['nom_fichier'])) {
201 $this->metier_instance->valF['fichier'] = $this->filename_prefix . $data['nom_fichier'];
202 }
203 if (isset($data['motivation'])) {
204 $this->metier_instance->valF['motivation'] = $data['motivation'];
205 }
206
207 $ret = parent::modifier($this->metier_instance->valF,
208 "L'avis de la consultation $id a été pris en compte",
209 "Erreur pendant le traitemande de la demande pour la consultation $id");
210 if ($ret != $this->OK) {
211 // delete the file on disk
212 if (isset($data['nom_fichier'])) {
213 shell_exec("rm -f $this->filename");
214 }
215 }
216 return $ret;
217 }
218
219
220 }
221
222 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26