Skip to content

Commit

Permalink
WIP event series and event planning creation
Browse files Browse the repository at this point in the history
  • Loading branch information
catdesu committed Mar 5, 2024
1 parent 7cf8c33 commit 3775b83
Show file tree
Hide file tree
Showing 11 changed files with 719 additions and 21 deletions.
2 changes: 2 additions & 0 deletions orif/common/Config/AdminPanelConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class AdminPanelConfig extends \CodeIgniter\Config\BaseConfig
'tim_lang.badgesList', 'pageLink'=>'Badges'],
['label'=>'tim_lang.Defaultplanning', 'title'=>
'tim_lang.Defaultplanning', 'pageLink'=>'DefaultPlannings'],
['label'=>'tim_lang.event_plannings_list', 'title'=>
'tim_lang.event_plannings_list', 'pageLink'=>'admin/event-plannings'],
['label'=>'tim_lang.event_types_list', 'title'=>
'tim_lang.event_types_list', 'pageLink'=>'admin/event-types'],
];
Expand Down
59 changes: 40 additions & 19 deletions orif/timbreuse/Config/Routes.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
<?php

// User groups routes
$routes->get('admin/user-groups', '\Timbreuse\Controllers\UserGroups');
$routes->get('admin/user-groups/create', '\Timbreuse\Controllers\UserGroups::create');
$routes->get('admin/user-groups/create/(:num)', '\Timbreuse\Controllers\UserGroups::create/$1');
$routes->post('admin/user-groups/create', '\Timbreuse\Controllers\UserGroups::create');
$routes->get('admin/user-groups/update/(:num)', '\Timbreuse\Controllers\UserGroups::update/$1');
$routes->get('admin/user-groups/update/(:num)/(:num)', '\Timbreuse\Controllers\UserGroups::update/$1/$2');
$routes->post('admin/user-groups/update/(:num)', '\Timbreuse\Controllers\UserGroups::update/$1');
$routes->get('admin/user-groups/select-parent', '\Timbreuse\Controllers\UserGroups::selectParent');
$routes->get('admin/user-groups/select-parent/(:num)', '\Timbreuse\Controllers\UserGroups::selectParent/$1');

// Event types routes
$routes->get('admin/event-types', '\Timbreuse\Controllers\EventTypes');
$routes->get('admin/event-types/create', '\Timbreuse\Controllers\EventTypes::create');
$routes->post('admin/event-types/create', '\Timbreuse\Controllers\EventTypes::create');
$routes->get('admin/event-types/update/(:num)', '\Timbreuse\Controllers\EventTypes::update/$1');
$routes->post('admin/event-types/update/(:num)', '\Timbreuse\Controllers\EventTypes::update/$1');
$routes->get('admin/event-types/delete/(:num)', '\Timbreuse\Controllers\EventTypes::delete/$1');
$routes->post('admin/event-types/delete/(:num)/(:num)', '\Timbreuse\Controllers\EventTypes::delete/$1/$2');


// Admin routes
$routes->group('admin', function($routes) {
// User groups routes
$routes->group('user-groups', function($routes) {
$routes->get('', '\Timbreuse\Controllers\UserGroups');
$routes->get('create', '\Timbreuse\Controllers\UserGroups::create');
$routes->get('create/(:num)', '\Timbreuse\Controllers\UserGroups::create/$1');
$routes->post('create', '\Timbreuse\Controllers\UserGroups::create');
$routes->get('update/(:num)', '\Timbreuse\Controllers\UserGroups::update/$1');
$routes->get('update/(:num)/(:num)', '\Timbreuse\Controllers\UserGroups::update/$1/$2');
$routes->post('update/(:num)', '\Timbreuse\Controllers\UserGroups::update/$1');
$routes->get('select-parent', '\Timbreuse\Controllers\UserGroups::selectParent');
$routes->get('select-parent/(:num)', '\Timbreuse\Controllers\UserGroups::selectParent/$1');
});

// Event plannings
$routes->group('event-plannings', function($routes) {
$routes->get('', '\Timbreuse\Controllers\EventPlannings');
$routes->get('personal/create', '\Timbreuse\Controllers\EventPlannings::createPersonal');
$routes->post('personal/create', '\Timbreuse\Controllers\EventPlannings::createPersonal');
$routes->get('group/create', '\Timbreuse\Controllers\EventPlannings::createGroup');
$routes->post('group/create', '\Timbreuse\Controllers\EventPlannings::createGroup');
});

// Event types routes
$routes->group('event-types', function($routes) {
$routes->get('', '\Timbreuse\Controllers\EventTypes');
$routes->get('create', '\Timbreuse\Controllers\EventTypes::create');
$routes->post('create', '\Timbreuse\Controllers\EventTypes::create');
$routes->get('update/(:num)', '\Timbreuse\Controllers\EventTypes::update/$1');
$routes->post('update/(:num)', '\Timbreuse\Controllers\EventTypes::update/$1');
$routes->get('delete/(:num)', '\Timbreuse\Controllers\EventTypes::delete/$1');
$routes->post('delete/(:num)/(:num)', '\Timbreuse\Controllers\EventTypes::delete/$1/$2');
});
});

