From 916b803b587961bc0425e1d26968a3ea41b454e8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 19 Jul 2016 11:27:35 +0200 Subject: [PATCH] =?UTF-8?q?Modification=20des=20valeurs=20en=20BDD=20+=20G?= =?UTF-8?q?estion=20de=20la=20m=C3=A9thode=20'machineDefault/init'=20avec?= =?UTF-8?q?=20toutes=20les=20valeurs=20utiles=20au=20fonctionnement=20de?= =?UTF-8?q?=20la=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/repositories.json | 13 ++++------ manager/module/machineDefault.php | 40 +++++++++++++++++++++++++++---- manager/repo/chip.php | 17 +++++++++++++ manager/repo/pin_merge.php | 17 +++++++++++++ manager/repo/state.php | 39 ++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 manager/repo/chip.php create mode 100644 manager/repo/pin_merge.php create mode 100644 manager/repo/state.php diff --git a/config/repositories.json b/config/repositories.json index ebd49fc..c5bc068 100755 --- a/config/repositories.json +++ b/config/repositories.json @@ -98,14 +98,11 @@ "getByIdTarget" ], - "action": [ - "getAll", - "getById" - ], - - "global_state": [ - "getAll" - ], + "action": [ "getAll", "getById" ], + "global_state": [ "getAll" ], + "chip": [ "getAll" ], + "pin_merge": [ "getAll", "getByIdChip" ], + "state": [ "getForChip" ], "permission": [ "getAll", diff --git a/manager/module/machineDefault.php b/manager/module/machineDefault.php index 6a876b4..4f8191d 100755 --- a/manager/module/machineDefault.php +++ b/manager/module/machineDefault.php @@ -380,15 +380,47 @@ /* [2] On récupère la liste des états =========================================================*/ - $statesReq = new Repo('global_state/getAll'); - $states = ($statesReq->error==0) ? $statesReq->answer() : []; + $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() : []; + + // 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 =========================================================*/ return [ - 'actions' => $actions, - 'states' => $states + 'actions' => $actions, + 'globalStates' => $globalStates, + 'chips' => $chips ]; } diff --git a/manager/repo/chip.php b/manager/repo/chip.php new file mode 100644 index 0000000..925374a --- /dev/null +++ b/manager/repo/chip.php @@ -0,0 +1,17 @@ + diff --git a/manager/repo/pin_merge.php b/manager/repo/pin_merge.php new file mode 100644 index 0000000..e09ea4c --- /dev/null +++ b/manager/repo/pin_merge.php @@ -0,0 +1,17 @@ + diff --git a/manager/repo/state.php b/manager/repo/state.php new file mode 100644 index 0000000..303d75d --- /dev/null +++ b/manager/repo/state.php @@ -0,0 +1,39 @@ + UID de la puce + * + * @return states 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(); + } + + } + + +?>