ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilIndividualAssessmentUserGrading.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2020 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3 
4 declare(strict_types=1);
5 
6 use \ILIAS\UI\Component\Input\Field;
7 use \ILIAS\Refinery\Factory as Refinery;
9 
11 {
15  protected $name;
16 
20  protected $record;
21 
25  protected $internal_note;
26 
30  protected $file;
31 
35  protected $is_file_visible;
36 
40  protected $learning_progress;
41 
45  protected $place;
46 
50  protected $event_time;
51 
55  protected $notify;
56 
60  protected $finalized;
61 
62  public function __construct(
63  string $name,
64  string $record,
65  string $internal_note,
66  ?string $file,
67  bool $is_file_visible,
69  string $place,
71  bool $notify,
72  bool $finalized = false
73  ) {
74  $this->name = $name;
75  $this->record = $record;
76  $this->internal_note = $internal_note;
77  $this->file = $file;
78  $this->is_file_visible = $is_file_visible;
79  $this->learning_progress = $learning_progress;
80  $this->place = $place;
81  $this->event_time = $event_time;
82  $this->notify = $notify;
83  $this->finalized = $finalized;
84  }
85 
86  public function getName() : string
87  {
88  return $this->name;
89  }
90 
91  public function getRecord() : string
92  {
93  return $this->record;
94  }
95 
96  public function getInternalNote() : string
97  {
98  return $this->internal_note;
99  }
100 
101  public function getFile() : ?string
102  {
103  return $this->file;
104  }
105 
106  public function hasFile() : bool
107  {
108  return !empty($this->file);
109  }
110 
111  public function isFileVisible() : bool
112  {
113  return $this->is_file_visible;
114  }
115 
116  public function getLearningProgress() : int
117  {
119  }
120 
121  public function getPlace() : string
122  {
123  return $this->place;
124  }
125 
126  public function getEventTime() : ?DateTimeImmutable
127  {
128  return $this->event_time;
129  }
130 
131  public function isNotify() : bool
132  {
133  return $this->notify;
134  }
135 
136  public function isFinalized() : bool
137  {
138  return $this->finalized;
139  }
140 
141  public function withFinalized(bool $finalize) : ilIndividualAssessmentUserGrading
142  {
143  $clone = clone $this;
144  $clone->finalized = $finalize;
145  return $clone;
146  }
147 
149  {
150  $clone = clone $this;
151  $clone->file = $file;
152  return $clone;
153  }
154 
155  public function toFormInput(
156  Field\Factory $input,
157  DataFactory $data_factory,
158  \ilLanguage $lng,
159  Refinery $refinery,
160  array $grading_options,
161  bool $may_be_edited = true,
162  bool $place_required = false,
163  bool $amend = false,
164  ilIndividualAssessmentMemberGUI $file_handler
165  ) : Field\Input {
166  $name = $input
167  ->text($lng->txt('name'), '')
168  ->withDisabled(true)
169  ->withValue($this->getName())
170  ;
171 
172  $record = $input
173  ->textarea($lng->txt('iass_record'), $lng->txt('iass_record_info'))
174  ->withValue($this->getRecord())
175  ->withDisabled(!$may_be_edited)
176  ;
177 
178  $internal_note = $input
179  ->textarea($lng->txt('iass_internal_note'), $lng->txt('iass_internal_note_info'))
180  ->withValue($this->getInternalNote())
181  ->withDisabled(!$may_be_edited)
182  ;
183 
184  $file = $input
185  ->file($file_handler, $lng->txt('iass_upload_file'), $lng->txt('iass_file_dropzone'))
186  ->withValue($this->hasFile() ? [$this->getFile()] : null)
187  ;
188 
189  $file_visible = $input
190  ->checkbox($lng->txt('iass_file_visible_examinee'))
191  ->withValue($this->isFileVisible())
192  ->withDisabled(!$may_be_edited)
193  ;
194 
195  $learning_progress = $input
196  ->select($lng->txt('grading'), $grading_options)
198  ->withDisabled(!$may_be_edited)
199  ->withRequired(true)
200  ;
201 
202  $place = $input
203  ->text($lng->txt('iass_place'))
204  ->withValue($this->getPlace())
205  ->withRequired($place_required)
206  ->withDisabled(!$may_be_edited)
207  ;
208 
209  $event_time = $input
210  ->dateTime($lng->txt('iass_event_time'))
211  ->withRequired($place_required)
212  ->withDisabled(!$may_be_edited)
213  ;
214 
215  if (!is_null($this->getEventTime())) {
216  $format = $data_factory->dateFormat()->standard()->toString();
217  $event_time = $event_time->withValue($this->getEventTime()->format($format));
218  }
219 
220  $notify = $input
221  ->checkbox($lng->txt('iass_notify'), $lng->txt('iass_notify_explanation'))
222  ->withValue($this->isNotify())
223  ->withDisabled(!$may_be_edited)
224  ;
225 
226  $fields = [
227  'name' => $name,
228  'record' => $record,
229  'internal_note' => $internal_note,
230  'file' => $file,
231  'file_visible' => $file_visible,
232  'learning_progress' => $learning_progress,
233  'place' => $place,
234  'event_time' => $event_time,
235  'notify' => $notify
236  ];
237 
238  if (!$amend) {
239  $finalized = $input
240  ->checkbox($lng->txt('iass_finalize'), $lng->txt('iass_finalize_info'))
241  ->withValue($this->isFinalized())
242  ->withDisabled(!$may_be_edited)
243  ;
244 
245  $fields['finalized'] = $finalized;
246  }
247 
248  return $input->section(
249  $fields,
250  $lng->txt('iass_edit_record')
251  )->withAdditionalTransformation(
252  $refinery->custom()->transformation(function ($values) use ($amend) {
253  $finalized = $this->isFinalized();
254  if (!$amend) {
255  $finalized = $values['finalized'];
256  }
257 
258  $file = $this->getFile();
259  if (
260  isset($values['file'][0]) &&
261  trim($values['file'][0]) != ''
262  ) {
263  $file = $values['file'][0];
264  }
265 
267  $values['name'],
268  $values['record'],
269  $values['internal_note'],
270  $file,
271  $values['file_visible'],
272  (int) $values['learning_progress'],
273  $values['place'],
274  $values['event_time'],
275  $values['notify'],
276  $finalized
277  );
278  })
279  );
280  }
281 }
This is what a factory for input fields looks like.
Definition: Factory.php:10
toFormInput(Field\Factory $input, DataFactory $data_factory, \ilLanguage $lng, Refinery $refinery, array $grading_options, bool $may_be_edited=true, bool $place_required=false, bool $amend=false, ilIndividualAssessmentMemberGUI $file_handler)
$lng
$format
Definition: metadata.php:218
__construct(string $name, string $record, string $internal_note, ?string $file, bool $is_file_visible, int $learning_progress, string $place, ?DateTimeImmutable $event_time, bool $notify, bool $finalized=false)
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...