ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.FlashcardShuffleManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\Data\Factory as DataFactory;
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
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}
Builds data types.
Definition: Factory.php:36