ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilUserQuestionResult.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  public static $USER_SOLUTION_IDENTIFIER_KEY = "key";
29  public static $USER_SOLUTION_IDENTIFIER_VALUE = "value";
30 
31 
35  protected $question;
36 
40  protected $active_id;
41 
45  protected $pass;
46 
51 
55  protected $solutions = array();
56 
58  {
59  $this->question = $question;
60  $this->active_id = $active_id;
61  $this->pass = $pass;
62  }
63 
68  public function addKeyValue($key, $value): void
69  {
70  $this->solutions[] = array(
71  self::$USER_SOLUTION_IDENTIFIER_KEY => $key,
72  self::$USER_SOLUTION_IDENTIFIER_VALUE => $value
73  );
74  }
75 
79  public function removeByKey($key): void
80  {
81  foreach ($this->solutions as $array_key => $solution) {
82  if ($solution[self::$USER_SOLUTION_IDENTIFIER_KEY] == $key) {
83  unset($this->solutions[$array_key]);
84  break;
85  }
86  }
87  }
88 
95  public function getUserSolutionsByIdentifier($identifier): array
96  {
97  if (
98  $identifier != self::$USER_SOLUTION_IDENTIFIER_KEY &&
99  $identifier != self::$USER_SOLUTION_IDENTIFIER_VALUE
100  ) {
101  throw new Exception(sprintf("Unkown Identifier %s", $identifier));
102  }
103 
104  $solutions = array();
105  foreach ($this->solutions as $solution) {
106  $solutions[] = $solution[$identifier];
107  }
108  return $solutions;
109  }
110 
114  public function getSolutions(): array
115  {
116  return $this->solutions;
117  }
118 
124  public function getSolutionForKey($key): ?array
125  {
126  foreach ($this->solutions as $solution) {
127  if ($solution[self::$USER_SOLUTION_IDENTIFIER_KEY] == $key) {
128  return $solution;
129  }
130  }
131  return null;
132  }
133 
138  {
139  $this->reached_percentage = $reached_percentage;
140  }
141 
145  public function getReachedPercentage(): int
146  {
148  }
149 
153  public function hasSolutions(): bool
154  {
155  return count($this->solutions) > 0;
156  }
157 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
__construct($question, $active_id, $pass)
setReachedPercentage($reached_percentage)