ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Glossary\Flashcard\FlashcardManager Class Reference
+ Collaboration diagram for ILIAS\Glossary\Flashcard\FlashcardManager:

Public Member Functions

 __construct (Glossary\InternalDomainService $domain_service, Glossary\InternalRepoServiceInterface $repo, Glossary\InternalDataService $data_service, int $glo_ref_id, int $user_id)
 
 setSessionInitialTerms (int $box_nr, array $initial_terms)
 
 getSessionInitialTerms (int $box_nr)
 
 setSessionTerms (int $box_nr, array $terms)
 
 getSessionTerms (int $box_nr)
 
 getAllTermsWithoutEntry ()
 
 getAllUserTerms ()
 
 getUserTermsForBox (int $box_nr)
 
 getNonTodayUserTermsForBox (int $box_nr)
 
 getTodayUserTermsForBox (int $box_nr)
 
 getItemsForBoxCount (int $box_nr)
 
 getLastAccessForBox (int $box_nr)
 
 getLastAccessForBoxAsDaysText (int $box_nr)
 
 getBoxNr (int $term_id)
 
 createOrUpdateBoxAccessEntry (int $box_nr)
 
 createOrUpdateUserTermEntry (int $term_id, bool $correct)
 
 resetEntries ()
 
 deleteAllUserEntries ()
 
 deleteAllGlossaryEntries ()
 
 deleteAllTermEntries (int $term_id)
 

Protected Member Functions

 getNow ()
 
 filterTermsNotInGlossary (array $terms)
 Filter out the terms, for which already exist entries, but are not part of the glossary currently/anymore. More...
 

Protected Attributes

Glossary InternalDomainService $domain
 
FlashcardShuffleManager $shuffle_manager
 
Glossary InternalRepoServiceInterface $repo
 
Glossary InternalDataService $data_service
 
FlashcardTermDBRepository $term_db_repo
 
FlashcardBoxDBRepository $box_db_repo
 
FlashcardSessionRepositoryInterface $session_repo
 
int $glo_id
 
int $user_id
 
ilObjGlossary $glossary
 
ClockInterface $clock
 
array $all_glossary_term_ids = []
 

Detailed Description

Author
Thomas Famula famul.nosp@m.a@le.nosp@m.ifos..nosp@m.de

Definition at line 31 of file class.FlashcardManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Glossary\Flashcard\FlashcardManager::__construct ( Glossary\InternalDomainService  $domain_service,
Glossary\InternalRepoServiceInterface  $repo,
Glossary\InternalDataService  $data_service,
int  $glo_ref_id,
int  $user_id 
)

Definition at line 49 of file class.FlashcardManager.php.

55 {
56 $data_factory = new DataFactory();
57
58 $this->domain = $domain_service;
59 $this->shuffle_manager = $this->domain->flashcardShuffle();
60 $this->repo = $repo;
61 $this->data_service = $data_service;
62 $this->term_db_repo = $this->repo->flashcardTerm();
63 $this->box_db_repo = $this->repo->flashcardBox();
64 $this->session_repo = $this->repo->flashcardSession();
65 $this->glo_id = \ilObject::_lookupObjectId($glo_ref_id);
66 $this->user_id = $user_id;
67 $this->glossary = new \ilObjGlossary($glo_ref_id);
68 $this->clock = $data_factory->clock()->system();
69
70 $all_glossary_terms = $this->glossary->getTermList(
71 "",
72 "",
73 "",
74 0,
75 false,
76 false,
77 null,
78 false,
79 true
80 );
81 foreach ($all_glossary_terms as $term) {
82 $this->all_glossary_term_ids[] = (int) $term["id"];
83 }
84 }
Glossary InternalRepoServiceInterface $repo
static _lookupObjectId(int $ref_id)

