mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
Fix style and add config file to php-cs-fixer
This commit is contained in:
parent
485a0cb6fd
commit
fab9e256ab
40 changed files with 2360 additions and 1128 deletions
|
@ -1,8 +1,19 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of PHP CS Fixer.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace controllers\publics;
|
||||
|
||||
/**
|
||||
* Page des commandes
|
||||
* Page des commandes.
|
||||
*/
|
||||
class Command extends \descartes\Controller
|
||||
{
|
||||
|
@ -15,12 +26,14 @@ namespace controllers\publics;
|
|||
|
||||
$this->internal_command = new \controllers\internals\Command($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
|
||||
|
||||
\controllers\internals\Tool::verifyconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne tous les users, sous forme d'un tableau permettant l'administration de ces users
|
||||
* Cette fonction retourne tous les users, sous forme d'un tableau permettant l'administration de ces users.
|
||||
*
|
||||
* @param mixed $page
|
||||
*/
|
||||
public function list($page = 0)
|
||||
{
|
||||
|
@ -30,29 +43,36 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de commands
|
||||
* Cette fonction va supprimer une liste de commands.
|
||||
*
|
||||
* @param array int $_GET['ids'] : Les id des commandes à supprimer
|
||||
* @param mixed $csrf
|
||||
*
|
||||
* @return boolean;
|
||||
*/
|
||||
public function delete($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf)) {
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
|
||||
$this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$ids = $_GET['ids'] ?? [];
|
||||
foreach ($ids as $id) {
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$this->internal_command->delete($id);
|
||||
}
|
||||
|
||||
|
||||
$this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne la page d'ajout d'une commande
|
||||
* Cette fonction retourne la page d'ajout d'une commande.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
|
@ -60,34 +80,39 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne la page d'édition des commandes
|
||||
* Cette fonction retourne la page d'édition des commandes.
|
||||
*
|
||||
* @param array int $_GET['ids'] : Les id des commandes à editer
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
global $db;
|
||||
$ids = $_GET['ids'] ?? [];
|
||||
|
||||
|
||||
$commands = $this->internal_command->get_by_ids($ids);
|
||||
|
||||
$this->render('command/edit', array(
|
||||
$this->render('command/edit', [
|
||||
'commands' => $commands,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction insert une nouvelle commande
|
||||
* Cette fonction insert une nouvelle commande.
|
||||
*
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @param string $_POST['name'] : Le nom de la commande
|
||||
* @param string $_POST['name'] : Le nom de la commande
|
||||
* @param string $_POST['script'] : Le script a appeler
|
||||
* @param boolean $_POST['admin'] : Si la commande necessite les droits d'admin (par défaut non)
|
||||
* @param bool $_POST['admin'] : Si la commande necessite les droits d'admin (par défaut non)
|
||||
*
|
||||
* @return boolean;
|
||||
*/
|
||||
public function create($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf)) {
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
|
||||
$this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -95,49 +120,61 @@ namespace controllers\publics;
|
|||
$script = $_POST['script'] ?? false;
|
||||
$admin = (isset($_POST['admin']) ? $_POST['admin'] : false);
|
||||
|
||||
if (!$name || !$script) {
|
||||
if (!$name || !$script)
|
||||
{
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Renseignez au moins un nom et un script.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
}
|
||||
|
||||
|
||||
if (!$this->internal_command->create($name, $script, $admin)) {
|
||||
if (!$this->internal_command->create($name, $script, $admin))
|
||||
{
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible créer cette commande.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('commands', 'add'));
|
||||
}
|
||||
|
||||
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'La commande a bien été crée.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction met à jour une commande
|
||||
* Cette fonction met à jour une commande.
|
||||
*
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @param array $_POST['commands'] : Un tableau des commandes avec leur nouvelle valeurs
|
||||
*
|
||||
* @return boolean;
|
||||
*/
|
||||
public function update($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf)) {
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
|
||||
$this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$nb_commands_update = 0;
|
||||
foreach ($_POST['commands'] as $command) {
|
||||
foreach ($_POST['commands'] as $command)
|
||||
{
|
||||
$update_command = $this->internal_command->update($command['id'], $command['name'], $command['script'], $command['admin']);
|
||||
$nb_commands_update += (int) $update_command;
|
||||
}
|
||||
|
||||
if ($nb_commands_update != count($_POST['commands'])) {
|
||||
if ($nb_commands_update !== \count($_POST['commands']))
|
||||
{
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certaines commandes n\'ont pas pu êtres mises à jour.');
|
||||
$this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Toutes les commandes ont été modifiées avec succès.');
|
||||
$this->redirect(\descartes\Router::url('Command', 'list'));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue