2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
|
|
|
namespace controllers\publics;
|
2019-10-29 18:36:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Page des events
|
|
|
|
*/
|
|
|
|
class Event extends \descartes\Controller
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
private $internal_event;
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
|
|
|
* Cette fonction est appelée avant toute les autres :
|
|
|
|
* Elle vérifie que l'utilisateur est bien connecté
|
|
|
|
* @return void;
|
|
|
|
*/
|
2019-10-30 00:17:10 +01:00
|
|
|
public function __construct()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
|
|
|
|
|
|
|
$this->internal_event = new \controllers\internals\Event($bdd);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
\controllers\internals\Tool::verifyconnect();
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
|
|
|
* Cette fonction retourne tous les events, sous forme d'un tableau permettant l'administration de ces events
|
|
|
|
*/
|
|
|
|
public function list($page = 0)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
$page = (int) $page;
|
|
|
|
$limit = 25;
|
2019-10-30 00:17:10 +01:00
|
|
|
$events = $this->internal_event->get_list($limit, $page);
|
2019-10-29 14:57:13 +01:00
|
|
|
$this->render('event/list', ['events' => $events, 'limit' => $limit, 'page' => $page, 'nb_results' => count($events)]);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-29 14:57:13 +01:00
|
|
|
* Cette fonction va supprimer une liste de events
|
|
|
|
* @param array int $_GET['ids'] : Les id des eventes à supprimer
|
|
|
|
* @return boolean;
|
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function delete($csrf)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
if (!$this->verify_csrf($csrf)) {
|
2019-10-29 14:57:13 +01:00
|
|
|
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Event', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
if (!\controllers\internals\Tool::is_admin()) {
|
2019-10-29 14:57:13 +01:00
|
|
|
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être admin pour pouvoir supprimer des events.');
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Event', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$ids = $_GET['ids'] ?? [];
|
2019-10-29 18:36:25 +01:00
|
|
|
foreach ($ids as $id) {
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->internal_event->delete($id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Event', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|