1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | /** |
||
5 | * Class EvalForm. |
||
6 | * |
||
7 | * Extends FormValidator with add&edit forms for evaluations |
||
8 | * |
||
9 | * @author Stijn Konings |
||
10 | */ |
||
11 | class EvalForm extends FormValidator |
||
12 | { |
||
13 | const TYPE_ADD = 1; |
||
14 | const TYPE_EDIT = 2; |
||
15 | const TYPE_MOVE = 3; |
||
16 | const TYPE_RESULT_ADD = 4; |
||
17 | const TYPE_RESULT_EDIT = 5; |
||
18 | const TYPE_ALL_RESULTS_EDIT = 6; |
||
19 | const TYPE_ADD_USERS_TO_EVAL = 7; |
||
20 | |||
21 | protected $evaluation_object; |
||
22 | private $result_object; |
||
23 | private $extra; |
||
24 | |||
25 | /** |
||
26 | * Builds a form containing form items based on a given parameter. |
||
27 | * |
||
28 | * @param int $form_type 1=add, 2=edit,3=move,4=result_add |
||
29 | * @param Evaluation $evaluation_object the category object |
||
30 | * @param obj $result_object the result object |
||
31 | * @param string $form_name |
||
32 | * @param string $method |
||
33 | * @param string $action |
||
34 | */ |
||
35 | public function __construct( |
||
36 | $form_type, |
||
37 | $evaluation_object, |
||
38 | $result_object, |
||
39 | $form_name, |
||
40 | $method = 'post', |
||
41 | $action = null, |
||
42 | $extra1 = null, |
||
43 | $extra2 = null |
||
44 | ) { |
||
45 | parent::__construct($form_name, $method, $action); |
||
46 | |||
47 | if (isset($evaluation_object)) { |
||
48 | $this->evaluation_object = $evaluation_object; |
||
49 | } |
||
50 | if (isset($result_object)) { |
||
51 | $this->result_object = $result_object; |
||
52 | } |
||
53 | if (isset($extra1)) { |
||
54 | $this->extra = $extra1; |
||
55 | } |
||
56 | |||
57 | switch ($form_type) { |
||
58 | case self::TYPE_EDIT: |
||
59 | $this->build_editing_form(); |
||
60 | break; |
||
61 | case self::TYPE_ADD: |
||
62 | $this->build_add_form(); |
||
63 | break; |
||
64 | case self::TYPE_MOVE: |
||
65 | $this->build_editing_form(); |
||
66 | break; |
||
67 | case self::TYPE_RESULT_ADD: |
||
68 | $this->build_result_add_form(); |
||
69 | break; |
||
70 | case self::TYPE_RESULT_EDIT: |
||
71 | $this->build_result_edit_form(); |
||
72 | break; |
||
73 | case self::TYPE_ALL_RESULTS_EDIT: |
||
74 | $this->build_all_results_edit_form(); |
||
75 | break; |
||
76 | case self::TYPE_ADD_USERS_TO_EVAL: |
||
77 | $this->build_add_user_to_eval(); |
||
78 | break; |
||
79 | } |
||
80 | $this->setDefaults(); |
||
81 | } |
||
82 | |||
83 | public function display() |
||
84 | { |
||
85 | parent::display(); |
||
86 | } |
||
87 | |||
88 | public function setDefaults($defaults = [], $filter = null) |
||
89 | { |
||
90 | parent::setDefaults($defaults, $filter); |
||
91 | } |
||
92 | |||
93 | public function sort_by_user($item1, $item2) |
||
94 | { |
||
95 | $user1 = $item1['user']; |
||
96 | $user2 = $item2['user']; |
||
97 | if (api_sort_by_first_name()) { |
||
98 | $result = api_strcmp($user1['firstname'], $user2['firstname']); |
||
99 | if (0 == $result) { |
||
100 | return api_strcmp($user1['lastname'], $user2['lastname']); |
||
101 | } |
||
102 | } else { |
||
103 | $result = api_strcmp($user1['lastname'], $user2['lastname']); |
||
104 | if (0 == $result) { |
||
105 | return api_strcmp($user1['firstname'], $user2['firstname']); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | return $result; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * This form will build a form to add users to an evaluation. |
||
114 | */ |
||
115 | protected function build_add_user_to_eval() |
||
116 | { |
||
117 | $this->addElement('header', get_lang('ChooseUser')); |
||
118 | $select = $this->addElement( |
||
119 | 'select', |
||
120 | 'firstLetterUser', |
||
121 | get_lang('FirstLetter'), |
||
122 | null, |
||
123 | [ |
||
124 | 'onchange' => 'document.add_users_to_evaluation.submit()', |
||
125 | ] |
||
126 | ); |
||
127 | $select->addOption('', ''); |
||
128 | for ($i = 65; $i <= 90; $i++) { |
||
129 | $letter = chr($i); |
||
130 | if (isset($this->extra) && $this->extra == $letter) { |
||
131 | $select->addOption($letter, $letter, 'selected'); |
||
132 | } else { |
||
133 | $select->addOption($letter, $letter); |
||
134 | } |
||
135 | } |
||
136 | $select = $this->addElement( |
||
137 | 'select', |
||
138 | 'add_users', |
||
139 | null, |
||
140 | null, |
||
141 | [ |
||
142 | 'multiple' => 'multiple', |
||
143 | 'size' => '15', |
||
144 | 'style' => 'width:250px', |
||
145 | ] |
||
146 | ); |
||
147 | foreach ($this->evaluation_object->get_not_subscribed_students() as $user) { |
||
148 | if ((!isset($this->extra)) || empty($this->extra) || api_strtoupper(api_substr($user[1], 0, 1)) == $this->extra |
||
149 | ) { |
||
150 | $select->addOption($user[1].' '.$user[2].' ('.$user[3].')', $user[0]); |
||
151 | } |
||
152 | } |
||
153 | $this->addButtonCreate(get_lang('AddUserToEval'), 'submit_button'); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * This function builds a form to edit all results in an evaluation. |
||
158 | */ |
||
159 | protected function build_all_results_edit_form() |
||
160 | { |
||
161 | //extra field for check on maxvalue |
||
162 | $this->addElement('header', get_lang('EditResult')); |
||
163 | $renderer = &$this->defaultRenderer(); |
||
164 | // set new form template |
||
165 | $form_template = '<form{attributes}> |
||
166 | <div class="table-responsive"> |
||
167 | <table class="table table-hover table-striped data_table" border="0" cellpadding="5" cellspacing="5">{content}</table> |
||
168 | </div> |
||
169 | </form>'; |
||
170 | $renderer->setFormTemplate($form_template); |
||
171 | |||
172 | if (api_is_western_name_order()) { |
||
173 | $renderer->setHeaderTemplate( |
||
174 | '<tr> |
||
175 | <th>'.get_lang('OfficialCode').'</th> |
||
176 | <th>'.get_lang('UserName').'</th> |
||
177 | <th>'.get_lang('FirstName').'</th> |
||
178 | <th>'.get_lang('LastName').'</th> |
||
179 | <th>'.get_lang('Qualify').'</th> |
||
180 | </tr>' |
||
181 | ); |
||
182 | } else { |
||
183 | $renderer->setHeaderTemplate( |
||
184 | '<tr> |
||
185 | <th>'.get_lang('OfficialCode').'</th> |
||
186 | <th>'.get_lang('UserName').'</th> |
||
187 | <th>'.get_lang('LastName').'</th> |
||
188 | <th>'.get_lang('FirstName').'</th> |
||
189 | <th>'.get_lang('Qualify').'</th> |
||
190 | </tr>' |
||
191 | ); |
||
192 | } |
||
193 | $template_submit = '<tr> |
||
194 | <td colspan="4" ></td> |
||
195 | <td> |
||
196 | {element} |
||
197 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
198 | </td> |
||
199 | </tr>'; |
||
200 | |||
201 | $results_and_users = []; |
||
202 | foreach ($this->result_object as $result) { |
||
203 | $user = api_get_user_info($result->get_user_id()); |
||
204 | $results_and_users[] = ['result' => $result, 'user' => $user]; |
||
205 | } |
||
206 | usort($results_and_users, ['EvalForm', 'sort_by_user']); |
||
207 | $defaults = []; |
||
208 | |||
209 | $model = ExerciseLib::getCourseScoreModel(); |
||
210 | |||
211 | foreach ($results_and_users as $result_and_user) { |
||
212 | $user = $result_and_user['user']; |
||
213 | $result = $result_and_user['result']; |
||
214 | $renderer = &$this->defaultRenderer(); |
||
215 | |||
216 | if (api_is_western_name_order()) { |
||
217 | $user_info = '<td align="left" >'.$user['firstname'].'</td>'; |
||
218 | $user_info .= '<td align="left" >'.$user['lastname'].'</td>'; |
||
219 | } else { |
||
220 | $user_info = '<td align="left" >'.$user['lastname'].'</td>'; |
||
221 | $user_info .= '<td align="left" >'.$user['firstname'].'</td>'; |
||
222 | } |
||
223 | |||
224 | $template = '<tr> |
||
225 | <td align="left" >'.$user['official_code'].'</td> |
||
226 | <td align="left" >'.$user['username'].'</td> |
||
227 | '.$user_info.' |
||
228 | <td align="left">{element} / '.$this->evaluation_object->get_max().' |
||
229 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
230 | </td> |
||
231 | </tr>'; |
||
232 | |||
233 | if (empty($model)) { |
||
234 | $this->addFloat( |
||
235 | 'score['.$result->get_id().']', |
||
236 | $this->build_stud_label($user['user_id'], $user['username'], $user['lastname'], $user['firstname']), |
||
237 | false, |
||
238 | [ |
||
239 | 'maxlength' => 5, |
||
240 | ], |
||
241 | false, |
||
242 | 0, |
||
243 | $this->evaluation_object->get_max() |
||
244 | ); |
||
245 | $defaults['score['.$result->get_id().']'] = $result->get_score(); |
||
246 | } else { |
||
247 | $questionWeighting = $this->evaluation_object->get_max(); |
||
248 | $select = $this->addSelect( |
||
249 | 'score['.$result->get_id().']', |
||
250 | get_lang('Score'), |
||
251 | [], |
||
252 | ['disable_js' => true, 'id' => 'score_'.$result->get_id()] |
||
253 | ); |
||
254 | |||
255 | foreach ($model['score_list'] as $item) { |
||
256 | $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2); |
||
257 | $modelStyle = ExerciseLib::getModelStyle($item, $i); |
||
258 | $attributes = ['class' => $item['css_class']]; |
||
259 | if ($result->get_score() == $i) { |
||
260 | $attributes['selected'] = 'selected'; |
||
261 | } |
||
262 | $select->addOption($modelStyle, $i, $attributes); |
||
263 | } |
||
264 | $select->updateSelectWithSelectedOption($this); |
||
265 | |||
266 | $template = '<tr> |
||
267 | <td align="left" >'.$user['official_code'].'</td> |
||
268 | <td align="left" >'.$user['username'].'</td> |
||
269 | '.$user_info.' |
||
270 | <td align="left">{element} <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
271 | </td> |
||
272 | </tr>'; |
||
273 | } |
||
274 | $renderer->setElementTemplate($template, 'score['.$result->get_id().']'); |
||
275 | } |
||
276 | |||
277 | if (empty($model)) { |
||
278 | $this->setDefaults($defaults); |
||
279 | } |
||
280 | $this->addButtonSave(get_lang('EditResult')); |
||
281 | $renderer->setElementTemplate($template_submit, 'submit'); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * This function builds a form to move an item to another category. |
||
286 | */ |
||
287 | protected function build_move_form() |
||
288 | { |
||
289 | $renderer = &$this->defaultRenderer(); |
||
290 | $renderer->setCustomElementTemplate('<span>{element}</span> '); |
||
291 | $this->addElement('static', null, null, '"'.$this->evaluation_object->get_name().'" '); |
||
292 | $this->addElement('static', null, null, get_lang('MoveTo').' : '); |
||
293 | $select = $this->addElement('select', 'move_cat', null, null); |
||
294 | $line = ''; |
||
295 | foreach ($this->evaluation_object->get_target_categories() as $cat) { |
||
296 | for ($i = 0; $i < $cat[2]; $i++) { |
||
297 | $line .= '—'; |
||
298 | } |
||
299 | $select->addOption($line.' '.$cat[1], $cat[0]); |
||
300 | $line = ''; |
||
301 | } |
||
302 | $this->addButtonSave(get_lang('Ok'), 'submit'); |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * Builds a result form containing inputs for all students with a given course_code. |
||
307 | */ |
||
308 | protected function build_result_add_form() |
||
309 | { |
||
310 | $renderer = &$this->defaultRenderer(); |
||
311 | $renderer->setFormTemplate( |
||
312 | '<form{attributes}> |
||
313 | <div class="table-responsive"> |
||
314 | <table class="table table-hover table-striped data_table"> |
||
315 | {content} |
||
316 | </table> |
||
317 | </div> |
||
318 | </form>' |
||
319 | ); |
||
320 | |||
321 | $users = GradebookUtils::get_users_in_course($this->evaluation_object->get_course_code()); |
||
322 | $nr_users = 0; |
||
323 | //extra field for check on maxvalue |
||
324 | $this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max()); |
||
325 | $this->addElement('hidden', 'minvalue', 0); |
||
326 | $this->addElement('header', get_lang('AddResult')); |
||
327 | |||
328 | if (api_is_western_name_order()) { |
||
329 | $renderer->setHeaderTemplate( |
||
330 | '<tr> |
||
331 | <th>'.get_lang('OfficialCode').'</th> |
||
332 | <th>'.get_lang('UserName').'</th> |
||
333 | <th>'.get_lang('FirstName').'</th> |
||
334 | <th>'.get_lang('LastName').'</th> |
||
335 | <th>'.get_lang('Qualify').'</th> |
||
336 | </tr>' |
||
337 | ); |
||
338 | } else { |
||
339 | $renderer->setHeaderTemplate( |
||
340 | '<tr> |
||
341 | <th>'.get_lang('OfficialCode').'</th> |
||
342 | <th>'.get_lang('UserName').'</th> |
||
343 | <th>'.get_lang('LastName').'</th> |
||
344 | <th>'.get_lang('FirstName').'</th> |
||
345 | <th>'.get_lang('Qualify').'</th> |
||
346 | </tr>' |
||
347 | ); |
||
348 | } |
||
349 | |||
350 | $firstUser = true; |
||
351 | foreach ($users as $user) { |
||
352 | $element_name = 'score['.$user[0].']'; |
||
353 | $scoreColumnProperties = ['maxlength' => 5]; |
||
354 | if ($firstUser) { |
||
355 | $scoreColumnProperties['autofocus'] = ''; |
||
356 | $firstUser = false; |
||
357 | } |
||
358 | |||
359 | //user_id, user.username, lastname, firstname |
||
360 | $this->addFloat( |
||
361 | $element_name, |
||
362 | $this->build_stud_label($user[0], $user[1], $user[2], $user[3]), |
||
363 | false, |
||
364 | $scoreColumnProperties, |
||
365 | false, |
||
366 | 0, |
||
367 | $this->evaluation_object->get_max() |
||
368 | ); |
||
369 | |||
370 | if (api_is_western_name_order()) { |
||
371 | $user_info = '<td align="left" >'.$user[3].'</td>'; |
||
372 | $user_info .= '<td align="left" >'.$user[2].'</td>'; |
||
373 | } else { |
||
374 | $user_info = '<td align="left" >'.$user[2].'</td>'; |
||
375 | $user_info .= '<td align="left" >'.$user[3].'</td>'; |
||
376 | } |
||
377 | $nr_users++; |
||
378 | |||
379 | $template = '<tr> |
||
380 | <td align="left" >'.$user[4].'</td> |
||
381 | <td align="left" >'.$user[1].'</td> |
||
382 | '.$user_info.' |
||
383 | <td align="left">{element} / '.$this->evaluation_object->get_max().' |
||
384 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
385 | </td> |
||
386 | </tr>'; |
||
387 | $renderer->setElementTemplate($template, $element_name); |
||
388 | } |
||
389 | $this->addElement('hidden', 'nr_users', $nr_users); |
||
390 | $this->addElement('hidden', 'evaluation_id', $this->result_object->get_evaluation_id()); |
||
391 | $this->addButtonSave(get_lang('AddResult'), 'submit'); |
||
392 | |||
393 | $template_submit = '<tr> |
||
394 | <td colspan="4" ></td> |
||
395 | <td > |
||
396 | {element} |
||
397 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
398 | </td> |
||
399 | </tr>'; |
||
400 | $renderer->setElementTemplate($template_submit, 'submit'); |
||
401 | } |
||
402 | |||
403 | /** |
||
404 | * Builds a form to edit a result. |
||
405 | */ |
||
406 | protected function build_result_edit_form() |
||
407 | { |
||
408 | $userInfo = api_get_user_info($this->result_object->get_user_id()); |
||
409 | $this->addHeader(get_lang('User').': '.$userInfo['complete_name']); |
||
410 | |||
411 | $model = ExerciseLib::getCourseScoreModel(); |
||
412 | |||
413 | if (empty($model)) { |
||
414 | $this->addFloat( |
||
415 | 'score', |
||
416 | [ |
||
417 | get_lang('Score'), |
||
418 | null, |
||
419 | '/ '.$this->evaluation_object->get_max(), |
||
420 | ], |
||
421 | false, |
||
422 | [ |
||
423 | 'size' => '4', |
||
424 | 'maxlength' => '5', |
||
425 | ], |
||
426 | false, |
||
427 | 0, |
||
428 | $this->evaluation_object->get_max() |
||
429 | ); |
||
430 | $this->setDefaults( |
||
431 | [ |
||
432 | 'score' => $this->result_object->get_score(), |
||
433 | 'maximum' => $this->evaluation_object->get_max(), |
||
434 | ] |
||
435 | ); |
||
436 | } else { |
||
437 | $questionWeighting = $this->evaluation_object->get_max(); |
||
438 | $select = $this->addSelect('score', get_lang('Score'), [], ['disable_js' => true]); |
||
439 | |||
440 | foreach ($model['score_list'] as $item) { |
||
441 | $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2); |
||
442 | $model = ExerciseLib::getModelStyle($item, $i); |
||
443 | $attributes = ['class' => $item['css_class']]; |
||
444 | if ($this->result_object->get_score() == $i) { |
||
445 | $attributes['selected'] = 'selected'; |
||
446 | } |
||
447 | $select->addOption($model, $i, $attributes); |
||
448 | } |
||
449 | $select->updateSelectWithSelectedOption($this); |
||
450 | } |
||
451 | |||
452 | $allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts'); |
||
453 | if ($allowMultipleAttempts) { |
||
454 | $this->addTextarea('comment', get_lang('Comment')); |
||
455 | } |
||
456 | |||
457 | $this->addButtonSave(get_lang('Edit')); |
||
458 | $this->addElement('hidden', 'hid_user_id', $this->result_object->get_user_id()); |
||
459 | } |
||
460 | |||
461 | /** |
||
462 | * Builds a form to add an evaluation. |
||
463 | */ |
||
464 | protected function build_add_form() |
||
465 | { |
||
466 | $this->setDefaults( |
||
467 | [ |
||
468 | 'hid_user_id' => $this->evaluation_object->get_user_id(), |
||
469 | 'hid_category_id' => $this->evaluation_object->get_category_id(), |
||
470 | 'hid_course_code' => $this->evaluation_object->get_course_code(), |
||
471 | 'created_at' => api_get_utc_datetime(), |
||
472 | ] |
||
473 | ); |
||
474 | $this->build_basic_form(); |
||
475 | if ($this->evaluation_object->get_course_code() == null) { |
||
476 | $this->addElement('checkbox', 'adduser', null, get_lang('AddUserToEval')); |
||
477 | } else { |
||
478 | $this->addElement('checkbox', 'addresult', null, get_lang('AddResult')); |
||
479 | } |
||
480 | $this->addButtonCreate(get_lang('AddAssessment'), 'submit'); |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * Builds a form to edit an evaluation. |
||
485 | */ |
||
486 | protected function build_editing_form() |
||
487 | { |
||
488 | $parent_cat = Category::load($this->evaluation_object->get_category_id()); |
||
489 | //@TODO $weight_mask is replaced? |
||
490 | if ($parent_cat[0]->get_parent_id() == 0) { |
||
491 | $weight_mask = $this->evaluation_object->get_weight(); |
||
492 | } else { |
||
493 | $cat = Category::load($parent_cat[0]->get_parent_id()); |
||
494 | $global_weight = $cat[0]->get_weight(); |
||
495 | $weight_mask = $global_weight * $this->evaluation_object->get_weight() / $parent_cat[0]->get_weight(); |
||
496 | } |
||
497 | $weight = $weight_mask = $this->evaluation_object->get_weight(); |
||
498 | |||
499 | $this->setDefaults([ |
||
500 | 'hid_id' => $this->evaluation_object->get_id(), |
||
501 | 'name' => $this->evaluation_object->get_name(), |
||
502 | 'description' => $this->evaluation_object->get_description(), |
||
503 | 'hid_user_id' => $this->evaluation_object->get_user_id(), |
||
504 | 'hid_course_code' => $this->evaluation_object->get_course_code(), |
||
505 | 'hid_category_id' => $this->evaluation_object->get_category_id(), |
||
506 | 'created_at' => api_get_utc_datetime($this->evaluation_object->get_date()), |
||
507 | 'weight' => $weight, |
||
508 | 'weight_mask' => $weight_mask, |
||
509 | 'max' => $this->evaluation_object->get_max(), |
||
510 | 'visible' => $this->evaluation_object->is_visible(), |
||
511 | ]); |
||
512 | $id_current = isset($this->id) ? $this->id : null; |
||
513 | $this->addElement('hidden', 'hid_id', $id_current); |
||
514 | $this->build_basic_form(1); |
||
515 | $this->addButtonSave(get_lang('ModifyEvaluation'), 'submit'); |
||
516 | } |
||
517 | |||
518 | /** |
||
519 | * Builds a basic form that is used in add and edit. |
||
520 | * |
||
521 | * @param int $edit |
||
522 | */ |
||
523 | private function build_basic_form($edit = 0) |
||
524 | { |
||
525 | $form_title = get_lang('NewEvaluation'); |
||
526 | if (!empty($_GET['editeval'])) { |
||
527 | $form_title = get_lang('EditEvaluation'); |
||
528 | } |
||
529 | |||
530 | $this->addHeader($form_title); |
||
531 | $this->addElement('hidden', 'hid_user_id'); |
||
532 | $this->addElement('hidden', 'hid_course_code'); |
||
533 | |||
534 | $this->addText( |
||
535 | 'name', |
||
536 | get_lang('EvaluationName'), |
||
537 | true, |
||
538 | [ |
||
539 | 'maxlength' => '50', |
||
540 | 'id' => 'evaluation_title', |
||
541 | ] |
||
542 | ); |
||
543 | |||
544 | $cat_id = $this->evaluation_object->get_category_id(); |
||
545 | |||
546 | $session_id = api_get_session_id(); |
||
547 | $course_code = api_get_course_id(); |
||
548 | $all_categories = Category:: load( |
||
549 | null, |
||
550 | null, |
||
551 | $course_code, |
||
552 | null, |
||
553 | null, |
||
554 | $session_id, |
||
555 | false |
||
556 | ); |
||
557 | |||
558 | if (1 == count($all_categories)) { |
||
559 | $this->addElement('hidden', 'hid_category_id', $cat_id); |
||
560 | } else { |
||
561 | $select_gradebook = $this->addElement( |
||
562 | 'select', |
||
563 | 'hid_category_id', |
||
564 | get_lang('SelectGradebook'), |
||
565 | [], |
||
566 | ['id' => 'hid_category_id'] |
||
567 | ); |
||
568 | $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero'); |
||
569 | $default_weight = 0; |
||
570 | if (!empty($all_categories)) { |
||
571 | foreach ($all_categories as $my_cat) { |
||
572 | if ($my_cat->get_course_code() == api_get_course_id()) { |
||
573 | $grade_model_id = $my_cat->get_grade_model_id(); |
||
574 | if (empty($grade_model_id)) { |
||
575 | if ($my_cat->get_parent_id() == 0) { |
||
576 | $default_weight = $my_cat->get_weight(); |
||
577 | $select_gradebook->addOption(get_lang('Default'), $my_cat->get_id()); |
||
578 | $cats_added[] = $my_cat->get_id(); |
||
579 | } else { |
||
580 | $select_gradebook->addOption(Security::remove_XSS($my_cat->get_name()), $my_cat->get_id()); |
||
581 | $cats_added[] = $my_cat->get_id(); |
||
582 | } |
||
583 | } else { |
||
584 | $select_gradebook->addOption(get_lang('Select'), 0); |
||
585 | } |
||
586 | if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) { |
||
587 | $default_weight = $my_cat->get_weight(); |
||
588 | } |
||
589 | } |
||
590 | } |
||
591 | } |
||
592 | } |
||
593 | |||
594 | $this->addFloat( |
||
595 | 'weight_mask', |
||
596 | [ |
||
597 | get_lang('Weight'), |
||
598 | null, |
||
599 | ' [0 .. <span id="max_weight">'.$all_categories[0]->get_weight().'</span>] ', |
||
600 | ], |
||
601 | true, |
||
602 | [ |
||
603 | 'size' => '4', |
||
604 | 'maxlength' => '5', |
||
605 | ] |
||
606 | ); |
||
607 | |||
608 | $model = ExerciseLib::getCourseScoreModel(); |
||
609 | |||
610 | if ($edit) { |
||
611 | if (empty($model)) { |
||
612 | if (!$this->evaluation_object->has_results()) { |
||
613 | $this->addText( |
||
614 | 'max', |
||
615 | get_lang('QualificationNumeric'), |
||
616 | true, |
||
617 | [ |
||
618 | 'maxlength' => '5', |
||
619 | ] |
||
620 | ); |
||
621 | } else { |
||
622 | $this->addText( |
||
623 | 'max', |
||
624 | [get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')], |
||
625 | false, |
||
626 | [ |
||
627 | 'maxlength' => '5', |
||
628 | 'disabled' => 'disabled', |
||
629 | ] |
||
630 | ); |
||
631 | } |
||
632 | } else { |
||
633 | $class = ''; |
||
634 | foreach ($model['score_list'] as $item) { |
||
635 | $class = $item['css_class']; |
||
636 | } |
||
637 | $this->addText( |
||
638 | 'max', |
||
639 | get_lang('QualificationNumeric'), |
||
640 | false, |
||
641 | [ |
||
642 | 'maxlength' => '5', |
||
643 | 'class' => $class, |
||
644 | 'disabled' => 'disabled', |
||
645 | ] |
||
646 | ); |
||
647 | |||
648 | $defaults['max'] = $item['max']; |
||
649 | $this->setDefaults($defaults); |
||
650 | } |
||
651 | } else { |
||
652 | if (empty($model)) { |
||
653 | $this->addText( |
||
654 | 'max', |
||
655 | get_lang('QualificationNumeric'), |
||
656 | true, |
||
657 | [ |
||
658 | 'maxlength' => '5', |
||
659 | ] |
||
660 | ); |
||
661 | $default_max = api_get_setting('gradebook_default_weight'); |
||
662 | $defaults['max'] = isset($default_max) ? $default_max : 100; |
||
663 | $this->setDefaults($defaults); |
||
664 | } else { |
||
665 | $class = ''; |
||
666 | foreach ($model['score_list'] as $item) { |
||
667 | $class = $item['css_class']; |
||
668 | } |
||
669 | $this->addText( |
||
670 | 'max', |
||
671 | get_lang('QualificationNumeric'), |
||
672 | false, |
||
673 | [ |
||
674 | 'maxlength' => '5', |
||
675 | 'class' => $class, |
||
676 | 'disabled' => 'disabled', |
||
677 | ] |
||
678 | ); |
||
679 | |||
680 | $defaults['max'] = $item['max']; |
||
681 | $this->setDefaults($defaults); |
||
682 | } |
||
683 | } |
||
684 | |||
685 | $this->addElement('textarea', 'description', get_lang('Description')); |
||
686 | $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required'); |
||
687 | $this->addElement('checkbox', 'visible', null, get_lang('Visible')); |
||
688 | $this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); |
||
689 | $this->addRule( |
||
690 | 'max', |
||
691 | get_lang('NegativeValue'), |
||
692 | 'compare', |
||
693 | '>=', |
||
694 | 'server', |
||
695 | false, |
||
696 | false, |
||
697 | 0 |
||
698 | ); |
||
699 | $setting = api_get_setting('tool_visible_by_default_at_creation'); |
||
700 | $visibility_default = 1; |
||
701 | if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') { |
||
702 | $visibility_default = 0; |
||
703 | } |
||
704 | $this->setDefaults(['visible' => $visibility_default]); |
||
705 | } |
||
706 | |||
707 | /** |
||
708 | * @param $id |
||
709 | * @param $username |
||
710 | * @param $lastname |
||
711 | * @param $firstname |
||
712 | * |
||
713 | * @return string |
||
714 | */ |
||
715 | private function build_stud_label($id, $username, $lastname, $firstname) |
||
716 | { |
||
717 | $opendocurl_start = ''; |
||
718 | $opendocurl_end = ''; |
||
719 | // evaluation's origin is a link |
||
720 | if ($this->evaluation_object->get_category_id() < 0) { |
||
721 | $link = LinkFactory::get_evaluation_link($this->evaluation_object->get_id()); |
||
722 | $doc_url = $link->get_view_url($id); |
||
0 ignored issues
–
show
|
|||
723 | if (null != $doc_url) { |
||
724 | $opendocurl_start .= '<a href="'.$doc_url.'" target="_blank">'; |
||
725 | $opendocurl_end = '</a>'; |
||
726 | } |
||
727 | } |
||
728 | |||
729 | return $opendocurl_start.api_get_person_name($firstname, $lastname).' ('.$username.')'.$opendocurl_end; |
||
730 | } |
||
731 | } |
||
732 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.