raspisms/controllers/internals/Command.php

100 lines
2.9 KiB
PHP
Raw Normal View History

2019-10-29 14:57:13 +01:00
<?php
namespace controllers\internals;
2019-10-29 18:36:25 +01:00
/**
* Classe des commandes
*/
class Command extends \descartes\InternalController
{
2019-10-29 14:57:13 +01:00
private $model_command;
private $internal_event;
2019-10-29 14:57:13 +01:00
2019-10-29 18:36:25 +01:00
public function __construct(\PDO $bdd)
2019-10-29 14:57:13 +01:00
{
$this->model_command = new \models\Command($bdd);
$this->internal_event = new \controllers\internals\Event($bdd);
}
2019-10-29 18:36:25 +01:00
/**
2019-10-29 14:57:13 +01:00
* Return the list of commands as an array
* @param mixed(int|bool) $nb_entry : Le nombre d'entrées à retourner par page
* @param mixed(int|bool) $page : Le numéro de page en cours
* @return array : La liste des commandes
2019-10-29 18:36:25 +01:00
*/
public function list($nb_entry = false, $page = false)
{
return $this->model_command->list($nb_entry, $nb_entry * $page);
2019-10-29 18:36:25 +01:00
}
2019-10-29 14:57:13 +01:00
2019-10-29 18:36:25 +01:00
/**
2019-10-29 14:57:13 +01:00
* Cette fonction retourne une liste des commandes sous forme d'un tableau
* @param array int $ids : Les ids des entrées à retourner
* @return array : La liste des commandes
2019-10-29 18:36:25 +01:00
*/
public function get_by_ids($ids)
{
//Recupération des commandes
return $this->model_command->get_by_ids($ids);
2019-10-29 14:57:13 +01:00
}
/**
* Cette fonction permet de compter le nombre de scheduleds
* @return int : Le nombre d'entrées dans la table
*/
2019-10-29 18:36:25 +01:00
public function count()
2019-10-29 14:57:13 +01:00
{
return $this->model_command->count();
2019-10-29 14:57:13 +01:00
}
2019-10-29 18:36:25 +01:00
/**
* Cette fonction va supprimer une commande
* @param array $id : L'id de la commande à supprimer
* @return int : Le nombre de commandes supprimées;
*/
public function delete($id)
2019-10-29 14:57:13 +01:00
{
return $this->model_command->delete_by_id($id);
2019-10-29 18:36:25 +01:00
}
2019-10-29 14:57:13 +01:00
2019-10-29 18:36:25 +01:00
/**
2019-10-29 14:57:13 +01:00
* Cette fonction insert une nouvelle commande
* @param array $command : La commande à insérer
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle commande insérée
2019-10-29 18:36:25 +01:00
*/
public function create($name, $script, $admin)
2019-10-29 14:57:13 +01:00
{
$command = [
'name' => $name,
'script' => $script,
'admin' => $admin,
];
$result = $this->model_command->insert($command);
2019-10-29 14:57:13 +01:00
2019-10-29 18:36:25 +01:00
if (!$result) {
2019-10-29 14:57:13 +01:00
return false;
}
$this->internal_event->create('COMMAND_ADD', 'Ajout commande : ' . $name . ' => ' . $script);
2019-10-29 14:57:13 +01:00
return $result;
2019-10-29 18:36:25 +01:00
}
2019-10-29 14:57:13 +01:00
2019-10-29 18:36:25 +01:00
/**
2019-10-29 14:57:13 +01:00
* Cette fonction met à jour un commande
* @return int : le nombre de ligne modifiées
2019-10-29 18:36:25 +01:00
*/
public function update($id, $name, $script, $admin)
2019-10-29 14:57:13 +01:00
{
$command = [
'name' => $name,
'script' => $script,
'admin' => $admin,
];
$result = $this->model_command->update($id, $command);
2019-10-29 14:57:13 +01:00
return $result;
}
2019-10-29 18:36:25 +01:00
}