ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\Glossary\Flashcard\FlashcardManager Class Reference
+ Collaboration diagram for ILIAS\Glossary\Flashcard\FlashcardManager:

Public Member Functions

 __construct (InternalDomainService $domain_service, Glossary\InternalRepoServiceInterface $repo, 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 ()
 
 getAllUserTermIds ()
 
 getUserTermIdsForBox (int $box_nr)
 
 getNonTodayUserTermIdsForBox (int $box_nr)
 
 getTodayUserTermIdsForBox (int $box_nr)
 
 getItemsForBoxCount (int $box_nr)
 
 getLastAccessForBox (int $box_nr)
 
 getLastAccessForBoxAsDaysText (int $box_nr)
 
 getBoxNr (int $term_id)
 
 getBoxProgress (array $current_terms, array $all_terms)
 
 createOrUpdateBoxAccessEntry (int $box_nr)
 
 createOrUpdateUserTermEntry (int $term_id, bool $correct)
 
 resetEntries ()
 
 deleteAllUserEntries ()
 
 deleteAllGlossaryEntries ()
 
 deleteAllTermEntries (int $term_id)
 

Protected Member Functions

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

Protected Attributes

InternalDomainService $domain
 
FlashcardShuffleManager $shuffle_manager
 
Glossary InternalRepoServiceInterface $repo
 
FlashcardTermDBRepository $term_db_repo
 
FlashcardBoxDBRepository $box_db_repo
 
FlashcardSessionRepository $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 32 of file class.FlashcardManager.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

References ILIAS\Glossary\Flashcard\FlashcardManager\$repo, ILIAS\Glossary\Flashcard\FlashcardManager\$user_id, ilObject\_lookupObjectId(), ILIAS\Glossary\InternalDomainService\flashcardShuffle(), ILIAS\Glossary\InternalRepoServiceInterface\flashcardTerm(), and ILIAS\Repository\int().

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

Member Function Documentation

◆ createOrUpdateBoxAccessEntry()

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

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

290  : void {
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);
293  }

◆ createOrUpdateUserTermEntry()

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

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

References ILIAS\Glossary\Flashcard\FlashcardManager\getBoxNr().

298  : void {
299  $box_nr = $this->getBoxNr($term_id);
300  $now = $this->clock->now()->format("Y-m-d H:i:s");
301 
302  if ($box_nr !== 0) {
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);
305  } else {
306  $box_nr = $correct ? 2 : 1;
307  $this->term_db_repo->createEntry($term_id, $this->user_id, $this->glo_id, $box_nr, $now);
308  }
309  }
+ Here is the call graph for this function:

◆ deleteAllGlossaryEntries()

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

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

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

◆ deleteAllTermEntries()

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

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

334  : void {
335  $this->term_db_repo->deleteAllTermEntries($term_id);
336  }

◆ deleteAllUserEntries()

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

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

317  : void
318  {
319  $this->term_db_repo->deleteAllUserEntries($this->user_id);
320  $this->box_db_repo->deleteAllUserEntries($this->user_id);
321  }

◆ filterTermsNotInGlossary()

ILIAS\Glossary\Flashcard\FlashcardManager::filterTermsNotInGlossary ( array  $term_ids)
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
int[]$term_ids
Returns
int[]

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

References $id.

Referenced by ILIAS\Glossary\Flashcard\FlashcardManager\getNonTodayUserTermIdsForBox(), ILIAS\Glossary\Flashcard\FlashcardManager\getTodayUserTermIdsForBox(), and ILIAS\Glossary\Flashcard\FlashcardManager\getUserTermIdsForBox().

158  : array {
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;
163  }
164  }
165 
166  return $term_ids_filtered;
167  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ getAllTermsWithoutEntry()

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

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

References ILIAS\Glossary\Flashcard\FlashcardManager\getAllUserTermIds().

Referenced by ILIAS\Glossary\Flashcard\FlashcardManager\getItemsForBoxCount().

120  : array
121  {
122  $terms_with_entry = $this->getAllUserTermIds();
123 
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;
128  }
129  }
130  $terms_without_entry = $this->shuffle_manager->shuffleEntries($terms_without_entry);
131 
132  return $terms_without_entry;
133  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllUserTermIds()

ILIAS\Glossary\Flashcard\FlashcardManager::getAllUserTermIds ( )
Returns
int[]

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

References ILIAS\Repository\int().

Referenced by ILIAS\Glossary\Flashcard\FlashcardManager\getAllTermsWithoutEntry().

