Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs-display #30

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 38 additions & 25 deletions orif/timbreuse/Controllers/PersoLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Timbreuse\Models\UsersModel;
use CodeIgniter\I18n\Time;
use Timbreuse\Models\AccessTimModel;
use Timbreuse\Models\EventPlanningsModel;
use Timbreuse\Models\LogsFakeLogsModel;
use Timbreuse\Models\PlanningsModel;

Expand Down Expand Up @@ -179,7 +178,7 @@ protected function create_planning_link(?int $timUserId=null): array
{
helper('UtilityFunctions');
if ($timUserId === get_tim_user_id()) {
$button['link'] = base_url('/Plannings/get_plannings_list/');
$button['link'] = base_url('/Plannings/get_plannings_list');
} else {
$button['link'] = base_url(
"/Plannings/get_plannings_list/$timUserId");
Expand All @@ -200,16 +199,16 @@ protected function create_event_planning_link(?int $timUserId=null): array
return $button;
}

protected function get_buttons_for_log_views($day, $period,
?int $timUserId=null): array
public function get_buttons_for_log_views($day, string $period,
?int $timUserId=null): array
{
$data['buttons'] = $this->create_buttons($period);
$data['buttons'] = array_merge(
$this->create_time_links($day, $period),
$data['buttons']
);
$data['buttons'] = array();

$data['buttons'] = array_merge($this->create_buttons($period, $timUserId), $data['buttons']);
$data['buttons'] = array_merge($this->create_time_links($day, $period), $data['buttons']);
array_push($data['buttons'], $this->create_planning_link($timUserId));
array_push ($data['buttons'], $this->create_event_planning_link($timUserId));

return $data;
}

Expand Down Expand Up @@ -753,28 +752,42 @@ protected function create_title(array $user, Time $day,
}
}