References ILIAS\Glossary\Flashcard\FlashcardManager\$data_service, ILIAS\Glossary\Flashcard\FlashcardManager\$repo, ILIAS\Glossary\Flashcard\FlashcardManager\$user_id, ilObject\_lookupObjectId(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

Member Function Documentation

◆ createOrUpdateBoxAccessEntry()

ILIAS\Glossary\Flashcard\FlashcardManager::createOrUpdateBoxAccessEntry ( int  $box_nr)

Definition at line 281 of file class.FlashcardManager.php.

283 : void {
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);
287 }

◆ createOrUpdateUserTermEntry()

ILIAS\Glossary\Flashcard\FlashcardManager::createOrUpdateUserTermEntry ( int  $term_id,
bool  $correct 
)

Definition at line 289 of file class.FlashcardManager.php.

292 : void {
293 $box_nr = $this->getBoxNr($term_id);
294 $now = $this->getNow()->format("Y-m-d H:i:s");
295
296 if ($box_nr) {
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);
300 } else {
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);
304 }
305 }

◆ deleteAllGlossaryEntries()

ILIAS\Glossary\Flashcard\FlashcardManager::deleteAllGlossaryEntries ( )

Definition at line 319 of file class.FlashcardManager.php.

319 : void
320 {
321 if ($this->glo_id === 0) {
322 throw new \ilGlossaryException("No glossary id given in FlashcardManager.");
323 }
324 $this->term_db_repo->deleteAllGlossaryEntries($this->glo_id);
325 $this->box_db_repo->deleteAllGlossaryEntries($this->glo_id);
326 }

◆ deleteAllTermEntries()

ILIAS\Glossary\Flashcard\FlashcardManager::deleteAllTermEntries ( int  $term_id)

Definition at line 328 of file class.FlashcardManager.php.

330 : void {
331 $this->term_db_repo->deleteAllTermEntries($term_id);
332 }

◆ deleteAllUserEntries()

ILIAS\Glossary\Flashcard\FlashcardManager::deleteAllUserEntries ( )

Definition at line 313 of file class.FlashcardManager.php.

313 : void
314 {
315 $this->term_db_repo->deleteAllUserEntries($this->user_id);
316 $this->box_db_repo->deleteAllUserEntries($this->user_id);
317 }

◆ filterTermsNotInGlossary()

ILIAS\Glossary\Flashcard\FlashcardManager::filterTermsNotInGlossary ( array  $terms)
protected

Filter out the terms, for which already exist entries, but are not part of the glossary currently/anymore.

Only relevant for virtual glossaries.

Parameters
Term[]$terms
Returns
Term[]

Definition at line 160 of file class.FlashcardManager.php.

162 : array {
163 $terms_filtered = [];
164 foreach ($terms as $term) {
165 if (in_array($term->getTermId(), $this->all_glossary_term_ids)) {
166 $terms_filtered[] = $term;
167 }
168 }
169
170 return $terms_filtered;
171 }

◆ getAllTermsWithoutEntry()

ILIAS\Glossary\Flashcard\FlashcardManager::getAllTermsWithoutEntry ( )
Returns
Term[]

Definition at line 128 of file class.FlashcardManager.php.

128 : array
129 {
130 $terms_with_entry = array_map(fn($term) => $term->getTermId(), $this->getAllUserTerms());
131
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);
136 }
137 }
138 $terms_without_entry = $this->shuffle_manager->shuffleEntries($terms_without_entry);
139
140 return $terms_without_entry;
141 }

◆ getAllUserTerms()

ILIAS\Glossary\Flashcard\FlashcardManager::getAllUserTerms ( )
Returns
Term[]

Definition at line 146 of file class.FlashcardManager.php.

146 : array
147 {
148 $entries = $this->term_db_repo->getAllUserEntries($this->user_id, $this->glo_id);
149
150 return $entries;
151 }

◆ getBoxNr()

ILIAS\Glossary\Flashcard\FlashcardManager::getBoxNr ( int  $term_id)

Definition at line 273 of file class.FlashcardManager.php.

275 : ?int {
276 $entry = $this->term_db_repo->getEntry($term_id, $this->user_id, $this->glo_id);
277
278 return $entry?->getBoxNr();
279 }

◆ getItemsForBoxCount()

