Total Complexity | 117 |
Total Lines | 617 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like DisplayGradebook often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DisplayGradebook, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class DisplayGradebook |
||
11 | { |
||
12 | /** |
||
13 | * Displays the header for the result page containing the navigation tree and links. |
||
14 | * |
||
15 | * @param Evaluation $evalobj |
||
16 | * @param int $selectcat |
||
17 | * @param string $page |
||
18 | */ |
||
19 | public static function display_header_result($evalobj, $selectcat, $page) |
||
20 | { |
||
21 | $links = []; |
||
22 | if (api_is_allowed_to_edit(null, true)) { |
||
23 | if ('statistics' !== $page) { |
||
24 | $links[] = '<a href="'.Category::getUrl().'selectcat='.$selectcat.'">'. |
||
25 | Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Assessment home')) |
||
26 | .'</a>'; |
||
27 | if ('view_result' === $page) { |
||
28 | if (!empty($evalobj->getCourseId()) && !$evalobj->has_results()) { |
||
29 | $links[] = '<a href="gradebook_add_result.php?'.api_get_cidreq().'&selectcat='.$selectcat.'&selecteval='.$evalobj->get_id().'"> |
||
30 | '.Display::getMdiIcon(ActionIcon::GRADE, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Grade learners')).'</a>'; |
||
31 | } |
||
32 | |||
33 | if (api_is_platform_admin() || false == $evalobj->is_locked()) { |
||
|
|||
34 | $links[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&import=">'. |
||
35 | Display::getMdiIcon(ActionIcon::IMPORT_ARCHIVE, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Import marks')).'</a>'; |
||
36 | } |
||
37 | |||
38 | if ($evalobj->has_results()) { |
||
39 | $links[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&export=">'. |
||
40 | Display::getMdiIcon(ActionIcon::EXPORT_PDF, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('PDF Report')).'</a>'; |
||
41 | |||
42 | if (api_is_platform_admin() || false == $evalobj->is_locked()) { |
||
43 | $links[] = '<a href="gradebook_edit_result.php?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'">'. |
||
44 | Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Grade learners')).'</a>'; |
||
45 | $links[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&deleteall=" onclick="return confirmationall();">'. |
||
46 | Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Delete marks')).'</a>'; |
||
47 | } |
||
48 | } |
||
49 | $links[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&print=&selecteval='.$evalobj->get_id().'" target="_blank">'. |
||
50 | Display::getMdiIcon(ActionIcon::PRINT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Print')).'</a>'; |
||
51 | } |
||
52 | } else { |
||
53 | $links[] = '<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '. |
||
54 | Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Assessment home')).'</a>'; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | $scoredisplay = ScoreDisplay::instance(); |
||
59 | $student_score = ''; |
||
60 | $average = ''; |
||
61 | if ($evalobj->has_results()) { |
||
62 | // TODO this check needed ? |
||
63 | $score = $evalobj->calc_score(); |
||
64 | if (null != $score) { |
||
65 | $model = ExerciseLib::getCourseScoreModel(); |
||
66 | if (empty($model)) { |
||
67 | $average = get_lang('Average').' :<b> '.$scoredisplay->display_score($score, SCORE_AVERAGE).'</b>'; |
||
68 | $student_score = $evalobj->calc_score(api_get_user_id()); |
||
69 | $student_score = Display::tag( |
||
70 | 'h3', |
||
71 | get_lang('Score').': '.$scoredisplay->display_score($student_score, SCORE_DIV_PERCENT) |
||
72 | ); |
||
73 | |||
74 | $allowMultipleAttempts = ('true' === api_get_setting('gradebook.gradebook_multiple_evaluation_attempts')); |
||
75 | if ($allowMultipleAttempts) { |
||
76 | $results = Result::load(null, api_get_user_id(), $evalobj->get_id()); |
||
77 | if (!empty($results)) { |
||
78 | /** @var Result $resultData */ |
||
79 | foreach ($results as $resultData) { |
||
80 | $student_score .= ResultTable::getResultAttemptTable($resultData); |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | $description = ''; |
||
89 | if ('' == !$evalobj->get_description()) { |
||
90 | $description = get_lang('Description').' :<b> '.$evalobj->get_description().'</b><br>'; |
||
91 | } |
||
92 | |||
93 | if (!empty($evalobj->getCourseId())) { |
||
94 | $course = get_lang('Independent from course'); |
||
95 | } else { |
||
96 | $course = api_get_course_info_by_id($evalobj->getCourseId())['title']; |
||
97 | } |
||
98 | |||
99 | $evalinfo = '<h2>'.$evalobj->get_name().'</h2><hr>'; |
||
100 | $evalinfo .= $description; |
||
101 | $evalinfo .= get_lang('Course').' :<b> '.$course.'</b><br />'; |
||
102 | if (empty($model)) { |
||
103 | $evalinfo .= get_lang('Maximum score').' :<b> '.$evalobj->get_max().'</b><br>'.$average; |
||
104 | } |
||
105 | |||
106 | if (!api_is_allowed_to_edit()) { |
||
107 | $evalinfo .= $student_score; |
||
108 | } |
||
109 | |||
110 | if (!$evalobj->has_results()) { |
||
111 | $evalinfo .= '<br /><i>'.get_lang('No results in evaluation for now').'</i>'; |
||
112 | } |
||
113 | if ('statistics' != $page) { |
||
114 | if (api_is_allowed_to_edit(null, true)) { |
||
115 | $links[] = '<a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '. |
||
116 | Display::getMdiIcon('chart-box', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Graphical view')).'</a>'; |
||
117 | } |
||
118 | } |
||
119 | |||
120 | echo Display::toolbarGradeAction($links); |
||
121 | echo $evalinfo; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Displays the header for the flatview page containing filters. |
||
126 | * |
||
127 | * @param $catobj |
||
128 | * @param $showeval |
||
129 | * @param $showlink |
||
130 | */ |
||
131 | public static function display_header_reduce_flatview($catobj, $showeval, $showlink, $simple_search_form) |
||
132 | { |
||
133 | $header = '<div class="actions">'; |
||
134 | if (0 == $catobj->get_parent_id()) { |
||
135 | $select_cat = $catobj->get_id(); |
||
136 | $url = Category::getUrl(); |
||
137 | } else { |
||
138 | $select_cat = $catobj->get_parent_id(); |
||
139 | $url = 'gradebook_flatview.php'; |
||
140 | } |
||
141 | $header .= '<a href="'.$url.'?'.api_get_cidreq().'&selectcat='.$select_cat.'">'. |
||
142 | Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Assessment home')).'</a>'; |
||
143 | |||
144 | $pageNum = isset($_GET['flatviewlist_page_nr']) ? (int) $_GET['flatviewlist_page_nr'] : null; |
||
145 | $perPage = isset($_GET['flatviewlist_per_page']) ? (int) $_GET['flatviewlist_per_page'] : null; |
||
146 | $offset = isset($_GET['offset']) ? $_GET['offset'] : '0'; |
||
147 | |||
148 | $exportCsvUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([ |
||
149 | 'export_format' => 'csv', |
||
150 | 'export_report' => 'export_report', |
||
151 | 'selectcat' => $catobj->get_id(), |
||
152 | ]); |
||
153 | |||
154 | $header .= Display::url( |
||
155 | Display::getMdiIcon(ActionIcon::EXPORT_CSV, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('CSV export')), |
||
156 | $exportCsvUrl |
||
157 | ); |
||
158 | |||
159 | $exportXlsUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([ |
||
160 | 'export_format' => 'xls', |
||
161 | 'export_report' => 'export_report', |
||
162 | 'selectcat' => $catobj->get_id(), |
||
163 | ]); |
||
164 | |||
165 | $header .= Display::url( |
||
166 | Display::getMdiIcon(ActionIcon::EXPORT_SPREADSHEET, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Excel export')), |
||
167 | $exportXlsUrl |
||
168 | ); |
||
169 | |||
170 | $exportDocUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([ |
||
171 | 'export_format' => 'doc', |
||
172 | 'export_report' => 'export_report', |
||
173 | 'selectcat' => $catobj->get_id(), |
||
174 | ]); |
||
175 | |||
176 | $header .= Display::url( |
||
177 | Display::getMdiIcon(ActionIcon::EXPORT_DOC, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Export as .doc')), |
||
178 | $exportDocUrl |
||
179 | ); |
||
180 | |||
181 | $exportPrintUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([ |
||
182 | 'print' => '', |
||
183 | 'selectcat' => $catobj->get_id(), |
||
184 | ]); |
||
185 | |||
186 | $header .= Display::url( |
||
187 | Display::getMdiIcon(ActionIcon::PRINT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Print')), |
||
188 | $exportPrintUrl, |
||
189 | ['target' => '_blank'] |
||
190 | ); |
||
191 | |||
192 | $exportPdfUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([ |
||
193 | 'exportpdf' => '', |
||
194 | 'selectcat' => $catobj->get_id(), |
||
195 | 'offset' => $offset, |
||
196 | 'flatviewlist_page_nr' => $pageNum, |
||
197 | 'flatviewlist_per_page' => $perPage, |
||
198 | ]); |
||
199 | |||
200 | $header .= Display::url( |
||
201 | Display::getMdiIcon(ActionIcon::EXPORT_PDF, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Export to PDF')), |
||
202 | $exportPdfUrl |
||
203 | ); |
||
204 | |||
205 | $header .= '</div>'; |
||
206 | echo $header; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Displays the header for the gradebook containing the navigation tree and links. |
||
211 | * |
||
212 | * @param Category $catobj |
||
213 | * @param int $showtree '1' will show the browse tree and naviation buttons |
||
214 | * @param $selectcat |
||
215 | * @param bool $is_course_admin |
||
216 | * @param bool $is_platform_admin |
||
217 | * @param FormValidator $simple_search_form |
||
218 | * @param bool $show_add_qualification Whether to show or not the link to add a new qualification |
||
219 | * (we hide it in case of the course-embedded tool where we have |
||
220 | * only one per course or session) |
||
221 | * @param bool $show_add_link Whether to show or not the link to add a new item inside |
||
222 | * the qualification (we hide it in case of the course-embedded tool |
||
223 | * where we have only one qualification per course or session) |
||
224 | * @param array $certificateLinkInfo |
||
225 | */ |
||
226 | public static function header( |
||
227 | $catobj, |
||
228 | $showtree, |
||
229 | $selectcat, |
||
230 | $is_course_admin, |
||
231 | $is_platform_admin, |
||
232 | $simple_search_form, |
||
233 | $show_add_qualification = true, |
||
234 | $show_add_link = true, |
||
235 | $certificateLinkInfo = [] |
||
236 | ) { |
||
237 | $userId = api_get_user_id(); |
||
238 | $courseId = api_get_course_int_id(); |
||
239 | $sessionId = api_get_session_id(); |
||
240 | if (!$is_course_admin) { |
||
241 | $model = ExerciseLib::getCourseScoreModel(); |
||
242 | if (!empty($model)) { |
||
243 | return ''; |
||
244 | } |
||
245 | } |
||
246 | |||
247 | // Student. |
||
248 | $status = CourseManager::getUserInCourseStatus($userId, $courseId); |
||
249 | $sessionStatus = 0; |
||
250 | |||
251 | if (!empty($sessionId)) { |
||
252 | $sessionStatus = SessionManager::get_user_status_in_course_session( |
||
253 | $userId, |
||
254 | $courseId, |
||
255 | $sessionId |
||
256 | ); |
||
257 | } |
||
258 | |||
259 | $courseId = CourseManager::get_course_by_category($selectcat); |
||
260 | $messageResource = Category::show_message_resource_delete($courseId); |
||
261 | $grade_model_id = $catobj->get_grade_model_id(); |
||
262 | $header = null; |
||
263 | if (isset($catobj) && !empty($catobj)) { |
||
264 | $categories = Category::load( |
||
265 | null, |
||
266 | null, |
||
267 | 0, |
||
268 | $catobj->get_id(), |
||
269 | null, |
||
270 | $sessionId |
||
271 | ); |
||
272 | } |
||
273 | |||
274 | if (!$is_course_admin && (1 != $status || 0 == $sessionStatus) && 0 != $selectcat) { |
||
275 | $catcourse = Category::load($catobj->get_id()); |
||
276 | /** @var Category $category */ |
||
277 | $category = $catcourse[0]; |
||
278 | $main_weight = $category->get_weight(); |
||
279 | $scoredisplay = ScoreDisplay::instance(); |
||
280 | $allevals = $category->get_evaluations($userId, true); |
||
281 | $alllinks = $category->get_links($userId, true); |
||
282 | $allEvalsLinks = array_merge($allevals, $alllinks); |
||
283 | $item_value_total = 0; |
||
284 | $scoreinfo = null; |
||
285 | |||
286 | for ($count = 0; $count < count($allEvalsLinks); $count++) { |
||
287 | $item = $allEvalsLinks[$count]; |
||
288 | $score = $item->calc_score($userId); |
||
289 | if (!empty($score)) { |
||
290 | $divide = 0 == $score[1] ? 1 : $score[1]; |
||
291 | $item_value = $score[0] / $divide * $item->get_weight(); |
||
292 | $item_value_total += $item_value; |
||
293 | } |
||
294 | } |
||
295 | |||
296 | $item_total = $main_weight; |
||
297 | $total_score = [$item_value_total, $item_total]; |
||
298 | $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT); |
||
299 | |||
300 | if ('0' == !$catobj->get_id() && !isset($_GET['studentoverview']) && !isset($_GET['search'])) { |
||
301 | $additionalButtons = null; |
||
302 | if (!empty($certificateLinkInfo)) { |
||
303 | $additionalButtons .= '<div class="btn-group pull-right">'; |
||
304 | $additionalButtons .= isset($certificateLinkInfo['certificate_link']) ? $certificateLinkInfo['certificate_link'] : ''; |
||
305 | $additionalButtons .= isset($certificateLinkInfo['badge_link']) ? $certificateLinkInfo['badge_link'] : ''; |
||
306 | $additionalButtons .= '</div>'; |
||
307 | } |
||
308 | $scoreinfo .= '<strong>'.sprintf(get_lang('Total: %s'), $scorecourse_display.$additionalButtons).'</strong>'; |
||
309 | } |
||
310 | echo Display::return_message($scoreinfo, 'normal', false); |
||
311 | } |
||
312 | |||
313 | // show navigation tree and buttons? |
||
314 | if ('1' == $showtree || isset($_GET['studentoverview'])) { |
||
315 | $header = '<div class="actions"><table>'; |
||
316 | $header .= '<tr>'; |
||
317 | if ('0' == !$selectcat) { |
||
318 | $header .= '<td><a href="'.api_get_self().'?selectcat='.$catobj->get_parent_id().'">'. |
||
319 | Display::getMdiIcon( |
||
320 | ActionIcon::BACK, |
||
321 | 'ch-tool-icon', |
||
322 | null, |
||
323 | ICON_SIZE_MEDIUM, |
||
324 | get_lang('Back to').' '.get_lang('Main folder') |
||
325 | ). |
||
326 | '</a></td>'; |
||
327 | } |
||
328 | $header .= '<td>'.get_lang('Current course').'</td>'. |
||
329 | '<td><form name="selector"><select name="selectcat" onchange="document.selector.submit()">'; |
||
330 | $cats = Category::load(); |
||
331 | |||
332 | $tree = $cats[0]->get_tree(); |
||
333 | unset($cats); |
||
334 | $line = null; |
||
335 | foreach ($tree as $cat) { |
||
336 | for ($i = 0; $i < $cat[2]; $i++) { |
||
337 | $line .= '—'; |
||
338 | } |
||
339 | $line = isset($line) ? $line : ''; |
||
340 | if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) { |
||
341 | $header .= '<option selected value='.$cat[0].'>'.$line.' '.$cat[1].'</option>'; |
||
342 | } else { |
||
343 | $header .= '<option value='.$cat[0].'>'.$line.' '.$cat[1].'</option>'; |
||
344 | } |
||
345 | $line = ''; |
||
346 | } |
||
347 | $header .= '</select></form></td>'; |
||
348 | if (!empty($simple_search_form) && empty($messageResource)) { |
||
349 | $header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>'; |
||
350 | } else { |
||
351 | $header .= '<td></td>'; |
||
352 | } |
||
353 | if (!($is_course_admin && |
||
354 | empty($messageResource) && |
||
355 | isset($_GET['selectcat']) && 0 != $_GET['selectcat']) && |
||
356 | isset($_GET['studentoverview']) |
||
357 | ) { |
||
358 | $header .= '<td style="vertical-align: top;"> |
||
359 | <a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank"> |
||
360 | '.Display::getMdiIcon(ActionIcon::EXPORT_PDF, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Export to PDF')).' |
||
361 | '.get_lang('Export to PDF').'</a>'; |
||
362 | } |
||
363 | $header .= '</td></tr>'; |
||
364 | $header .= '</table></div>'; |
||
365 | } |
||
366 | |||
367 | // for course admin & platform admin add item buttons are added to the header |
||
368 | $actionsLeft = ''; |
||
369 | $actionsRight = ''; |
||
370 | $my_api_cidreq = api_get_cidreq(); |
||
371 | $isCoach = api_is_coach(api_get_session_id(), api_get_course_int_id()); |
||
372 | $accessToRead = api_is_allowed_to_edit(null, true) || $isCoach; |
||
373 | $accessToEdit = api_is_allowed_to_edit(null, true); |
||
374 | |||
375 | if ($accessToRead) { |
||
376 | $my_category = $catobj->showAllCategoryInfo($catobj->get_id()); |
||
377 | if ('0' != $selectcat && $accessToEdit) { |
||
378 | if ('' == $my_api_cidreq) { |
||
379 | $my_api_cidreq = 'cid='.$my_category['c_id']; |
||
380 | } |
||
381 | if ($show_add_link && empty($messageResource)) { |
||
382 | $actionsLeft .= '<a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'" >'. |
||
383 | Display::getMdiIcon('table-plus', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add classroom activity')).'</a>'; |
||
384 | $cats = Category::load($selectcat); |
||
385 | |||
386 | if (isset($cats[0]) && !empty($cats[0]->getCourseId()) && empty($messageResource)) { |
||
387 | $actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
388 | Display::getMdiIcon('link-plus', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add online activity')).'</a>'; |
||
389 | } else { |
||
390 | $actionsLeft .= '<a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
391 | Display::getMdiIcon('link-plus', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add online activity')).'</a>'; |
||
392 | } |
||
393 | } |
||
394 | } |
||
395 | if ((empty($grade_model_id) || -1 == $grade_model_id) && $accessToEdit) { |
||
396 | $actionsLeft .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'. |
||
397 | Display::getMdiIcon(ActionIcon::CREATE_FOLDER, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add assessment')).'</a></td>'; |
||
398 | } |
||
399 | |||
400 | if ('0' != $selectcat && $accessToRead) { |
||
401 | if (empty($messageResource)) { |
||
402 | $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
403 | Display::getMdiIcon('chart-box', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('List View')).'</a>'; |
||
404 | |||
405 | if (1 == $my_category['generate_certificates']) { |
||
406 | $actionsLeft .= Display::url( |
||
407 | Display::getMdiIcon('format-list-text', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('See list of learner certificates')), |
||
408 | "gradebook_display_certificate.php?$my_api_cidreq&cat_id=".$selectcat |
||
409 | ); |
||
410 | } |
||
411 | |||
412 | $actionsLeft .= Display::url( |
||
413 | Display::getMdiIcon('account', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Students list report')), |
||
414 | "gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat |
||
415 | ); |
||
416 | |||
417 | $allow = api_get_configuration_value('gradebook_custom_student_report'); |
||
418 | if ($allow) { |
||
419 | $actionsLeft .= Display::url( |
||
420 | get_lang('Generate custom report'), |
||
421 | api_get_path(WEB_AJAX_PATH)."gradebook.ajax.php?$my_api_cidreq&a=generate_custom_report", |
||
422 | ['class' => 'btn btn--plain ajax'] |
||
423 | ); |
||
424 | } |
||
425 | |||
426 | // Right icons |
||
427 | if ($accessToEdit) { |
||
428 | $actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id( |
||
429 | ).'&cid='.$catobj->getCourseId().'&sid='.$catobj->get_session_id().'">'. |
||
430 | Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit')).'</a>'; |
||
431 | |||
432 | if ('true' == api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') && |
||
433 | 1 == api_get_course_setting('customcertificate_course_enable') |
||
434 | ) { |
||
435 | $actionsRight .= '<a href="'.api_get_path( |
||
436 | WEB_PLUGIN_PATH |
||
437 | ).'CustomCertificate/src/index.php?'. |
||
438 | $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'. |
||
439 | Display::getMdiIcon('certificate', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Attach certificate')).'</a>'; |
||
440 | } else { |
||
441 | $course = api_get_course_entity($courseId); |
||
442 | $resourceId = $course->resourceNode->getId(); |
||
443 | $certificateLink = api_get_path(WEB_PATH) . 'resources/document/'.$resourceId.'/?'.api_get_cidreq().'&filetype=certificate'; |
||
444 | $actionsRight .= '<a href="'.$certificateLink.'">'. |
||
445 | Display::getMdiIcon('certificate', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Attach certificate')).'</a>'; |
||
446 | } |
||
447 | |||
448 | if (empty($categories)) { |
||
449 | $actionsRight .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id( |
||
450 | ).'&'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
451 | Display::getMdiIcon('percent-box', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Weight in Report')).'</a>'; |
||
452 | } |
||
453 | $score_display_custom = api_get_setting('gradebook_score_display_custom'); |
||
454 | if ('true' == api_get_setting('teachers_can_change_score_settings') && |
||
455 | 'true' == $score_display_custom |
||
456 | ) { |
||
457 | $actionsRight .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
458 | Display::getMdiIcon('podium', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Skills ranking')).'</a>'; |
||
459 | } |
||
460 | } |
||
461 | } |
||
462 | } |
||
463 | } elseif (isset($_GET['search'])) { |
||
464 | echo $header = '<b>'.get_lang('Search results').' :</b>'; |
||
465 | } |
||
466 | |||
467 | $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( |
||
468 | api_get_user_id(), |
||
469 | api_get_course_info() |
||
470 | ); |
||
471 | |||
472 | if ($isDrhOfCourse) { |
||
473 | $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
474 | Display::getMdiIcon('chart-box', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('List View')). |
||
475 | '</a>'; |
||
476 | } |
||
477 | |||
478 | if ($isCoach || api_is_allowed_to_edit(null, true)) { |
||
479 | echo $toolbar = Display::toolbarAction( |
||
480 | 'gradebook-actions', |
||
481 | [$actionsLeft, $actionsRight] |
||
482 | ); |
||
483 | } |
||
484 | |||
485 | if ($accessToEdit || api_is_allowed_to_edit(null, true)) { |
||
486 | $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0; |
||
487 | $weight = '<strong>'.get_lang('Total weight').' : </strong>'.$weight; |
||
488 | $min_certification = intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0; |
||
489 | |||
490 | if (!empty($min_certification)) { |
||
491 | $model = ExerciseLib::getCourseScoreModel(); |
||
492 | if (!empty($model)) { |
||
493 | $defaultCertification = api_number_format($min_certification, 2); |
||
494 | $questionWeighting = $catobj->get_weight(); |
||
495 | foreach ($model['score_list'] as $item) { |
||
496 | $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2); |
||
497 | $model = ExerciseLib::getModelStyle($item, $i); |
||
498 | if ($defaultCertification == $i) { |
||
499 | $min_certification = $model; |
||
500 | break; |
||
501 | } |
||
502 | } |
||
503 | } |
||
504 | } |
||
505 | |||
506 | $min_certification = get_lang('Minimum certification score').' : '.$min_certification; |
||
507 | $edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cid='.$catobj->getCourseId().'&sid='.$catobj->get_session_id().'">'. |
||
508 | Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit')).'</a>'; |
||
509 | |||
510 | $msg = $weight.' - '.$min_certification.$edit_icon; |
||
511 | //@todo show description |
||
512 | $description = (('' == $catobj->get_description() || is_null($catobj->get_description())) ? '' : '<strong>'.get_lang('Assessment description').'</strong>'.': '.$catobj->get_description()); |
||
513 | echo Display::return_message($msg, 'normal', false); |
||
514 | if (!empty($description)) { |
||
515 | echo Display::div($description, []); |
||
516 | } |
||
517 | } |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * @param Category $catobj |
||
522 | * @param $is_course_admin |
||
523 | * @param $is_platform_admin |
||
524 | * @param $simple_search_form |
||
525 | * @param bool $show_add_qualification |
||
526 | * @param bool $show_add_link |
||
527 | */ |
||
528 | public function display_reduce_header_gradebook( |
||
568 | } |
||
569 | |||
570 | /** |
||
571 | * @param int $userId |
||
572 | * @param int $categoryId |
||
573 | * |
||
574 | * @return string |
||
575 | */ |
||
576 | public static function display_header_user($userId, $categoryId) |
||
627 | } |
||
628 | } |
||
629 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.