Subversion Repositories eFlore/Applications.cel

Rev

Rev 2458 | Rev 2486 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
2458 jpm 2
// declare(encoding='UTF-8');
3
/**
4
 * Service rendant publique une observation.
5
 *
6
 * @internal   Mininum PHP version : 5.2
7
 * @category   CEL
8
 * @package    Services
9
 * @subpackage Observations
10
 * @version    0.1
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
1867 raphael 17
 */
762 aurelien 18
class InventoryTransmit extends Cel  {
1301 aurelien 19
 
2461 jpm 20
	private $idUtilisateur = null;
21
	private $ordres = null;
22
 
23
	public function updateElement($ressources, $data) {
24
		$this->verifierRessources($ressources);
25
		$this->verifierData($data);
26
 
27
		$transmission = intval($data['transmission']);
28
		$date = ($transmission == 1) ? 'NOW()' : 'NULL';
29
 
30
		$idsObsConcat = implode(',', $this->getIdsObs());
31
 
32
		$requete = 'UPDATE cel_obs '.
33
			"SET transmission = $transmission, date_transmission = $date, date_modification = NOW() ".
34
			"WHERE id_observation IN ($idsObsConcat) ".
35
			' -- '.__FILE__.':'.__LINE__;
36
		$resultatObs = Cel::db()->executer($requete);
37
 
38
		$requete = 'UPDATE cel_images '.
39
			"SET transmission = $transmission, date_transmission = $date, date_modification = NOW() ".
40
			"WHERE ce_observation IN ($idsObsConcat) ".
41
			' -- '.__FILE__.':'.__LINE__;
42
		$resultatImg = Cel::db()->executer($requete);
43
 
44
		return ($resultatObs != 0 && $resultatImg != 0);
45
	}
46
 
47
	private function verifierRessources($ressources) {
48
		if (!isset($ressources[0])) {
2458 jpm 49
			return false;
2461 jpm 50
		} else {
51
			$this->controleUtilisateur($ressources[0]);
52
			$this->idUtilisateur = $ressources[0];
2458 jpm 53
		}
2461 jpm 54
		if (!isset($ressources[1])) {
55
			return false;
56
		} else {
57
			$this->ordres = $ressources[1];
58
		}
59
	}
60
 
61
	private function verifierData($data) {
62
		$transmission = (int) $data['transmission'];
2458 jpm 63
		if ($transmission != 0 && $transmission != 1) {
64
			return false;
65
		}
2461 jpm 66
	}
416 aurelien 67
 
2461 jpm 68
	private function getIdsObs() {
69
		$idUtilisateurP = Cel::db()->proteger($this->idUtilisateur);
70
		$ordres = $this->nettoyerOrdres();
71
		$ordreConcat = implode(',', $ordres);
2458 jpm 72
 
2461 jpm 73
		$requete = 'SELECT id_observation '.
74
			'FROM cel_obs '.
75
			"WHERE ce_utilisateur = $idUtilisateurP ".
76
			"AND ordre IN ($ordreConcat) ".
2458 jpm 77
			' -- '.__FILE__.':'.__LINE__;
2461 jpm 78
		$resultats = Cel::db()->executer($requete);
79
 
80
		$idsObs = array();
81
		if ($idsObs && is_array($idsObs)) {
82
			foreach ($resultats as $infos) {
83
				$idsObs[] = $infos['id_observation'];
84
			}
85
		}
86
		return $idsObs;
416 aurelien 87
	}
2461 jpm 88
 
89
	private function nettoyerOrdres() {
90
		$ordres = explode(',', $this->ordres);
91
		$ordresNettoyes = array();
92
		foreach ($ordres as $ordre) {
93
			if (preg_match('/^\d+$/', $ordre)) {
94
				$ordresNettoyes[] = $ordre;
95
			}
96
		}
97
		return $ordresNettoyes;
98
	}
2458 jpm 99
}