2016-02-04 22:45:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager;
|
|
|
|
|
|
|
|
|
|
|
|
// FORMAT:
|
|
|
|
//
|
|
|
|
// path: "nomModule/nomMethode"
|
|
|
|
// data1: {donnee1}
|
|
|
|
// data2: {donnee2}
|
|
|
|
// ...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
class ModuleAnswer{
|
|
|
|
|
|
|
|
// Attributs prives utiles (initialisation)
|
|
|
|
private $data;
|
|
|
|
public $error;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* CONSTRUCTEUR D'UNE REPONSE DE MODULE
|
|
|
|
*
|
2016-02-05 08:10:37 +00:00
|
|
|
* @error<ModuleError> Erreur passee par la requete (si existe)
|
|
|
|
*
|
2016-02-04 22:45:03 +00:00
|
|
|
*/
|
2016-02-05 08:10:37 +00:00
|
|
|
public function __construct($error=ManagerError::Success){
|
2016-02-04 23:07:03 +00:00
|
|
|
$this->data = array();
|
2016-02-05 08:10:37 +00:00
|
|
|
$this->error = $error;
|
2016-02-04 22:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 23:07:03 +00:00
|
|
|
/* AJOUTE UNE DONNEE A LA REPONSE
|
2016-02-04 22:45:03 +00:00
|
|
|
*
|
2016-02-04 23:07:03 +00:00
|
|
|
* @key<String> Le nom de la valeur a ajouter
|
2016-02-05 07:54:21 +00:00
|
|
|
* @value<mixed*> La valeur a ajouter
|
2016-02-04 22:45:03 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-02-04 23:07:03 +00:00
|
|
|
public function append($key, $value){
|
|
|
|
// Ajoute une entree pour la cle @key et de valeur @value
|
|
|
|
$this->data[$key] = $value;
|
2016-02-04 22:45:03 +00:00
|
|
|
|
2016-02-04 23:07:03 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2016-02-04 22:45:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 23:07:03 +00:00
|
|
|
/* AJOUTE TOUTES LES DONNEES A LA REPONSE
|
2016-02-04 22:45:03 +00:00
|
|
|
*
|
2016-02-04 23:07:03 +00:00
|
|
|
* @dataset<Array> Le tableau associatif correspondant a la reponse
|
2016-02-04 22:45:03 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-02-04 23:07:03 +00:00
|
|
|
public function appendAll($dataset){
|
|
|
|
// Ajoute une entree pour la cle @key et de valeur @value
|
|
|
|
$this->data = $dataset;
|
2016-02-04 22:45:03 +00:00
|
|
|
|
2016-02-04 23:07:03 +00:00
|
|
|
return $this;
|
2016-02-04 22:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-05 07:54:21 +00:00
|
|
|
|
|
|
|
/* RECUPERE UNE DONNEE DE LA REPONSE
|
|
|
|
*
|
|
|
|
* @key<String> Le nom de la valeur a recuperer
|
|
|
|
*
|
|
|
|
* @return value<mixed*> La valeur a cette cle
|
|
|
|
* @return error<null> Retourne NULL si aucune valeur pour cette cle
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get($key){
|
|
|
|
// Si la valeur de cle @key n'existe pas, on retourne NULL
|
|
|
|
if( !isset($this->data[$key]) )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// Sinon, on retourne la valeur associee
|
|
|
|
return $this->data[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RECUPERE TOUTES LES DONNEES DE LA REPONSE
|
|
|
|
*
|
|
|
|
* @return data<Array> Les donnees de la reponse
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function getAll(){
|
|
|
|
// Sinon, on retourne la valeur associee
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 23:07:03 +00:00
|
|
|
/* SERIALISATION A PARTIR DES DONNEES
|
2016-02-04 22:45:03 +00:00
|
|
|
*
|
2016-02-04 23:07:03 +00:00
|
|
|
* @return json<String> Retourne les donnees serialisees
|
2016-02-04 22:45:03 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-02-04 23:07:03 +00:00
|
|
|
public function serialize(){
|
2016-02-04 22:45:03 +00:00
|
|
|
|
2016-02-08 20:46:11 +00:00
|
|
|
// On rajoute l'erreur au message
|
|
|
|
$returnData = array_merge( array('ModuleError' => $this->error), $this->data );
|
2016-02-05 08:10:37 +00:00
|
|
|
|
|
|
|
return json_encode($returnData);
|
2016-02-04 22:45:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|