Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
1502 aurelien 1
<?php
1873 raphael 2
/**
3
 * @category  PHP
4
 * @package   jrest
5
 * @author    Aurélien Peronnet <aurelien@tela-botania.org>
6
 * @author    Raphaël Droz <raphael@tela-botania.org>
7
 * @copyright 2013 Tela-Botanica
8
 * @license   Licence CECILL <http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt>
9
 * @license	  GPL v3 <http://www.gnu.org/licenses/gpl.txt>
10
 *
11
 */
12
 
1502 aurelien 13
class CelValidationObservation extends Cel {
14
	/**
15
	* Méthode appelée avec une requête de type POST avec un identifiant d'obs.
16
	* Modifie le taxon associé à une observation avec les informations envoyées
1870 raphael 17
	* Utilisé par:
18
	* - del/services/modules/0.1/determinations/ValiderDetermination.php::modifierObservationParDetermination()
1502 aurelien 19
	*
20
	* @param int $uid[0] identifiant observation
21
	* @param pairs array tableau contenant les valeurs à modifier
1873 raphael 22
	* @param pairs['obsKeywordDelete'] optional string: mot-clef à délier à cette observation
1502 aurelien 23
	*/
1870 raphael 24
	public function updateElement($uid, $pairs) {
1502 aurelien 25
		// ce service est uniquement destiné à être appelé en local,
26
		// depuis le serveur lui même
27
		// en particulier par l'application identiplante
28
		$this->controleAppelIpAutorisee();
1870 raphael 29
		self::verifierParametresObligatoires($uid, $pairs);
1502 aurelien 30
		$id = $uid[0];
31
 
32
		$gestion_observation = new GestionObservation($this->config);
1873 raphael 33
		$pairs = array_map('trim', $pairs);
1502 aurelien 34
		$utilisateur = $pairs['ce_utilisateur'];
1870 raphael 35
		unset($pairs['ce_utilisateur'], $pairs['id_observation']);
1873 raphael 36
 
37
		// mise à jour des mots-clefs suite à une validation:
38
		// typiquement, DEL modifierObservationParDetermination()
39
		// nous enverra obsKeywordDelete=aDeterminer en plus de certitude=Certaine
40
		$obsKeywordDelete = @trim($pairs['obsKeywordDelete']);
41
		// $imgKeywordDelete = @trim($pairs['imgKeywordDelete']);
42
		unset($pairs['obsKeywordDelete']); // , $pairs['imgKeywordDelete']);
43
 
1502 aurelien 44
		$modification = $gestion_observation->modifierObservationPublique($utilisateur, $id, $pairs);
1870 raphael 45
		if($modification) {
1873 raphael 46
			// quel impact de ces valeurs de retour ?
47
			if($kid = InventoryKeyWordList::getMotsClefId($utilisateur, 'obs', $obsKeywordDelete))
48
				InventoryKeyWordObsLink::unlinkKeyword($this->config, 'obs', explode(',', $id), $utilisateur, $kid);
49
			/* if($kid = InventoryKeyWordList::getMotsClefId($utilisateur, 'images', $imgKeywordDelete))
50
			   InventoryKeyWordObsLink::unlinkKeyword($this->config, 'obs', explode(',', $id), $utilisateur, $kid); */
1870 raphael 51
			header("Content-Type: text/plain; charset=utf-8");
52
			die("OK"); // attention, compatibilité avec ValiderDetermination.php de DEL !
1502 aurelien 53
		}
1870 raphael 54
		elseif($modification === 0) {
55
			http_response_code(304); // Not Modified
56
			header("Content-Type: text/plain; charset=utf-8");
57
			die("Not Modified");
58
		}
59
		else {
60
			http_response_code(500); // Internal Server Error
61
			header("Content-Type: text/plain; charset=utf-8");
62
			die("Impossible de modifier l'observation associée à cet identifiant " . mysql_error());
63
		}
1502 aurelien 64
	}
65
 
1870 raphael 66
	static function verifierParametresObligatoires($uid, $params) {
67
		if(!@intval($uid[0]) || !@intval($params['id_observation'])) {
68
			header("Content-Type: text/plain; charset=utf-8");
69
			die("L'identifiant d'observation doit être un entier");
1502 aurelien 70
		}
1870 raphael 71
 
72
		// TODO: check sur 'id_observation' en tant que param est superflu ?
73
		$params_obligatoires = array('id_observation', 'ce_utilisateur', 'nom_sel');
1502 aurelien 74
		foreach($params_obligatoires as $param) {
1870 raphael 75
			if(@trim($params[$param])) continue;
76
			http_response_code(412); // Precondition Failed
77
			header("Content-Type: text/plain; charset=utf-8");
78
			die(sprintf("Paramètre %s manquant (parmi %s)", $param, implode(', ', $params_obligatoires)));
1502 aurelien 79
		}
80
	}
81
}