ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.FlashcardShuffleManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Glossary\Flashcard;
22 
25 
30 {
31  public function __construct()
32  {
33  }
34 
35  public function shuffleEntries(
36  array $box_entries
37  ): array {
38  shuffle($box_entries);
39  return $box_entries;
40  }
41 
42  public function shuffleEntriesWithEqualDay(
43  array $box_entries
44  ): array {
45  $tmp_entries = [];
46  $tmp_day = "";
47  $i = 0;
48  // split entries per day
49  foreach ($box_entries as $entry) {
50  $entry_day = substr($entry["last_access"], 0, 10);
51  if (empty($tmp_day)
52  || $entry_day === $tmp_day
53  ) {
54  $tmp_entries[$i][] = $entry;
55  } else {
56  $tmp_entries[++$i][] = $entry;
57  }
58  $tmp_day = $entry_day;
59  }
60 
61  $entries = [];
62  // shuffle entries with same day
63  foreach ($tmp_entries as $entries_per_day) {
64  shuffle($entries_per_day);
65  foreach ($entries_per_day as $entry) {
66  $entries[] = $entry;
67  }
68  }
69 
70  return $entries;
71  }
72 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...