ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.FlashcardShuffleManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Glossary\Flashcard;
22 
25 
30 {
31  public function __construct()
32  {
33  }
34 
39  public function shuffleEntries(
40  array $box_entries
41  ): array {
42  $box_entries = $this->shuffle($box_entries);
43  return $box_entries;
44  }
45 
50  public function shuffleEntriesWithEqualDay(
51  array $box_entries
52  ): array {
53  $tmp_entries = [];
54  $tmp_day = "";
55  $i = 0;
56  // split entries per day
57  foreach ($box_entries as $entry) {
58  $entry_day = substr($entry->getLastAccess(), 0, 10);
59  if (empty($tmp_day)
60  || $entry_day === $tmp_day
61  ) {
62  $tmp_entries[$i][] = $entry;
63  } else {
64  $tmp_entries[++$i][] = $entry;
65  }
66  $tmp_day = $entry_day;
67  }
68 
69  $entries = [];
70  // shuffle entries with same day
71  foreach ($tmp_entries as $entries_per_day) {
72  $entries_per_day = $this->shuffle($entries_per_day);
73  foreach ($entries_per_day as $entry) {
74  $entries[] = $entry;
75  }
76  }
77 
78  return $entries;
79  }
80 
81  protected function shuffle(array $entries): array
82  {
83  shuffle($entries);
84 
85  return $entries;
86  }
87 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...