From 0945b7da1b7e50ec6a9cdca8cf6482e36007f426 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 24 Sep 2017 19:46:35 +0200 Subject: [PATCH] Now there is no more 'pin_merge' so CHIP have their 'pins' in itself --- build/database/repo/chip.php | 55 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/build/database/repo/chip.php b/build/database/repo/chip.php index b7654a1..30e35c6 100755 --- a/build/database/repo/chip.php +++ b/build/database/repo/chip.php @@ -11,16 +11,59 @@ protected static function table_name(){ static $table_name = 'chip'; return $table_name; } - /* RENVOIE LA LISTE DES CARTES/PUCES DISPONIBLES EN FONCTION DES MODULES DE L'ENTREPOT + /* RENVOIE LA LISTE DES CARTES/PUCES DISPONIBLES EN FONCTION DES MODULES DU GROUPE DE MACHINE + * + * @id_warehouse UID de l'entrepot + * @id_machine UID de la machine * * @return chips Liste des puces/cartes disponibles * */ - public static function getAll($id_warehouse){ - /* [1] On récupère les modules de l'entrepot courant - =========================================================*/ - $module_merge = Table::get('module_merge') - ->whereIdWarehouse(7); + public static function getForMachine($id_warehouse, $id_machine){ + + /* (1) On récupère les groupes de la machine + ---------------------------------------------------------*/ + $get_clus = new Repo('machine/getClusters', [$id_warehouse, $id_machine]); + + $clusters = $get_clus->answer(); + + if( $clusters === false ) + return []; + + + /* (2) On récupère les modules associés aux clusters + ---------------------------------------------------------*/ + $module_ids = []; + + foreach($clusters as $cluster){ + + $get_mods = new Repo('module/getByMachineCluster', [$id_warehouse, $cluster['id_machine_cluster']]); + + $mods = $get_mods->answer(); + + // si pas déja -> on ajoute l'id module à la liste + if( is_array($mods) && !in_array($mods['id_module'], $module_ids) ) + $module_ids[] = $mods['id_module']; + + } + + + /* (3) On récupère la liste des CHIPS + ---------------------------------------------------------*/ + $chips = []; + foreach($module_ids as $module_id){ + + $chip_req = Table::get('chip') + ->select('*') + ->whereIdModule($module_id); + + $fetched = $chip_req->fetch(); + + // only one by ids + $chips[$fetched['id_chip']] = $fetched; + + } + $chip = Table::get('chip')