ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ExcPeerReviewDistribution.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /* Copyright (c) 1998-2021 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
6 
33 {
37  protected $user_ids = [];
38 
42  protected $user_order = [];
43 
47  protected $num_assignments;
48 
54  public function __construct(array $user_ids, $num_assignments)
55  {
56  $this->user_ids = array_values($user_ids); // ensure numerical indexing
57 
58  // we cannot assign more users to a single user than count($user_ids) - 1
59  $num_assignments = min($num_assignments, count($user_ids) - 1);
60 
61  // we cannot create a negative number of assignments
63 
64  $this->num_assignments = $num_assignments;
65  $this->initDistribution();
66  }
67 
71  protected function initDistribution()
72  {
73  $this->user_order = $this->randomUserOrder($this->user_ids);
74  }
75 
81  protected function randomUserOrder($user_ids) : array
82  {
83  $order = [];
84  while (count($user_ids) > 0) {
85  $next = rand(0, count($user_ids) - 1);
86  $order[] = $user_ids[$next];
87  unset($user_ids[$next]);
88  $user_ids = array_values($user_ids); // re-index
89  }
90  return $order;
91  }
92 
97  public function getUserOrder() : array
98  {
99  return $this->user_order;
100  }
101 
108  public function getPeersOfRater($user_id)
109  {
110  $peers = [];
111  $key = array_search($user_id, $this->user_order);
112  if ($key === false) {
113  return [];
114  }
115  for ($j = 1; $j <= $this->num_assignments; $j++) {
116  $peer_key = ($key + $j) % (count($this->user_order));
117  $peers[] = $this->user_order[$peer_key];
118  }
119  return $peers;
120  }
121 }
__construct(array $user_ids, $num_assignments)
ExcPeerReviewDistribution constructor.
Calculates peer review distribution (rater to peer assignments)
$key
Definition: croninfo.php:18