Subversion Repositories Applications.referentiel

Rev

Rev 23 | Rev 26 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23 Rev 24
1
<?php
1
<?php
2
/**
2
/**
3
 * Service permettant d'enregistrer une demande de traitement ou de consulter les infos sur les traitements.
3
 * Service permettant d'enregistrer une demande de traitement ou de consulter les infos sur les traitements.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 *
6
 *
7
 * @category	Php 5.2
7
 * @category	Php 5.2
8
 * @package		Referentiel
8
 * @package		Referentiel
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
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>
11
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
 * @copyright	2010 Tela-Botanica
12
 * @copyright	2010 Tela-Botanica
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class Traitement extends Ref {
15
class Traitement extends Ref {
-
 
16
	
16
	/**
17
	/**
17
	 * Méthode principale appelée avec une requête de type GET.
18
	 * Méthode principale appelée avec une requête de type GET.
18
	 */
19
	 */
19
	public function getElement($param = array()) {
20
	public function getElement($param = array()) {
20
		// Initialisation des variables
21
		// Initialisation des variables
21
		$info = array();
22
		$info = array();
22
				
23
				
23
		// Nour recherchons le type de requête demandé
24
		// Nour recherchons le type de requête demandé
24
		$p = $this->traiterParametresUrl(array('type', 'projet'), $param, false);
25
		$p = $this->traiterParametresUrl(array('type', 'projet'), $param, false);
25
		
26
		
26
		$type = $p['type'];
27
		$type = $p['type'];
27
		$projet = $p['projet'];
28
		$projet = $p['projet'];
28
		
29
		
29
		if (!is_null($type)) {
30
		if (!is_null($type)) {
30
			if (!is_null($projet)) {
31
			if (!is_null($projet)) {
31
				$methode = 'getElement'.$type;
32
				$methode = 'getElement'.$type;
32
				if (method_exists($this, $methode)) {
33
				if (method_exists($this, $methode)) {
33
					//array_shift($param);
34
					//array_shift($param);
34
					$info = $this->$methode($projet);
35
					$info = $this->$methode($projet);
35
				} else {
36
				} else {
36
					$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
37
					$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
37
				}
38
				}
38
				
39
				
39
			} else {
40
			} else {
40
				$this->messages[] = "Veuillez préciser le nom de code du projet comme premier paramêtre (ex. : bdnff).";
41
				$this->messages[] = "Veuillez préciser le nom de code du projet comme premier paramêtre (ex. : bdnff).";
41
			}
42
			}
42
		} else {
43
		} else {
43
			$this->messages[] = "Veuillez préciser le type de requête.";
44
			$this->messages[] = "Veuillez préciser le type de requête.";
44
		}
45
		}
45
		
46
		
46
		// Envoie sur la sortie standard
47
		// Envoie sur la sortie standard
47
		$this->envoyer($info);
48
		$this->envoyer($info);
48
	}
49
	}
-
 
50
	
-
 
51
	/**
-
 
52
	 * Retourne les infos sur les traitements en cours ou en attentes.
-
 
53
	 */
-
 
54
	public function getElementEnCours($projet) {
-
 
55
		$projet = $this->bdd->quote($projet);
-
 
56
		$requete =	($this->distinct ? 'SELECT DISTINCT' : 'SELECT').' * '.
-
 
57
					'FROM ref_traitement '.
-
 
58
					"WHERE referentiel_code = $projet ".
-
 
59
					'	AND date_fin IS NULL '.
-
 
60
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'meta_date_creation  DESC').' ';
-
 
61
		$this->debug[] = $requete;
-
 
62
		
-
 
63
		// Récupération des résultats
-
 
64
		try {
-
 
65
			$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
-
 
66
			if ($donnees === false) {
-
 
67
				$this->messages[] = "La requête a retourné aucun résultat.";
-
 
68
			}
-
 
69
		} catch (PDOException $e) {
-
 
70
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
-
 
71
		}
-
 
72
		return $donnees;
-
 
73
	}
49
	
74
	
50
	/**
75
	/**
51
	 * Méthode appelée pour ajouter un traitement.
76
	 * Méthode appelée pour ajouter un traitement.
52
	 * Retour l'id du nouvel enregistrement ou false!
77
	 * Retour l'id du nouvel enregistrement ou false!
53
	 */
78
	 */
54
	public function createElement($params) {
79
	public function createElement($params) {
55
		$params_proteges = $this->traiterParametresPost(array('referentiel_code'), $params);
80
		$params_proteges = $this->traiterParametresPost(array('referentiel_code'), $params);
56
		$meta_date_creation = date ("Y-m-d H:i:s");
81
		$meta_date_creation = date ("Y-m-d H:i:s");
57
		$nom = $this->bdd->quote("Traitement {$params['referentiel_code']} - $meta_date_creation");
82
		$nom = $this->bdd->quote("Traitement {$params['referentiel_code']} - $meta_date_creation");
58
		$meta_date_creation = $this->bdd->quote($meta_date_creation);
83
		$meta_date_creation = $this->bdd->quote($meta_date_creation);
59
		
84
		
60
		try {
85
		try {
61
			$requete = 	"INSERT INTO ref_traitement ".
86
			$requete = 	"INSERT INTO ref_traitement ".
62
   						' (referentiel_code, nom, meta_date_creation) '.
87
   						' (referentiel_code, nom, meta_date_creation) '.
63
						" VALUES ({$params_proteges['referentiel_code']}, $nom, $meta_date_creation) ";
88
						" VALUES ({$params_proteges['referentiel_code']}, $nom, $meta_date_creation) ";
64
			$resultat = $this->bdd->exec($requete);
89
			$resultat = $this->bdd->exec($requete);
65
			if ($resultat === false) {
90
			if ($resultat === false) {
66
				$id = false;
91
				$id = false;
67
				$this->debug[] = "Traitement NON ajouté.";
92
				$this->debug[] = "Traitement NON ajouté.";
68
			} else {
93
			} else {
69
				$id = $this->bdd->lastInsertId();
94
				$id = $this->bdd->lastInsertId();
70
			}
95
			}
71
		} catch (PDOException $e) {
96
		} catch (PDOException $e) {
72
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
97
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
73
		}
98
		}
74
	   	
99
	   	
75
	   	$this->envoyer($id);
100
	   	$this->envoyer($id);
76
	}
101
	}
77
}
102
}
78
?>
103
?>