ILIAS\Glossary\Flashcard\FlashcardManager::getItemsForBoxCount ( int  $box_nr)

Definition at line 228 of file class.FlashcardManager.php.

230 : int {
231 if ($box_nr === FlashcardBox::FIRST_BOX) {
232 $items_without_box = count($this->getAllTermsWithoutEntry());
233 $items_in_box = count($this->getUserTermsForBox($box_nr));
234 $item_cnt = $items_without_box + $items_in_box;
235 } else {
236 $item_cnt = count($this->getUserTermsForBox($box_nr));
237 }
238
239 return $item_cnt;
240 }

◆ getLastAccessForBox()

ILIAS\Glossary\Flashcard\FlashcardManager::getLastAccessForBox ( int  $box_nr)

Definition at line 242 of file class.FlashcardManager.php.

244 : ?string {
245 $entry = $this->box_db_repo->getEntry($box_nr, $this->user_id, $this->glo_id);
246
247 return $entry?->getLastAccess();
248 }

◆ getLastAccessForBoxAsDaysText()

ILIAS\Glossary\Flashcard\FlashcardManager::getLastAccessForBoxAsDaysText ( int  $box_nr)

Definition at line 250 of file class.FlashcardManager.php.

252 : string {
253 $lng = $this->domain->lng();
254 $date_str = $this->getLastAccessForBox($box_nr);
255 if (!$date_str) {
256 return $lng->txt("never");
257 }
258 $date_tmp = new \ilDateTime($date_str, IL_CAL_DATETIME);
259 $date = new DateTime($date_tmp->get(IL_CAL_DATE));
260 $now = new DateTime($this->getNow()->format("Y-m-d"));
261 $diff = $date->diff($now)->days;
262 if ($diff < 0) {
263 return "invalid";
264 } elseif ($diff === 0) {
265 return $lng->txt("today");
266 } elseif ($diff === 1) {
267 return $lng->txt("yesterday");
268 } else {
269 return sprintf($lng->txt("glo_days_ago"), $diff);
270 }
271 }
const IL_CAL_DATE
const IL_CAL_DATETIME
global $lng
Definition: privfeed.php:31

◆ getNonTodayUserTermsForBox()

ILIAS\Glossary\Flashcard\FlashcardManager::getNonTodayUserTermsForBox ( int  $box_nr)
Returns
Term[]

Definition at line 189 of file class.FlashcardManager.php.

191 : array {
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;
200 }
201 }
202 $non_recent_terms = $this->filterTermsNotInGlossary($non_recent_terms);
203
204 return $non_recent_terms;
205 }
filterTermsNotInGlossary(array $terms)
Filter out the terms, for which already exist entries, but are not part of the glossary currently/any...

References getNow().

+ Here is the call graph for this function:

◆ getNow()

ILIAS\Glossary\Flashcard\FlashcardManager::getNow ( )
protected

Definition at line 86 of file class.FlashcardManager.php.

86 : \DateTimeImmutable
87 {
88 $now = $this->clock->now();
89
90 return $now;
91 }

◆ getSessionInitialTerms()

ILIAS\Glossary\Flashcard\FlashcardManager::getSessionInitialTerms ( int  $box_nr)
Returns
Term[]

Definition at line 103 of file class.FlashcardManager.php.

105 : array {
106 return $this->session_repo->getInitialTerms($this->glo_id, $this->user_id, $box_nr);
107 }

◆ getSessionTerms()

ILIAS\Glossary\Flashcard\FlashcardManager::getSessionTerms ( int  $box_nr)
Returns
Term[]

Definition at line 119 of file class.FlashcardManager.php.

121 : array {
122 return $this->session_repo->getTerms($this->glo_id, $this->user_id, $box_nr);
123 }

◆ getTodayUserTermsForBox()

ILIAS\Glossary\Flashcard\FlashcardManager::getTodayUserTermsForBox ( int  $box_nr)
Returns
Term[]

Definition at line 210 of file class.FlashcardManager.php.

