Subversion Repositories Applications.referentiel

Compare Revisions

Ignore whitespace Rev 22 → Rev 23

/trunk/services/modules/Traitement.php
New file
0,0 → 1,78
<?php
/**
* Service permettant d'enregistrer une demande de traitement ou de consulter les infos sur les traitements.
* Encodage en entrée : utf8
* Encodage en sortie : utf8
*
* @category Php 5.2
* @package Referentiel
* @author Jean-Pascal MILCENT <jpm@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 2010 Tela-Botanica
* @version $Id$
*/
class Traitement extends Ref {
/**
* Méthode principale appelée avec une requête de type GET.
*/
public function getElement($param = array()) {
// Initialisation des variables
$info = array();
// Nour recherchons le type de requête demandé
$p = $this->traiterParametresUrl(array('type', 'projet'), $param, false);
$type = $p['type'];
$projet = $p['projet'];
if (!is_null($type)) {
if (!is_null($projet)) {
$methode = 'getElement'.$type;
if (method_exists($this, $methode)) {
//array_shift($param);
$info = $this->$methode($projet);
} else {
$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
}
} else {
$this->messages[] = "Veuillez préciser le nom de code du projet comme premier paramêtre (ex. : bdnff).";
}
} else {
$this->messages[] = "Veuillez préciser le type de requête.";
}
// Envoie sur la sortie standard
$this->envoyer($info);
}
/**
* Méthode appelée pour ajouter un traitement.
* Retour l'id du nouvel enregistrement ou false!
*/
public function createElement($params) {
$params_proteges = $this->traiterParametresPost(array('referentiel_code'), $params);
$meta_date_creation = date ("Y-m-d H:i:s");
$nom = $this->bdd->quote("Traitement {$params['referentiel_code']} - $meta_date_creation");
$meta_date_creation = $this->bdd->quote($meta_date_creation);
try {
$requete = "INSERT INTO ref_traitement ".
' (referentiel_code, nom, meta_date_creation) '.
" VALUES ({$params_proteges['referentiel_code']}, $nom, $meta_date_creation) ";
$resultat = $this->bdd->exec($requete);
if ($resultat === false) {
$id = false;
$this->debug[] = "Traitement NON ajouté.";
} else {
$id = $this->bdd->lastInsertId();
}
} catch (PDOException $e) {
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
}
$this->envoyer($id);
}
}
?>