1 |
mlimic |
806 |
<?php |
2 |
|
|
|
3 |
|
|
/* |
4 |
|
|
define('HOST', 'localhost'); |
5 |
|
|
define('PORT', 5672); |
6 |
|
|
define('USER', 'guest'); |
7 |
|
|
define('PASS', 'guest'); |
8 |
|
|
define('VHOST', '/'); |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
require_once('./php/php-amqplib/vendor/autoload.php'); |
13 |
|
|
use PhpAmqpLib\Connection\AMQPConnection; |
14 |
|
|
use PhpAmqpLib\Message\AMQPMessage; |
15 |
|
|
//Si le AMQP_DEBUG est defini, on peut utiliser sortie du AMQP sur CLI // ??? |
16 |
|
|
define('AMQP_DEBUG', true); |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
class MessageSender { |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
public static $ERP_DEMANDE_COMPLETUDE_PC = 'erpDemandeCompletudePc'; |
23 |
|
|
public static $ERP_QUALIFIE = 'erpQualifie'; |
24 |
|
|
public static $ERP_DEMANDE_QUALIFICATION_PC = 'erpDemandeQualificationPc'; |
25 |
|
|
public static $ERP_DEMANDE_INSTRUCTION_PC = 'erpDemandeInstructionPc'; |
26 |
|
|
public static $ERP_CONSULTATION_CONFORMITE = 'erpConsultationConformite'; |
27 |
|
|
public static $ERP_DEMANDE_OUVERTURE_PC = 'erpDemandeOuverturePc'; |
28 |
|
|
public static $ERP_DEPOT_DOSSIER_DAT = 'erpDepotDossierDat'; |
29 |
|
|
public static $ERP_ANNULATION_DEMANDE = 'erpAnnulationDemande'; |
30 |
|
|
public static $ERP_DEMANDE_OUVERTURE_DAT = 'erpDemandeOuvertureDat'; |
31 |
|
|
public static $ERP_DECISION_CONFORMITE_EFFECTUE = 'erpDecisionConformiteEffectue'; |
32 |
mlimic |
810 |
public static $ERP_ARRETE_PC_EFFECTUE = 'erpArretePcEffectue'; |
33 |
mlimic |
806 |
|
34 |
|
|
var $BAD_DATA = -2; |
35 |
|
|
var $OK = 0; |
36 |
|
|
var $KO = -1; |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
public function __construct() { |
40 |
|
|
$this->ret_array = array(); |
41 |
|
|
$this->ret_array['date'] = date('d/m/Y H:i'); |
42 |
|
|
$this->ret_array['emetteur'] = 'admin'; //$_SESSION['login']; |
43 |
|
|
$this->dossier_instruction = null; |
44 |
|
|
$this->competence = null; |
45 |
|
|
$this->contrainte_plu = null; |
46 |
mlimic |
810 |
$this->consultation = null; |
47 |
mlimic |
811 |
$this->decision = null; |
48 |
mlimic |
806 |
|
49 |
|
|
// les donnees de la connexion |
50 |
|
|
$this->queue = 'ERP_CHANNEL'; |
51 |
|
|
$this->host = 'localhost'; |
52 |
|
|
$this->port = '5672'; |
53 |
|
|
$this->user = 'guest'; |
54 |
|
|
$this->password = 'guest'; |
55 |
|
|
$this->vhost = '/'; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
/** |
60 |
|
|
* Precondition: $msg_type est egal a valeur d'une des $ERP_* |
61 |
|
|
*/ |
62 |
|
|
public function sendMessage($method) { |
63 |
|
|
if (method_exists($this, $method)) { |
64 |
|
|
return $this->$method(); |
65 |
|
|
} |
66 |
|
|
return $this->KO; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
|
70 |
|
|
private function enqueueRequest() { |
71 |
|
|
$msg_str = json_encode($this->ret_array); |
72 |
|
|
print '$msg_str:'.$msg_str; |
73 |
|
|
|
74 |
|
|
if ($msg_str === false) { |
75 |
|
|
return $this->KO; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
$exchange = 'router'; |
79 |
|
|
$queue = $this->queue; |
80 |
|
|
|
81 |
|
|
$conn = new AMQPConnection($this->host, $this->port, $this->user, |
82 |
|
|
$this->password, $this->vhost); |
83 |
|
|
$ch = $conn->channel(); |
84 |
|
|
if (is_null($ch)) { |
85 |
|
|
return -1; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
$ch->queue_declare($queue, false, true, false, false); |
89 |
|
|
|
90 |
|
|
$ch->exchange_declare($exchange, 'direct', false, true, false); |
91 |
|
|
|
92 |
|
|
$ch->queue_bind($queue, $exchange); |
93 |
|
|
|
94 |
mlimic |
811 |
$msg = new AMQPMessage($msg_str, |
95 |
mlimic |
806 |
array('content_type' => 'text/plain', 'delivery_mode' => 2)); |
96 |
|
|
$ch->basic_publish($msg, $exchange); |
97 |
|
|
|
98 |
|
|
$ch->close(); |
99 |
|
|
$conn->close(); |
100 |
|
|
|
101 |
|
|
return 0; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
|
105 |
|
|
public function setDossierInstructionIdentifier($id) { |
106 |
|
|
$this->dossier_instruction = $id; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
public function setCompetence($competence) { |
111 |
|
|
$this->competence = $competence; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
|
115 |
|
|
public function setContraintePlu($contrainte_plu) { |
116 |
|
|
$this->contrainte_plu = $contrainte_plu; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
|
120 |
mlimic |
810 |
public function setConsultationIdentifier($id) { |
121 |
|
|
$this->consultation = $id; |
122 |
|
|
} |
123 |
mlimic |
811 |
|
124 |
|
|
|
125 |
|
|
public function setDecision($decision) { |
126 |
|
|
$this->decision = $decision; |
127 |
|
|
} |
128 |
mlimic |
810 |
|
129 |
mlimic |
811 |
|
130 |
|
|
private function generic($msg_type, $contenu_keys = null) { |
131 |
|
|
$this->ret_array["type"] = $msg_type; |
132 |
|
|
if (is_null($this->dossier_instruction)) { |
133 |
|
|
// manque des donnees |
134 |
|
|
return $this->BAD_DATA; |
135 |
|
|
} |
136 |
|
|
$this->ret_array['date'] = date('d/m/Y H:i'); |
137 |
|
|
$this->ret_array['emetteur'] = $_SESSION['login']; |
138 |
|
|
$this->ret_array['dossier_instruction'] = $this->dossier_instruction; |
139 |
|
|
|
140 |
|
|
if (!is_null($contenu_keys)) { |
141 |
mlimic |
810 |
$contenu = array(); |
142 |
mlimic |
811 |
foreach ($contenu_keys as $attrib) { |
143 |
mlimic |
810 |
if (is_null($this->$attrib)) { |
144 |
|
|
return $this->BAD_DATA; |
145 |
|
|
} |
146 |
|
|
$contenu[$attrib] = $this->$attrib; |
147 |
|
|
} |
148 |
|
|
$this->ret_array['contenu'] = $contenu; |
149 |
|
|
} |
150 |
|
|
return $this->enqueueRequest(); |
151 |
mlimic |
806 |
} |
152 |
|
|
|
153 |
mlimic |
811 |
|
154 |
mlimic |
810 |
private function erpQualifie() { |
155 |
mlimic |
811 |
$contenu_keys = array('competence', |
156 |
mlimic |
810 |
'contrainte_plu'); |
157 |
mlimic |
811 |
return $this->generic('ERP Qualifié', |
158 |
|
|
$contenu_keys); |
159 |
mlimic |
810 |
} |
160 |
mlimic |
806 |
|
161 |
mlimic |
810 |
|
162 |
mlimic |
806 |
private function erpDemandeCompletudePc() { |
163 |
mlimic |
810 |
return $this->generic('Demande de complétude dossier ERP'); |
164 |
mlimic |
806 |
} |
165 |
|
|
|
166 |
mlimic |
810 |
|
167 |
|
|
private function erpDemandeQualificationPc() { |
168 |
|
|
return $this->generic('Demande de qualification ERP'); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
|
172 |
|
|
private function erpDemandeInstructionPc() { |
173 |
|
|
if (is_null($this->consultation)) { |
174 |
|
|
return $this->BAD_DATA; |
175 |
|
|
} |
176 |
mlimic |
811 |
//$this->ret_array['type'] = 'Demande d\'avis de dossier PC pour un ERP'; |
177 |
mlimic |
810 |
$this->ret_array['consultation'] = $this->consultation; |
178 |
mlimic |
811 |
return $this->generic('Demande d\'avis de dossier PC pour un ERP'); |
179 |
mlimic |
810 |
} |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
private function erpArretePcEffectue() { |
183 |
mlimic |
811 |
if (is_null($this->dossier_instruction) |
184 |
|
|
|| is_null($this->decision)) { |
185 |
|
|
// manque des donnees |
186 |
|
|
return $this->BAD_DATA; |
187 |
|
|
} |
188 |
|
|
return $this->generic('Arrêté PC effectué', |
189 |
|
|
array('decision')); |
190 |
mlimic |
810 |
} |
191 |
|
|
|
192 |
mlimic |
811 |
|
193 |
|
|
private function erpConsultationConformite() { |
194 |
|
|
if (is_null($this->consultation)) { |
195 |
|
|
return $this->BAD_DATA; |
196 |
|
|
} |
197 |
|
|
$this->ret_array['consultation'] = $this->consultation; |
198 |
|
|
return $this->generic('Consultation ERP pour conformité'); |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
|
202 |
|
|
private function erpDemandeOuverturePc() { |
203 |
|
|
return $this->generic('Demande d\'ouverture ERP PC'); |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
|
207 |
|
|
private function erpDepotDossierDat() { |
208 |
|
|
return $this->generic('Dépôt de dossier DAT'); |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
|
212 |
|
|
public function erpAnnulationDemande() { |
213 |
|
|
return $this->generic('Annulation de la demande'); |
214 |
|
|
} |
215 |
|
|
|
216 |
|
|
|
217 |
|
|
public function erpDemandeOuvertureDat() { |
218 |
|
|
return $this->generic('Demande d\'ouverture ERP DAT'); |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
|
222 |
|
|
public function erpDecisionConformiteEffectue() { |
223 |
|
|
return $this->generic('Décision de conformité effectuée'); |
224 |
|
|
} |
225 |
mlimic |
806 |
} |
226 |
|
|
|
227 |
|
|
?> |