Rev 2458 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
// declare(encoding='UTF-8');
/**
* Service rendant publique une observation.
*
* @internal Mininum PHP version : 5.2
* @category CEL
* @package Services
* @subpackage Observations
* @version 0.1
* @author Mathias CHOUET <mathias@tela-botanica.org>
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
*/
class InventoryTransmit extends Cel {
private $idUtilisateur = null;
private $ordres = null;
public function updateElement($ressources, $data) {
$this->verifierRessources($ressources);
$this->verifierData($data);
$transmission = intval($data['transmission']);
$date = ($transmission == 1) ? 'NOW()' : 'NULL';
$idsObsConcat = implode(',', $this->getIdsObs());
$requete = 'UPDATE cel_obs '.
"SET transmission = $transmission, date_transmission = $date, date_modification = NOW() ".
"WHERE id_observation IN ($idsObsConcat) ".
' -- '.__FILE__.':'.__LINE__;
$resultatObs = Cel::db()->executer($requete);
$requete = 'UPDATE cel_images '.
"SET transmission = $transmission, date_transmission = $date, date_modification = NOW() ".
"WHERE ce_observation IN ($idsObsConcat) ".
' -- '.__FILE__.':'.__LINE__;
$resultatImg = Cel::db()->executer($requete);
return ($resultatObs != 0 && $resultatImg != 0);
}
private function verifierRessources($ressources) {
if (!isset($ressources[0])) {
return false;
} else {
$this->controleUtilisateur($ressources[0]);
$this->idUtilisateur = $ressources[0];
}
if (!isset($ressources[1])) {
return false;
} else {
$this->ordres = $ressources[1];
}
}
private function verifierData($data) {
$transmission = (int) $data['transmission'];
if ($transmission != 0 && $transmission != 1) {
return false;
}
}
private function getIdsObs() {
$idUtilisateurP = Cel::db()->proteger($this->idUtilisateur);
$ordres = $this->nettoyerOrdres();
$ordreConcat = implode(',', $ordres);
$requete = 'SELECT id_observation '.
'FROM cel_obs '.
"WHERE ce_utilisateur = $idUtilisateurP ".
"AND ordre IN ($ordreConcat) ".
' -- '.__FILE__.':'.__LINE__;
$resultats = Cel::db()->executer($requete);
$idsObs = array();
if ($idsObs && is_array($idsObs)) {
foreach ($resultats as $infos) {
$idsObs[] = $infos['id_observation'];
}
}
return $idsObs;
}
private function nettoyerOrdres() {
$ordres = explode(',', $this->ordres);
$ordresNettoyes = array();
foreach ($ordres as $ordre) {
if (preg_match('/^\d+$/', $ordre)) {
$ordresNettoyes[] = $ordre;
}
}
return $ordresNettoyes;
}
}