2016-02-04 18:23:16 +00:00
|
|
|
<?php define('__ROOT__', dirname(__FILE__) );
|
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
use \manager\ModuleRequest;
|
|
|
|
use \manager\ResourceDispatcher;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Repo;
|
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
debug();
|
2016-02-04 18:23:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* NSERTION DES UTILISATEURS DANS LA BDD DEPUIS JSON
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function insertUsersFromJSON(){
|
2016-02-14 11:37:19 +00:00
|
|
|
$json = ResourceDispatcher::getResource('f/json/generated_users/conf');
|
2016-02-04 18:23:16 +00:00
|
|
|
$json = json_decode( $json, true );
|
|
|
|
|
|
|
|
// Pour chaque entree
|
|
|
|
foreach( $json as $user ){
|
|
|
|
|
2016-02-14 12:55:06 +00:00
|
|
|
// Creation de la requete
|
|
|
|
$request = new ModuleRequest('userDefault/create', array(
|
|
|
|
$user['code'],
|
|
|
|
$user['username'],
|
|
|
|
$user['firstname'],
|
|
|
|
$user['lastname'],
|
|
|
|
$user['email'],
|
|
|
|
$user['password'],
|
|
|
|
$user['status']
|
2016-02-04 18:23:16 +00:00
|
|
|
));
|
2016-02-14 12:55:06 +00:00
|
|
|
$answer = $request->dispatch();
|
|
|
|
// Debug error
|
|
|
|
var_dump( $answer->error == ManagerError::Success );
|
2016-02-04 18:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
}//insertUsersFromJSON();
|
2016-02-04 18:23:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-10 07:54:23 +00:00
|
|
|
/* NSERTION DES MACHINES DANS LA BDD DEPUIS JSON
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function insertMachinesFromJSON(){
|
2016-02-14 11:37:19 +00:00
|
|
|
$json = ResourceDispatcher::getResource('f/json/generated_machines/conf');
|
2016-02-10 07:54:23 +00:00
|
|
|
$json = json_decode( $json, true );
|
|
|
|
|
|
|
|
// Pour chaque entree
|
|
|
|
foreach( $json as $machine ){
|
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
// Creation de la requete
|
|
|
|
$request = new ModuleRequest('machineDefault/create', array(
|
|
|
|
$machine['code'],
|
|
|
|
$machine['name']
|
2016-02-10 07:54:23 +00:00
|
|
|
));
|
2016-02-14 13:16:47 +00:00
|
|
|
$answer = $request->dispatch();
|
|
|
|
// Debug error
|
|
|
|
var_dump( $answer->error == ManagerError::Success );
|
2016-02-10 07:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
}//insertMachinesFromJSON();
|
2016-02-10 07:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 18:23:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 19:21:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* AFFICHAGE DES UTILISATEURS DE LA BDD
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function selectUsers(){
|
|
|
|
|
|
|
|
// Creation de la requete
|
2016-02-14 11:37:19 +00:00
|
|
|
$requete = new ModuleRequest('userDefault/getAll');
|
2016-02-04 23:07:03 +00:00
|
|
|
$answer = $requete->dispatch();
|
2016-02-04 19:21:01 +00:00
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
var_dump( ManagerError::explicit($answer->error) );
|
2016-02-05 07:54:21 +00:00
|
|
|
var_dump( $answer->get('users') );
|
2016-02-04 20:15:43 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-10 07:54:23 +00:00
|
|
|
}//selectUsers();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* AFFICHAGE DES MACHINES DE LA BDD
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function selectMachines(){
|
|
|
|
|
|
|
|
// Creation de la requete
|
2016-02-14 11:37:19 +00:00
|
|
|
$requete = new ModuleRequest('machineDefault/getAll');
|
2016-02-10 07:54:23 +00:00
|
|
|
$answer = $requete->dispatch();
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
var_dump( ManagerError::explicit($answer->error) );
|
2016-02-10 07:54:23 +00:00
|
|
|
var_dump( $answer->get('machines') );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-11 09:34:26 +00:00
|
|
|
}//selectMachines();
|
2016-02-04 20:15:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 19:21:01 +00:00
|
|
|
|
|
|
|
|
2016-02-04 20:15:43 +00:00
|
|
|
|
|
|
|
/* AFFICHAGE DES UTILISATEURS DE LA BDD (MIS EN PAGE)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function displayUsers(){
|
|
|
|
|
|
|
|
// Creation de la requete
|
2016-02-14 11:37:19 +00:00
|
|
|
$request = new ModuleRequest('userDefault/getAll');
|
2016-02-05 08:18:01 +00:00
|
|
|
$answer = $request->dispatch();
|
2016-02-04 23:07:03 +00:00
|
|
|
|
2016-02-11 15:00:41 +00:00
|
|
|
// Debug error
|
2016-02-14 11:37:19 +00:00
|
|
|
if( $answer->error != ManagerError::Success )
|
|
|
|
var_dump( ManagerError::explicit($answer->error) );
|
2016-02-04 20:15:43 +00:00
|
|
|
|
2016-02-11 15:00:41 +00:00
|
|
|
// display result
|
|
|
|
var_dump( $answer->getAll() );
|
2016-02-04 19:21:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-04 23:07:03 +00:00
|
|
|
}//displayUsers();
|
2016-02-04 19:21:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 18:23:16 +00:00
|
|
|
/* TEST DU DISPATCHER DES MANAGERS
|
|
|
|
*
|
|
|
|
* @return nomRetour<typeRetour> Description du retour
|
|
|
|
|
|
|
|
*/
|
|
|
|
function testModuleDispatcher(){
|
|
|
|
|
2016-02-04 19:21:01 +00:00
|
|
|
// Creation d'une requete en objet
|
2016-02-14 11:37:19 +00:00
|
|
|
$req1 = new ModuleRequest('firstModule/returnvar', array('id_user' => 10, 'code' => '11-22-33-44') );
|
2016-02-04 19:21:01 +00:00
|
|
|
// Creation d'une requete a partir d'un json en <String>
|
2016-02-14 11:37:19 +00:00
|
|
|
$req2 = ModuleRequest::fromString('{"path": "firstModule/returnvar", "data": {"id_user":10, "code":"11-22-33-44"}}');
|
2016-02-04 18:23:16 +00:00
|
|
|
|
2016-02-04 20:15:43 +00:00
|
|
|
var_dump( $req1->dispatch() );
|
2016-02-04 18:23:16 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-04 20:15:43 +00:00
|
|
|
}//testModuleDispatcher();
|
2016-02-04 18:23:16 +00:00
|
|
|
|
|
|
|
|
2016-02-11 09:34:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* TEST DU DISPATCHER DES REPO
|
|
|
|
*
|
|
|
|
* @return nomRetour<typeRetour> Description du retour
|
|
|
|
|
|
|
|
*/
|
|
|
|
function testRepoDispatcher(){
|
|
|
|
|
|
|
|
// Creation d'une requete en objet
|
2016-02-14 11:37:19 +00:00
|
|
|
$req1 = new Repo('user/getById', array('19'));
|
|
|
|
// $req1 = new Repo('user/getByCode', array('92-55-B9-B3'));
|
2016-02-11 09:34:26 +00:00
|
|
|
var_dump( $req1->answer() );
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
if( $req1->error != ManagerError::Success )
|
|
|
|
var_dump( ManagerError::explicit($req1->error) );
|
2016-02-11 09:34:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-11 15:00:41 +00:00
|
|
|
}//testRepoDispatcher();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* INSERTION (COMPOSITE) DES UTILISATEURS DE LA BDD
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function insertUsersComposite(){
|
|
|
|
|
|
|
|
// Creation de la requete
|
2016-02-14 11:37:19 +00:00
|
|
|
$request = new ModuleRequest('userDefault/create', array('92-55-B9-B1', 'b', 'bla', 'bla', 'bla@test.com', 'sadas', '1') );
|
2016-02-11 15:00:41 +00:00
|
|
|
$answer = $request->dispatch();
|
|
|
|
// Debug error
|
2016-02-14 11:37:19 +00:00
|
|
|
if( $answer->error != ManagerError::Success )
|
|
|
|
var_dump( ManagerError::explicit($answer->error) );
|
2016-02-11 15:00:41 +00:00
|
|
|
|
|
|
|
var_dump( $answer->getAll() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
}//insertUsersComposite();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RETOURNE LES GROUPES D'UN UTILISATEUR
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getUserClusters(){
|
|
|
|
$id_user = 115;
|
|
|
|
|
|
|
|
// Groupes de l'utilisateur 'a'
|
|
|
|
$getUser1Clusters = new Repo('user/getClusters', array($id_user));
|
|
|
|
$user1Clusters = $getUser1Clusters->answer();
|
|
|
|
var_dump( $user1Clusters );
|
|
|
|
|
|
|
|
// On ajoute un groupe a l'utilisateur 100
|
|
|
|
$linkA = new Repo('cluster/link', array($user1Clusters[0]['id_cluster'], 100) );
|
|
|
|
var_dump( $linkA->answer() );
|
|
|
|
$getUser2Clusters = new Repo('user/getClusters', array(100));
|
|
|
|
var_dump( $getUser2Clusters->answer() );
|
|
|
|
|
|
|
|
// On retire un groupe a l'utilisateur 100
|
|
|
|
$unlinkA = new Repo('cluster/unlink', array($user1Clusters[0]['id_cluster'], 100) );
|
|
|
|
var_dump( $linkA->answer() );
|
|
|
|
$getUser2Clusters = new Repo('user/getClusters', array(100));
|
|
|
|
var_dump( $getUser2Clusters->answer() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}//getUserClusters();
|
2016-02-14 14:53:59 +00:00
|
|
|
|
|
|
|
|
2016-02-04 18:23:16 +00:00
|
|
|
?>
|