ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGlossaryFlashcardGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI;
24
31{
32 protected ilCtrl $ctrl;
33 protected ilLanguage $lng;
36 protected UI\Factory $ui_fac;
37 protected UI\Renderer $ui_ren;
40
41 public function __construct()
42 {
43 global $DIC;
44
45 $this->ctrl = $DIC->ctrl();
46 $this->lng = $DIC->language();
47 $this->tpl = $DIC->ui()->mainTemplate();
48 $this->tabs_gui = $DIC->tabs();
49 $this->ui_fac = $DIC->ui()->factory();
50 $this->ui_ren = $DIC->ui()->renderer();
51
52 $this->request = $DIC->glossary()
53 ->internal()
54 ->gui()
55 ->presentation()
56 ->request();
57 $gs = $DIC->glossary()->internal();
58 $this->manager = $gs->domain()->flashcard($this->request->getRefId());
59 }
60
61 public function executeCommand(): void
62 {
63 $next_class = $this->ctrl->getNextClass($this);
64 $cmd = $this->ctrl->getCmd();
65
66 switch ($next_class) {
67 case "ilglossaryflashcardboxgui":
68 $flash_boxes = new ilGlossaryFlashcardBoxGUI();
69 $this->ctrl->forwardCommand($flash_boxes);
70 break;
71
72 default:
73 $cmd = $this->ctrl->getCmd("listBoxes");
74 $ret = $this->$cmd();
75 break;
76 }
77 }
78
79 public function listBoxes(): void
80 {
81 $flashcard_tpl = new ilTemplate("tpl.flashcard_overview.html", true, true, "components/ILIAS/Glossary");
82
83 $reset_btn = $this->ui_fac->button()->standard(
84 $this->lng->txt("glo_reset_all_boxes"),
85 $this->ctrl->getLinkTarget($this, "confirmResetBoxes")
86 );
87 $flashcard_tpl->setVariable("RESET_BUTTON", $this->ui_ren->render($reset_btn));
88
89 $intro_box = $this->ui_fac->panel()->standard(
90 $this->lng->txt("glo_introduction"),
91 $this->ui_fac->legacy()->content($this->lng->txt("glo_flashcards_intro"))
92 );
93 $flashcard_tpl->setVariable("INTRO_BOX", $this->ui_ren->render($intro_box));
94
95 $boxes = [];
96 for ($b = 1; $b <= 5; $b++) {
97 $box = $this->getItemBox($b);
98 $boxes[] = $box;
99 }
100
101 $boxes_pnl = $this->ui_fac->panel()->listing()->standard(
102 $this->lng->txt("glo_boxes"),
103 [$this->ui_fac->item()->group("", $boxes)]
104 );
105 $flashcard_tpl->setVariable("BOXES", $this->ui_ren->render($boxes_pnl));
106
107 $this->tpl->setContent($flashcard_tpl->get());
108 }
109
110 protected function getItemBox(int $nr): \ILIAS\UI\Component\Item\Item
111 {
112 $item_cnt = $this->manager->getItemsForBoxCount($nr);
113 $last_access = $this->manager->getLastAccessForBoxAsDaysText($nr);
114
115 if (($this->manager->getUserTermsForBox($nr) && $nr !== Flashcard\FlashcardBox::LAST_BOX)
116 || ($this->manager->getAllTermsWithoutEntry() && $nr === Flashcard\FlashcardBox::FIRST_BOX)) {
117 $this->ctrl->setParameterByClass("ilglossaryflashcardboxgui", "box_id", $nr);
118 $title = $this->ui_fac->link()->standard(
119 $this->lng->txt("glo_box") . " " . $nr,
120 $this->ctrl->getLinkTargetByClass('ilglossaryflashcardboxgui', 'show')
121 );
122 } else {
123 $title = $this->lng->txt("glo_box") . " " . $nr;
124 }
125
126 $box = $this->ui_fac->item()->standard($title);
127 if ($nr === Flashcard\FlashcardBox::LAST_BOX) {
128 $box = $box->withProperties([
129 $this->lng->txt("glo_flashcards") => (string) $item_cnt
130 ]);
131 } else {
132 $box = $box->withProperties([
133 $this->lng->txt("glo_flashcards") => (string) $item_cnt,
134 $this->lng->txt("glo_box_last_presented") => $last_access
135 ]);
136 }
137
138 return $box;
139 }
140
141 public function confirmResetBoxes(): void
142 {
143 $yes_button = $this->ui_fac->button()->standard(
144 $this->lng->txt("yes"),
145 $this->ctrl->getLinkTarget($this, "resetBoxes")
146 );
147 $no_button = $this->ui_fac->button()->standard(
148 $this->lng->txt("no"),
149 $this->ctrl->getLinkTarget($this, "cancelResetBoxes")
150 );
151 $cbox = $this->ui_fac->messageBox()->confirmation($this->lng->txt("glo_boxes_really_reset"))
152 ->withButtons([$yes_button, $no_button]);
153 $this->tpl->setContent($this->ui_ren->render($cbox));
154 }
155
156 public function cancelResetBoxes(): void
157 {
158 $this->ctrl->redirectByClass("ilglossarypresentationgui", "showFlashcards");
159 }
160
161 public function resetBoxes(): void
162 {
163 $this->manager->resetEntries();
164 $this->tpl->setOnScreenMessage('success', $this->lng->txt("glo_boxes_reset"), true);
165 $this->ctrl->redirectByClass("ilglossarypresentationgui", "showFlashcards");
166 }
167}
Definition: UI.php:24
Class ilCtrl provides processing control methods.
GUI class for glossary flashcard boxes.
GUI class for glossary flashcards.
Presentation PresentationGUIRequest $request
ilGlobalTemplateInterface $tpl
Flashcard FlashcardManager $manager
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26