92 |
* @return OK on success or not applicable, KO on DB error |
* @return OK on success or not applicable, KO on DB error |
93 |
*/ |
*/ |
94 |
public function updateConsultationsStates($data) { |
public function updateConsultationsStates($data) { |
95 |
$table_name = 'consultation'; |
$table_name = 'test'; |
96 |
$sql = "SELECT consultation FROM $table_name WHERE ". |
$sql = "SELECT consultation FROM $table_name WHERE ". |
97 |
" date_limite < DATE '". date('Y-m-d', time()) . |
" date_limite < DATE '". date('Y-m-d', time()) . |
98 |
"' AND date_retour IS NULL AND avis_consultation IS NULL"; |
"' AND date_retour IS NULL AND avis_consultation IS NULL"; |
99 |
|
|
100 |
$res = $this->db->query($sql); |
$res = $this->db->query($sql); |
101 |
// In case of error |
// In case of error |
102 |
if (database::isError($res, true)) { |
if ($this->checkDBError($res)) { |
|
//print ' ERROR in SELECTION '; |
|
103 |
return $this->KO; |
return $this->KO; |
104 |
} |
} |
105 |
|
|
106 |
$ids = array(); |
$ids = array(); |
107 |
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) { |
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) { |
|
//print '$row'.$row; |
|
108 |
$ids[] = $row[0]; |
$ids[] = $row[0]; |
109 |
} |
} |
110 |
$res->free(); |
$res->free(); |
112 |
// if there are no consultations that need to have |
// if there are no consultations that need to have |
113 |
// their state set to Favorable, return OK |
// their state set to Favorable, return OK |
114 |
if (count($ids) == 0) { |
if (count($ids) == 0) { |
115 |
return $this->OK; |
$this->setMessage("No updates to make."); |
116 |
|
return $this->NA; |
117 |
} |
} |
118 |
|
|
119 |
// get the idenfier of the evaluation: 'Favorable' |
// get the idenfier of the evaluation: 'Favorable' |
120 |
$sql = "SELECT avis_consultation FROM avis_consultation WHERE ". |
$sql = "SELECT avis_consultation FROM avis_consultation WHERE ". |
121 |
"libelle = 'Favorable'"; |
"libelle = 'Favorable'"; |
122 |
$res = $this->db->query($sql); |
$res = $this->db->query($sql); |
123 |
if (database::isError($res, true)) { |
if ($this->checkDBError($res)) { |
|
$res->free(); |
|
124 |
return $this->KO; |
return $this->KO; |
125 |
} |
} |
126 |
|
|
127 |
$favorable = -1; |
$favorable = -1; |
128 |
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) { |
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) { |
129 |
$favorable = $row[0]; |
$favorable = $row[0]; |
132 |
|
|
133 |
// if we did not find the evaluation 'Favorable', return error |
// if we did not find the evaluation 'Favorable', return error |
134 |
if ($favorable < 0) { |
if ($favorable < 0) { |
135 |
|
$this->setMessage("String 'Favorable' is not present ". |
136 |
|
"in column avis_consultation.libelle."); |
137 |
return $this->KO; |
return $this->KO; |
138 |
} |
} |
139 |
|
|
140 |
// update the consultation table to set the 'Favorable' evaluation for |
// update the consultation table to set the 'Favorable' evaluation for |
141 |
// the pertinent consultations |
// the pertinent consultations |
142 |
$fields = array('avis_consultation' => $favorable); |
$fields = array('avis_consultation' => $favorable); |
143 |
$res = $this->db->autoExecute($table_name, $fields, DB_AUTOQUERY_UPDATE, |
$res = $this->db->autoExecute($table_name, $fields, DB_AUTOQUERY_UPDATE, |
144 |
'consultation IN ('.implode(',', $ids).')'); |
'consultation IN ('.implode(',', $ids).')'); |
145 |
if (database::isError($res, true)) { |
if ($this->checkDBError($res)) { |
|
$res->free(); |
|
146 |
return $this->KO; |
return $this->KO; |
147 |
} |
} |
148 |
|
|
149 |
return $this->OK; |
// $res->getDebugInfo(), $res->getMessage() |
150 |
|
$this->setMessage('Evaluation (avis) of '.count($ids). |
151 |
|
' requests for consultation was set to "Tacite".'); |
152 |
|
return $this->OK; |
153 |
} |
} |
154 |
|
|
155 |
} |
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
?> |
?> |