Ajout de 'getById' utilisant la clé primaire pour 'parentRepo'

Gestion d'une clé primaire, une seule pour l'instant
This commit is contained in:
xdrm-brackets 2016-04-19 14:35:40 +02:00
parent 2cad3ac40e
commit 1b4b114225
14 changed files with 96 additions and 72 deletions

View File

@ -63,9 +63,13 @@
// var_dump($response); // var_dump($response);
// var_dump( Database::delNumeric( Database::getPDO()->query("SHOW COLUMNS FROM users")->fetchAll() ) );
var_dump( \manager\repo\user::getByLogin('xdrm') ); $req_users = new ModuleRequest('user/getAll');
// var_dump( \manager\repo\user::getByLogin('xdrm') ); $answer_users = $req_users->dispatch();
// var_dump( \manager\repo\subject::getByPseudo('jeannot') ); var_dump($answer_users->get('users'));
// var_dump( \manager\repo\user::getById(1) );
// // var_dump( \manager\repo\user::getByLogin('xdrm') );
// // var_dump( \manager\repo\subject::getById(1) );
?> ?>

View File

@ -87,7 +87,6 @@
} }
}, },
"call_log": { "call_log": {
"unserialize": { "unserialize": {
"description": "Recupere le contenu d'un fichier XML de journal d'appel.", "description": "Recupere le contenu d'un fichier XML de journal d'appel.",
@ -129,11 +128,11 @@
"generate": { "generate": {
"description": "Creation d'un token de nom et de duree donnee", "description": "Création d'un token de nom et de durée donnée",
"permissions": ["admin"], "permissions": ["admin"],
"parameters": { "parameters": {
"name": { "description": "Nom attribue au token", "type": "varchar(3,50)" }, "name": { "description": "Nom attribué au token", "type": "varchar(3,50)" },
"duration": { "description": "Duree du token en nombre de jours", "type": "numeric" } "duration": { "description": "Durée du token en nombre de jours", "type": "id" }
} }
} }
}, },

View File

@ -56,7 +56,7 @@ APIClass.prototype = {
/* DEBUG : affiche la réponse BRUTE de http://host/api/ */ /* DEBUG : affiche la réponse BRUTE de http://host/api/ */
// console.log('http://host/api/ => '+ptrAPI.xhr[i].responseText); // console.log('http://host/api/ => '+ptrAPI.xhr[i].responseText);
// console.log( JSON.parse(ptrAPI.xhr[i].responseText) ); console.log( JSON.parse(ptrAPI.xhr[i].responseText) );
/* si success de requête */ /* si success de requête */
if( [0,200].indexOf(ptrAPI.xhr[i].status) > -1 ){ // si fichier existe et reçu if( [0,200].indexOf(ptrAPI.xhr[i].status) > -1 ){ // si fichier existe et reçu

View File

@ -58,6 +58,41 @@
/* RETOURNE L'UTILISATEUR D'ID DONNE
*
* @id_user<int> UID de l'utilisateur en question
*
* @return user<Array> Tableau contenant les informations de l'utilisateur
*
*/
public static function getById($params){
extract($params);
/* [1] On recupere les donnees de l'utilisateur
=========================================================*/
$getUser = new Repo('user/getById', array($id_user));
$user_data = $getUser->answer();
// Si aucun utilisateur n'est trouve
if( $user_data === false ) return array('ModuleError' => ManagerError::ModuleError);
/* [2] On met les permissions au bon format (string -> array)
=========================================================*/
$user_data['permission'] = explode( ',', str_replace(' ', '', $user_data['permission']) );
/* [3] Gestion du retour
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'user' => $user_data
);
}
/* RETOURNE LA LISTE DE TOUS LES UTILISATEURS /* RETOURNE LA LISTE DE TOUS LES UTILISATEURS
* *
* @return users<Array> Tableau contenant les informations de tous les utilisateurs * @return users<Array> Tableau contenant les informations de tous les utilisateurs

View File

@ -31,30 +31,42 @@
/* [2] On charge la liste des colonnes de la table /* [2] On charge la liste des colonnes de la table
=========================================================*/ =========================================================*/
$getColumns = Database::getPDO()->query('SHOW COLUMNS FROM '.static::table_name()); $getColumns = Database::getPDO()->query('SHOW COLUMNS FROM '.static::table_name());
$cols = $getColumns->fetchAll(); $cols = Database::delNumeric( $getColumns->fetchAll() );
$table_columns = array(); $table_columns = array(
'_PRIMARY_' => array() // Contiendra les champs de la clé primaire
);
// On ajoute la liste des colonnes // On ajoute la liste des colonnes
foreach($cols as $column) foreach($cols as $column){
// On enregistre la clé primaire (si elle l'est)
if( $column['Key'] == 'PRI' ) array_push($table_columns['_PRIMARY_'], $column['Field']);
array_push($table_columns, $column['Field']); array_push($table_columns, $column['Field']);
}
/* [3] On vérifie que la valeur après 'get' est dans $table_columns /* [3] On vérifie que la valeur après 'get' est dans $table_columns
=========================================================*/ =========================================================*/
$columnName = strtolower($matches[1]); $columnName = strtolower($matches[1]);
$getAll = count($matches) > 2; // Si 'getAll' $getAll = count($matches) > 2; // Si 'getAll'
$getById = $columnName == 'id';
$getSomething = count($args) > 0 && in_array($columnName, $table_columns); // Si 'getX', et 'X' dans la liste des colonnes $getSomething = count($args) > 0 && in_array($columnName, $table_columns); // Si 'getX', et 'X' dans la liste des colonnes
// Si ni 'getAll' ni 'getSomething' -> erreur // Si ni 'getAll' ni 'getSomething' -> erreur
if( !$getAll && !$getSomething ) return false; if( !$getById && !$getAll && !$getSomething ) return false;
/* [4] On rédige la requête /* [4] On rédige la requête
=========================================================*/ =========================================================*/
$getRequestString = 'SELECT * FROM '.static::table_name(); $getRequestString = 'SELECT * FROM '.static::table_name();
// Si c'est 'getById', on ajoute une condition
if( $getById ){
$getRequestString .= ' WHERE '.$table_columns['_PRIMARY_'][0].' = :value';
// Si c'est 'getSomething', on ajoute une condition // Si c'est 'getSomething', on ajoute une condition
if( $getSomething ) $getRequestString .= ' WHERE '.$columnName.' = :value'; }else if( $getSomething )
$getRequestString .= ' WHERE '.$columnName.' = :value';
$getRequestString .= ' ORDER BY 1 ASC'; $getRequestString .= ' ORDER BY 1 ASC';
@ -65,7 +77,7 @@
=========================================================*/ =========================================================*/
// Si 'getSomething', on ajoute le champ // Si 'getSomething', on ajoute le champ
$getRequest->execute(array( $getRequest->execute(array(
':value' => $getSomething ? $args[0] : null ':value' => ($getSomething||$getById) ? $args[0] : null
)); ));

View File

@ -6,7 +6,7 @@
class subject extends parentRepo{ class subject extends parentRepo{
protected static function table_name(){ static $table_name = 'Personnes'; return $table_name; } protected static function table_name(){ static $table_name = 'sujets'; return $table_name; }
@ -21,9 +21,9 @@
public static function getById($id_subject){ public static function getById($id_subject){
/* [1] On effectue la requete /* [1] On effectue la requete
=========================================================*/ =========================================================*/
$getSubject = Database::getPDO()->prepare("SELECT idPersonne, pseudo, prenom, nom, id_facebook, telephone $getSubject = Database::getPDO()->prepare("SELECT idSujet, pseudo, prenom, nom, id_facebook, telephone
FROM Personnes FROM sujets
WHERE idPersonne = :id_subject"); WHERE idSujet = :id_subject");
$getSubject->execute(array( ':id_subject' => $id_subject )); $getSubject->execute(array( ':id_subject' => $id_subject ));
@ -51,9 +51,9 @@
public static function getAll(){ public static function getAll(){
/* [1] On effectue la requete /* [1] On effectue la requete
=========================================================*/ =========================================================*/
$getSubjects = Database::getPDO()->query("SELECT idPersonne, pseudo, prenom, nom, id_facebook, telephone $getSubjects = Database::getPDO()->query("SELECT idSujet, pseudo, prenom, nom, id_facebook, telephone
FROM Personnes FROM sujets
ORDER BY idPersonne ASC"); ORDER BY idSujet ASC");
/* [2] On recupere le resultat de la requete /* [2] On recupere le resultat de la requete
@ -97,7 +97,7 @@
/* [1] On écrit la requête /* [1] On écrit la requête
=========================================================*/ =========================================================*/
$request_create = 'INSERT INTO Personnes(idPersonne, pseudo, nom, prenom, id_facebook, telephone) '; $request_create = 'INSERT INTO sujets(idSujet, pseudo, nom, prenom, id_facebook, telephone) ';
$request_create .= 'VALUES ('; $request_create .= 'VALUES (';
$request_create .= 'DEFAULT, '; // idPersone $request_create .= 'DEFAULT, '; // idPersone
$request_create .= strlen($username) ? ':pseudo, ' : 'NULL, '; // pseudo $request_create .= strlen($username) ? ':pseudo, ' : 'NULL, '; // pseudo

View File

@ -47,32 +47,6 @@
/* RETOURNE LE TOKEN D'ID SPECIFIE OU FALSE
*
* @id_token<int> UID du token en question
*
* @return token<Array> Retourne les donnees du token ou FALSE si erreur
*
*/
public static function getById($id_token){
/* [0] Verification des INPUT
=========================================================*/
if( !Database::check('id', $id_token) ) return false;
/* [1] On cherche dans la bdd
=========================================================*/
$get_token = Database::getPDO()->prepare("SELECT id_token FROM api_token WHERE id_token = :id_token");
$get_token->execute( array( ':id_token' => $id_token ) );
/* [2] On renvoie la valeur ou FALSE
=========================================================*/
return $get_token->fetch();
}
/* VERIFIE SI UN TOKEN EST VALIDE /* VERIFIE SI UN TOKEN EST VALIDE
* *
* @token<String> Token en question * @token<String> Token en question

View File

@ -612,7 +612,7 @@
<span class="warning"><strong>Dead Code</strong></span> <span class="warning"><strong>Dead Code</strong></span>
</p> </p>
<p> <p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 20:36:30 UTC 2016.</small> <small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Tue Apr 19 12:25:45 UTC 2016.</small>
</p> </p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a> <a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer> </footer>

View File

@ -247,7 +247,7 @@
<span class="warning"><strong>Dead Code</strong></span> <span class="warning"><strong>Dead Code</strong></span>
</p> </p>
<p> <p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 20:36:30 UTC 2016.</small> <small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Tue Apr 19 12:25:45 UTC 2016.</small>
</p> </p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a> <a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer> </footer>

View File

@ -517,7 +517,7 @@
<span class="warning"><strong>Dead Code</strong></span> <span class="warning"><strong>Dead Code</strong></span>
</p> </p>
<p> <p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 20:36:30 UTC 2016.</small> <small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Tue Apr 19 12:25:45 UTC 2016.</small>
</p> </p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a> <a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer> </footer>

View File

@ -214,7 +214,7 @@
<span class="warning"><strong>Dead Code</strong></span> <span class="warning"><strong>Dead Code</strong></span>
</p> </p>
<p> <p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 20:36:30 UTC 2016.</small> <small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Tue Apr 19 12:25:45 UTC 2016.</small>
</p> </p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a> <a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer> </footer>

View File

@ -43,13 +43,13 @@
<tr> <tr>
<td class="warning">Total</td> <td class="warning">Total</td>
<td class="warning big"> <div class="progress"> <td class="warning big"> <div class="progress">
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="66.83" aria-valuemin="0" aria-valuemax="100" style="width: 66.83%"> <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="63.38" aria-valuemin="0" aria-valuemax="100" style="width: 63.38%">
<span class="sr-only">66.83% covered (warning)</span> <span class="sr-only">63.38% covered (warning)</span>
</div> </div>
</div> </div>
</td> </td>
<td class="warning small"><div align="right">66.83%</div></td> <td class="warning small"><div align="right">63.38%</div></td>
<td class="warning small"><div align="right">270&nbsp;/&nbsp;404</div></td> <td class="warning small"><div align="right">270&nbsp;/&nbsp;426</div></td>
<td class="danger big"> <div class="progress"> <td class="danger big"> <div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="44.44" aria-valuemin="0" aria-valuemax="100" style="width: 44.44%"> <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="44.44" aria-valuemin="0" aria-valuemax="100" style="width: 44.44%">
<span class="sr-only">44.44% covered (danger)</span> <span class="sr-only">44.44% covered (danger)</span>
@ -59,13 +59,13 @@
<td class="danger small"><div align="right">44.44%</div></td> <td class="danger small"><div align="right">44.44%</div></td>
<td class="danger small"><div align="right">20&nbsp;/&nbsp;45</div></td> <td class="danger small"><div align="right">20&nbsp;/&nbsp;45</div></td>
<td class="danger big"> <div class="progress"> <td class="danger big"> <div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="11.11" aria-valuemin="0" aria-valuemax="100" style="width: 11.11%"> <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="10.00" aria-valuemin="0" aria-valuemax="100" style="width: 10.00%">
<span class="sr-only">11.11% covered (danger)</span> <span class="sr-only">10.00% covered (danger)</span>
</div> </div>
</div> </div>
</td> </td>
<td class="danger small"><div align="right">11.11%</div></td> <td class="danger small"><div align="right">10.00%</div></td>
<td class="danger small"><div align="right">1&nbsp;/&nbsp;9</div></td> <td class="danger small"><div align="right">1&nbsp;/&nbsp;10</div></td>
</tr> </tr>
<tr> <tr>
@ -99,13 +99,13 @@
<tr> <tr>
<td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="repo/index.html">repo</a></td> <td class="danger"><span class="glyphicon glyphicon-folder-open"></span> <a href="repo/index.html">repo</a></td>
<td class="danger big"> <div class="progress"> <td class="danger big"> <div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="16.28" aria-valuemin="0" aria-valuemax="100" style="width: 16.28%"> <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="10.77" aria-valuemin="0" aria-valuemax="100" style="width: 10.77%">
<span class="sr-only">16.28% covered (danger)</span> <span class="sr-only">10.77% covered (danger)</span>
</div> </div>
</div> </div>
</td> </td>
<td class="danger small"><div align="right">16.28%</div></td> <td class="danger small"><div align="right">10.77%</div></td>
<td class="danger small"><div align="right">7&nbsp;/&nbsp;43</div></td> <td class="danger small"><div align="right">7&nbsp;/&nbsp;65</div></td>
<td class="danger big"> <div class="progress"> <td class="danger big"> <div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="20.00" aria-valuemin="0" aria-valuemax="100" style="width: 20.00%"> <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="20.00" aria-valuemin="0" aria-valuemax="100" style="width: 20.00%">
<span class="sr-only">20.00% covered (danger)</span> <span class="sr-only">20.00% covered (danger)</span>
@ -121,7 +121,7 @@
</div> </div>
</td> </td>
<td class="danger small"><div align="right">0.00%</div></td> <td class="danger small"><div align="right">0.00%</div></td>
<td class="danger small"><div align="right">0&nbsp;/&nbsp;1</div></td> <td class="danger small"><div align="right">0&nbsp;/&nbsp;2</div></td>
</tr> </tr>
<tr> <tr>
@ -350,7 +350,7 @@
<span class="success"><strong>High</strong>: 90% to 100%</span> <span class="success"><strong>High</strong>: 90% to 100%</span>
</p> </p>
<p> <p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 20:36:30 UTC 2016.</small> <small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Tue Apr 19 12:25:45 UTC 2016.</small>
</p> </p>
</footer> </footer>
</div> </div>

View File

@ -315,7 +315,7 @@
<span class="warning"><strong>Dead Code</strong></span> <span class="warning"><strong>Dead Code</strong></span>
</p> </p>
<p> <p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 20:36:30 UTC 2016.</small> <small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Tue Apr 19 12:25:45 UTC 2016.</small>
</p> </p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a> <a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer> </footer>

View File

@ -27,7 +27,7 @@ if( permission('admin') ){
?><section data-sublink='tokens'> ?><section data-sublink='tokens'>
<h6 class='center'>Gestion des accès distants</h6><br> <h6 class='center'>Gestion des accès distants</h6><br>
<!-- [1] Panel d'ajout/suppression de token --> <!-- [1] Panel d'ajout/suppression de token -->
<section data-panel-list> <section data-panel-list>
<!-- Header --> <!-- Header -->
@ -39,7 +39,7 @@ if( permission('admin') ){
<!-- Description des tokens actifs --> <!-- Description des tokens actifs -->
<div data-description>Liste des accès distants actifs. Ils seront automatiquement désactivés a la date d'expiration. Veuillez toutefois les supprimer.</div> <div data-description>Liste des accès distants actifs. Ils seront automatiquement désactivés a la date d'expiration. Veuillez toutefois les supprimer.</div>
<!-- Creation d'un nouvel element (cache) --> <!-- Creation d'un nouvel element (cache) -->
<div data-add> <div data-add>
<span class='label'>Nom de l'accès</span><input type='text' placeholder='token' id='add-name'><br> <span class='label'>Nom de l'accès</span><input type='text' placeholder='token' id='add-name'><br>
<span class='label'>Duree de vie (jours)</span><input type='text' value='10' id='add-duration'><br> <span class='label'>Duree de vie (jours)</span><input type='text' value='10' id='add-duration'><br>
<input type='submit' value='Ajouter un accès' id='add-token-submit'> <input type='submit' value='Ajouter un accès' id='add-token-submit'>
@ -83,7 +83,7 @@ if( permission('admin') ){
=========================================================*/ =========================================================*/
// permission: admin // permission: admin
//=======================================================// //=======================================================//
/* (1) On recupere la liste des utilisateurs */ /* (1) On recupere la liste des utilisateurs */
$req_users = new ModuleRequest('user/getAll'); $req_users = new ModuleRequest('user/getAll');
$answer_users = $req_users->dispatch(); $answer_users = $req_users->dispatch();
@ -96,7 +96,7 @@ if( permission('admin') ){
?><section data-sublink='users'> ?><section data-sublink='users'>
<h6 class='center'>Gestion des utilisateurs</h6><br> <h6 class='center'>Gestion des utilisateurs</h6><br>
<!-- [1] Panel d'ajout/suppression d'utilisateur --> <!-- [1] Panel d'ajout/suppression d'utilisateur -->
<section data-panel-list> <section data-panel-list>
<!-- Header --> <!-- Header -->
@ -156,4 +156,4 @@ if( permission('admin') ){
<!-- FIN PERMISSION ADMIN --> <!-- FIN PERMISSION ADMIN -->
<?php } ?> <?php } ?>