From 51f06a69e457b73189145d37828a591742334f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20K=C5=82opotek=20-=20INTERDUO?= Date: Tue, 19 Mar 2024 09:06:39 +0100 Subject: [PATCH 1/2] improvement: make userlist more unificated/compact by cumulating users into {user_list_compact} --- lib/LMSManagers/LMSEventManager.php | 7 +++-- lib/LMSManagers/LMSHelpdeskManager.php | 29 +++++++++++++----- .../LMSHelpdeskManagerInterface.php | 4 ++- lib/SmartyPlugins/LMSSmartyPlugins.php | 30 +++++++++++++++++++ .../function.user_compact_list.php | 30 +++++++++++++++++++ modules/eventinfo.php | 11 ++++++- modules/eventlist.php | 2 ++ templates/default/event/eventinfo.html | 7 +---- templates/default/event/eventlistboxrow.html | 25 ++++------------ templates/default/rt/rtcategorylist.html | 6 ++-- 10 files changed, 111 insertions(+), 40 deletions(-) create mode 100644 lib/SmartyPlugins/function.user_compact_list.php diff --git a/lib/LMSManagers/LMSEventManager.php b/lib/LMSManagers/LMSEventManager.php index 4b087f685d..bc4727161d 100644 --- a/lib/LMSManagers/LMSEventManager.php +++ b/lib/LMSManagers/LMSEventManager.php @@ -293,9 +293,9 @@ public function GetEvent($id) $event['helpdesk'] = !empty($event['ticketid']); $event['userlist'] = $this->db->GetAllByKey( - 'SELECT u.id, u.rname, u.name, u.login + 'SELECT u.id, u.rname, u.name, u.login, u.deleted, u.access FROM vusers u - JOIN eventassignments a ON a.userid = u.id + JOIN eventassignments a ON a.userid = u.id WHERE a.eventid = ?', 'id', array($id) @@ -514,11 +514,12 @@ public function GetEventList(array $params) $row['nodelocation'] = $customerstuffaddresses[$row['customerid']]; } - $row['userlist'] = $this->db->GetAll( + $row['userlist'] = $this->db->GetAllByKey( 'SELECT userid AS id, vusers.name, vusers.access, vusers.deleted, vusers.accessfrom, vusers.accessto FROM eventassignments, vusers WHERE userid = vusers.id AND eventid = ? ', + 'id', array($row['id']) ); diff --git a/lib/LMSManagers/LMSHelpdeskManager.php b/lib/LMSManagers/LMSHelpdeskManager.php index b2f9d241bd..af0a9bbda3 100644 --- a/lib/LMSManagers/LMSHelpdeskManager.php +++ b/lib/LMSManagers/LMSHelpdeskManager.php @@ -893,10 +893,13 @@ public function GetUserRightsToCategory($user, $category, $ticket = null) return ($owner === '1'); } - public function GetCategoryList($stats = true) + public function GetCategoryList($stats = true, $owners = true) { - if ($result = $this->db->GetAll('SELECT id, name, description, style - FROM rtcategories ORDER BY name')) { + if ($result = $this->db->GetAll( + 'SELECT id, name, description, style + FROM rtcategories + ORDER BY name' + )) { if ($stats) { foreach ($result as $idx => $row) { foreach ($this->GetCategoryStats($row['id']) as $sidx => $row2) { @@ -904,15 +907,27 @@ public function GetCategoryList($stats = true) } } } - foreach ($result as $idx => $category) { - $result[$idx]['owners'] = $this->db->GetAll('SELECT u.id, name FROM rtcategoryusers cu - LEFT JOIN vusers u ON cu.userid = u.id - WHERE categoryid = ?', array($category['id'])); + if ($owners) { + foreach ($result as $idx => $row) { + $result[$idx]['owners'] = $this->GetCategoryUsers($row['id']); + } } } return $result; } + public function GetCategoryUsers($categoryid) + { + return $this->db->GetAll( + 'SELECT u.id, u.name, u.deleted, + (CASE WHEN u.access = 1 AND u.accessfrom <= ?NOW? AND (u.accessto >=?NOW? OR u.accessto = 0) THEN 1 ELSE 0 END) AS access + FROM rtcategoryusers cu + LEFT JOIN vusers u ON cu.userid = u.id + WHERE categoryid = ?', + array($categoryid) + ); + } + public function GetCategoryStats($id) { if ($result = $this->db->GetAll('SELECT state, COUNT(state) AS scount diff --git a/lib/LMSManagers/LMSHelpdeskManagerInterface.php b/lib/LMSManagers/LMSHelpdeskManagerInterface.php index 8c74cf6e2e..a4330c9ef6 100644 --- a/lib/LMSManagers/LMSHelpdeskManagerInterface.php +++ b/lib/LMSManagers/LMSHelpdeskManagerInterface.php @@ -61,7 +61,9 @@ public function GetCategory($id); public function GetUserRightsToCategory($user, $category, $ticket = null); - public function GetCategoryList($stats = true); + public function GetCategoryList($stats = true, $owners = true); + + public function GetCategoryUsers($categoryid); public function GetCategoryStats($id); diff --git a/lib/SmartyPlugins/LMSSmartyPlugins.php b/lib/SmartyPlugins/LMSSmartyPlugins.php index 2e8b60aa47..82e43a03ef 100644 --- a/lib/SmartyPlugins/LMSSmartyPlugins.php +++ b/lib/SmartyPlugins/LMSSmartyPlugins.php @@ -1337,6 +1337,36 @@ public static function networkDeviceTypesFunction(array $params, $template) . ''; } + public static function userCompactListFunction(array $params, $template) + { + $default_user_row_limit = 4; + + $elemid = $params['elemid'] ?? false; + $elemname = $params['elemname'] ?? false; + $class = $params['class'] ?? false; + $limit = empty($params['limit']) ? $default_user_row_limit : intval($params['limit']); + $userlist = empty($params['userlist']) ? trans('No avaiable users') : $params['userlist']; + $usercount = sizeof($userlist); + $ul = ''; + + foreach ($userlist as $item) { + $ul .= '' + . htmlspecialchars(substr(trans($item['name']), 0, 40)) + . '
'; + } + + return '
' + . ($usercount < $limit ? + $ul : self::hintFunction(array('content' => $ul, 'icon' => 'user'), $template) . $usercount) + . '
'; + } + public static function userSelectionFunction(array $params, $template) { static $userlist = array(); diff --git a/lib/SmartyPlugins/function.user_compact_list.php b/lib/SmartyPlugins/function.user_compact_list.php new file mode 100644 index 0000000000..ce2eec545c --- /dev/null +++ b/lib/SmartyPlugins/function.user_compact_list.php @@ -0,0 +1,30 @@ +redirect('?m=eventlist'); } +$user_row_limit = ConfigHelper::getConfig( + 'timetable.row_user_limit', + ConfigHelper::getConfig('phpui.timetable_user_row_limit', 4) +); $event = $LMS->GetEvent($_GET['id']); @@ -34,6 +38,11 @@ $SESSION->add_history_entry(); -$SMARTY->assign('event', $event); +$SMARTY->assign( + array( + 'event' => $event, + 'user_row_limit' => $user_row_limit, + ) +); $SMARTY->display('event/eventinfo.html'); diff --git a/modules/eventlist.php b/modules/eventlist.php index f43cb5543b..281af386d3 100644 --- a/modules/eventlist.php +++ b/modules/eventlist.php @@ -38,6 +38,7 @@ $hide_disabled_users = ConfigHelper::checkConfig('timetable.hide_disabled_users', ConfigHelper::checkConfig('phpui.timetable_hide_disabled_users')); $show_delayed_events = ConfigHelper::checkConfig('timetable.show_delayed_events', ConfigHelper::checkConfig('phpui.timetable_overdue_events')); $big_networks = ConfigHelper::checkConfig('phpui.big_networks'); +$user_row_limit = ConfigHelper::getConfig('timetable.row_user_limit', ConfigHelper::getConfig('phpui.timetable_user_row_limit', 4)); $params['userid'] = Auth::GetCurrentUser(); if (!empty($filter['edate'])) { @@ -248,5 +249,6 @@ 'overdue_events_only' => $overdue_events_only, 'getHolidays', getHolidays($year ?? null), 'customerlist' => $big_networks ? null : $LMS->GetCustomerNames(), + 'user_row_limit' => $user_row_limit, )); $SMARTY->display('event/eventlist.html'); diff --git a/templates/default/event/eventinfo.html b/templates/default/event/eventinfo.html index 76fdde7e2f..0d8e92fbc8 100644 --- a/templates/default/event/eventinfo.html +++ b/templates/default/event/eventinfo.html @@ -301,12 +301,7 @@

{$layout.pagetitle}

{trans("Users")} - {foreach $event.userlist as $userid => $user} - {$user.rname|escape} - {if !$user@last} -
- {/if} - {/foreach} + {user_compact_list limit=$user_row_limit userlist=$event.userlist} {/if} diff --git a/templates/default/event/eventlistboxrow.html b/templates/default/event/eventlistboxrow.html index 85a26ee2f0..03f06e1906 100644 --- a/templates/default/event/eventlistboxrow.html +++ b/templates/default/event/eventlistboxrow.html @@ -15,7 +15,7 @@ {/if} - + {if $event.endtime == 86400} {trans("whole day")} {else} @@ -28,24 +28,11 @@ {if $overdue == 1}
{$event.date|date_format:"Y-m-d"} {/if} - {$imadded=0} - {$user_row_limit = intval(ConfigHelper::getConfig('timetable.row_user_limit', ConfigHelper::getConfig('phpui.timetable_user_row_limit', 4)))} - {if !empty($event.userlist)} - {if !$user_row_limit || count($event.userlist) <= $user_row_limit} - {foreach $event.userlist as $user} - {if $layout.logid == $user.id} - {$imadded=1} - {/if} -
- {$user.name|trunescape:25} - {/foreach} - {else} -
- - {$event.userlist|@count} - {/if} + {user_compact_list limit=$user_row_limit userlist=$event.userlist} + {if in_array($layout.logid, array_column($event.userlist, 'id'))} + {assign var="imadded" value=1} + {else} + {assign var="imadded" value=0} {/if} diff --git a/templates/default/rt/rtcategorylist.html b/templates/default/rt/rtcategorylist.html index 283900775b..f9988aaa61 100644 --- a/templates/default/rt/rtcategorylist.html +++ b/templates/default/rt/rtcategorylist.html @@ -1,6 +1,8 @@ {extends file="layout.html"} {block name=title}LMS: {$layout.pagetitle|striphtml}{/block} {block name=module_content} +{$user_row_limit = ConfigHelper::getConfig('rt.row_user_limit', 4)} +

{$layout.pagetitle}

@@ -59,9 +61,7 @@

{$layout.pagetitle}

- {foreach $category.owners as $key => $owner} - {$owner.name}{if $key+1 {$category.new|default:0} From 574a025da9da40b50ee1a9a4dcb33b271c5c8f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20K=C5=82opotek=20-=20INTERDUO?= Date: Tue, 19 Mar 2024 13:56:34 +0100 Subject: [PATCH 2/2] improvement: added ID of event in title --- modules/eventinfo.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/eventinfo.php b/modules/eventinfo.php index 52a7be5911..cac00f5d34 100644 --- a/modules/eventinfo.php +++ b/modules/eventinfo.php @@ -26,15 +26,17 @@ if (!$_GET['id']) { $SESSION->redirect('?m=eventlist'); +} else { + $id = intval($_GET['id']); } $user_row_limit = ConfigHelper::getConfig( 'timetable.row_user_limit', ConfigHelper::getConfig('phpui.timetable_user_row_limit', 4) ); -$event = $LMS->GetEvent($_GET['id']); +$event = $LMS->GetEvent($id); -$layout['pagetitle'] = trans('Event Info'); +$layout['pagetitle'] = trans('Event Info') . '#' . $id; $SESSION->add_history_entry();