From a82d785461093ff84ee4755fee0f6d8ce003c679 Mon Sep 17 00:00:00 2001 From: Tim Schmitz Date: Mon, 9 Dec 2024 13:39:36 +0100 Subject: [PATCH] Tracking: personal learning progress shows courses without period as current, titles as links --- .../class.ilLPPersonalGUI.php | 32 +++++++++++++++---- .../classes/View/Renderer/Renderer.php | 10 ++++-- .../View/Renderer/RendererInterface.php | 7 +++- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/components/ILIAS/Tracking/classes/View/PersonalLearningProgress/class.ilLPPersonalGUI.php b/components/ILIAS/Tracking/classes/View/PersonalLearningProgress/class.ilLPPersonalGUI.php index 0e29c5b715f5..ccc2de8cbcab 100644 --- a/components/ILIAS/Tracking/classes/View/PersonalLearningProgress/class.ilLPPersonalGUI.php +++ b/components/ILIAS/Tracking/classes/View/PersonalLearningProgress/class.ilLPPersonalGUI.php @@ -28,6 +28,8 @@ use ILIAS\UI\URLBuilder; use ILIAS\Data\Factory as DataFactory; use ILIAS\UI\Component\Item\Standard as UIStandardItem; +use ILIAS\StaticURL\Services as StaticURL; +use ILIAS\Data\URI as URI; /** * @ilCtrl_IsCalledBy ilLPPersonalGUI: ilDashboardGUI @@ -60,11 +62,13 @@ class ilLPPersonalGUI protected RefineryFactory $refinery; protected DataFactory $data_factory; protected ilAccessHandler $access; + protected StaticURL $static_url; protected ViewFactoryInterface $tracking_view; public function __construct() { global $DIC; + $this->ui = $DIC->ui(); $this->ctrl = $DIC->ctrl(); $this->user = $DIC->user(); @@ -73,6 +77,7 @@ public function __construct() $this->refinery = $DIC->refinery(); $this->access = $DIC->access(); $this->data_factory = new DataFactory(); + $this->static_url = $DIC['static_url']; $this->tracking_view = new ViewFactory(); $this->lng->loadLanguageModule("trac"); } @@ -167,7 +172,8 @@ protected function buildPanelItems( ->withProperty($this->lng->txt(self::LNG_VAR_PROPERTY_CRS_ONLINE), $offline_str); $item = $this->tracking_view->renderer()->service()->standardItem( $combinedInfo->getObjectInfo(), - $property_builder->getList() + $property_builder->getList(), + $this->buildLinkToCourse($obj_id) ); if ( $combinedInfo->getLPInfo()->getLPMode() !== ilLPObjSettings::LP_MODE_UNDEFINED && @@ -187,28 +193,28 @@ protected function isPresentable( ilDateTime|null $crs_end ): bool { $now = new ilDateTime(time(), IL_CAL_UNIX); - $crs_start = is_null($crs_start) ? $crs_end : $crs_start; - $crs_end = is_null($crs_end) ? $crs_start : $crs_end; - $dates_set = !is_null($crs_start) && !is_null($crs_end); + $crs_start = (is_null($crs_start) || $crs_start->isNull()) ? $now : $crs_start; + $crs_end = (is_null($crs_end) || $crs_end->isNull()) ? $now : $crs_end; if ($presentation_mode === self::PRESENTATION_OPTION_ALL) { return true; } + // courses without end are never in the past if ( - $dates_set && $presentation_mode === self::PRESENTATION_OPTION_PAST && ilDateTime::_after($now, $crs_end) ) { return true; } + // courses without start are never in the future if ( - $dates_set && $presentation_mode === self::PRESENTATION_OPTION_FUTURE && ilDateTime::_before($now, $crs_start) ) { return true; } + // courses without start and end are always current + // courses without start or end are current if their end/start is not in the past/future if ( - $dates_set && $presentation_mode === self::PRESENTATION_OPTION_CURRENT && ilDateTime::_within($now, $crs_start, $crs_end) ) { @@ -241,4 +247,16 @@ protected function hasReadAccess(int $obj_id): bool } return false; } + + protected function buildLinkToCourse(int $obj_id): ?URI + { + $ref_ids = ilObject::_getAllReferences($obj_id); + if (count($ref_ids) === 0) { + return null; + } + return $this->static_url->builder()->build( + 'crs', + $this->data_factory->refId((int) current($ref_ids)) + ); + } } diff --git a/components/ILIAS/Tracking/classes/View/Renderer/Renderer.php b/components/ILIAS/Tracking/classes/View/Renderer/Renderer.php index a88e35803b04..23654b4e0e42 100644 --- a/components/ILIAS/Tracking/classes/View/Renderer/Renderer.php +++ b/components/ILIAS/Tracking/classes/View/Renderer/Renderer.php @@ -31,6 +31,7 @@ use ILIAS\UI\Component\Symbol\Icon\Standard as UIStandardIcon; use ilLPObjSettings; use ilLPStatus; +use ILIAS\Data\URI; class Renderer implements RendererInterface { @@ -59,7 +60,8 @@ public function fixedSizeProgressMeter( public function standardItem( ObjectDataInterface $object_info, - PropertyListInterface $property_list + PropertyListInterface $property_list, + ?URI $title_link = null ): UIStandardItem { $properties = []; foreach ($property_list as $property) { @@ -70,7 +72,11 @@ public function standardItem( $object_info->getType() . " Icon", UIIconIcon::MEDIUM ); - return $this->ui->factory()->item()->standard($object_info->getTitle()) + $title = $object_info->getTitle(); + if ($title_link !== null) { + $title = $this->ui->factory()->link()->standard($title, (string) $title_link); + } + return $this->ui->factory()->item()->standard($title) ->withProperties($properties) ->withDescription($object_info->getDescription()) ->withLeadIcon($icon); diff --git a/components/ILIAS/Tracking/classes/View/Renderer/RendererInterface.php b/components/ILIAS/Tracking/classes/View/Renderer/RendererInterface.php index 176c6fe8b7a7..a41488754dbd 100644 --- a/components/ILIAS/Tracking/classes/View/Renderer/RendererInterface.php +++ b/components/ILIAS/Tracking/classes/View/Renderer/RendererInterface.php @@ -25,6 +25,7 @@ use ILIAS\Tracking\View\PropertyList\PropertyListInterface; use ILIAS\UI\Component\Item\Standard as UIStandardItem; use ILIAS\UI\Component\Chart\ProgressMeter\Standard as UIStandardProgressMeter; +use ILIAS\Data\URI; interface RendererInterface { @@ -32,9 +33,13 @@ public function standardProgressMeter( LPInterface $lp_info ): UIStandardProgressMeter; + /** + * The optional link is applied to the title. + */ public function standardItem( ObjectDataInterface $object_info, - PropertyListInterface $property_list + PropertyListInterface $property_list, + ?URI $title_link = null ): UIStandardItem; public function fixedSizeProgressMeter(