Subversion Repositories Applications.referentiel

Rev

Rev 24 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
23 jpm 1
<?php
2
/**
3
 * Service permettant d'enregistrer une demande de traitement ou de consulter les infos sur les traitements.
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
6
 *
7
 * @category	Php 5.2
8
 * @package		Referentiel
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
 * @copyright	2010 Tela-Botanica
13
 * @version		$Id$
14
 */
15
class Traitement extends Ref {
16
	/**
17
	 * Méthode principale appelée avec une requête de type GET.
18
	 */
19
	public function getElement($param = array()) {
20
		// Initialisation des variables
21
		$info = array();
22
 
23
		// Nour recherchons le type de requête demandé
24
		$p = $this->traiterParametresUrl(array('type', 'projet'), $param, false);
25
 
26
		$type = $p['type'];
27
		$projet = $p['projet'];
28
 
29
		if (!is_null($type)) {
30
			if (!is_null($projet)) {
31
				$methode = 'getElement'.$type;
32
				if (method_exists($this, $methode)) {
33
					//array_shift($param);
34
					$info = $this->$methode($projet);
35
				} else {
36
					$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
37
				}
38
 
39
			} else {
40
				$this->messages[] = "Veuillez préciser le nom de code du projet comme premier paramêtre (ex. : bdnff).";
41
			}
42
		} else {
43
			$this->messages[] = "Veuillez préciser le type de requête.";
44
		}
45
 
46
		// Envoie sur la sortie standard
47
		$this->envoyer($info);
48
	}
49
 
50
	/**
51
	 * Méthode appelée pour ajouter un traitement.
52
	 * Retour l'id du nouvel enregistrement ou false!
53
	 */
54
	public function createElement($params) {
55
		$params_proteges = $this->traiterParametresPost(array('referentiel_code'), $params);
56
		$meta_date_creation = date ("Y-m-d H:i:s");
57
		$nom = $this->bdd->quote("Traitement {$params['referentiel_code']} - $meta_date_creation");
58
		$meta_date_creation = $this->bdd->quote($meta_date_creation);
59
 
60
		try {
61
			$requete = 	"INSERT INTO ref_traitement ".
62
   						' (referentiel_code, nom, meta_date_creation) '.
63
						" VALUES ({$params_proteges['referentiel_code']}, $nom, $meta_date_creation) ";
64
			$resultat = $this->bdd->exec($requete);
65
			if ($resultat === false) {
66
				$id = false;
67
				$this->debug[] = "Traitement NON ajouté.";
68
			} else {
69
				$id = $this->bdd->lastInsertId();
70
			}
71
		} catch (PDOException $e) {
72
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
73
		}
74
 
75
	   	$this->envoyer($id);
76
	}
77
}
78
?>