/[openfoncier]/trunk/services/outgoing/messageenqueuer.php
ViewVC logotype

Contents of /trunk/services/outgoing/messageenqueuer.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 810 - (show annotations)
Thu Nov 22 17:29:21 2012 UTC (12 years, 2 months ago) by mlimic
Original Path: trunk/services/messagesender.php
File size: 5409 byte(s)
Ajout des methodes pour envoyer des messages "Demande de completude de dossier PC pour un ERP", "Demande de qualification de dossier PC pour un ERP", "Demande d'instruction de dossier PC pour un ERP", "Arrete d'un dossier PC effectue"

1 <?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 public static $ERP_ARRETE_PC_EFFECTUE = 'erpArretePcEffectue';
33
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 $this->consultation = null;
47
48 // les donnees de la connexion
49 $this->queue = 'ERP_CHANNEL';
50 $this->host = 'localhost';
51 $this->port = '5672';
52 $this->user = 'guest';
53 $this->password = 'guest';
54 $this->vhost = '/';
55 }
56
57
58 /**
59 * Precondition: $msg_type est egal a valeur d'une des $ERP_*
60 */
61 public function sendMessage($method) {
62 if (method_exists($this, $method)) {
63 return $this->$method();
64 }
65 return $this->KO;
66 }
67
68
69 private function enqueueRequest() {
70 $msg_str = json_encode($this->ret_array);
71 print '$msg_str:'.$msg_str;
72
73 if ($msg_str === false) {
74 return $this->KO;
75 }
76
77 $exchange = 'router';
78 $queue = $this->queue;
79
80 $conn = new AMQPConnection($this->host, $this->port, $this->user,
81 $this->password, $this->vhost);
82 $ch = $conn->channel();
83 if (is_null($ch)) {
84 return -1;
85 }
86
87 $ch->queue_declare($queue, false, true, false, false);
88
89 $ch->exchange_declare($exchange, 'direct', false, true, false);
90
91 $ch->queue_bind($queue, $exchange);
92
93 //$msg_body = implode(' ', array_slice($argv, 1));
94 $msg = new AMQPMessage($msg_str, //$msg_body,
95 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 public function setConsultationIdentifier($id) {
121 $this->consultation = $id;
122 }
123
124 private function generic($msg_type, $obligatory = null) {
125 $this->ret_array = array("type" => $msg_type);
126 if (!is_null($obligatory)) {
127 $contenu = array();
128 foreach ($obligatory as $attrib) {
129 if (is_null($this->$attrib)) {
130 return $this->BAD_DATA;
131 }
132 $contenu[$attrib] = $this->$attrib;
133 //$this->ret_array[$attrib] = $this->$attrib;
134 }
135 $this->ret_array['contenu'] = $contenu;
136 }
137 if (is_null($this->dossier_instruction)) {
138 // manque des donnees
139 return $this->BAD_DATA;
140 }
141 return $this->enqueueRequest();
142 }
143
144 private function erpQualifie() {
145 $obligatory = array('dossier_instruction', 'competence',
146 'contrainte_plu');
147 return $this->generic('Demande de complétude dossier ERP',
148 $obligatory);
149 }
150
151
152 private function erpDemandeCompletudePc() {
153 return $this->generic('Demande de complétude dossier ERP');
154 }
155
156
157 private function erpDemandeQualificationPc() {
158 return $this->generic('Demande de qualification ERP');
159 }
160
161
162 private function erpDemandeInstructionPc() {
163 if (is_null($this->consultation)) {
164 return $this->BAD_DATA;
165 }
166 $this->ret_array['type'] = 'Demande d\'avis de dossier PC pour un ERP';
167 $this->ret_array['consultation'] = $this->consultation;
168 return $this->enqueueRequest();
169 }
170
171
172 private function erpArretePcEffectue() {
173 return $this->generic('Demande de qualification ERP',
174 array('Decision'));
175 }
176
177 }
178
179 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26