SMMP/build/database/repo/etree.php

111 lines
2.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace database\repo;
use \database\core\DatabaseDriver;
use \error\core\Err;
use \database\core\Repo;
use \orm\core\Table;
use \orm\core\Rows;
class etree extends parentRepo{
protected static function table_name(){ static $table_name = 'etree'; return $table_name; }
/* [1] Fetch all etrees for the given machine_cluster
*
* @id_warehouse<int> UID of the given warehouse
* @id_machine_cluster<int> UID of the given machine_cluster
*
* @return etrees<Array> The list of etrees
* FALSE on error
*
=========================================================*/
public static function getForMachineCluster($id_warehouse, $id_machine_cluster){
/* (1) On récupère le ETREE de la machine
---------------------------------------------------------*/
$module = Table::get('module')
->select('id_module')
->select('name');
$etree = Table::get('etree')
->select('id_etree')
->select('daemon')
->join('id_module', $module);
$merge = Table::get('module_merge')
->join('id_etree', $etree)
->whereIdWarehouse($id_warehouse)
->whereIdMachineCluster($id_machine_cluster);
return $merge->fetch();
}
/* [2] Parses an e-tree full name (mod_name-etree_name)
*
* @full_name<String> Full name to parse
*
* @return info<Array> The useful data (id_module, id_etree)
* FALSE on error
*
=========================================================*/
public static function parse($full_name){
/* (1) On vérifie le format (permet l'extraction des données) */
if( !preg_match('@^(.+)-(.+)$@', $full_name, $matches) )
return false;
/* (2) On recherche le module */
$module = Table::get('module')
->select('id_module')
->select('name')
->unique()
->whereName($matches[1])
->fetch();
/* (3) Si on ne trouve pas de module -> error */
if( !is_array($module) || !isset($module['id_module']) )
return false;
/* (5) On cherche l'e-tree */
$etree = Table::get('etree')
->select('id_etree')
->select('daemon')
->whereIdModule($module['id_module'])
->whereDaemon($matches[2])
->unique()
->fetch();
/* (6) Si erreur */
if( !is_array($etree) || !isset($etree['id_etree']) )
return false;
/* (7) Si tout ok, on retourne les données */
return [
'id_module' => $module['id_module'],
'module_name' => $module['name'],
'id_etree' => $etree['id_etree'],
'etree_name' => $etree['daemon']
];
}
}
?>