raspisms/controllers/internals/Command.php

78 lines
2.3 KiB
PHP
Raw Normal View History

2019-10-29 14:57:13 +01:00
<?php
/*
2019-11-10 17:48:54 +01:00
* This file is part of RaspiSMS.
*
2019-11-10 17:48:54 +01:00
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
2019-11-10 17:48:54 +01:00
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
2019-10-29 14:57:13 +01:00
namespace controllers\internals;
2019-10-29 18:36:25 +01:00
class Command extends StandardController
2019-10-29 18:36:25 +01:00
{
protected $model = false;
2019-10-29 18:36:25 +01:00
/**
* Get the model for the Controller
* @return \descartes\Model
2019-10-29 18:36:25 +01:00
*/
protected function get_model () : \descartes\Model
2019-10-29 18:36:25 +01:00
{
$this->model = $this->model ?? new \models\Command($this->$bdd);
return $this->model;
2019-10-29 14:57:13 +01:00
}
2019-10-29 14:57:13 +01:00
/**
* Create a new command
* @param int $id_user : User id
* @param string $name : Command name
* @param string $script : Script file
* @param bool $admin : Is command admin only
* @return mixed bool|int : False if cannot create command, id of the new command else
2019-10-29 14:57:13 +01:00
*/
public function create(int $id_user, string $name, string $script, bool $admin)
2019-10-29 14:57:13 +01:00
{
$command = [
'id_user' => $id_user,
2019-10-29 14:57:13 +01:00
'name' => $name,
'script' => $script,
'admin' => $admin,
];
$result = $this->model_command->insert($command);
if (!$result)
{
2019-10-29 14:57:13 +01:00
return false;
}
$this->internal_event->create($id_user, '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 18:36:25 +01:00
/**
* Update a command
* @param int $id_user : User id
* @param int $id : Command id
* @param string $name : Command name
* @param string $script : Script file
* @param bool $admin : Is command admin only
* @return mixed bool|int : False if cannot create command, id of the new command else
2019-10-29 18:36:25 +01:00
*/
public function update_for_user(int $id_user, int $id, string $name, string $script, bool $admin)
2019-10-29 14:57:13 +01:00
{
$command = [
'name' => $name,
'script' => $script,
'admin' => $admin,
];
return $this->model_command->update_for_user($id_user, $id, $command);
2019-10-29 14:57:13 +01:00
}
2019-10-29 18:36:25 +01:00
}