20 |
* @var mixed Array containing function pointers (i.e. function names) |
* @var mixed Array containing function pointers (i.e. function names) |
21 |
* that are (dereferenced and) called to perform the synchronization tasks. |
* that are (dereferenced and) called to perform the synchronization tasks. |
22 |
*/ |
*/ |
23 |
var $fptrs = array('user' => 'synchronizeUsers'); // 'UserManager' |
var $fptrs = array('user' => 'synchronizeUsers', |
24 |
|
'consultation' => 'updateConsultationsStates'); // 'UserManager' |
25 |
|
|
26 |
|
|
27 |
/* |
/* |
83 |
} |
} |
84 |
return $this->OK; |
return $this->OK; |
85 |
} |
} |
86 |
|
|
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 ($this->checkDBError($res, 'Erreur lors de mise à jour')) { |
103 |
|
return $this->KO; |
104 |
|
} |
105 |
|
|
106 |
|
$ids = array(); |
107 |
|
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) { |
108 |
|
$ids[] = $row[0]; |
109 |
|
} |
110 |
|
$res->free(); |
111 |
|
|
112 |
|
// if there are no consultations that need to have |
113 |
|
// their state set to Favorable, return OK |
114 |
|
if (count($ids) == 0) { |
115 |
|
$this->setMessage("Aucune mise à jour"); |
116 |
|
return $this->NA; |
117 |
|
} |
118 |
|
|
119 |
|
// get the idenfier of the evaluation: 'Favorable' |
120 |
|
$sql = "SELECT avis_consultation FROM avis_consultation WHERE ". |
121 |
|
"libelle = 'Favorable'"; |
122 |
|
$res = $this->db->query($sql); |
123 |
|
if ($this->checkDBError($res, 'Erreur lors de mise à jour')) { |
124 |
|
return $this->KO; |
125 |
|
} |
126 |
|
|
127 |
|
$favorable = -1; |
128 |
|
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) { |
129 |
|
$favorable = $row[0]; |
130 |
|
} |
131 |
|
$res->free(); |
132 |
|
|
133 |
|
// if we did not find the evaluation 'Favorable', return error |
134 |
|
if ($favorable < 0) { |
135 |
|
$this->setMessage("'Favorable' n'est pas présent ". |
136 |
|
"dans la columne : avis_consultation.libelle"); |
137 |
|
return $this->KO; |
138 |
|
} |
139 |
|
|
140 |
|
// update the consultation table to set the 'Favorable' evaluation for |
141 |
|
// the pertinent consultations |
142 |
|
$fields = array('avis_consultation' => $favorable); |
143 |
|
$res = $this->db->autoExecute($table_name, $fields, DB_AUTOQUERY_UPDATE, |
144 |
|
'consultation IN ('.implode(',', $ids).')'); |
145 |
|
if ($this->checkDBError($res, 'Erreur lors de mise à jour')) { |
146 |
|
return $this->KO; |
147 |
|
} |
148 |
|
|
149 |
|
// $res->getDebugInfo(), $res->getMessage() |
150 |
|
$this->setMessage('Il y a eu '.count($ids).' demandes de consultations dont '. |
151 |
|
'l\'avis été passé à Tacite'); |
152 |
|
return $this->OK; |
153 |
|
} |
154 |
|
|
155 |
} |
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
?> |
?> |