212 : array {
213 $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
214 $recent_terms = [];
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;
220 }
221 }
222 $recent_terms = $this->shuffle_manager->shuffleEntries($recent_terms);
223 $recent_terms = $this->filterTermsNotInGlossary($recent_terms);
224
225 return $recent_terms;
226 }

References getNow().

+ Here is the call graph for this function:

◆ getUserTermsForBox()

ILIAS\Glossary\Flashcard\FlashcardManager::getUserTermsForBox ( int  $box_nr)
Returns
Term[]

Definition at line 176 of file class.FlashcardManager.php.

178 : array {
179 $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
180 $entries = $this->shuffle_manager->shuffleEntriesWithEqualDay($entries);
181 $entries = $this->filterTermsNotInGlossary($entries);
182
183 return $entries;
184 }

◆ resetEntries()

ILIAS\Glossary\Flashcard\FlashcardManager::resetEntries ( )

Definition at line 307 of file class.FlashcardManager.php.

307 : void
308 {
309 $this->term_db_repo->deleteEntries($this->glo_id, $this->user_id);
310 $this->box_db_repo->deleteEntries($this->glo_id, $this->user_id);
311 }

◆ setSessionInitialTerms()

ILIAS\Glossary\Flashcard\FlashcardManager::setSessionInitialTerms ( int  $box_nr,
array  $initial_terms 
)

Definition at line 93 of file class.FlashcardManager.php.

96 : void {
97 $this->session_repo->setInitialTerms($this->glo_id, $this->user_id, $box_nr, $initial_terms);
98 }

◆ setSessionTerms()

ILIAS\Glossary\Flashcard\FlashcardManager::setSessionTerms ( int  $box_nr,
array  $terms 
)

Definition at line 109 of file class.FlashcardManager.php.

112 : void {
113 $this->session_repo->setTerms($this->glo_id, $this->user_id, $box_nr, $terms);
114 }

Field Documentation

◆ $all_glossary_term_ids

array ILIAS\Glossary\Flashcard\FlashcardManager::$all_glossary_term_ids = []
protected

Definition at line 47 of file class.FlashcardManager.php.

◆ $box_db_repo

FlashcardBoxDBRepository ILIAS\Glossary\Flashcard\FlashcardManager::$box_db_repo
protected

Definition at line 38 of file class.FlashcardManager.php.

◆ $clock

ClockInterface ILIAS\Glossary\Flashcard\FlashcardManager::$clock
protected

Definition at line 43 of file class.FlashcardManager.php.

◆ $data_service

Glossary InternalDataService ILIAS\Glossary\Flashcard\FlashcardManager::$data_service
protected

◆ $domain

Glossary InternalDomainService ILIAS\Glossary\Flashcard\FlashcardManager::$domain
protected

Definition at line 33 of file class.FlashcardManager.php.

◆ $glo_id

int ILIAS\Glossary\Flashcard\FlashcardManager::$glo_id
protected

Definition at line 40 of file class.FlashcardManager.php.

◆ $glossary

ilObjGlossary ILIAS\Glossary\Flashcard\FlashcardManager::$glossary
protected

Definition at line 42 of file class.FlashcardManager.php.

◆ $repo

Glossary InternalRepoServiceInterface ILIAS\Glossary\Flashcard\FlashcardManager::$repo
protected

◆ $session_repo

FlashcardSessionRepositoryInterface ILIAS\Glossary\Flashcard\FlashcardManager::$session_repo
protected

Definition at line 39 of file class.FlashcardManager.php.

◆ $shuffle_manager

FlashcardShuffleManager ILIAS\Glossary\Flashcard\FlashcardManager::$shuffle_manager
protected

Definition at line 34 of file class.FlashcardManager.php.

◆ $term_db_repo

FlashcardTermDBRepository ILIAS\Glossary\Flashcard\FlashcardManager::$term_db_repo
protected

Definition at line 37 of file class.FlashcardManager.php.

◆ $user_id

int ILIAS\Glossary\Flashcard\FlashcardManager::$user_id
protected

The documentation for this class was generated from the following file: