ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGlossaryFlashcardBoxGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI;
24
30{
31 protected ilCtrl $ctrl;
32 protected ilLanguage $lng;
34 protected UI\Factory $ui_fac;
35 protected UI\Renderer $ui_ren;
38 protected int $box_nr = 0;
39 protected array $initial_terms_in_box = [];
40 protected array $terms_in_box = [];
43
44 public function __construct()
45 {
46 global $DIC;
47
48 $this->ctrl = $DIC->ctrl();
49 $this->lng = $DIC->language();
50 $this->tpl = $DIC->ui()->mainTemplate();
51 $this->ui_fac = $DIC->ui()->factory();
52 $this->ui_ren = $DIC->ui()->renderer();
53 $this->request = $DIC->glossary()
54 ->internal()
55 ->gui()
56 ->presentation()
57 ->request();
58 $gs = $DIC->glossary()->internal();
59 $this->manager = $gs->domain()->flashcard($this->request->getRefId());
60
61 $this->ctrl->saveParameter($this, ["box_id"]);
62 $this->box_nr = $this->request->getBoxId();
63 $this->initial_terms_in_box = $this->manager->getSessionInitialTerms($this->box_nr);
64 $this->terms_in_box = $this->manager->getSessionTerms($this->box_nr);
65 $this->current_term = $this->terms_in_box[0] ?? null;
66 $this->glossary = new ilObjGlossary($this->request->getRefId());
67 }
68
69 public function executeCommand(): void
70 {
71 $next_class = $this->ctrl->getNextClass($this);
72 $cmd = $this->ctrl->getCmd();
73
74 switch ($next_class) {
75 default:
76 $cmd = $this->ctrl->getCmd("show");
77 $ret = $this->$cmd();
78 break;
79 }
80 }
81
82 public function show(): void
83 {
84 if ($this->box_nr === Flashcard\FlashcardBox::FIRST_BOX) {
85 $cnt_all = count($this->manager->getUserTermsForBox($this->box_nr))
86 + count($this->manager->getAllTermsWithoutEntry());
87 $cnt_remaining = count($this->manager->getNonTodayUserTermsForBox($this->box_nr))
88 + count($this->manager->getAllTermsWithoutEntry());
89 } else {
90 $cnt_all = count($this->manager->getUserTermsForBox($this->box_nr));
91 $cnt_remaining = count($this->manager->getNonTodayUserTermsForBox($this->box_nr));
92 }
93 $cnt_today = count($this->manager->getTodayUserTermsForBox($this->box_nr));
94
95 if (($this->box_nr === Flashcard\FlashcardBox::FIRST_BOX
96 && !$this->manager->getAllTermsWithoutEntry()
97 && !$this->manager->getNonTodayUserTermsForBox($this->box_nr)
98 && $this->manager->getTodayUserTermsForBox($this->box_nr))
99 || ($this->box_nr !== Flashcard\FlashcardBox::FIRST_BOX
100 && !$this->manager->getNonTodayUserTermsForBox($this->box_nr)
101 && $this->manager->getTodayUserTermsForBox($this->box_nr))) {
102 $all_button = $this->ui_fac->button()->standard(
103 sprintf($this->lng->txt("glo_use_all_flashcards"), $cnt_all),
104 $this->ctrl->getLinkTarget($this, "showAllItems")
105 );
106 $cbox = $this->ui_fac->messageBox()->info(
107 sprintf($this->lng->txt("glo_flashcards_from_today_only_info"), $cnt_all)
108 )->withButtons([$all_button]);
109 $this->tpl->setContent($this->ui_ren->render($cbox));
110 } elseif ($this->manager->getTodayUserTermsForBox($this->box_nr)) {
111 $remaining_button = $this->ui_fac->button()->standard(
112 sprintf($this->lng->txt("glo_use_remaining_flashcards"), $cnt_remaining),
113 $this->ctrl->getLinkTarget($this, "showRemainingItems")
114 );
115 $all_button = $this->ui_fac->button()->standard(
116 sprintf($this->lng->txt("glo_use_all_flashcards"), $cnt_all),
117 $this->ctrl->getLinkTarget($this, "showAllItems")
118 );
119 $cbox = $this->ui_fac->messageBox()->info(
120 sprintf($this->lng->txt("glo_flashcards_from_today_confirmation"), $cnt_today, $cnt_remaining, $cnt_all)
121 )->withButtons([$remaining_button, $all_button]);
122 $this->tpl->setContent($this->ui_ren->render($cbox));
123 } else {
124 $this->showAllItems();
125 }
126 }
127
128 public function showAllItems(): void
129 {
130 $this->showItems(true);
131 }
132
133 public function showRemainingItems(): void
134 {
135 $this->showItems(false);
136 }
137
138 public function showItems(bool $all): void
139 {
140 if ($all) {
141 $terms = $this->manager->getUserTermsForBox($this->box_nr);
142 } else {
143 $terms = $this->manager->getNonTodayUserTermsForBox($this->box_nr);
144 }
145 if ($this->box_nr === Flashcard\FlashcardBox::FIRST_BOX) {
146 $terms_without_entry = $this->manager->getAllTermsWithoutEntry();
147 $terms = array_merge($terms_without_entry, $terms);
148 }
149 $this->manager->setSessionInitialTerms($this->box_nr, $terms);
150 $this->manager->setSessionTerms($this->box_nr, $terms);
151 $this->manager->createOrUpdateBoxAccessEntry($this->box_nr);
152 $this->ctrl->redirect($this, "showHidden");
153 }
154
155 public function showHidden(): void
156 {
158
159 if ($this->glossary->getFlashcardsMode() === "term") {
160 $flashcard = $this->ui_fac->panel()->standard(
161 sprintf($this->lng->txt("glo_what_means_term"), $this->getTermText()),
162 $this->ui_fac->legacy()->content("???")
163 );
164 } else {
165 $flashcard = $this->ui_fac->panel()->standard(
166 $this->lng->txt("glo_what_means_definition"),
167 $this->ui_fac->legacy()->content($this->getDefinitionPage())
168 );
169 }
170
171 $btn_show = $this->ui_fac->button()->standard(
172 $this->lng->txt("glo_check"),
173 $this->ctrl->getLinkTarget($this, "showRevealed")
174 );
175
176 $btn_quit = $this->ui_fac->button()->standard(
177 $this->lng->txt("glo_quit_box"),
178 $this->ctrl->getLinkTargetByClass("ilglossarypresentationgui", "showFlashcards")
179 );
180
181 $html = $this->ui_ren->render($flashcard)
182 . $this->ui_ren->render($btn_show)
183 . $this->ui_ren->render($btn_quit);
184 $this->tpl->setContent($html);
185 }
186
187 public function showRevealed(): void
188 {
190
191 $flashcard = $this->ui_fac->panel()->standard(
192 $this->getTermText(),
193 $this->ui_fac->legacy()->content($this->getDefinitionPage())
194 );
195
196 $btn_correct = $this->ui_fac->button()->standard(
197 $this->lng->txt("glo_answered_correctly"),
198 $this->ctrl->getLinkTarget($this, "answerCorrectly")
199 );
200
201 $btn_not_correct = $this->ui_fac->button()->standard(
202 $this->lng->txt("glo_answered_not_correctly"),
203 $this->ctrl->getLinkTarget($this, "answerIncorrectly")
204 );
205
206 $html = $this->ui_ren->render($flashcard)
207 . $this->ui_ren->render($btn_correct)
208 . $this->ui_ren->render($btn_not_correct);
209 $this->tpl->setContent($html);
210 }
211
212 protected function setFlashcardTitleAndDescription(): void
213 {
214 $this->tpl->setTitle($this->glossary->getTitle() . ": " . $this->lng->txt("glo_box") . " " . $this->box_nr);
215
216 $current_cnt = (count($this->initial_terms_in_box) - count($this->terms_in_box)) + 1;
217 $all_cnt = count($this->initial_terms_in_box);
218 $progress_txt = sprintf($this->lng->txt("glo_flashcards_progress"), $current_cnt, $all_cnt);
219 $this->tpl->setDescription($progress_txt);
220 }
221
222 public function answerCorrectly(): void
223 {
224 $this->answer(true);
225 }
226
227 public function answerIncorrectly(): void
228 {
229 $this->answer(false);
230 }
231
232 public function answer(bool $correct): void
233 {
234 $this->manager->createOrUpdateUserTermEntry($this->current_term?->getTermId(), $correct);
235 array_shift($this->terms_in_box);
236 $this->manager->setSessionTerms($this->box_nr, $this->terms_in_box);
237 if ($this->terms_in_box) {
238 $this->ctrl->redirect($this, "showHidden");
239 }
240 $this->tpl->setOnScreenMessage("success", $this->lng->txt("glo_box_completed"), true);
241 $this->ctrl->redirectByClass("ilglossarypresentationgui", "showFlashcards");
242 }
243
244 protected function getTermText(): string
245 {
246 $text = ilGlossaryTerm::_lookGlossaryTerm($this->current_term?->getTermId());
247 return $text;
248 }
249
250 protected function getDefinitionPage(): string
251 {
252 $page_gui = new ilGlossaryDefPageGUI($this->current_term?->getTermId());
253 return $page_gui->showPage();
254 }
255}
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
GUI class for glossary flashcard boxes.
Presentation PresentationGUIRequest $request
static _lookGlossaryTerm(int $term_id)
get glossary term
language handling
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26