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 $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($defaultValues = [], $filter = null) |
||
89 | { |
||
90 | parent::setDefaults($defaultValues, $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->addHeader(get_lang('Choose users for this evaluation')); |
||
118 | $select = $this->addSelect( |
||
119 | 'firstLetterUser', |
||
120 | get_lang('First letter'), |
||
121 | null, |
||
122 | [ |
||
123 | 'onchange' => 'document.add_users_to_evaluation.submit()', |
||
124 | ] |
||
125 | ); |
||
126 | $select->addOption('', ''); |
||
127 | for ($i = 65; $i <= 90; $i++) { |
||
128 | $letter = chr($i); |
||
129 | if (isset($this->extra) && $this->extra == $letter) { |
||
130 | $select->addOption($letter, $letter, 'selected'); |
||
131 | } else { |
||
132 | $select->addOption($letter, $letter); |
||
133 | } |
||
134 | } |
||
135 | $select = $this->addSelect( |
||
136 | 'add_users', |
||
137 | null, |
||
138 | null, |
||
139 | [ |
||
140 | 'multiple' => 'multiple', |
||
141 | 'size' => '15', |
||
142 | 'style' => 'width:250px', |
||
143 | ] |
||
144 | ); |
||
145 | foreach ($this->evaluation_object->get_not_subscribed_students() as $user) { |
||
146 | if ((!isset($this->extra)) || empty($this->extra) || api_strtoupper(api_substr($user[1], 0, 1)) == $this->extra |
||
147 | ) { |
||
148 | $select->addoption($user[1].' '.$user[2].' ('.$user[3].')', $user[0]); |
||
149 | } |
||
150 | } |
||
151 | $this->addButtonCreate(get_lang('Add users to evaluation'), 'submit_button'); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * This function builds a form to edit all results in an evaluation. |
||
156 | */ |
||
157 | protected function build_all_results_edit_form() |
||
158 | { |
||
159 | //extra field for check on maxvalue |
||
160 | $this->addElement('header', get_lang('Grade learners')); |
||
161 | $renderer = &$this->defaultRenderer(); |
||
162 | // set new form template |
||
163 | $form_template = '<form{attributes}> |
||
164 | <div class="table-responsive"> |
||
165 | <table class="data_table" border="0" cellpadding="5" cellspacing="5">{content}</table> |
||
166 | </div> |
||
167 | </form>'; |
||
168 | $renderer->setFormTemplate($form_template); |
||
169 | |||
170 | if (api_is_western_name_order()) { |
||
171 | $renderer->setHeaderTemplate( |
||
172 | '<tr> |
||
173 | <th>'.get_lang('Code').'</th> |
||
174 | <th>'.get_lang('Username').'</th> |
||
175 | <th>'.get_lang('First name').'</th> |
||
176 | <th>'.get_lang('Last name').'</th> |
||
177 | <th>'.get_lang('Grade activity').'</th> |
||
178 | </tr>' |
||
179 | ); |
||
180 | } else { |
||
181 | $renderer->setHeaderTemplate( |
||
182 | '<tr> |
||
183 | <th>'.get_lang('Code').'</th> |
||
184 | <th>'.get_lang('Username').'</th> |
||
185 | <th>'.get_lang('Last name').'</th> |
||
186 | <th>'.get_lang('First name').'</th> |
||
187 | <th>'.get_lang('Grade activity').'</th> |
||
188 | </tr>' |
||
189 | ); |
||
190 | } |
||
191 | $template_submit = '<tr> |
||
192 | <td colspan="4" ></td> |
||
193 | <td> |
||
194 | {element} |
||
195 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
196 | </td> |
||
197 | </tr>'; |
||
198 | |||
199 | $results_and_users = []; |
||
200 | foreach ($this->result_object as $result) { |
||
201 | $user = api_get_user_info($result->get_user_id()); |
||
202 | $results_and_users[] = ['result' => $result, 'user' => $user]; |
||
203 | } |
||
204 | usort($results_and_users, ['EvalForm', 'sort_by_user']); |
||
205 | $defaults = []; |
||
206 | |||
207 | $model = ExerciseLib::getCourseScoreModel(); |
||
208 | |||
209 | foreach ($results_and_users as $result_and_user) { |
||
210 | $user = $result_and_user['user']; |
||
211 | $result = $result_and_user['result']; |
||
212 | $renderer = &$this->defaultRenderer(); |
||
213 | |||
214 | if (api_is_western_name_order()) { |
||
215 | $user_info = '<td align="left" >'.$user['firstname'].'</td>'; |
||
216 | $user_info .= '<td align="left" >'.$user['lastname'].'</td>'; |
||
217 | } else { |
||
218 | $user_info = '<td align="left" >'.$user['lastname'].'</td>'; |
||
219 | $user_info .= '<td align="left" >'.$user['firstname'].'</td>'; |
||
220 | } |
||
221 | |||
222 | $template = '<tr> |
||
223 | <td align="left" >'.$user['official_code'].'</td> |
||
224 | <td align="left" >'.$user['username'].'</td> |
||
225 | '.$user_info.' |
||
226 | <td align="left">{element} / '.$this->evaluation_object->get_max().' |
||
227 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
228 | </td> |
||
229 | </tr>'; |
||
230 | |||
231 | if (empty($model)) { |
||
232 | $this->addFloat( |
||
233 | 'score['.$result->get_id().']', |
||
234 | $this->build_stud_label($user['user_id'], $user['username'], $user['lastname'], $user['firstname']), |
||
235 | false, |
||
236 | [ |
||
237 | 'maxlength' => 5, |
||
238 | ], |
||
239 | false, |
||
240 | 0, |
||
241 | $this->evaluation_object->get_max() |
||
242 | ); |
||
243 | $defaults['score['.$result->get_id().']'] = $result->get_score(); |
||
244 | } else { |
||
245 | $questionWeighting = $this->evaluation_object->get_max(); |
||
246 | $select = $this->addSelect( |
||
247 | 'score['.$result->get_id().']', |
||
248 | get_lang('Score'), |
||
249 | [], |
||
250 | ['disable_js' => true, 'id' => 'score_'.$result->get_id()] |
||
251 | ); |
||
252 | |||
253 | foreach ($model['score_list'] as $item) { |
||
254 | $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2); |
||
255 | $modelStyle = ExerciseLib::getModelStyle($item, $i); |
||
256 | $attributes = ['class' => $item['css_class']]; |
||
257 | if ($result->get_score() == $i) { |
||
258 | $attributes['selected'] = 'selected'; |
||
259 | } |
||
260 | $select->addOption($modelStyle, $i, $attributes); |
||
261 | } |
||
262 | $select->updateSelectWithSelectedOption($this); |
||
263 | |||
264 | $template = '<tr> |
||
265 | <td align="left" >'.$user['official_code'].'</td> |
||
266 | <td align="left" >'.$user['username'].'</td> |
||
267 | '.$user_info.' |
||
268 | <td align="left">{element} <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
269 | </td> |
||
270 | </tr>'; |
||
271 | } |
||
272 | $renderer->setElementTemplate($template, 'score['.$result->get_id().']'); |
||
273 | } |
||
274 | |||
275 | if (empty($model)) { |
||
276 | $this->setDefaults($defaults); |
||
277 | } |
||
278 | $this->addButtonSave(get_lang('Grade learners')); |
||
279 | $renderer->setElementTemplate($template_submit, 'submit'); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * This function builds a form to move an item to another category. |
||
284 | */ |
||
285 | protected function build_move_form() |
||
286 | { |
||
287 | $renderer = &$this->defaultRenderer(); |
||
288 | $renderer->setCustomElementTemplate('<span>{element}</span> '); |
||
289 | $this->addElement('static', null, null, '"'.$this->evaluation_object->get_name().'" '); |
||
290 | $this->addElement('static', null, null, get_lang('Move to').' : '); |
||
291 | $select = $this->addSelect('move_cat', null, null); |
||
292 | $line = ''; |
||
293 | foreach ($this->evaluation_object->get_target_categories() as $cat) { |
||
294 | for ($i = 0; $i < $cat[2]; $i++) { |
||
295 | $line .= '—'; |
||
296 | } |
||
297 | $select->addoption($line.' '.$cat[1], $cat[0]); |
||
298 | $line = ''; |
||
299 | } |
||
300 | $this->addButtonSave(get_lang('Validate'), 'submit'); |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * Builds a result form containing inputs for all students with a given course_code. |
||
305 | */ |
||
306 | protected function build_result_add_form() |
||
307 | { |
||
308 | $renderer = &$this->defaultRenderer(); |
||
309 | $renderer->setFormTemplate( |
||
310 | '<form{attributes}> |
||
311 | <div class="table-responsive"> |
||
312 | <table class="data_table"> |
||
313 | {content} |
||
314 | </table> |
||
315 | </div> |
||
316 | </form>' |
||
317 | ); |
||
318 | |||
319 | $users = GradebookUtils::get_users_in_course($this->evaluation_object->get_course_code()); |
||
320 | $nr_users = 0; |
||
321 | //extra field for check on maxvalue |
||
322 | $this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max()); |
||
323 | $this->addElement('hidden', 'minvalue', 0); |
||
324 | $this->addElement('header', get_lang('Grade learners')); |
||
325 | |||
326 | if (api_is_western_name_order()) { |
||
327 | $renderer->setHeaderTemplate( |
||
328 | '<tr> |
||
329 | <th>'.get_lang('Code').'</th> |
||
330 | <th>'.get_lang('Username').'</th> |
||
331 | <th>'.get_lang('First name').'</th> |
||
332 | <th>'.get_lang('Last name').'</th> |
||
333 | <th>'.get_lang('Grade activity').'</th> |
||
334 | </tr>' |
||
335 | ); |
||
336 | } else { |
||
337 | $renderer->setHeaderTemplate( |
||
338 | '<tr> |
||
339 | <th>'.get_lang('Code').'</th> |
||
340 | <th>'.get_lang('Username').'</th> |
||
341 | <th>'.get_lang('Last name').'</th> |
||
342 | <th>'.get_lang('First name').'</th> |
||
343 | <th>'.get_lang('Grade activity').'</th> |
||
344 | </tr>' |
||
345 | ); |
||
346 | } |
||
347 | |||
348 | $firstUser = true; |
||
349 | foreach ($users as $user) { |
||
350 | $element_name = 'score['.$user[0].']'; |
||
351 | $scoreColumnProperties = ['maxlength' => 5]; |
||
352 | if ($firstUser) { |
||
353 | $scoreColumnProperties['autofocus'] = ''; |
||
354 | $firstUser = false; |
||
355 | } |
||
356 | |||
357 | //user_id, user.username, lastname, firstname |
||
358 | $this->addFloat( |
||
359 | $element_name, |
||
360 | $this->build_stud_label($user[0], $user[1], $user[2], $user[3]), |
||
361 | false, |
||
362 | $scoreColumnProperties, |
||
363 | false, |
||
364 | 0, |
||
365 | $this->evaluation_object->get_max() |
||
366 | ); |
||
367 | |||
368 | if (api_is_western_name_order()) { |
||
369 | $user_info = '<td align="left" >'.$user[3].'</td>'; |
||
370 | $user_info .= '<td align="left" >'.$user[2].'</td>'; |
||
371 | } else { |
||
372 | $user_info = '<td align="left" >'.$user[2].'</td>'; |
||
373 | $user_info .= '<td align="left" >'.$user[3].'</td>'; |
||
374 | } |
||
375 | $nr_users++; |
||
376 | |||
377 | $template = '<tr> |
||
378 | <td align="left" >'.$user[4].'</td> |
||
379 | <td align="left" >'.$user[1].'</td> |
||
380 | '.$user_info.' |
||
381 | <td align="left">{element} / '.$this->evaluation_object->get_max().' |
||
382 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
383 | </td> |
||
384 | </tr>'; |
||
385 | $renderer->setElementTemplate($template, $element_name); |
||
386 | } |
||
387 | $this->addElement('hidden', 'nr_users', $nr_users); |
||
388 | $this->addElement('hidden', 'evaluation_id', $this->result_object->get_evaluation_id()); |
||
389 | $this->addButtonSave(get_lang('Grade learners'), 'submit'); |
||
390 | |||
391 | $template_submit = '<tr> |
||
392 | <td colspan="4" ></td> |
||
393 | <td > |
||
394 | {element} |
||
395 | <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> |
||
396 | </td> |
||
397 | </tr>'; |
||
398 | $renderer->setElementTemplate($template_submit, 'submit'); |
||
399 | } |
||
400 | |||
401 | /** |
||
402 | * Builds a form to edit a result. |
||
403 | */ |
||
404 | protected function build_result_edit_form() |
||
405 | { |
||
406 | $userInfo = api_get_user_info($this->result_object->get_user_id()); |
||
407 | $this->addHeader(get_lang('User').': '.$userInfo['complete_name']); |
||
408 | |||
409 | $model = ExerciseLib::getCourseScoreModel(); |
||
410 | |||
411 | if (empty($model)) { |
||
412 | $this->addFloat( |
||
413 | 'score', |
||
414 | [ |
||
415 | get_lang('Score'), |
||
416 | null, |
||
417 | '/ '.$this->evaluation_object->get_max(), |
||
418 | ], |
||
419 | false, |
||
420 | [ |
||
421 | 'size' => '4', |
||
422 | 'maxlength' => '5', |
||
423 | ], |
||
424 | false, |
||
425 | 0, |
||
426 | $this->evaluation_object->get_max() |
||
427 | ); |
||
428 | $this->setDefaults( |
||
429 | [ |
||
430 | 'score' => $this->result_object->get_score(), |
||
431 | 'maximum' => $this->evaluation_object->get_max(), |
||
432 | ] |
||
433 | ); |
||
434 | } else { |
||
435 | $questionWeighting = $this->evaluation_object->get_max(); |
||
436 | $select = $this->addSelect('score', get_lang('Score'), [], ['disable_js' => true]); |
||
437 | |||
438 | foreach ($model['score_list'] as $item) { |
||
439 | $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2); |
||
440 | $model = ExerciseLib::getModelStyle($item, $i); |
||
441 | $attributes = ['class' => $item['css_class']]; |
||
442 | if ($this->result_object->get_score() == $i) { |
||
443 | $attributes['selected'] = 'selected'; |
||
444 | } |
||
445 | $select->addOption($model, $i, $attributes); |
||
446 | } |
||
447 | $select->updateSelectWithSelectedOption($this); |
||
448 | } |
||
449 | |||
450 | $allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts'); |
||
451 | if ($allowMultipleAttempts) { |
||
452 | $this->addTextarea('comment', get_lang('Comment')); |
||
453 | } |
||
454 | |||
455 | $this->addButtonSave(get_lang('Edit')); |
||
456 | $this->addElement('hidden', 'hid_user_id', $this->result_object->get_user_id()); |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * Builds a form to add an evaluation. |
||
461 | */ |
||
462 | protected function build_add_form() |
||
463 | { |
||
464 | $this->setDefaults( |
||
465 | [ |
||
466 | 'hid_user_id' => $this->evaluation_object->get_user_id(), |
||
467 | 'hid_category_id' => $this->evaluation_object->get_category_id(), |
||
468 | 'hid_course_code' => $this->evaluation_object->get_course_code(), |
||
469 | 'created_at' => api_get_utc_datetime(), |
||
470 | ] |
||
471 | ); |
||
472 | $this->build_basic_form(); |
||
473 | if (null == $this->evaluation_object->get_course_code()) { |
||
474 | $this->addElement('checkbox', 'adduser', null, get_lang('Add users to evaluation')); |
||
475 | } else { |
||
476 | $this->addElement('checkbox', 'addresult', null, get_lang('Grade learners')); |
||
477 | } |
||
478 | $this->addButtonCreate(get_lang('Add this classroom activity to the assessment'), 'submit'); |
||
479 | } |
||
480 | |||
481 | /** |
||
482 | * Builds a form to edit an evaluation. |
||
483 | */ |
||
484 | protected function build_editing_form() |
||
485 | { |
||
486 | $parent_cat = Category::load($this->evaluation_object->get_category_id()); |
||
487 | //@TODO $weight_mask is replaced? |
||
488 | if (0 == $parent_cat[0]->get_parent_id()) { |
||
489 | $weight_mask = $this->evaluation_object->get_weight(); |
||
490 | } else { |
||
491 | $cat = Category::load($parent_cat[0]->get_parent_id()); |
||
492 | $global_weight = $cat[0]->get_weight(); |
||
493 | $weight_mask = $global_weight * $this->evaluation_object->get_weight() / $parent_cat[0]->get_weight(); |
||
494 | } |
||
495 | $weight = $weight_mask = $this->evaluation_object->get_weight(); |
||
496 | |||
497 | $this->setDefaults([ |
||
498 | 'hid_id' => $this->evaluation_object->get_id(), |
||
499 | 'name' => $this->evaluation_object->get_name(), |
||
500 | 'description' => $this->evaluation_object->get_description(), |
||
501 | 'hid_user_id' => $this->evaluation_object->get_user_id(), |
||
502 | 'hid_course_code' => $this->evaluation_object->get_course_code(), |
||
503 | 'hid_category_id' => $this->evaluation_object->get_category_id(), |
||
504 | 'created_at' => api_get_utc_datetime($this->evaluation_object->get_date()), |
||
505 | 'weight' => $weight, |
||
506 | 'weight_mask' => $weight_mask, |
||
507 | 'max' => $this->evaluation_object->get_max(), |
||
508 | 'visible' => $this->evaluation_object->is_visible(), |
||
509 | ]); |
||
510 | $id_current = isset($this->id) ? $this->id : null; |
||
511 | $this->addElement('hidden', 'hid_id', $id_current); |
||
512 | $this->build_basic_form(1); |
||
513 | $this->addButtonSave(get_lang('Save assessment'), 'submit'); |
||
514 | } |
||
515 | |||
516 | /** |
||
517 | * Builds a basic form that is used in add and edit. |
||
518 | * |
||
519 | * @param int $edit |
||
520 | */ |
||
521 | private function build_basic_form($edit = 0) |
||
522 | { |
||
523 | $form_title = get_lang('Add classroom activity'); |
||
524 | if (!empty($_GET['editeval']) && 1 == $_GET['editeval']) { |
||
525 | $form_title = get_lang('Edit evaluation'); |
||
526 | } |
||
527 | |||
528 | $this->addHeader($form_title); |
||
529 | $this->addElement('hidden', 'hid_user_id'); |
||
530 | $this->addElement('hidden', 'hid_course_code'); |
||
531 | |||
532 | $this->addText( |
||
533 | 'name', |
||
534 | get_lang('Assessment'), |
||
535 | true, |
||
536 | [ |
||
537 | 'maxlength' => '50', |
||
538 | 'id' => 'evaluation_title', |
||
539 | ] |
||
540 | ); |
||
541 | |||
542 | $cat_id = $this->evaluation_object->get_category_id(); |
||
543 | |||
544 | $session_id = api_get_session_id(); |
||
545 | $course_code = api_get_course_id(); |
||
546 | $all_categories = Category:: load( |
||
547 | null, |
||
548 | null, |
||
549 | $course_code, |
||
550 | null, |
||
551 | null, |
||
552 | $session_id, |
||
553 | false |
||
554 | ); |
||
555 | |||
556 | if (1 == count($all_categories)) { |
||
557 | $this->addElement('hidden', 'hid_category_id', $cat_id); |
||
558 | } else { |
||
559 | $select_gradebook = $this->addSelect( |
||
560 | 'hid_category_id', |
||
561 | get_lang('Select assessment'), |
||
562 | [], |
||
563 | ['id' => 'hid_category_id'] |
||
564 | ); |
||
565 | $this->addRule('hid_category_id', get_lang('Required field'), 'nonzero'); |
||
566 | $default_weight = 0; |
||
567 | if (!empty($all_categories)) { |
||
568 | foreach ($all_categories as $my_cat) { |
||
569 | if ($my_cat->get_course_code() == api_get_course_id()) { |
||
570 | $grade_model_id = $my_cat->get_grade_model_id(); |
||
571 | if (empty($grade_model_id)) { |
||
572 | if (0 == $my_cat->get_parent_id()) { |
||
573 | $default_weight = $my_cat->get_weight(); |
||
574 | $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); |
||
575 | $cats_added[] = $my_cat->get_id(); |
||
576 | } else { |
||
577 | $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); |
||
578 | $cats_added[] = $my_cat->get_id(); |
||
579 | } |
||
580 | } else { |
||
581 | $select_gradebook->addoption(get_lang('Select'), 0); |
||
582 | } |
||
583 | if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) { |
||
584 | $default_weight = $my_cat->get_weight(); |
||
585 | } |
||
586 | } |
||
587 | } |
||
588 | } |
||
589 | } |
||
590 | |||
591 | $this->addFloat( |
||
592 | 'weight_mask', |
||
593 | [ |
||
594 | get_lang('Weight'), |
||
595 | null, |
||
596 | ' [0 .. <span id="max_weight">'.$all_categories[0]->get_weight().'</span>] ', |
||
597 | ], |
||
598 | true, |
||
599 | [ |
||
600 | 'size' => '4', |
||
601 | 'maxlength' => '5', |
||
602 | ] |
||
603 | ); |
||
604 | |||
605 | $model = ExerciseLib::getCourseScoreModel(); |
||
606 | |||
607 | if ($edit) { |
||
608 | if (empty($model)) { |
||
609 | if (!$this->evaluation_object->has_results()) { |
||
610 | $this->addText( |
||
611 | 'max', |
||
612 | get_lang('Maximum score'), |
||
613 | true, |
||
614 | [ |
||
615 | 'maxlength' => '5', |
||
616 | ] |
||
617 | ); |
||
618 | } else { |
||
619 | $this->addText( |
||
620 | 'max', |
||
621 | [get_lang('Maximum score'), get_lang('Cannot change the score')], |
||
622 | false, |
||
623 | [ |
||
624 | 'maxlength' => '5', |
||
625 | 'disabled' => 'disabled', |
||
626 | ] |
||
627 | ); |
||
628 | } |
||
629 | } else { |
||
630 | $class = ''; |
||
631 | foreach ($model['score_list'] as $item) { |
||
632 | $class = $item['css_class']; |
||
633 | } |
||
634 | $this->addText( |
||
635 | 'max', |
||
636 | get_lang('Maximum score'), |
||
637 | false, |
||
638 | [ |
||
639 | 'maxlength' => '5', |
||
640 | 'class' => $class, |
||
641 | 'disabled' => 'disabled', |
||
642 | ] |
||
643 | ); |
||
644 | |||
645 | $defaults['max'] = $item['max']; |
||
646 | $this->setDefaults($defaults); |
||
647 | } |
||
648 | } else { |
||
649 | if (empty($model)) { |
||
650 | $this->addText( |
||
651 | 'max', |
||
652 | get_lang('Maximum score'), |
||
653 | true, |
||
654 | [ |
||
655 | 'maxlength' => '5', |
||
656 | ] |
||
657 | ); |
||
658 | $default_max = api_get_setting('gradebook_default_weight'); |
||
659 | $defaults['max'] = isset($default_max) ? $default_max : 100; |
||
660 | $this->setDefaults($defaults); |
||
661 | } else { |
||
662 | $class = ''; |
||
663 | foreach ($model['score_list'] as $item) { |
||
664 | $class = $item['css_class']; |
||
665 | } |
||
666 | $this->addText( |
||
667 | 'max', |
||
668 | get_lang('Maximum score'), |
||
669 | false, |
||
670 | [ |
||
671 | 'maxlength' => '5', |
||
672 | 'class' => $class, |
||
673 | 'disabled' => 'disabled', |
||
674 | ] |
||
675 | ); |
||
676 | |||
677 | $defaults['max'] = $item['max']; |
||
678 | $this->setDefaults($defaults); |
||
679 | } |
||
680 | } |
||
681 | |||
682 | $this->addElement('textarea', 'description', get_lang('Description')); |
||
683 | $this->addRule('hid_category_id', get_lang('Required field'), 'required'); |
||
684 | $this->addElement('checkbox', 'visible', null, get_lang('Visible')); |
||
685 | $this->addRule('max', get_lang('Only numbers'), 'numeric'); |
||
686 | $this->addRule( |
||
687 | 'max', |
||
688 | get_lang('Negative value'), |
||
689 | 'compare', |
||
690 | '>=', |
||
691 | 'server', |
||
692 | false, |
||
693 | false, |
||
694 | 0 |
||
695 | ); |
||
696 | $setting = api_get_setting('tool_visible_by_default_at_creation'); |
||
697 | $visibility_default = 1; |
||
698 | if (isset($setting['gradebook']) && 'false' == $setting['gradebook']) { |
||
699 | $visibility_default = 0; |
||
700 | } |
||
701 | $this->setDefaults(['visible' => $visibility_default]); |
||
702 | } |
||
703 | |||
704 | /** |
||
705 | * @param $id |
||
706 | * @param $username |
||
707 | * @param $lastname |
||
708 | * @param $firstname |
||
709 | * |
||
710 | * @return string |
||
711 | */ |
||
712 | private function build_stud_label($id, $username, $lastname, $firstname) |
||
713 | { |
||
714 | $opendocurl_start = ''; |
||
715 | $opendocurl_end = ''; |
||
716 | // evaluation's origin is a link |
||
717 | if ($this->evaluation_object->get_category_id() < 0) { |
||
718 | $link = LinkFactory::get_evaluation_link($this->evaluation_object->get_id()); |
||
719 | $doc_url = $link->get_view_url($id); |
||
0 ignored issues
–
show
|
|||
720 | if (null != $doc_url) { |
||
721 | $opendocurl_start .= '<a href="'.$doc_url.'" target="_blank">'; |
||
722 | $opendocurl_end = '</a>'; |
||
723 | } |
||
724 | } |
||
725 | |||
726 | return $opendocurl_start.api_get_person_name($firstname, $lastname).' ('.$username.')'.$opendocurl_end; |
||
727 | } |
||
728 | } |
||
729 |
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.