77 lines
1.6 KiB
PHP
77 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace api\module;
|
||
|
use \database\core\DatabaseDriver;
|
||
|
use \manager\sessionManager;
|
||
|
use \error\core\Error;
|
||
|
use \error\core\Err;
|
||
|
use \database\core\Repo;
|
||
|
use \api\core\Request;
|
||
|
use \orm\core\Rows;
|
||
|
use \orm\core\Table;
|
||
|
|
||
|
class motheure{
|
||
|
|
||
|
public function __construct(){}
|
||
|
public function __destruct(){}
|
||
|
|
||
|
|
||
|
/* RETURNS THE TOTAL COUNT FOR A MACHINE
|
||
|
*
|
||
|
* @id_machine<id> Identifiant de la machine
|
||
|
*
|
||
|
* @return count<int> Retourne le compte horaire
|
||
|
*
|
||
|
*/
|
||
|
public function getCount($params){
|
||
|
extract($params);
|
||
|
|
||
|
|
||
|
/* (1) Check if machine have motheure etree activated
|
||
|
---------------------------------------------------------*/
|
||
|
$mod = Table::get('module')
|
||
|
->whereName('motheure');
|
||
|
|
||
|
$etree = Table::get('etree')
|
||
|
->whereDaemon('simple')
|
||
|
->join('id_module', $mod);
|
||
|
|
||
|
$mc = Table::get('module_merge')
|
||
|
->join('id_etree', $etree);
|
||
|
|
||
|
$m = Table::get('machine')
|
||
|
->select('id_machine')
|
||
|
->whereId($id_machine);
|
||
|
|
||
|
$mc_m = Table::get('machine_cluster_merge')
|
||
|
->join('id_machine', $m)
|
||
|
->join('id_machine_cluster', $mc);
|
||
|
|
||
|
/* (1) If not the etree -> exit */
|
||
|
if( count($mc_m->fetch()) == 0 )
|
||
|
return ['error' => new Error(Err::NoMatchFound)];
|
||
|
|
||
|
|
||
|
/* (2) Get the motor count
|
||
|
---------------------------------------------------------*/
|
||
|
/* (1) Fetch count */
|
||
|
$count = Table::get('motheure')
|
||
|
->unique()
|
||
|
->select('count')
|
||
|
->whereIdMachine($id_machine)
|
||
|
->fetch();
|
||
|
|
||
|
/* (2) If no result -> return 0 */
|
||
|
if( !is_array($count) || !isset($count['count']) )
|
||
|
return ['count' => 0];
|
||
|
|
||
|
/* (3) Else -> return the count */
|
||
|
return [ 'count' => $count['count'] ];
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
?>
|