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(); + } + + } + + +?>