81 lines
1.9 KiB
PHP
Executable File
81 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace database\repo;
|
|
use \database\core\DatabaseDriver;
|
|
use \database\core\Repo;
|
|
use \orm\core\Table;
|
|
use \orm\core\Rows;
|
|
|
|
class chip extends parentRepo{
|
|
|
|
protected static function table_name(){ static $table_name = 'chip'; return $table_name; }
|
|
|
|
|
|
/* RENVOIE LA LISTE DES CARTES/PUCES DISPONIBLES EN FONCTION DES MODULES DU GROUPE DE MACHINE
|
|
*
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
* @id_machine<int> UID de la machine
|
|
*
|
|
* @return chips<Array> Liste des puces/cartes disponibles
|
|
*
|
|
*/
|
|
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/getForMachineCluster', [$id_warehouse, $cluster['id_machine_cluster']]);
|
|
|
|
$mods = $get_mods->answer();
|
|
|
|
foreach($mods as $module){
|
|
|
|
// si pas déja -> on ajoute l'id module à la liste
|
|
if( !in_array($module['id_module'], $module_ids) )
|
|
$module_ids[] = $module['id_module'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/* (3) On récupère la liste des CHIPS (associés aux modules)
|
|
---------------------------------------------------------*/
|
|
$chips = [];
|
|
foreach($module_ids as $module_id){
|
|
|
|
$chip_req = Table::get('chip')
|
|
->select('*')
|
|
->whereIdModule($module_id);
|
|
|
|
$chip_fetched = $chip_req->fetch();
|
|
|
|
foreach($chip_fetched as $chip)
|
|
$chips[] = $chip;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [2] On retourne le résultat
|
|
=========================================================*/
|
|
return $chips;
|
|
}
|
|
}
|
|
|
|
|
|
?>
|