3 declare(strict_types=1);
57 $this->domain = $domain_service;
61 $this->box_db_repo = $this->repo->flashcardBox();
62 $this->session_repo = $this->repo->flashcardSession();
65 $this->glossary = new \ilObjGlossary($glo_ref_id);
66 $this->clock = $data_factory->clock()->system();
68 $all_glossary_terms = $this->glossary->getTermList(
79 foreach ($all_glossary_terms as $term) {
80 $term_id = (
int) $term[
"id"];
81 $this->all_glossary_term_ids[] = $term_id;
89 $this->session_repo->setInitialTerms($this->glo_id, $this->user_id, $box_nr, $initial_terms);
98 return $this->session_repo->getInitialTerms($this->glo_id, $this->user_id, $box_nr);
105 $this->session_repo->setTerms($this->glo_id, $this->user_id, $box_nr, $terms);
114 return $this->session_repo->getTerms($this->glo_id, $this->user_id, $box_nr);
124 $terms_without_entry = [];
125 foreach ($this->all_glossary_term_ids as $term_id) {
126 if (!in_array($term_id, $terms_with_entry)) {
127 $terms_without_entry[] = $term_id;
130 $terms_without_entry = $this->shuffle_manager->shuffleEntries($terms_without_entry);
132 return $terms_without_entry;
140 $entries = $this->term_db_repo->getAllUserEntries($this->user_id, $this->glo_id);
142 foreach ($entries as $entry) {
143 $term_ids[] = (
int) $entry[
"term_id"];
159 $term_ids_filtered = [];
160 foreach ($term_ids as
$id) {
161 if (in_array($id, $this->all_glossary_term_ids)) {
162 $term_ids_filtered[] =
$id;
166 return $term_ids_filtered;
175 $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
176 $entries = $this->shuffle_manager->shuffleEntriesWithEqualDay($entries);
178 foreach ($entries as $entry) {
179 $term_ids[] = (
int) $entry[
"term_id"];
192 $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
193 $entries = $this->shuffle_manager->shuffleEntriesWithEqualDay($entries);
194 $non_recent_term_ids = [];
195 foreach ($entries as $entry) {
196 $entry_day = substr($entry[
"last_access"], 0, 10);
197 $today = $this->clock->now()->format(
"Y-m-d");
198 if ($entry_day !== $today) {
199 $non_recent_term_ids[] = (
int) $entry[
"term_id"];
204 return $non_recent_term_ids;
213 $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
214 $recent_term_ids = [];
215 foreach ($entries as $entry) {
216 $entry_day = substr($entry[
"last_access"], 0, 10);
217 $today = $this->clock->now()->format(
"Y-m-d");
218 if ($entry_day === $today) {
219 $recent_term_ids[] = (
int) $entry[
"term_id"];
222 $recent_term_ids = $this->shuffle_manager->shuffleEntries($recent_term_ids);
225 return $recent_term_ids;
234 $item_cnt = $items_without_box + $items_in_box;
245 $entry = $this->box_db_repo->getEntry($box_nr, $this->user_id, $this->glo_id);
246 $date = $entry[
"last_access"] ?? null;
254 $lng = $this->domain->lng();
257 return $lng->txt(
"never");
261 $now =
new DateTime($this->clock->now()->format(
"Y-m-d"));
262 $diff = $date->diff($now)->days;
264 return $lng->txt(
"today");
265 } elseif ($diff === 1) {
266 return $lng->txt(
"yesterday");
268 return sprintf(
$lng->txt(
"glo_days_ago"), $diff);
275 return $this->term_db_repo->getBoxNr($term_id, $this->user_id, $this->glo_id);
279 array $current_terms,
282 $shown_terms_cnt = count($all_terms) - count($current_terms);
283 $progress = (
int) round((($shown_terms_cnt + 1) / count($all_terms)) * 100);
291 $now = $this->clock->now()->format(
"Y-m-d H:i:s");
292 $this->box_db_repo->createOrUpdateEntry($box_nr, $this->user_id, $this->glo_id, $now);
299 $box_nr = $this->
getBoxNr($term_id);
300 $now = $this->clock->now()->format(
"Y-m-d H:i:s");
303 $box_nr = $correct ? ($box_nr + 1) : 1;
304 $this->term_db_repo->updateEntry($term_id, $this->user_id, $this->glo_id, $box_nr, $now);
306 $box_nr = $correct ? 2 : 1;
307 $this->term_db_repo->createEntry($term_id, $this->user_id, $this->glo_id, $box_nr, $now);
313 $this->term_db_repo->deleteEntries($this->glo_id, $this->user_id);
314 $this->box_db_repo->deleteEntries($this->glo_id, $this->user_id);
319 $this->term_db_repo->deleteAllUserEntries($this->user_id);
320 $this->box_db_repo->deleteAllUserEntries($this->user_id);
325 if ($this->glo_id === 0) {
326 throw new \ilGlossaryException(
"No glossary id given in FlashcardManager.");
328 $this->term_db_repo->deleteAllGlossaryEntries($this->glo_id);
329 $this->box_db_repo->deleteAllGlossaryEntries($this->glo_id);
335 $this->term_db_repo->deleteAllTermEntries($term_id);
setSessionTerms(int $box_nr, array $terms)
filterTermsNotInGlossary(array $term_ids)
Filter out the terms, for which already exist entries, but are not part of the glossary currently/any...
getTodayUserTermIdsForBox(int $box_nr)
setSessionInitialTerms(int $box_nr, array $initial_terms)
createOrUpdateBoxAccessEntry(int $box_nr)
getItemsForBoxCount(int $box_nr)
getAllTermsWithoutEntry()
getSessionInitialTerms(int $box_nr)
getUserTermIdsForBox(int $box_nr)
getLastAccessForBoxAsDaysText(int $box_nr)
FlashcardTermDBRepository $term_db_repo
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deleteAllTermEntries(int $term_id)
static _lookupObjectId(int $ref_id)
getNonTodayUserTermIdsForBox(int $box_nr)
deleteAllGlossaryEntries()
InternalDomainService $domain
FlashcardBoxDBRepository $box_db_repo
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
FlashcardSessionRepository $session_repo
getSessionTerms(int $box_nr)
__construct(InternalDomainService $domain_service, Glossary\InternalRepoServiceInterface $repo, int $glo_ref_id, int $user_id)
FlashcardShuffleManager $shuffle_manager
getLastAccessForBox(int $box_nr)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
createOrUpdateUserTermEntry(int $term_id, bool $correct)
getBoxProgress(array $current_terms, array $all_terms)
Glossary InternalRepoServiceInterface $repo
array $all_glossary_term_ids