// Event series routes
$routes->get('event-series/html/form', '\Timbreuse\Controllers\EventSeries::getCreateSeriesHTML');

$routes->group('Timbreuse', function($routes) {
$routes->add('home','\Timbreuse\Controllers\Home');
Expand Down
201 changes: 201 additions & 0 deletions orif/timbreuse/Controllers/EventPlannings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
<?php

namespace Timbreuse\Controllers;

use App\Controllers\BaseController;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use Timbreuse\Models\EventPlanningsModel;
use Timbreuse\Models\EventTypesModel;

class EventPlannings extends BaseController
{
// Class properties
private EventPlanningsModel $eventPlanningsModel;
private EventTypesModel $eventTypesModel;

/**
* Constructor
*/
public function initController(
RequestInterface $request,
ResponseInterface $response,
LoggerInterface $logger
): void {
// Set Access level before calling parent constructor
// Accessibility reserved to admin users
$this->access_level = config('\User\Config\UserConfig')->access_lvl_admin;
parent::initController($request, $response, $logger);

// Load required helpers
helper('form');

// Load required models
$this->eventPlanningsModel = new EventPlanningsModel();
$this->eventTypesModel = new EventTypesModel();
}

/**
* Display the event types list
*
* @return string
*/
public function index() : string {
$data['title'] = lang('tim_lang.event_plannings_list');
$data['list_title'] = ucfirst(lang('tim_lang.event_plannings_list'));

$data['columns'] = [
'event_date' => ucfirst(lang('tim_lang.field_event_date')),
'start_time' => ucfirst(lang('tim_lang.field_start_time')),
'end_time' => ucfirst(lang('tim_lang.field_end_time')),
'is_work_time' => ucfirst(lang('tim_lang.field_is_work_time')),
];

$data['items'] = $this->eventPlanningsModel->findAll();

$data['url_create'] = "admin/event-plannings/group/create";
$data['url_update'] = 'admin/event-plannings/update/';
$data['url_delete'] = 'admin/event-plannings/delete/';

return $this->display_view('Common\Views\items_list', $data);
}

/**
* Display the create form
*
* @return string|RedirectResponse
*/
public function createPersonal() : string|RedirectResponse {
$eventTypes = $this->eventTypesModel->where('is_personal_event_type', true)->findAll();
$data = [
'title' => lang('tim_lang.create_event_planning_title'),
'eventPlanning' => null,
'eventTypes' => $this->mapForSelectForm($eventTypes)
];

if (isset($_POST) && !empty($_POST)) {
$data['errors'] = $this->getPostDataAndSaveEventPlanning();

if (empty($data['errors'])) {
return redirect()->to(base_url('admin/event-types'));
}
}

return $this->display_view(['Timbreuse\Views\eventPlannings\personal\save_form'], $data);
}

/**
* Display the create form
*
* @return string|RedirectResponse
*/
public function createGroup() : string|RedirectResponse {
$eventTypes = $this->eventTypesModel->where('is_group_event_type', true)->findAll();
$data = [
'title' => lang('tim_lang.create_event_planning_title'),
'eventPlanning' => null,
'eventTypes' => $this->mapForSelectForm($eventTypes)
];

if (isset($_POST) && !empty($_POST)) {
$data['errors'] = $this->getPostDataAndSaveEventPlanning();

if (empty($data['errors'])) {
return redirect()->to(base_url('admin/event-types'));
}
}

return $this->display_view(['Timbreuse\Views\eventPlannings\group\save_form'], $data);
}

/**
* Retrieves the corresponding event type and display the update form
*
* @param int $id
* @return string|RedirectResponse
*/
public function update(int $id) : string|RedirectResponse {
$eventPlanning = $this->eventPlanningsModel->find($id);

if (is_null($eventPlanning)) {
return redirect()->to(base_url('admin/event-types'));
}

$data = [
'title' => lang('tim_lang.update_event_planning_title'),
'eventPlanning' => $eventPlanning
];

if (isset($_POST) && !empty($_POST)) {
$data['errors'] = $this->getPostDataAndSaveEventPlanning();

if (empty($data['errors'])) {
return redirect()->to(base_url('admin/event-types'));
}
}

return $this->display_view(['Timbreuse\Views\eventPlannings\save_form'], $data);
}

/**
* Display the delete form and delete the corresponding event type
*
* @param int $id
* @param int $action
* @return string|RedirectResponse
*/
public function delete(int $id, int $action = 0) : string|RedirectResponse {
$eventPlanning = $this->eventPlanningsModel->find($id);

if (!$eventPlanning) {
return redirect()->to(base_url('admin/event-types'));
}

$data = [
'title' => lang('tim_lang.delete_event_planning'),
'eventPlanning' => $eventPlanning
];

switch ($action) {
case 0:
return $this->display_view('Timbreuse\Views\eventPlannings\confirm_delete', $data);

case 1:
// In case soft delete is implemented
break;

case 2:
if (isset($_POST) && !empty($_POST) && !is_null($_POST['confirmation'])) {
$this->eventPlanningsModel->delete($id, true);
}
break;
}

return redirect()->to(base_url('admin/event-types'));
}

/**
* Retrieves post data from the request and saves the event type information
*
* @return array Validation errors encountered during the saving process
*/
private function getPostDataAndSaveEventPlanning() : array {
$eventPlanning = [
'id' => $this->request->getPost('id'),
'name' => $this->request->getPost('name'),
'is_group_event_planning' => (bool)$this->request->getPost('isGroupEventType'),
'is_personal_event_planning' => (bool)$this->request->getPost('isPersonalEventType'),
];

$this->eventPlanningsModel->save($eventPlanning);
return $this->eventPlanningsModel->errors();
}

private function mapForSelectForm($array) : array {
return array_combine(array_column($array, 'id'), array_map(function($row) {
return $row['name'];
}, $array));
}
}
51 changes: 51 additions & 0 deletions orif/timbreuse/Controllers/EventSeries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Timbreuse\Controllers;

use App\Controllers\BaseController;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use Timbreuse\Models\EventSeriesModel;

class EventSeries extends BaseController
{
// Class properties
private EventSeriesModel $eventSeriesModel;

/**
* Constructor
*/
public function initController(
RequestInterface $request,
ResponseInterface $response,
LoggerInterface $logger
): void {
// Set Access level before calling parent constructor
// Accessibility reserved to registered users
$this->access_level = config('\User\Config\UserConfig')->access_lvl_registered;
parent::initController($request, $response, $logger);

// Load required helpers
helper('form');

// Load required models
$this->eventSeriesModel = new EventSeriesModel();
}

public function getCreateSeriesHTML() : string {
$data = [
'daysOfWeek' => [
lang('tim_lang.monday'),
lang('tim_lang.tuesday'),
lang('tim_lang.wednesday'),
lang('tim_lang.thursday'),
lang('tim_lang.friday')
],
'eventSerie' => null
];

return json_encode(view('\Timbreuse\Views\eventSeries\create_series.php', $data));
}
}
2 changes: 1 addition & 1 deletion orif/timbreuse/Controllers/UserGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function selectParent(?int $id = null) : string {

$data['items'] = $this->userGroupsModel->where('id !=', $id)->findAll();

$data['url_update'] = base_url($pathToUserGroupForm);
$data['url_update'] = $pathToUserGroupForm;

return $this->display_view('Common\Views\items_list', $data);
}
Expand Down
23 changes: 22 additions & 1 deletion orif/timbreuse/Language/fr/tim_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
'field_event_date' => 'Date de l’événement',
'field_event_start_time' => 'Heure de début de l’événement',
'field_event_end_time' => 'Heure de fin de l’événement',
'field_is_work_time' => 'Est-ce un temps de travail ?',
'field_is_work_time' => 'Est-ce que cela compte comme du temps de travail ?',
'event_types_list' => 'Types d’événements',
'event_type' => 'Type d’événement',
'create_event_type_title' => 'Ajouter un type d’événement',
Expand All @@ -136,4 +136,25 @@
'btn_hard_delete_event_type' => 'Supprimer ce type d’événement',
'really_want_to_delete_event_type' => 'Voulez-vous vraiment supprimer ce type d’événement ?',
'delete_event_type' => 'Supprimer type d’événement',
'event_plannings_list' => 'Événements de planning',
'field_event_date' => 'Date de l’événement',
'field_start_time' => 'Heure de début',
'field_end_time' => 'Heure de fin',
'create_personal_event_planning_title' => 'Ajouter un événement personnel',
'create_group_event_planning_title' => 'Ajouter un événement de groupe',
'update_personal_event_planning_title' => 'Modifier un événement personnel',
'update_group_event_planning_title' => 'Modifier un événement de groupe',
'field_linked_user' => 'Utilisateur concerné',
'field_linked_user_group' => 'Groupe concerné',
'btn_select_linked_user' => 'Sélectionner un utilisateur',
'btn_select_linked_user_group' => 'Sélectionner un groupe d’utilisateurs',
'field_start_date' => 'Date de début',
'field_end_date' => 'Date de fin',
'field_recurrence_frequency' => 'Fréquence',
'field_recurrence_interval' => 'Intervalle',
'field_days_of_week' => 'Jours de la semaine',
'daily' => 'Quotidien',
'weekly' => 'Hebdomadaire',
'monthly' => 'Mensuel',
'btn_create_series' => 'Créer en série',
];
Loading

0 comments on commit 3775b83

Please sign in to comment.