Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions components/ILIAS/LearningSequence/LearningSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ public function init(
new \ilLearningSequenceSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
);

$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "js/lso_kiosk_rating.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public function getPageBuilderDecorator(CalledContexts $screen_context_stack): ?
}

$exit = $this->data_collection->get(\ilLSPlayer::GS_DATA_LS_METABARCONTROLS)['exit'];
$label = $this->dic['lng']->txt('lso_player_viewmodelabel');

$label = $this->data_collection->get(\ilLSPlayer::GS_DATA_LS_TITLE)
?? $this->dic['lng']->txt('lso_player_viewmodelabel');

$lnk = new URI($exit->getAction());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public function next(string $command, ?int $parameter = null): ControlBuilder
throw new \LogicException("Only one next-control per view...", 1);
}
$label = $this->lng->txt('lso_player_next');
if ($command === ilLSPlayer::LSO_CMD_FINISH) {
$label = $this->lng->txt('lso_player_finish');
}
$cmd = $this->url_builder->getHref($command, $parameter);
$btn = $this->ui_factory->button()->standard($label, $cmd);
if ($command === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,41 @@ public function buildToCSlate(LSTOCBuilder $toc, Icon $icon): Slate
);
}

public function addOnLoadCode(string $code, int $batch = 2): void
{
$this->layout_meta_content->addOnloadCode($code, $batch);
}

public function addJs(string $path, bool $add_version_number = false, int $batch = 2): void
{
$this->layout_meta_content->addJs($path, $add_version_number, $batch);
}

