1 |
<?php |
<?php |
2 |
|
/** |
3 |
|
* Ce fichier permet de déclarer la classe MessagesManager, qui effectue les |
4 |
|
* traitements pour la ressource 'messages'. |
5 |
|
* |
6 |
|
* @package openfoncier |
7 |
|
* @version SVN : $Id$ |
8 |
|
*/ |
9 |
|
|
10 |
|
// Inclusion de la classe de base MetierManager |
11 |
|
require_once("./metier/metiermanager.php"); |
12 |
|
|
13 |
|
// Inclusion de la classe métier dossier_message |
14 |
|
include_once('../obj/dossier_message.class.php'); |
15 |
|
|
16 |
|
/** |
17 |
|
* Cette classe hérite de la classe MetierManager. Elle permet d'effectuer des |
18 |
|
* traitements pour la ressource 'messages'. |
19 |
|
* |
20 |
|
* @todo XXX Traduire et commenter toutes les méthodes |
21 |
|
*/ |
22 |
class MessagesManager extends MetierManager { |
class MessagesManager extends MetierManager { |
23 |
|
|
24 |
|
/** |
25 |
function __construct() { |
* |
26 |
|
*/ |
27 |
|
var $TYPE_COMPLETUDE_ACC = 'Mise à jour de complétude ERP ACC'; |
28 |
|
var $TYPE_COMPLETUDE_SECU = 'Mise à jour de complétude ERP SECU'; |
29 |
|
var $TYPE_QUALIFICATION_ERP = 'Mise à jour de qualification'; |
30 |
|
var $TYPE_DOSSIER_ENJEUX = 'Dossier à enjeux ERP'; |
31 |
|
|
32 |
|
/** |
33 |
|
* Constructeur |
34 |
|
* |
35 |
|
* @todo XXX Ajouter la description des attributs |
36 |
|
*/ |
37 |
|
public function __construct() { |
38 |
|
|
39 |
|
// Appel du constructeur parent |
40 |
parent::__construct(); |
parent::__construct(); |
41 |
|
|
42 |
|
// |
43 |
|
$this->table = 'messages'; |
44 |
|
|
45 |
} |
} |
46 |
|
|
47 |
|
/** |
48 |
function __destruct() { |
* Destructeur |
49 |
|
*/ |
50 |
|
public function __destruct() { |
51 |
|
|
52 |
|
// Appel du destructeur parent |
53 |
parent::__destruct(); |
parent::__destruct(); |
54 |
|
|
55 |
} |
} |
56 |
|
|
57 |
|
/** |
58 |
function completude_dossier_ACC($data) { |
* |
59 |
|
*/ |
60 |
|
private function generic(&$data, $type, $contenu_strs) { |
61 |
|
// check that the type of the message is good |
62 |
|
if ($data['type'] != $type) { |
63 |
|
$this->setMessage('Le type de message n\'est pas correct.'); |
64 |
|
return $this->BAD_DATA; |
65 |
|
} |
66 |
|
|
67 |
|
// verification que le dossier existe dans la BD |
68 |
|
$sql = "SELECT dossier FROM ".DB_PREFIXE."dossier"; |
69 |
|
$res = $this->db->query($sql); |
70 |
|
if ($this->checkDBError($res, 'Erreur lors de recuperation des dossiers')) { |
71 |
|
return $this->KO; |
72 |
|
} |
73 |
|
|
74 |
|
$this->dossiers = array(); |
75 |
|
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) { |
76 |
|
$this->dossiers[$row[0]] = $row[1]; |
77 |
|
} |
78 |
|
$res->free(); |
79 |
|
|
80 |
|
// check that the decision received corresponds to a decision in DB |
81 |
|
if (!in_array($data['dossier_instruction'], array_keys($this->dossiers))) { |
82 |
|
$this->setMessage("Le dossier spécifié dans le message n'existe pas"); |
83 |
|
return $this->KO; |
84 |
|
} |
85 |
|
|
86 |
|
// create the object to hold the data to be stored in DB |
87 |
|
$this->metier_instance = new dossier_message("]", $this->db, 0); |
88 |
|
|
89 |
|
// check that the date is correct |
90 |
|
$date_db = null; |
91 |
|
if (!$this->timestampValid($data['date'], $date_db, true)) { |
92 |
|
$this->setMessage('Le date n\'est pas correct.'); |
93 |
|
return $this->BAD_DATA; |
94 |
|
} |
95 |
|
|
96 |
|
// check that the contenu contains all elements and prepare the |
97 |
|
// contenu |
98 |
|
$contenu = ''; |
99 |
|
$valid_contenu = true; |
100 |
|
foreach ($contenu_strs as $contenu_str => $possible_vals) { |
101 |
|
$value = $data['contenu'][$contenu_str]; |
102 |
|
if (empty($value)) { |
103 |
|
$valid_contenu = false; |
104 |
|
break; |
105 |
|
} |
106 |
|
if ($possible_vals && !in_array(strtolower($value), $possible_vals)) { |
107 |
|
$valid_contenu = false; |
108 |
|
break; |
109 |
|
} |
110 |
|
$contenu .= $contenu_str.' : '.$value.' |
111 |
|
'; // il faut que cette ligne soit comme ca pour que le \n est ajoute a la fin the $contenu |
112 |
|
} |
113 |
|
if ($valid_contenu === false) { |
114 |
|
$this->setMessage('Le contenu du message n\'est pas correct.'); |
115 |
|
return $this->BAD_DATA; |
116 |
|
} |
117 |
|
|
118 |
|
// do some data overwrite and duplication so that the array |
119 |
|
// contains the keys searched for |
120 |
|
$data['contenu'] = $contenu; |
121 |
|
$data['dossier'] = $data['dossier_instruction']; |
122 |
|
$data['date_emission'] = $date_db; // the date |
123 |
|
|
124 |
return $this->OK; |
return $this->OK; |
125 |
} |
} |
126 |
|
|
127 |
|
|
128 |
|
/** |
129 |
|
* Called when ERP wants to indicate if the dossier d'instruction |
130 |
|
* is complete with respect to services for handicapped persons. |
131 |
|
* |
132 |
|
* @param mixed $data The data received in the request. |
133 |
|
* @return string 'OK'. |
134 |
|
*/ |
135 |
|
public function completude_dossier_ACC($data) { |
136 |
|
|
137 |
|
$key_val_pairs = array('Complétude ERP ACC' => array('oui', 'non'), |
138 |
|
'Motivation Complétude ERP ACC' => null); |
139 |
|
$ret = $this->generic($data, |
140 |
|
$this->TYPE_COMPLETUDE_ACC, |
141 |
|
$key_val_pairs); |
142 |
|
|
143 |
|
if ($ret != $this->OK) { |
144 |
|
return $ret; |
145 |
|
} |
146 |
|
return parent::ajouter($data, |
147 |
|
"Mise à jour de complétude ERP ACC à été faite avec success", |
148 |
|
"Echec dans la mise à jour de complétude ERP ACC"); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
function completude_dossier_SECU($data) { |
/** |
153 |
return $this->OK; |
* Called when ERP wants to indicate if the dossier d'instruction |
154 |
|
* is complete with respect to security (e.g. fire) regulations. |
155 |
|
* |
156 |
|
* @param mixed $data The data received in the request. |
157 |
|
* @return string 'OK'. |
158 |
|
*/ |
159 |
|
public function completude_dossier_SECU($data) { |
160 |
|
|
161 |
|
$key_val_pairs = array('Complétude ERP SECU' => array('oui', 'non'), |
162 |
|
'Motivation Complétude ERP SECU' => null); |
163 |
|
$ret = $this->generic($data, |
164 |
|
$this->TYPE_COMPLETUDE_SECU, |
165 |
|
$key_val_pairs); |
166 |
|
|
167 |
|
if ($ret != $this->OK) { |
168 |
|
return $ret; |
169 |
|
} |
170 |
|
return parent::ajouter($data, |
171 |
|
"Mise à jour de complétude ERP SECU à été faite avec success", |
172 |
|
"Echec dans la mise à jour de complétude ERP SECU"); |
173 |
} |
} |
174 |
|
|
175 |
|
|
176 |
function qualification_dossier($data) { |
/** |
177 |
return $this->OK; |
* Called when ERP wants to indicate if the dossier d'instruction |
178 |
|
* is an ERP dossier or not. |
179 |
|
* |
180 |
|
* @param mixed $data The data received in the request. |
181 |
|
* @return string 'OK'. |
182 |
|
*/ |
183 |
|
public function qualification_dossier($data) { |
184 |
|
$key_val_pairs = array('Confirmation ERP' => array('oui', 'non'), |
185 |
|
'Type de dossier ERP' => null, |
186 |
|
'Catégorie de dossier ERP' => null); |
187 |
|
$ret = $this->generic($data, |
188 |
|
$this->TYPE_QUALIFICATION_ERP, |
189 |
|
$key_val_pairs); |
190 |
|
|
191 |
|
if ($ret != $this->OK) { |
192 |
|
return $ret; |
193 |
|
} |
194 |
|
return parent::ajouter($data, |
195 |
|
"Mise à jour de la qualification ERP à été faite avec success", |
196 |
|
"Echec dans la mise à jour de la qualification ERP"); |
197 |
} |
} |
198 |
|
|
199 |
|
|
200 |
function dossier_enjeux($data) { |
/** |
201 |
return $this->OK; |
* Called when ERP wants to indicate if the dossier d'instruction |
202 |
|
* is important, i.e. dossier a enjeux. |
203 |
|
* |
204 |
|
* @param mixed $data The data received in the request. |
205 |
|
* @return string 'OK'. |
206 |
|
*/ |
207 |
|
public function dossier_enjeux($data) { |
208 |
|
$key_val_pairs = array('Dossier à enjeux ERP' => array('oui', 'non')); |
209 |
|
$ret = $this->generic($data, |
210 |
|
$this->TYPE_DOSSIER_ENJEUX, |
211 |
|
$key_val_pairs); |
212 |
|
|
213 |
|
if ($ret != $this->OK) { |
214 |
|
return $ret; |
215 |
|
} |
216 |
|
return parent::ajouter($data, |
217 |
|
"Mise à jour du dossier \"Dossier à enjeux ERP\" à été faite avec success", |
218 |
|
"Echec dans la mise à jour du dossier \"Dossier à enjeux ERP\""); |
219 |
} |
} |
220 |
|
|
221 |
} |
} |