protected function create_buttons(string $period): array
protected function create_buttons(string $period, $timUserId = null): array
{
$data = array();
array_push($data,
$today = Time::today()->toDateString();
$uriSegments = explode('/', current_url());
$lastSegment = array_pop($uriSegments);

if (filter_var($lastSegment, FILTER_VALIDATE_INT) !== false) {
$path = "AdminLogs/time_list/$timUserId";
} else {
if (url_is('*get_plannings_list') || url_is('*event-plannings') || url_is('*PersoLogs/perso_time*')) {
$path = "PersoLogs/perso_time";
} else {
$path = "AdminLogs/time_list/$timUserId";
}
}

array_push($data,
[
'link' => '../' . Time::today()->toDateString() . '/' .
$period,
'link' => base_url("$path/$today/$period"),
'label' => ucfirst(lang('tim_lang.today')),
],
[
'link' => base_url("$path/$today/day"),
'label' => ucfirst(lang('tim_lang.day'))
],
[
'link' => base_url("$path/$today/week"),
'label' => ucfirst(lang('tim_lang.week'))
],
[
'link' => base_url("$path/$today/month"),
'label' => ucfirst(lang('tim_lang.month'))
]
);
array_push($data, [
'link' => 'day',
'label' => ucfirst(lang('tim_lang.day'))
]);
array_push($data, [
'link' => 'week',
'label' => ucfirst(lang('tim_lang.week'))
]);
array_push($data, [
'link' => 'month',
'label' => ucfirst(lang('tim_lang.month'))
]);

return $data;
}

Expand Down
9 changes: 8 additions & 1 deletion orif/timbreuse/Controllers/PersonalEventPlannings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
use Timbreuse\Models\UsersModel;
use User\Models\User_model;
use Timbreuse\Controllers\EventSeries;
use Timbreuse\Controllers\PersoLogs;
use CodeIgniter\I18n\Time;

class PersonalEventPlannings extends BaseController
{
// Class properties
protected EventSeries $eventSeriesController;
private PersoLogs $persoLogsController;
private EventPlanningsModel $eventPlanningsModel;
private EventTypesModel $eventTypesModel;
private UsersModel $userSyncModel;
Expand Down Expand Up @@ -46,6 +49,7 @@ public function initController(

// Load required controllers
$this->eventSeriesController = new EventSeries();
$this->persoLogsController = new PersoLogs();
}

/**
Expand Down Expand Up @@ -84,6 +88,9 @@ public function index(?int $timUserId = null) : string|RedirectResponse {
$data['isVisible'] = true;
$data['route'] = $isAdminView ? "AdminLogs/time_list/{$timUserId}" : 'PersoLogs/perso_time';

$data['period'] = 'day';
$data['buttons'] = $this->persoLogsController->get_buttons_for_log_views(Time::today(), $data['period'], $timUserId)['buttons'];

$data['columns'] = [
'event_type_name' => ucfirst(lang('tim_lang.event_type')),
'event_date' => ucfirst(lang('tim_lang.field_event_date')),
Expand Down Expand Up @@ -114,7 +121,7 @@ public function index(?int $timUserId = null) : string|RedirectResponse {
$data['url_delete'] = $eventPlannigRoute . 'delete/serie-or-occurence/';

return $this->display_view([
'Timbreuse\Views\common\return_button',
'Timbreuse\Views\period_menu',
'Common\Views\items_list'], $data);
}

Expand Down
28 changes: 20 additions & 8 deletions orif/timbreuse/Controllers/Plannings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Timbreuse\Models\AccessTimModel;
use Timbreuse\Models\UsersModel;
use CodeIgniter\Model;
use Timbreuse\Controllers\PersoLogs;

use CodeIgniter\I18n\Time;
use CodeIgniter\API\ResponseTrait;
Expand All @@ -20,6 +21,9 @@ class Plannings extends BaseController
use ResponseTrait; # API Response Trait
# to rename, common it is confus,
# here common is beetween create and edit

private PersoLogs $persoLogsController;

protected function get_common_rules(): array
{
$rules['dateEnd'] = 'permit_empty';
Expand Down Expand Up @@ -103,6 +107,7 @@ public function initController(RequestInterface $request,
->access_lvl_registered;
parent::initController($request, $response, $logger);
$this->session = \Config\Services::session();
$this->persoLogsController = new PersoLogs();
}


Expand Down Expand Up @@ -541,9 +546,9 @@ protected function get_user_data_for_plannings_list(int $timUserId,
$withDeleted);
$data['url_create'] = $this->get_link_with_id_or_not(
'Plannings/create_planning', $timUserId);
$data['buttons'][0]['link'] =
/* $data['buttons'][0]['link'] =
"../../AdminLogs/time_list/$timUserId";
$data['buttons'][0]['label'] = ucfirst(lang('tim_lang.back'));
$data['buttons'][0]['label'] = ucfirst(lang('tim_lang.back')); */
$data['url_getView'] =
"Plannings/get_plannings_list/$timUserId/$withDeleted";
$data['url_duplicate'] = 'Plannings/copy_planning/';
Expand Down Expand Up @@ -610,16 +615,23 @@ public function get_plannings_list(?int $timUserId=null,
?bool $withDeleted=false): string
{
$timUserId = $timUserId ?? $this->get_tim_user_id();
if (!$this->is_access($timUserId))
{
$data['period'] = 'day';
$data['buttons'] = $this->persoLogsController->get_buttons_for_log_views(Time::today(), $data['period'], $timUserId)['buttons'];

//dd(current_url(), $data['buttons']);

if (!$this->is_access($timUserId)) {
return $this->display_unauthorize();
}
$data = $this->get_data_for_plannings_list($timUserId, $withDeleted);
# check if the user check himself and show return button if not himself

$data = array_merge($data, $this->get_data_for_plannings_list($timUserId, $withDeleted));

// check if the user check himself and show return button if not himself
if ($timUserId === $this->get_tim_user_id()) {
return $this->display_view('Common\Views\items_list', $data);
return $this->display_view(['Timbreuse\Views\period_menu', 'Common\Views\items_list'], $data);
}
return $this->display_view(['Timbreuse\Views\menu',

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

Expand Down
11 changes: 9 additions & 2 deletions orif/timbreuse/Views/period_menu.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<div class="container py-1">
<ul class='nav nav-pills'>
<?php foreach ($buttons as $button) : ?>
<?php foreach ($buttons as $i => $button) : ?>
<li class='nav-item'>
<a href="<?= esc($button['link']) ?>" class='nav-link
<?php
if ($button['link'] == $period) {
$uriSegments = explode('/', $button['link']);
$lastSegment = array_pop($uriSegments);

if (filter_var($lastSegment, FILTER_VALIDATE_INT) !== false) {
$lastSegment = array_pop($uriSegments);
}

if (url_is("*$lastSegment*") && $i > 2) {
echo 'active';
} else if (($button['label'] == ucfirst(lang('tim_lang.siteData'))) && ($isFakeLog)) {
echo 'active';
Expand Down
Loading