SMMP/automate.php

202 lines
3.7 KiB
PHP
Raw Normal View History

<?php define('__ROOT__', dirname(__FILE__) );
require_once __ROOT__.'/manager/autoloader.php';
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
/* NSERTION DES UTILISATEURS DANS LA BDD DEPUIS JSON
*
*
* @return status<Boolean> TRUE si aucune erreur, sinon FALSE
*
*/
function insertUsersFromJSON(){
$json = \manager\ResourceDispatcher::getResource('f/json/generated_users/conf');
$json = json_decode( $json, true );
// Pour chaque entree
foreach( $json as $user ){
$insertRequest = \manager\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 = \manager\ResourceDispatcher::getResource('f/json/generated_machines/conf');
$json = json_decode( $json, true );
// Pour chaque entree
foreach( $json as $machine ){
$insertRequest = \manager\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 manager\ModuleRequest('userDefaultModule/getAll');
$answer = $requete->dispatch();
2016-02-05 08:18:01 +00:00
var_dump( \manager\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 manager\ModuleRequest('machineDefaultModule/getAll');
$answer = $requete->dispatch();
var_dump( \manager\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 \manager\ModuleRequest('firstModule/getUsers');
2016-02-05 08:18:01 +00:00
$answer = $request->dispatch();
// Debug error
2016-02-05 08:18:01 +00:00
var_dump( $answer->error );
var_dump( \manager\ManagerError::explicit($answer->error) );
2016-02-05 08:18:01 +00:00
$users = $answer->get('users');
return true;
}//displayUsers();
/* TEST DU DISPATCHER DES MANAGERS
*
* @return nomRetour<typeRetour> Description du retour
*/
function testModuleDispatcher(){
// Creation d'une requete en objet
$req1 = new manager\ModuleRequest('firstModule/returnvar', array('id_user' => 10, 'code' => '11-22-33-44') );
// Creation d'une requete a partir d'un json en <String>
$req2 = manager\ModuleRequest::fromString('{"path": "firstModule/returnvar", "data": {"id_user":10, "code":"11-22-33-44"}}');
var_dump( $req1->dispatch() );
return true;
}//testModuleDispatcher();
?>