83 lines
1.9 KiB
PHP
Executable File
83 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/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')
|
|
->join('id_module', $module_merge)
|
|
->select('*');
|
|
|
|
|
|
|
|
/* [2] On retourne le résultat
|
|
=========================================================*/
|
|
return $chip->fetch();
|
|
}
|
|
}
|
|
|
|
|
|
?>
|