Dev. motheure::increment + fetchDefault::motheure_simple calling motheure::increment

This commit is contained in:
xdrm-brackets 2017-10-13 16:46:30 +02:00
parent 9dbfe754b4
commit 474d60394d
3 changed files with 124 additions and 6 deletions

View File

@ -100,9 +100,9 @@
// {2} Process + get response //
$log_res = $log_req->dispatch();
// {3} Exit on failure //
if( $log_res->error->get() != Err::Success )
break;
// {3} Ignore failure //
// if( $log_res->error->get() != Err::Success )
// continue;
// {4} Register count if success //
$count++;
@ -115,6 +115,52 @@
}
/* [2] Gestion des données historiques de l'etree SIMPLE du module MOTHEURE
*
* @data<mixed> Données à traiter
*
* @return saved<numeric> Nombre de lignes ajoutées
*
=========================================================*/
public function motheure_simple($params){
extract($params);
/* (1) Initialize data
---------------------------------------------------------*/
/* (1) Initialisation du compteur de lignes enregistrées */
$count = 0;
/* (2) Calcl the total to add */
$total = 0;
foreach($data as $entry){
// Only if positive numeric
if( is_numeric($entry) && $entry > 0 )
$total += intval($entry);
$count++;
}
/* (2) Update the table in the database
---------------------------------------------------------*/
/* (1) Build request to store each entry */
$upd_req = new Request('motheure/increment', [
'count' => $total
]);
// {2} Process + get response //
$upd_res = $log_req->dispatch();
/* (3) Retourne le nombre d'entrées enregistrées */
return [ 'saved' => $count ];
}
}

View File

@ -16,13 +16,13 @@
public function __destruct(){}
/* RETURNS THE TOTAL COUNT FOR A MACHINE
/* (1) 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);
@ -70,6 +70,70 @@
}
/* (2) Increment the motor count
*
* @count<int> Count to add to motor count of the machine
*
---------------------------------------------------------*/
public function increment(){
extract($params);
/* (1) Check if entry exists
---------------------------------------------------------*/
/* (1) Check if there is an entry for the current machine */
$already_exists = is_array(Table::get('motheure')
->unique()
->select('id_motheure')
->select('id_machine')
->whereIdMachine($_SESSION['SATS']['id'])
->fetch());
/* (2) If does not exist, create entry
---------------------------------------------------------*/
if( !$already_exists ){
/* (1) Insert new entry */
$inserted = Table::get('motheure')
->insert([
'id_motheure' => Rows::INSERT_DEFAULT,
'id_machine' => $_SESSION['SATS']['id'],
'count' => $count
]);
/* (2) Propagate error */
return [ 'error' => ($inserted) ? new Error(Err::Success) : new Error(Err::RepoError) ];
/* (3) If already exists, update entry
---------------------------------------------------------*/
}else{
/* (1) Update entry */
$updated = Table::get('motheure')
->unique()
->whereIdMachine($_SESSION['SATS']['id'])
->edit([
'count' => $count
]);
/* (2) Propagate error */
return [ 'error' => ($updated) ? new Error(Err::Success) : new Error(Err::RepoError) ];
}
/* (x) Default error */
return [ 'error' => new Error(Err::Success) ];
}
}

View File

@ -23,6 +23,14 @@
"output": {
"count": { "description": "Compte horaire (en secondes)", "type": "int" }
}
},
"POST::increment": {
"description": "Incrémente le comptheure horaire d'une machine.",
"permissions": [["sats"]],
"parameters": {
"data": { "description": "Données du module", "type": "array<id>" }
},
"output": {}
}
},
@ -193,7 +201,7 @@
"machineDefault": {
"POST::update": {
"description": "Mise à jour d'un SAYS++TS.",
"description": "Mise à jour d'un SATS.",
"permissions": [["sats"]],
"parameters": {
"data": { "description": "Données (dépendent des modules).", "type": "array<mixed>" }