286 lines
5.6 KiB
PHP
Executable File
286 lines
5.6 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(__FILE__) );
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
use \manager\ModuleRequest;
|
|
use \manager\ResourceDispatcher;
|
|
use \manager\ManagerError;
|
|
use \manager\Repo;
|
|
|
|
debug();
|
|
|
|
|
|
|
|
|
|
|
|
/* NSERTION DES UTILISATEURS DANS LA BDD DEPUIS JSON
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function insertUsersFromJSON(){
|
|
$json = ResourceDispatcher::getResource('f/json/generated_users/conf');
|
|
$json = json_decode( $json, true );
|
|
|
|
// Pour chaque entree
|
|
foreach( $json as $user ){
|
|
|
|
$insertRequest = Database::getPDO()->prepare("INSERT INTO user(id_user, code, username, firstname, lastname, mail, password, status)
|
|
VALUES(
|
|
DEFAULT,
|
|
:code,
|
|
:username,
|
|
:firstname,
|
|
:lastname,
|
|
:mail,
|
|
:password,
|
|
:status
|
|
)");
|
|
|
|
$status = $insertRequest->execute(array(
|
|
':code' => $user['code'],
|
|
':username' => $user['username'],
|
|
':firstname' => $user['firstname'],
|
|
':lastname' => $user['lastname'],
|
|
':mail' => $user['email'],
|
|
':password' => $user['password'],
|
|
':status' => $user['status']
|
|
));
|
|
|
|
var_dump( $status );
|
|
}
|
|
|
|
return true;
|
|
|
|
}// insertUsersFromJSON();
|
|
|
|
|
|
|
|
|
|
/* NSERTION DES MACHINES DANS LA BDD DEPUIS JSON
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function insertMachinesFromJSON(){
|
|
$json = ResourceDispatcher::getResource('f/json/generated_machines/conf');
|
|
$json = json_decode( $json, true );
|
|
|
|
// Pour chaque entree
|
|
foreach( $json as $machine ){
|
|
|
|
$insertRequest = Database::getPDO()->prepare("INSERT INTO machine(id_machine, code, name)
|
|
VALUES(
|
|
DEFAULT,
|
|
:code,
|
|
:name
|
|
)");
|
|
|
|
$status = $insertRequest->execute(array(
|
|
':code' => $machine['code'],
|
|
':name' => $machine['name']
|
|
));
|
|
|
|
var_dump( $status );
|
|
}
|
|
|
|
return true;
|
|
|
|
}//insertMachinesFromJSON();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* AFFICHAGE DES UTILISATEURS DE LA BDD
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function selectUsers(){
|
|
|
|
// Creation de la requete
|
|
$requete = new ModuleRequest('userDefault/getAll');
|
|
$answer = $requete->dispatch();
|
|
|
|
var_dump( ManagerError::explicit($answer->error) );
|
|
var_dump( $answer->get('users') );
|
|
|
|
return true;
|
|
|
|
}//selectUsers();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* AFFICHAGE DES MACHINES DE LA BDD
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function selectMachines(){
|
|
|
|
// Creation de la requete
|
|
$requete = new ModuleRequest('machineDefault/getAll');
|
|
$answer = $requete->dispatch();
|
|
|
|
var_dump( ManagerError::explicit($answer->error) );
|
|
var_dump( $answer->get('machines') );
|
|
|
|
return true;
|
|
|
|
}//selectMachines();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* AFFICHAGE DES UTILISATEURS DE LA BDD (MIS EN PAGE)
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function displayUsers(){
|
|
|
|
// Creation de la requete
|
|
$request = new ModuleRequest('userDefault/getAll');
|
|
$answer = $request->dispatch();
|
|
|
|
// Debug error
|
|
if( $answer->error != ManagerError::Success )
|
|
var_dump( ManagerError::explicit($answer->error) );
|
|
|
|
// display result
|
|
var_dump( $answer->getAll() );
|
|
|
|
return true;
|
|
|
|
}//displayUsers();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* TEST DU DISPATCHER DES MANAGERS
|
|
*
|
|
* @return nomRetour<typeRetour> Description du retour
|
|
|
|
*/
|
|
function testModuleDispatcher(){
|
|
|
|
// Creation d'une requete en objet
|
|
$req1 = new ModuleRequest('firstModule/returnvar', array('id_user' => 10, 'code' => '11-22-33-44') );
|
|
// Creation d'une requete a partir d'un json en <String>
|
|
$req2 = ModuleRequest::fromString('{"path": "firstModule/returnvar", "data": {"id_user":10, "code":"11-22-33-44"}}');
|
|
|
|
var_dump( $req1->dispatch() );
|
|
|
|
return true;
|
|
|
|
}//testModuleDispatcher();
|
|
|
|
|
|
|
|
|
|
|
|
/* TEST DU DISPATCHER DES REPO
|
|
*
|
|
* @return nomRetour<typeRetour> Description du retour
|
|
|
|
*/
|
|
function testRepoDispatcher(){
|
|
|
|
// Creation d'une requete en objet
|
|
$req1 = new Repo('user/getById', array('19'));
|
|
// $req1 = new Repo('user/getByCode', array('92-55-B9-B3'));
|
|
var_dump( $req1->answer() );
|
|
|
|
if( $req1->error != ManagerError::Success )
|
|
var_dump( ManagerError::explicit($req1->error) );
|
|
|
|
|
|
return true;
|
|
|
|
}//testRepoDispatcher();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* INSERTION (COMPOSITE) DES UTILISATEURS DE LA BDD
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function insertUsersComposite(){
|
|
|
|
// Creation de la requete
|
|
$request = new ModuleRequest('userDefault/create', array('92-55-B9-B1', 'b', 'bla', 'bla', 'bla@test.com', 'sadas', '1') );
|
|
$answer = $request->dispatch();
|
|
// Debug error
|
|
if( $answer->error != ManagerError::Success )
|
|
var_dump( ManagerError::explicit($answer->error) );
|
|
|
|
var_dump( $answer->getAll() );
|
|
|
|
return true;
|
|
|
|
}//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();
|
|
?>
|