425 lines
8.7 KiB
PHP
Executable File
425 lines
8.7 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
use \manager\ModuleRequest;
|
|
use \manager\sessionManager;
|
|
use \manager\ResourceDispatcher;
|
|
use \manager\ManagerError;
|
|
use \manager\Repo;
|
|
use \manager\Database;
|
|
|
|
|
|
use \manager\ORM\Table;
|
|
use \manager\ORM\Rows;
|
|
use \manager\ORM\Row;
|
|
|
|
debug();
|
|
|
|
|
|
|
|
|
|
|
|
/* INSERTION DES UTILISATEURS DANS LA BDD DEPUIS JSON
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function insertUsersFromJSON(){
|
|
$json = file_get_contents(__ROOT__.'/config/generated_users.json');
|
|
$json = json_decode( $json, true );
|
|
|
|
// Pour chaque entree
|
|
foreach( $json as $user ){
|
|
|
|
// Creation de la requete
|
|
$request = new ModuleRequest('userDefault/create', [
|
|
'code' => $user['code'],
|
|
'username' => $user['username'],
|
|
'firstname' => $user['firstname'],
|
|
'lastname' => $user['lastname'],
|
|
'mail' => $user['email'],
|
|
'password' => $user['password'],
|
|
'status' => $user['status']
|
|
]);
|
|
$answer = $request->dispatch();
|
|
|
|
// Debug error
|
|
if( $answer->error != ManagerError::Success )
|
|
var_dump( $answer->error );
|
|
}
|
|
|
|
return true;
|
|
|
|
}//insertUsersFromJSON();
|
|
|
|
|
|
|
|
|
|
/* NSERTION DES MACHINES DANS LA BDD DEPUIS JSON
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function insertMachinesFromJSON(){
|
|
$json = file_get_contents(__ROOT__.'/config/generated_machines.json');
|
|
$json = json_decode( $json, true );
|
|
|
|
// Pour chaque entree
|
|
foreach( $json as $machine ){
|
|
|
|
// Creation de la requete
|
|
$request = new ModuleRequest('machineDefault/create', [
|
|
'name' => $machine['name']
|
|
]);
|
|
$answer = $request->dispatch();
|
|
|
|
// Debug error
|
|
if( $answer->error != ManagerError::Success )
|
|
var_dump( $answer->error );
|
|
}
|
|
|
|
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', ['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', ['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', ['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', [$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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* MODIFICATION D'UN UTILISATEUR
|
|
*
|
|
*
|
|
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
|
|
*
|
|
*/
|
|
function editUser(){
|
|
$id_user = 48;
|
|
|
|
$request = new ModuleRequest('userDefault/edit', array(
|
|
'B1-87-EA-BF',
|
|
'Abigail',
|
|
'Mcmillan',
|
|
'Savage',
|
|
'mcmillansavage@corecom.com',
|
|
'password',
|
|
0
|
|
));
|
|
|
|
|
|
// ["B1-87-EA-BF","Abigail01","Mcmillan","Savage","mcmillansavage@corecom.com","password",0]
|
|
|
|
var_dump( $request->dispatch() );
|
|
|
|
|
|
return true;
|
|
|
|
}//editUser();
|
|
|
|
|
|
// new ResourceDispatcher('f/svg/search/st/sub-menu-side/ff0000', true);
|
|
|
|
|
|
|
|
|
|
|
|
function createWarehouse(){
|
|
|
|
$insert = new Repo('admin/create', [
|
|
'FirstAdmin',
|
|
'adminmail@gmail.com',
|
|
'AdminPassword'
|
|
]);
|
|
var_dump( $insert->answer() );
|
|
|
|
|
|
$getAll = new Repo('admin/getAll');
|
|
}//createWarehouse();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug();
|
|
|
|
// $warehouse =
|
|
// Table::get('warehouse') // Access to table 'warehouse'
|
|
// ->whereName(['stef-montauban', Rows::COND_NOTEQ]); // condition : name = 'my-warehouse'
|
|
//
|
|
//
|
|
// $myUser =
|
|
// Table::get('user') // Access to table 'user'
|
|
// ->whereId([100, Rows::COND_INF]) // PRIMARY KEY (other condition on same field)
|
|
// ->whereUsername(['jo%', Rows::COND_LIKE]) // Dynamic getter 'getByMySuperColumn' -> 'my_super_column'
|
|
// ->select(['mail', 'username', 'firstname']) // Select clause
|
|
// ->select('id_user') // Select clause (added)
|
|
// ->join('id_warehouse', $warehouse) // joins warehouse (with name 'my-warehouse') to column 'id_warehouse'
|
|
// ->unique() // unique result
|
|
|
|
|
|
// SELECT
|
|
// ->fetch(); // Result
|
|
|
|
// UPDATE
|
|
// ->edit([
|
|
// 'id_warehouse' => Table::get('warehouse')->whereName('stef-montauban')->unique()->select('id_warehouse')->fetch()['id_warehouse']
|
|
// ]);
|
|
|
|
|
|
$id_user = 10;
|
|
$id_warehouse = 7;
|
|
$code = '13-34-56-67';
|
|
$username = '13';
|
|
$firstname = '12';
|
|
$lastname = '12';
|
|
$mail = '12@ds.com';
|
|
|
|
|
|
// $edit_user = Database::getPDO()->prepare("UPDATE user
|
|
// SET code = :code,
|
|
// username = :username,
|
|
// firstname = :firstname,
|
|
// lastname = :lastname,
|
|
// mail = :mail
|
|
// WHERE id_user = :id_user
|
|
// AND id_warehouse = :id_warehouse");
|
|
// $edit_user->execute([
|
|
// ':code' => $code,
|
|
// ':username' => $username,
|
|
// ':firstname' => $firstname,
|
|
// ':lastname' => $lastname,
|
|
// ':mail' => $mail,
|
|
// ':id_user' => $id_user,
|
|
// ':id_warehouse' => $id_warehouse
|
|
// ]);
|
|
|
|
|
|
|
|
// With ORM
|
|
$insert = Table::get('user')
|
|
->insert([
|
|
[
|
|
'id_user' => Rows::DEFAULT,
|
|
'id_warehouse' => 7,
|
|
'code' => 'AA-AA-AA-AA',
|
|
'username' => 'AA',
|
|
'firstname' => 'AA',
|
|
'lastname' => 'AA',
|
|
'mail' => 'AA@AA.AA'
|
|
],
|
|
[
|
|
'id_user' => Rows::DEFAULT,
|
|
'id_warehouse' => 7,
|
|
'code' => 'BB-BB-BB-BB',
|
|
'username' => 'BB',
|
|
'firstname' => 'BB',
|
|
'lastname' => 'BB',
|
|
'mail' => 'BB@BB.BB'
|
|
]
|
|
]);
|
|
|
|
|
|
var_dump($insert);
|
|
|
|
?>
|