ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ExcPeerReviewDistribution.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
49{
50 protected array $user_ids = [];
51 protected array $user_order = [];
52 protected int $num_assignments;
53
58 public function __construct(array $user_ids, int $num_assignments)
59 {
60 $this->user_ids = array_values($user_ids); // ensure numerical indexing
61
62 // we cannot assign more users to a single user than count($user_ids) - 1
64
65 // we cannot create a negative number of assignments
67
68 $this->num_assignments = $num_assignments;
69 $this->initDistribution();
70 }
71
72 protected function initDistribution(): void
73 {
74 $this->user_order = $this->randomUserOrder($this->user_ids);
75 }
76
82 protected function randomUserOrder(array $user_ids): array
83 {
84 $order = [];
85 while (count($user_ids) > 0) {
86 $next = rand(0, count($user_ids) - 1);
87 $order[] = $user_ids[$next];
88 unset($user_ids[$next]);
89 $user_ids = array_values($user_ids); // re-index
90 }
91 return $order;
92 }
93
94 public function getUserOrder(): array
95 {
96 return $this->user_order;
97 }
98
104 public function getPeersOfRater(int $user_id): array
105 {
106 $peers = [];
107 $key = array_search($user_id, $this->user_order);
108 if ($key === false) {
109 return [];
110 }
111 for ($j = 1; $j <= $this->num_assignments; $j++) {
112 $peer_key = ($key + $j) % (count($this->user_order));
113 $peers[] = $this->user_order[$peer_key];
114 }
115 return $peers;
116 }
117}
Calculates peer review distribution (rater to peer assignments)
__construct(array $user_ids, int $num_assignments)
ExcPeerReviewDistribution constructor.