Modification des valeurs en BDD + Gestion de la méthode 'machineDefault/init' avec toutes les valeurs utiles au fonctionnement de la machine

This commit is contained in:
xdrm-brackets 2016-07-19 11:27:35 +02:00
parent bce1487a43
commit 916b803b58
5 changed files with 114 additions and 12 deletions

View File

@ -98,14 +98,11 @@
"getByIdTarget" "getByIdTarget"
], ],
"action": [ "action": [ "getAll", "getById" ],
"getAll", "global_state": [ "getAll" ],
"getById" "chip": [ "getAll" ],
], "pin_merge": [ "getAll", "getByIdChip" ],
"state": [ "getForChip" ],
"global_state": [
"getAll"
],
"permission": [ "permission": [
"getAll", "getAll",

View File

@ -380,15 +380,47 @@
/* [2] On récupère la liste des états /* [2] On récupère la liste des états
=========================================================*/ =========================================================*/
$statesReq = new Repo('global_state/getAll'); $globalStatesReq = new Repo('global_state/getAll');
$globalStates = ($globalStatesReq->error==0) ? $globalStatesReq->answer() : [];
/* [3] On récupère la liste des MODULES (puces)
=========================================================*/
$chipsReq = new Repo('chip/getAll');
$chips = ($chipsReq->error==0) ? $chipsReq->answer() : [];
foreach($chips as $c=>$chip){
/* [4] On récupére la liste des PINS de chaque PUCE
=========================================================*/
$pinsReq = new Repo('pin_merge/getByIdChip', [$chip['id_chip']]);
$pins = ($pinsReq->error==0) ? $pinsReq->answer() : [];
$chips[$c]['pins'] = [];
foreach($pins as $p=>$pin)
$chips[$c]['pins'][$p] = $pin['pin'];
/* [5] On récupère valeurs pour chaque état de chaque PUCE
=========================================================*/
$chips[$c]['states'] = [];
$statesReq = new Repo('state/getForChip', [$chip['id_chip']]);
$states = ($statesReq->error==0) ? $statesReq->answer() : []; $states = ($statesReq->error==0) ? $statesReq->answer() : [];
// On met en forme les données : "val1,val2,val3" -> [val1, val2, val3]
foreach($states as $s=>$state)
$chips[$c]['states'][$state['state']] = explode(',', $state['pin_values']);
}
/* [3] Retorne les données /* [3] Retorne les données
=========================================================*/ =========================================================*/
return [ return [
'actions' => $actions, 'actions' => $actions,
'states' => $states 'globalStates' => $globalStates,
'chips' => $chips
]; ];
} }

17
manager/repo/chip.php Normal file
View File

@ -0,0 +1,17 @@
<?php
namespace manager\repo;
use \manager\Database;
use \manager\Repo;
use \manager\ManagerError;
use \manager\repo\cluster as clusterRepo;
class chip extends parentRepo{
protected static function table_name(){ static $table_name = 'chip'; return $table_name; }
}
?>

View File

@ -0,0 +1,17 @@
<?php
namespace manager\repo;
use \manager\Database;
use \manager\Repo;
use \manager\ManagerError;
use \manager\repo\cluster as clusterRepo;
class pin_merge extends parentRepo{
protected static function table_name(){ static $table_name = 'pin_merge'; return $table_name; }
}
?>

39
manager/repo/state.php Normal file
View File

@ -0,0 +1,39 @@
<?php
namespace manager\repo;
use \manager\Database;
use \manager\Repo;
use \manager\ManagerError;
use \manager\repo\cluster as clusterRepo;
class state extends parentRepo{
protected static function table_name(){ static $table_name = 'state'; return $table_name; }
/* RETOURNE LES VALEURS DE CHAQUE PIN POUR CHAQUE ETAT POUR UNE PUCE EN PARTICULIER
*
* @id_chip<int> UID de la puce
*
* @return states<Array> Retourne les données sous forme de tableau de la forme (state, chip, pin, value)
*
*/
public static function getForChip($id_chip){
$req = Database::getPDO()->prepare("SELECT s.state, pm.id_chip, GROUP_CONCAT(s.value) as pin_values
FROM state as s, pin_merge as pm
WHERE s.id_pin_merge = pm.id_pin_merge
AND pm.id_chip = :id_chip
GROUP BY s.state, pm.id_chip");
$req->execute([
':id_chip' => $id_chip
]);
return $req->fetchAll();
}
}
?>