138  : array
139  {
140  $entries = $this->term_db_repo->getAllUserEntries($this->user_id, $this->glo_id);
141  $term_ids = [];
142  foreach ($entries as $entry) {
143  $term_ids[] = (int) $entry["term_id"];
144  }
145 
146  return $term_ids;
147  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBoxNr()

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

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

Referenced by ILIAS\Glossary\Flashcard\FlashcardManager\createOrUpdateUserTermEntry().

274  : int {
275  return $this->term_db_repo->getBoxNr($term_id, $this->user_id, $this->glo_id);
276  }
+ Here is the caller graph for this function:

◆ getBoxProgress()

ILIAS\Glossary\Flashcard\FlashcardManager::getBoxProgress ( array  $current_terms,
array  $all_terms 
)

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

References ILIAS\Repository\int().

281  : int {
282  $shown_terms_cnt = count($all_terms) - count($current_terms);
283  $progress = (int) round((($shown_terms_cnt + 1) / count($all_terms)) * 100);
284 
285  return $progress;
286  }
+ Here is the call graph for this function:

◆ getItemsForBoxCount()

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

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

References ILIAS\Glossary\Flashcard\FlashcardBox\FIRST_BOX, ILIAS\Glossary\Flashcard\FlashcardManager\getAllTermsWithoutEntry(), and ILIAS\Glossary\Flashcard\FlashcardManager\getUserTermIdsForBox().

230  : int {
231  if ($box_nr === FlashcardBox::FIRST_BOX) {
232  $items_without_box = count($this->getAllTermsWithoutEntry());
233  $items_in_box = count($this->getUserTermIdsForBox($box_nr));
234  $item_cnt = $items_without_box + $items_in_box;
235  } else {
236  $item_cnt = count($this->getUserTermIdsForBox($box_nr));
237  }
238 
239  return $item_cnt;
240  }
+ Here is the call graph for this function:

◆ getLastAccessForBox()

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

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

Referenced by ILIAS\Glossary\Flashcard\FlashcardManager\getLastAccessForBoxAsDaysText().

244  : ?string {
245  $entry = $this->box_db_repo->getEntry($box_nr, $this->user_id, $this->glo_id);
246  $date = $entry["last_access"] ?? null;
247 
248  return $date;
249  }
+ Here is the caller graph for this function:

◆ getLastAccessForBoxAsDaysText()

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

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

References $lng, ILIAS\Glossary\Flashcard\FlashcardManager\getLastAccessForBox(), IL_CAL_DATE, and IL_CAL_DATETIME.

253  : string {
254  $lng = $this->domain->lng();
255  $date_str = $this->getLastAccessForBox($box_nr);
256  if (!$date_str) {
257  return $lng->txt("never");
258  }
259  $date_tmp = new \ilDateTime($date_str, IL_CAL_DATETIME);
260  $date = new DateTime($date_tmp->get(IL_CAL_DATE));
261  $now = new DateTime($this->clock->now()->format("Y-m-d"));
262  $diff = $date->diff($now)->days;
263  if ($diff === 0) {
264  return $lng->txt("today");
265  } elseif ($diff === 1) {
266  return $lng->txt("yesterday");
267  } else {
268  return sprintf($lng->txt("glo_days_ago"), $diff);
269  }
270  }
const IL_CAL_DATETIME
$lng
const IL_CAL_DATE
+ Here is the call graph for this function:

◆ getNonTodayUserTermIdsForBox()

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

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

References ILIAS\Glossary\Flashcard\FlashcardManager\filterTermsNotInGlossary(), and ILIAS\Repository\int().

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_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"];
200  }
201  }
202  $non_recent_term_ids = $this->filterTermsNotInGlossary($non_recent_term_ids);
203 
204  return $non_recent_term_ids;
205  }
filterTermsNotInGlossary(array $term_ids)
Filter out the terms, for which already exist entries, but are not part of the glossary currently/any...
+ Here is the call graph for this function:

◆ getSessionInitialTerms()

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

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

97  : array {
98  return $this->session_repo->getInitialTerms($this->glo_id, $this->user_id, $box_nr);
99  }

◆ getSessionTerms()

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

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

113  : array {
114  return $this->session_repo->getTerms($this->glo_id, $this->user_id, $box_nr);
115  }

◆ getTodayUserTermIdsForBox()

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

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

References ILIAS\Glossary\Flashcard\FlashcardManager\filterTermsNotInGlossary(), and ILIAS\Repository\int().

212  : array {
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"];
220  }
221  }
222  $recent_term_ids = $this->shuffle_manager->shuffleEntries($recent_term_ids);
223  $recent_term_ids = $this->filterTermsNotInGlossary($recent_term_ids);
224 
225  return $recent_term_ids;
226  }
filterTermsNotInGlossary(array $term_ids)
Filter out the terms, for which already exist entries, but are not part of the glossary currently/any...
+ Here is the call graph for this function:

◆ getUserTermIdsForBox()

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

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

References ILIAS\Glossary\Flashcard\FlashcardManager\filterTermsNotInGlossary(), and ILIAS\Repository\int().

Referenced by ILIAS\Glossary\Flashcard\FlashcardManager\getItemsForBoxCount().

174  : array {
175  $entries = $this->term_db_repo->getUserEntriesForBox($box_nr, $this->user_id, $this->glo_id);
176  $entries = $this->shuffle_manager->shuffleEntriesWithEqualDay($entries);
177  $term_ids = [];
178  foreach ($entries as $entry) {
179  $term_ids[] = (int) $entry["term_id"];
180  }
181  $term_ids = $this->filterTermsNotInGlossary($term_ids);
182 
183  return $term_ids;
184  }
filterTermsNotInGlossary(array $term_ids)
Filter out the terms, for which already exist entries, but are not part of the glossary currently/any...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetEntries()

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

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

311  : void
312  {
313  $this->term_db_repo->deleteEntries($this->glo_id, $this->user_id);
314  $this->box_db_repo->deleteEntries($this->glo_id, $this->user_id);
315  }

◆ setSessionInitialTerms()

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

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

88  : void {
89  $this->session_repo->setInitialTerms($this->glo_id, $this->user_id, $box_nr, $initial_terms);
90  }

◆ setSessionTerms()

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

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

104  : void {
105  $this->session_repo->setTerms($this->glo_id, $this->user_id, $box_nr, $terms);
106  }

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.

◆ $domain

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

Definition at line 34 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

FlashcardSessionRepository 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 35 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: