Skip to content

Commit

Permalink
Remove buttons on non admin page and add a marker on linked groups
Browse files Browse the repository at this point in the history
  • Loading branch information
catdesu committed Jul 2, 2024
1 parent 72e8d4c commit b954ee0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
3 changes: 3 additions & 0 deletions orif/timbreuse/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
});
});

$routes->get('user-groups', '\Timbreuse\Controllers\UserGroups::displayByUserId');
$routes->get('user-groups/(:num)', '\Timbreuse\Controllers\UserGroups::displayByUserId/$1');

// Personal event planning
$routes->group('event-plannings', function($routes) {
$routes->get('', '\Timbreuse\Controllers\PersonalEventPlannings::index');
Expand Down
5 changes: 3 additions & 2 deletions orif/timbreuse/Controllers/PersoLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ protected function create_event_planning_link(?int $timUserId=null): array
public function create_user_group_link(?int $timUserId=null): array
{
helper('UtilityFunctions');
if ($timUserId === get_tim_user_id()) {
if ($timUserId === get_tim_user_id()
&& $_SESSION['user_access'] < config('\User\Config\UserConfig')->access_lvl_admin) {
$button['link'] = base_url('user-groups');
} else {
$button['link'] = base_url("admin/user-groups/$timUserId");
$button['link'] = base_url("user-groups/$timUserId");
}
$button['label'] = ucfirst(lang('tim_lang.user_group_list'));
return $button;
Expand Down
2 changes: 1 addition & 1 deletion orif/timbreuse/Controllers/PersonalEventPlannings.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,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\period_menu',
'Timbreuse\Views\period_menu',
'Common\Views\items_list'], $data);
}

Expand Down
14 changes: 11 additions & 3 deletions orif/timbreuse/Controllers/UserGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function initController(
): void {
// Set Access level before calling parent constructor
// Accessibility reserved to admin users
$this->access_level = config('\User\Config\UserConfig')->access_lvl_admin;
$this->access_level = config('\User\Config\UserConfig')->access_lvl_registered;
parent::initController($request, $response, $logger);

// Load required helpers
Expand Down Expand Up @@ -94,8 +94,14 @@ private function getParents(?int $groupId): array|null {
*
* @return string
*/
public function displayByUserId(int $timUserId) : string {
public function displayByUserId(?int $timUserId = null) : string {
helper('UtilityFunctions');
if (is_null($timUserId)) {
$timUserId = get_tim_user_id();
}

$allParentGroups = [];
$linkedUserGroups = [];
$user = $this->userSyncModel->find($timUserId);

$data['title'] = lang('tim_lang.title_user_group_of', [
Expand All @@ -110,16 +116,18 @@ public function displayByUserId(int $timUserId) : string {
->findAll();

foreach ($userGroups as $userGroup) {
array_push($linkedUserGroups, $userGroup['id']);
$parentGroups = $this->getParents($userGroup['fk_parent_user_group_id']);

if (!is_null($parentGroups)) {
array_push($allParentGroups, ...$parentGroups);
}
}
}

$userGroups = array_merge($userGroups, $allParentGroups);

$data['userGroups'] = $this->formatForListView($userGroups);
$data['linkedUserGroups'] = $linkedUserGroups;

$data['period'] = 'day';
$data['buttons'] = $this->persoLogsController->get_buttons_for_log_views(Time::today(), $data['period'], $timUserId)['buttons'];
Expand Down
28 changes: 18 additions & 10 deletions orif/timbreuse/Views/userGroups/list.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php $isAdminView = url_is('*admin*'); ?>
<div class="container">
<div class="row mb-2">
<div class="text-left col-12">
<h3><?= esc($title) ?></h3>
</div>
<div class="col-sm-6 text-left">
<a class="btn btn-primary" href="<?= current_url() . '/create' ?>"><?= lang('common_lang.btn_add') ?></a>
</div>
<?php if ($isAdminView): ?>
<div class="col-sm-6 text-left">
<a class="btn btn-primary" href="<?= current_url() . '/create' ?>"><?= lang('common_lang.btn_add') ?></a>
</div>
<?php endif; ?>
</div>

<table class="table table-hover tree-table">
Expand All @@ -16,14 +19,19 @@
<tbody id="table-body">
<?php foreach($userGroups as $userGroup): ?>
<tr class="<?= is_null($userGroup['fk_parent_user_group_id']) ? 'bg-light' : '' ?>">
<td><?= ($userGroup['name']) ?></td>
<td>
<?= (isset($linkedUserGroups)
&& in_array($userGroup['id'], $linkedUserGroups) ? '<i class="bi bi-circle-fill"></i> ': '') . $userGroup['name'] ?>
</td>
<td class="text-right">
<a href="<?= current_url() . "/update/{$userGroup['id']}" ?>">
<i class="bi bi-pencil" style="font-size: 20px;"></i>
</a>
<a href="<?= current_url() . "/delete/{$userGroup['id']}" ?>">
<i class="bi bi-trash" style="font-size: 20px;"></i>
</a>
<?php if ($isAdminView): ?>
<a href="<?= current_url() . "/update/{$userGroup['id']}" ?>">
<i class="bi bi-pencil" style="font-size: 20px;"></i>
</a>
<a href="<?= current_url() . "/delete/{$userGroup['id']}" ?>">
<i class="bi bi-trash" style="font-size: 20px;"></i>
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach ?>
Expand Down

0 comments on commit b954ee0

Please sign in to comment.