2016-07-19 09:27:35 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
namespace database\repo;
|
2016-11-05 13:57:35 +00:00
|
|
|
use \database\core\DatabaseDriver;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \database\core\Repo;
|
|
|
|
use \orm\core\Table;
|
|
|
|
use \orm\core\Rows;
|
2016-07-19 09:27:35 +00:00
|
|
|
|
|
|
|
class chip extends parentRepo{
|
|
|
|
|
|
|
|
protected static function table_name(){ static $table_name = 'chip'; return $table_name; }
|
|
|
|
|
|
|
|
|
2017-09-24 17:46:35 +00:00
|
|
|
/* 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
|
2016-07-24 10:00:49 +00:00
|
|
|
*
|
|
|
|
* @return chips<Array> Liste des puces/cartes disponibles
|
|
|
|
*
|
|
|
|
*/
|
2017-09-24 17:46:35 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-24 23:14:35 +00:00
|
|
|
|
2016-07-24 10:18:30 +00:00
|
|
|
|
|
|
|
$chip = Table::get('chip')
|
2016-07-24 23:14:35 +00:00
|
|
|
->join('id_module', $module_merge)
|
2016-07-24 10:18:30 +00:00
|
|
|
->select('*');
|
|
|
|
|
2016-07-24 10:00:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] On retourne le résultat
|
|
|
|
=========================================================*/
|
2016-07-24 23:14:35 +00:00
|
|
|
return $chip->fetch();
|
2016-07-24 10:00:49 +00:00
|
|
|
}
|
2016-07-19 09:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|