19 declare(strict_types=1);
58 $this->domain = $domain_service;
59 $this->shuffle_manager = $this->domain->flashcardShuffle();
62 $this->term_db_repo = $this->repo->flashcardTerm();
63 $this->box_db_repo = $this->repo->flashcardBox();
64 $this->session_repo = $this->repo->flashcardSession();
67 $this->glossary = new \ilObjGlossary($glo_ref_id);
68 $this->clock = $data_factory->clock()->system();
70 $all_glossary_terms = $this->glossary->getTermList(
81 foreach ($all_glossary_terms as $term) {
82 $this->all_glossary_term_ids[] = (
int) $term[
"id"];
88 $now = $this->clock->now();
97 $this->session_repo->setInitialTerms($this->glo_id, $this->user_id, $box_nr, $initial_terms);
106 return $this->session_repo->getInitialTerms($this->glo_id, $this->user_id, $box_nr);
113 $this->session_repo->setTerms($this->glo_id, $this->user_id, $box_nr, $terms);
122 return $this->session_repo->getTerms($this->glo_id, $this->user_id, $box_nr);
132 $terms_without_entry = [];
133 foreach ($this->all_glossary_term_ids as $term_id) {
134 if (!in_array($term_id, $terms_with_entry)) {
135 $terms_without_entry[] = $this->data_service->flashcardTerm($term_id, $this->user_id, $this->glo_id, 1);
138 $terms_without_entry = $this->shuffle_manager->shuffleEntries($terms_without_entry);
140 return $terms_without_entry;
148 $entries = $this->term_db_repo->getAllUserEntries($this->user_id, $this->glo_id);
163 $terms_filtered = [];
164 foreach ($terms as $term) {
166 $terms_filtered[] = $term;
170 return $terms_filtered;
179 $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
180 $entries = $this->shuffle_manager->shuffleEntriesWithEqualDay($entries);
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_terms = [];
195 foreach ($entries as $entry) {
196 $entry_day = substr($entry->getLastAccess(), 0, 10);
197 $today = $this->
getNow()->format(
"Y-m-d");
198 if ($entry_day !== $today) {
199 $non_recent_terms[] = $entry;
204 return $non_recent_terms;
213 $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
215 foreach ($entries as $entry) {
216 $entry_day = substr($entry->getLastAccess(), 0, 10);
217 $today = $this->
getNow()->format(
"Y-m-d");
218 if ($entry_day === $today) {
219 $recent_terms[] = $entry;
222 $recent_terms = $this->shuffle_manager->shuffleEntries($recent_terms);
225 return $recent_terms;
234 $item_cnt = $items_without_box + $items_in_box;
245 $entry = $this->box_db_repo->getEntry($box_nr, $this->user_id, $this->glo_id);
247 return $entry?->getLastAccess();
253 $lng = $this->domain->lng();
256 return $lng->txt(
"never");
261 $diff = $date->diff($now)->days;
264 } elseif ($diff === 0) {
265 return $lng->txt(
"today");
266 } elseif ($diff === 1) {
267 return $lng->txt(
"yesterday");
269 return sprintf(
$lng->txt(
"glo_days_ago"), $diff);
276 $entry = $this->term_db_repo->getEntry($term_id, $this->user_id, $this->glo_id);
278 return $entry?->getBoxNr();
284 $now = $this->
getNow()->format(
"Y-m-d H:i:s");
285 $box = $this->data_service->flashcardBox($box_nr, $this->user_id, $this->glo_id, $now);
286 $this->box_db_repo->createOrUpdateEntry($box);
293 $box_nr = $this->
getBoxNr($term_id);
294 $now = $this->
getNow()->format(
"Y-m-d H:i:s");
297 $box_nr = $correct ? ($box_nr + 1) : 1;
298 $term = $this->data_service->flashcardTerm($term_id, $this->user_id, $this->glo_id, $box_nr, $now);
299 $this->term_db_repo->updateEntry($term);
301 $box_nr = $correct ? 2 : 1;
302 $term = $this->data_service->flashcardTerm($term_id, $this->user_id, $this->glo_id, $box_nr, $now);
303 $this->term_db_repo->createEntry($term);
309 $this->term_db_repo->deleteEntries($this->glo_id, $this->user_id);
310 $this->box_db_repo->deleteEntries($this->glo_id, $this->user_id);
315 $this->term_db_repo->deleteAllUserEntries($this->user_id);
316 $this->box_db_repo->deleteAllUserEntries($this->user_id);
321 if ($this->glo_id === 0) {
322 throw new \ilGlossaryException(
"No glossary id given in FlashcardManager.");
324 $this->term_db_repo->deleteAllGlossaryEntries($this->glo_id);
325 $this->box_db_repo->deleteAllGlossaryEntries($this->glo_id);
331 $this->term_db_repo->deleteAllTermEntries($term_id);
setSessionTerms(int $box_nr, array $terms)
setSessionInitialTerms(int $box_nr, array $initial_terms)
createOrUpdateBoxAccessEntry(int $box_nr)
getItemsForBoxCount(int $box_nr)
Glossary InternalDataService $data_service
FlashcardSessionRepositoryInterface $session_repo
getAllTermsWithoutEntry()
getSessionInitialTerms(int $box_nr)
getLastAccessForBoxAsDaysText(int $box_nr)
FlashcardTermDBRepository $term_db_repo
getTodayUserTermsForBox(int $box_nr)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
deleteAllTermEntries(int $term_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjectId(int $ref_id)
deleteAllGlossaryEntries()
FlashcardBoxDBRepository $box_db_repo
getNonTodayUserTermsForBox(int $box_nr)
getSessionTerms(int $box_nr)
FlashcardShuffleManager $shuffle_manager
getLastAccessForBox(int $box_nr)
Glossary InternalDomainService $domain
createOrUpdateUserTermEntry(int $term_id, bool $correct)
__construct(Glossary\InternalDomainService $domain_service, Glossary\InternalRepoServiceInterface $repo, Glossary\InternalDataService $data_service, int $glo_ref_id, int $user_id)
Glossary InternalRepoServiceInterface $repo
getUserTermsForBox(int $box_nr)
array $all_glossary_term_ids
filterTermsNotInGlossary(array $terms)
Filter out the terms, for which already exist entries, but are not part of the glossary currently/any...