public function render(
LSControlBuilder $control_builder,
string $obj_title,
string $obj_description,
Component $icon,
array $content
array $content,
string $obj_rating_html = ''
): string {
$this->tpl->setVariable(
"OBJECT_ICON",
$this->ui_renderer->render($icon)
);
$this->tpl->setVariable("OBJECT_TITLE", $obj_title);

$obj_description = trim($obj_description);
if ($obj_description !== '') {
$this->tpl->setCurrentBlock('obj_desc');
$this->tpl->setVariable(
'OBJECT_DESCRIPTION',
nl2br(ilLegacyFormElementsUtil::prepareFormOutput($obj_description, true))
);
$this->tpl->parseCurrentBlock();
}
$this->tpl->setVariable('OBJECT_RATING', $obj_rating_html);

$this->tpl->setVariable(
"PLAYER_NAVIGATION",
$this->ui_renderer->render([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public function __construct(
$this->url_builder = $url_builder;
}

public function getLearnerCurriculum(bool $with_action = false): ILIAS\UI\Component\Listing\Workflow\Linear
{
public function getLearnerCurriculum(
bool $with_action = false,
?string $title = null
): ILIAS\UI\Component\Listing\Workflow\Linear {
$steps = [];
$items = $this->ls_items->getItems();
foreach ($items as $item) {
Expand All @@ -69,7 +71,7 @@ public function getLearnerCurriculum(bool $with_action = false): ILIAS\UI\Compon
}

$workflow = $this->ui_factory->listing()->workflow()->linear(
$this->lng->txt('curriculum'),
$title ?? $this->lng->txt('curriculum'),
$steps
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public function __construct(
$this->usr_id = $usr_id;
}

public function hasItems() : bool
public function getLearningSequenceRefId(): int
{
return $this->ls_ref_id;
}

public function hasItems(): bool
{
return count($this->getItems()) > 0;
}
Expand Down
108 changes: 104 additions & 4 deletions components/ILIAS/LearningSequence/classes/Player/class.ilLSPlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ilLSPlayer
public const LSO_CMD_FINISH = 'lsofinish';

public const GS_DATA_LS_KIOSK_MODE = 'ls_kiosk_mode';
public const GS_DATA_LS_TITLE = 'ls_title';
public const GS_DATA_LS_CONTENT = 'ls_content';
public const GS_DATA_LS_MAINBARCONTROLS = 'ls_mainbar_controls';
public const GS_DATA_LS_METABARCONTROLS = 'ls_metabar_controls';
Expand All @@ -59,6 +60,10 @@ public function __construct(

public function play(RequestWrapper $get): ?string
{
$ls_ref_id = $this->ls_items->getLearningSequenceRefId();
$ls_obj_id = ilObject::_lookupObjId($ls_ref_id);
$ls_title = ilObject::_lookupTitle($ls_obj_id);

$items = $this->ls_items->getItems();

if (count($items) === 0) {
Expand Down Expand Up @@ -115,6 +120,7 @@ public function play(RequestWrapper $get): ?string

//content
$obj_title = $next_item->getTitle();
$obj_description = $next_item->getDescription();
$icon = $this->ui_factory->symbol()->icon()->standard(
$next_item->getType(),
$next_item->getType(),
Expand All @@ -141,11 +147,99 @@ public function play(RequestWrapper $get): ?string
//amend controls not set by the view
$control_builder = $this->buildDefaultControls($control_builder, $item, $item_position, $items);

// Keep a stable header layout: reserve the rating slot even if rating is not available.
// Otherwise the navigation/buttons would shift vertically.
$obj_rating_html = ' ';
$obj_id = ilObject::_lookupObjId($next_item->getRefId());
if ($obj_id > 0) {
$obj_type = ilObject::_lookupType($obj_id);
ilRating::preloadListGUIData([$obj_id]);
if ($obj_type !== '' && ilRating::hasRatingInListGUI($obj_id, $obj_type)) {
global $DIC;
$lng = $DIC->language();

$parent_ref_id = (int) $ls_ref_id;
$rating_container_id = 'lg_div_' . $next_item->getRefId() . '_pref_' . $parent_ref_id;

$ajax_hash = ilCommonActionDispatcherGUI::buildAjaxHash(
ilCommonActionDispatcherGUI::TYPE_REPOSITORY,
$next_item->getRefId(),
$obj_type,
$obj_id
);

$rating_gui = new ilRatingGUI();
$rating_gui->setObject($obj_id, $obj_type);
$rating_gui->setCtrlPath([
ilCommonActionDispatcherGUI::class,
ilRatingGUI::class
]);
$rating_gui->setYourRatingText($lng->txt('rating_your_rating'));

$rating_content = $rating_gui->getListGUIProperty(
$next_item->getRefId(),
true,
$ajax_hash,
$parent_ref_id
);

$tpl = new ilTemplate(
'tpl.lso_kiosk_rating_container.html',
true,
true,
'components/ILIAS/LearningSequence'
);
$tpl->setVariable('CONTAINER_ID', $rating_container_id);
$tpl->setVariable('CHILD_REF_ID', (string) $next_item->getRefId());
$tpl->setVariable('AJAX_HASH', htmlspecialchars($ajax_hash, ENT_QUOTES));
$tpl->setVariable('RATING_CONTENT', $rating_content);
$obj_rating_html = $tpl->get();

$ilCtrl = $DIC->ctrl();
$redraw_url = $ilCtrl->getLinkTargetByClass(
ilObjLearningSequenceLearnerGUI::class,
ilObjLearningSequenceLearnerGUI::CMD_REDRAW_LIST_ITEM,
'',
true,
false
);

$rating_url = $ilCtrl->getLinkTargetByClass(
[
ilCommonActionDispatcherGUI::class,
ilRatingGUI::class
],
'saveRating',
'',
true,
false
);

$this->page_renderer->addOnLoadCode(
"if (window.il && window.il.Object) {" .
" if (typeof window.il.Object.setRedrawListItemUrl === 'function') { window.il.Object.setRedrawListItemUrl(" . json_encode($redraw_url, JSON_THROW_ON_ERROR) . "); }" .
" if (typeof window.il.Object.setRatingUrl === 'function') { window.il.Object.setRatingUrl(" . json_encode($rating_url, JSON_THROW_ON_ERROR) . "); }" .
"}"
);

$this->page_renderer->addJs(
'assets/js/lso_kiosk_rating.js',
true
);
$this->page_renderer->addOnLoadCode(
"if (window.il && window.il.LSO && window.il.LSO.KioskRating && " .
"typeof window.il.LSO.KioskRating.init === 'function') { window.il.LSO.KioskRating.init(); }"
);
}
}

$rendered_body = $this->page_renderer->render(
$control_builder,
$obj_title,
$obj_description,
$icon,
$content
$content,
$obj_rating_html
);

$metabar_controls = [
Expand All @@ -154,7 +248,7 @@ public function play(RequestWrapper $get): ?string

$curriculum_slate = $this->page_renderer->buildCurriculumSlate(
$this->curriculum_builder
->getLearnerCurriculum(true)
->getLearnerCurriculum(true, $ls_title)
->withActive($item_position)
);
$mainbar_controls = [
Expand All @@ -169,6 +263,7 @@ public function play(RequestWrapper $get): ?string

$cc = $this->current_context;
$cc->addAdditionalData(self::GS_DATA_LS_KIOSK_MODE, true);
$cc->addAdditionalData(self::GS_DATA_LS_TITLE, $ls_title);
$cc->addAdditionalData(self::GS_DATA_LS_METABARCONTROLS, $metabar_controls);
$cc->addAdditionalData(self::GS_DATA_LS_MAINBARCONTROLS, $mainbar_controls);
$cc->addAdditionalData(self::GS_DATA_LS_CONTENT, $rendered_body);
Expand Down Expand Up @@ -299,7 +394,12 @@ protected function buildDefaultControls(
if (!$control_builder->getNextControl()) {
$direction_next = 1;
$cmd = '';
if (!$is_last) {
$param = $direction_next;

if ($is_last) {
$cmd = self::LSO_CMD_FINISH;
$param = null;
} else {
$available = $this->getNextItem($items, $item, $direction_next)
->getAvailability() === Step::AVAILABLE;

Expand All @@ -309,7 +409,7 @@ protected function buildDefaultControls(
}

$control_builder = $control_builder
->next($cmd, $direction_next);
->next($cmd, $param);
}

return $control_builder;
Expand Down
Loading
Loading