Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like GradebookUtils 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 GradebookUtils, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class GradebookUtils |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Adds a resource to the unique gradebook of a given course |
||
| 11 | * @param int |
||
| 12 | * @param string Course code |
||
| 13 | * @param int Resource type (use constants defined in linkfactory.class.php) |
||
| 14 | * @param int Resource ID in the corresponding tool |
||
| 15 | * @param string Resource name to show in the gradebook |
||
| 16 | * @param int Resource weight to set in the gradebook |
||
| 17 | * @param int Resource max |
||
| 18 | * @param string Resource description |
||
| 19 | * @param int Visibility (0 hidden, 1 shown) |
||
| 20 | * @param int Session ID (optional or 0 if not defined) |
||
| 21 | * @param int |
||
| 22 | * @param integer $resource_type |
||
| 23 | * @return boolean True on success, false on failure |
||
| 24 | */ |
||
| 25 | public static function add_resource_to_course_gradebook( |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Update a resource weight |
||
| 71 | * @param int Link/Resource ID |
||
| 72 | * @param string |
||
| 73 | * @param float |
||
| 74 | * @return bool false on error, true on success |
||
| 75 | */ |
||
| 76 | public static function updateResourceFromCourseGradebook($link_id, $courseId, $weight) |
||
| 77 | { |
||
| 78 | $courseId = (int) $courseId; |
||
| 79 | if (!empty($link_id)) { |
||
| 80 | $link_id = intval($link_id); |
||
| 81 | $sql = 'UPDATE ' . Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK) . ' |
||
|
|
|||
| 82 | SET weight = ' . "'" . Database::escape_string((float) $weight) . "'" . ' |
||
| 83 | WHERE c_id = "' . $courseId . '" AND id = ' . $link_id; |
||
| 84 | Database::query($sql); |
||
| 85 | } |
||
| 86 | |||
| 87 | return true; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Remove a resource from the unique gradebook of a given course |
||
| 92 | * @param int Link/Resource ID |
||
| 93 | * @return bool false on error, true on success |
||
| 94 | */ |
||
| 95 | View Code Duplication | public static function remove_resource_from_course_gradebook($link_id) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Block students |
||
| 111 | */ |
||
| 112 | public static function block_students() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Builds an img tag for a gradebook item |
||
| 121 | */ |
||
| 122 | public static function build_type_icon_tag($kind, $attributes = array()) |
||
| 123 | { |
||
| 124 | return Display::return_icon( |
||
| 125 | self::get_icon_file_name($kind), |
||
| 126 | ' ', |
||
| 127 | $attributes, |
||
| 128 | ICON_SIZE_SMALL |
||
| 129 | ); |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Returns the icon filename for a gradebook item |
||
| 134 | * @param string $type value returned by a gradebookitem's get_icon_name() |
||
| 135 | * @return string |
||
| 136 | */ |
||
| 137 | public static function get_icon_file_name($type) |
||
| 138 | { |
||
| 139 | switch ($type) { |
||
| 140 | case 'cat': |
||
| 141 | $icon = 'gradebook.png'; |
||
| 142 | break; |
||
| 143 | case 'evalempty': |
||
| 144 | $icon = 'empty_evaluation.png'; |
||
| 145 | break; |
||
| 146 | case 'evalnotempty': |
||
| 147 | $icon = 'no_empty_evaluation.png'; |
||
| 148 | break; |
||
| 149 | case 'exercise': |
||
| 150 | case LINK_EXERCISE: |
||
| 151 | $icon = 'quiz.png'; |
||
| 152 | break; |
||
| 153 | case 'learnpath': |
||
| 154 | case LINK_LEARNPATH: |
||
| 155 | $icon = 'learnpath.png'; |
||
| 156 | break; |
||
| 157 | case 'studentpublication': |
||
| 158 | case LINK_STUDENTPUBLICATION: |
||
| 159 | $icon = 'works.gif'; |
||
| 160 | break; |
||
| 161 | case 'link': |
||
| 162 | $icon = 'link.gif'; |
||
| 163 | break; |
||
| 164 | case 'forum': |
||
| 165 | case LINK_FORUM_THREAD: |
||
| 166 | $icon = 'forum.gif'; |
||
| 167 | break; |
||
| 168 | case 'attendance': |
||
| 169 | case LINK_ATTENDANCE: |
||
| 170 | $icon = 'attendance.gif'; |
||
| 171 | break; |
||
| 172 | case 'survey': |
||
| 173 | case LINK_SURVEY: |
||
| 174 | $icon = 'survey.gif'; |
||
| 175 | break; |
||
| 176 | case 'dropbox': |
||
| 177 | case LINK_DROPBOX: |
||
| 178 | $icon = 'dropbox.gif'; |
||
| 179 | break; |
||
| 180 | default: |
||
| 181 | $icon = 'link.gif'; |
||
| 182 | break; |
||
| 183 | } |
||
| 184 | |||
| 185 | return $icon; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Builds the course or platform admin icons to edit a category |
||
| 190 | * @param Category $cat category |
||
| 191 | * @param Category $selectcat id of selected category |
||
| 192 | * @return string |
||
| 193 | */ |
||
| 194 | public static function build_edit_icons_cat($cat, $selectcat) |
||
| 195 | { |
||
| 196 | $show_message = $cat->show_message_resource_delete($cat->getCourseId()); |
||
| 197 | $grade_model_id = $selectcat->get_grade_model_id(); |
||
| 198 | $selectcat = $selectcat->get_id(); |
||
| 199 | $modify_icons = null; |
||
| 200 | |||
| 201 | if ($show_message === false) { |
||
| 202 | $visibility_icon = ($cat->is_visible() == 0) ? 'invisible' : 'visible'; |
||
| 203 | $visibility_command = ($cat->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||
| 204 | |||
| 205 | $modify_icons .= '<a class="view_children" data-cat-id="'.$cat->get_id().'" href="javascript:void(0);">'. |
||
| 206 | Display::return_icon('view_more_stats.gif', get_lang('Show'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 207 | |||
| 208 | if (!api_is_allowed_to_edit(null, true)) { |
||
| 209 | $modify_icons .= Display::url( |
||
| 210 | Display::return_icon( |
||
| 211 | 'stats.png', |
||
| 212 | get_lang('FlatView'), |
||
| 213 | '', |
||
| 214 | ICON_SIZE_SMALL |
||
| 215 | ), |
||
| 216 | 'personal_stats.php?'.http_build_query([ |
||
| 217 | 'selectcat' => $cat->get_id() |
||
| 218 | ]).'&'.api_get_cidreq(), |
||
| 219 | [ |
||
| 220 | 'class' => 'ajax', |
||
| 221 | 'data-title' => get_lang('FlatView') |
||
| 222 | ] |
||
| 223 | ); |
||
| 224 | } |
||
| 225 | |||
| 226 | $courseParams = api_get_cidreq_params($cat->get_course_code(), $cat->get_session_id()); |
||
| 227 | |||
| 228 | if (api_is_allowed_to_edit(null, true)) { |
||
| 229 | // Locking button |
||
| 230 | if (api_get_setting('gradebook_locking_enabled') == 'true') { |
||
| 231 | if ($cat->is_locked()) { |
||
| 232 | View Code Duplication | if (api_is_platform_admin()) { |
|
| 233 | $modify_icons .= ' <a onclick="javascript:if (!confirm(\''.addslashes(get_lang('ConfirmToUnlockElement')).'\')) return false;" href="'.api_get_self().'?'.api_get_cidreq().'&category_id='.$cat->get_id().'&action=unlock">'. |
||
| 234 | Display::return_icon('lock.png', get_lang('UnLockEvaluation'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 235 | } else { |
||
| 236 | $modify_icons .= ' <a href="#">'.Display::return_icon('lock_na.png', get_lang('GradebookLockedAlert'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 237 | } |
||
| 238 | $modify_icons .= ' <a href="gradebook_flatview.php?export_pdf=category&selectcat='.$cat->get_id().'" >'.Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 239 | View Code Duplication | } else { |
|
| 240 | $modify_icons .= ' <a onclick="javascript:if (!confirm(\''.addslashes(get_lang('ConfirmToLockElement')).'\')) return false;" href="'.api_get_self().'?'.api_get_cidreq().'&category_id='.$cat->get_id().'&action=lock">'. |
||
| 241 | Display::return_icon('unlock.png', get_lang('LockEvaluation'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 242 | $modify_icons .= ' <a href="#" >'.Display::return_icon('pdf_na.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 243 | } |
||
| 244 | } |
||
| 245 | |||
| 246 | if (empty($grade_model_id) || $grade_model_id == -1) { |
||
| 247 | if ($cat->is_locked() && !api_is_platform_admin()) { |
||
| 248 | $modify_icons .= Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL); |
||
| 249 | } else { |
||
| 250 | $modify_icons .= '<a href="gradebook_edit_cat.php?editcat='.$cat->get_id().'&'.$courseParams.'">'. |
||
| 251 | Display::return_icon( |
||
| 252 | 'edit.png', |
||
| 253 | get_lang('Modify'), |
||
| 254 | '', |
||
| 255 | ICON_SIZE_SMALL |
||
| 256 | ).'</a>'; |
||
| 257 | } |
||
| 258 | } |
||
| 259 | |||
| 260 | $modify_icons .= '<a href="gradebook_edit_all.php?selectcat='.$cat->get_id().'&'.$courseParams.'">'. |
||
| 261 | Display::return_icon( |
||
| 262 | 'percentage.png', |
||
| 263 | get_lang('EditAllWeights'), |
||
| 264 | '', |
||
| 265 | ICON_SIZE_SMALL |
||
| 266 | ).'</a>'; |
||
| 267 | |||
| 268 | $modify_icons .= '<a href="gradebook_flatview.php?selectcat='.$cat->get_id().'&'.$courseParams.'">'. |
||
| 269 | Display::return_icon( |
||
| 270 | 'stats.png', |
||
| 271 | get_lang('FlatView'), |
||
| 272 | '', |
||
| 273 | ICON_SIZE_SMALL |
||
| 274 | ).'</a>'; |
||
| 275 | $modify_icons .= ' <a href="'.api_get_self().'?visiblecat='.$cat->get_id().'&'.$visibility_command.'=&selectcat='.$selectcat.'&'.$courseParams.'">'. |
||
| 276 | Display::return_icon( |
||
| 277 | $visibility_icon.'.png', |
||
| 278 | get_lang('Visible'), |
||
| 279 | '', |
||
| 280 | ICON_SIZE_SMALL |
||
| 281 | ).'</a>'; |
||
| 282 | |||
| 283 | if ($cat->is_locked() && !api_is_platform_admin()) { |
||
| 284 | $modify_icons .= Display::return_icon('delete_na.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL); |
||
| 285 | } else { |
||
| 286 | $modify_icons .= ' <a href="'.api_get_self().'?deletecat='.$cat->get_id().'&selectcat='.$selectcat.'&'.$courseParams.'" onclick="return confirmation();">'. |
||
| 287 | Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 288 | } |
||
| 289 | } |
||
| 290 | |||
| 291 | return $modify_icons; |
||
| 292 | } |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Builds the course or platform admin icons to edit an evaluation |
||
| 297 | * @param Evaluation $eval evaluation object |
||
| 298 | * @param int $selectcat id of selected category |
||
| 299 | * @return string |
||
| 300 | */ |
||
| 301 | View Code Duplication | public static function build_edit_icons_eval($eval, $selectcat) |
|
| 302 | { |
||
| 303 | $is_locked = $eval->is_locked(); |
||
| 304 | $eval->get_course_code(); |
||
| 305 | $cat = new Category(); |
||
| 306 | $message_eval = $cat->show_message_resource_delete($eval->getCourseId()); |
||
| 307 | $courseParams = api_get_cidreq_params($eval->get_course_code(), $eval->getSessionId()); |
||
| 308 | |||
| 309 | if ($message_eval === false && api_is_allowed_to_edit(null, true)) { |
||
| 310 | $visibility_icon = ($eval->is_visible() == 0) ? 'invisible' : 'visible'; |
||
| 311 | $visibility_command = ($eval->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||
| 312 | if ($is_locked && !api_is_platform_admin()) { |
||
| 313 | $modify_icons = Display::return_icon( |
||
| 314 | 'edit_na.png', |
||
| 315 | get_lang('Modify'), |
||
| 316 | '', |
||
| 317 | ICON_SIZE_SMALL |
||
| 318 | ); |
||
| 319 | } else { |
||
| 320 | $modify_icons = '<a href="gradebook_edit_eval.php?editeval='.$eval->get_id().'&'.$courseParams.'">'. |
||
| 321 | Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 322 | } |
||
| 323 | |||
| 324 | $modify_icons .= ' <a href="'.api_get_self().'?visibleeval='.$eval->get_id().'&'.$visibility_command.'=&selectcat='.$selectcat.'&'.$courseParams.' ">'. |
||
| 325 | Display::return_icon($visibility_icon.'.png', get_lang('Visible'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 326 | if (api_is_allowed_to_edit(null, true)) { |
||
| 327 | $modify_icons .= ' <a href="gradebook_showlog_eval.php?visiblelog='.$eval->get_id().'&selectcat='.$selectcat.' &'.$courseParams.'">'. |
||
| 328 | Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 329 | } |
||
| 330 | |||
| 331 | if ($is_locked && !api_is_platform_admin()) { |
||
| 332 | $modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL); |
||
| 333 | } else { |
||
| 334 | $modify_icons .= ' <a href="'.api_get_self().'?deleteeval='.$eval->get_id().'&selectcat='.$selectcat.' &'.$courseParams.'" onclick="return confirmation();">'. |
||
| 335 | Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 336 | } |
||
| 337 | return $modify_icons; |
||
| 338 | } |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Builds the course or platform admin icons to edit a link |
||
| 343 | * @param AbstractLink $link |
||
| 344 | * @param int $selectcat id of selected category |
||
| 345 | * |
||
| 346 | * @return string |
||
| 347 | */ |
||
| 348 | View Code Duplication | public static function build_edit_icons_link($link, $selectcat) |
|
| 349 | { |
||
| 350 | $cat = new Category(); |
||
| 351 | $message_link = $cat->show_message_resource_delete($link->getCourseId()); |
||
| 352 | $is_locked = $link->is_locked(); |
||
| 353 | |||
| 354 | $modify_icons = null; |
||
| 355 | |||
| 356 | if (!api_is_allowed_to_edit(null, true)) { |
||
| 357 | return null; |
||
| 358 | } |
||
| 359 | |||
| 360 | $courseParams = api_get_cidreq_params($link->get_course_code(), $link->get_session_id()); |
||
| 361 | |||
| 362 | if ($message_link === false) { |
||
| 363 | $visibility_icon = ($link->is_visible() == 0) ? 'invisible' : 'visible'; |
||
| 364 | $visibility_command = ($link->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||
| 365 | |||
| 366 | if ($is_locked && !api_is_platform_admin()) { |
||
| 367 | $modify_icons = Display::return_icon( |
||
| 368 | 'edit_na.png', |
||
| 369 | get_lang('Modify'), |
||
| 370 | '', |
||
| 371 | ICON_SIZE_SMALL |
||
| 372 | ); |
||
| 373 | } else { |
||
| 374 | $modify_icons = '<a href="gradebook_edit_link.php?editlink='.$link->get_id().'&'.$courseParams.'">'. |
||
| 375 | Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 376 | } |
||
| 377 | $modify_icons .= ' <a href="'.api_get_self().'?visiblelink='.$link->get_id().'&'.$visibility_command.'=&selectcat='.$selectcat.'&'.$courseParams.' ">'. |
||
| 378 | Display::return_icon($visibility_icon.'.png', get_lang('Visible'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 379 | $modify_icons .= ' <a href="gradebook_showlog_link.php?visiblelink='.$link->get_id().'&selectcat='.$selectcat.'&'.$courseParams.'">'. |
||
| 380 | Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 381 | |||
| 382 | //If a work is added in a gradebook you can only delete the link in the work tool |
||
| 383 | |||
| 384 | if ($is_locked && !api_is_platform_admin()) { |
||
| 385 | $modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL); |
||
| 386 | } else { |
||
| 387 | $modify_icons .= ' <a href="'.api_get_self().'?deletelink='.$link->get_id().'&selectcat='.$selectcat.' &'.$courseParams.'" onclick="return confirmation();">'. |
||
| 388 | Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 389 | } |
||
| 390 | |||
| 391 | return $modify_icons; |
||
| 392 | } |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Checks if a resource is in the unique gradebook of a given course |
||
| 397 | * @param int $courseId |
||
| 398 | * @param int $resource_type Resource type (use constants defined in linkfactory.class.php) |
||
| 399 | * @param int $resource_id Resource ID in the corresponding tool |
||
| 400 | * @param int $session_id Session ID (optional - 0 if not defined) |
||
| 401 | * |
||
| 402 | * @return array false on error or array of resource |
||
| 403 | */ |
||
| 404 | public static function isResourceInCourseGradebook($courseId, $resource_type, $resource_id, $session_id = 0) |
||
| 405 | { |
||
| 406 | $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
||
| 407 | $courseId = (int)$courseId; |
||
| 408 | $sql = "SELECT * FROM $table l |
||
| 409 | WHERE |
||
| 410 | c_id = '$courseId' AND |
||
| 411 | type = ".(int)$resource_type . " AND |
||
| 412 | ref_id = " . (int)$resource_id; |
||
| 413 | $res = Database::query($sql); |
||
| 414 | |||
| 415 | if (Database::num_rows($res) < 1) { |
||
| 416 | return false; |
||
| 417 | } |
||
| 418 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 419 | |||
| 420 | return $row; |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Remove a resource from the unique gradebook of a given course |
||
| 425 | * @param int Link/Resource ID |
||
| 426 | * @return bool false on error, true on success |
||
| 427 | */ |
||
| 428 | View Code Duplication | public static function get_resource_from_course_gradebook($link_id) |
|
| 429 | { |
||
| 430 | if (empty($link_id)) { |
||
| 431 | return false; |
||
| 432 | } |
||
| 433 | // TODO find the corresponding category (the first one for this course, ordered by ID) |
||
| 434 | $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
||
| 435 | $sql = "SELECT * FROM $l WHERE id = " . (int) $link_id; |
||
| 436 | $res = Database::query($sql); |
||
| 437 | $row = array(); |
||
| 438 | if (Database::num_rows($res) > 0) { |
||
| 439 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 440 | } |
||
| 441 | return $row; |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Return the course id |
||
| 446 | * @param int |
||
| 447 | * @return String |
||
| 448 | */ |
||
| 449 | View Code Duplication | public static function get_course_id_by_link_id($id_link) |
|
| 450 | { |
||
| 451 | $course_table = Database::get_main_table(TABLE_MAIN_COURSE); |
||
| 452 | $tbl_grade_links = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
||
| 453 | $sql = 'SELECT c.id FROM ' . $course_table . ' c |
||
| 454 | INNER JOIN ' . $tbl_grade_links . ' l |
||
| 455 | ON c.id = l.c_id |
||
| 456 | WHERE l.id=' . intval($id_link) . ' OR l.category_id=' . intval($id_link); |
||
| 457 | $res = Database::query($sql); |
||
| 458 | $array = Database::fetch_array($res, 'ASSOC'); |
||
| 459 | return $array['id']; |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @param $type |
||
| 464 | * @return string |
||
| 465 | */ |
||
| 466 | public static function get_table_type_course($type) |
||
| 467 | { |
||
| 468 | $table_evaluated = self::getEvaluateList(); |
||
| 469 | return Database::get_course_table($table_evaluated[$type][0]); |
||
| 470 | } |
||
| 471 | |||
| 472 | public static function getEvaluateList() |
||
| 473 | { |
||
| 474 | $table_evaluated = []; |
||
| 475 | $table_evaluated[LINK_EXERCISE] = array( |
||
| 476 | TABLE_QUIZ_TEST, |
||
| 477 | 'title', |
||
| 478 | 'id', |
||
| 479 | get_lang('Exercise'), |
||
| 480 | ); |
||
| 481 | $table_evaluated[LINK_DROPBOX] = array( |
||
| 482 | TABLE_DROPBOX_FILE, |
||
| 483 | 'name', |
||
| 484 | 'id', |
||
| 485 | get_lang('Dropbox'), |
||
| 486 | ); |
||
| 487 | $table_evaluated[LINK_STUDENTPUBLICATION] = array( |
||
| 488 | TABLE_STUDENT_PUBLICATION, |
||
| 489 | 'url', |
||
| 490 | 'id', |
||
| 491 | get_lang('Student_publication'), |
||
| 492 | ); |
||
| 493 | $table_evaluated[LINK_LEARNPATH] = array( |
||
| 494 | TABLE_LP_MAIN, |
||
| 495 | 'name', |
||
| 496 | 'id', |
||
| 497 | get_lang('Learnpath'), |
||
| 498 | ); |
||
| 499 | $table_evaluated[LINK_FORUM_THREAD] = array( |
||
| 500 | TABLE_FORUM_THREAD, |
||
| 501 | 'thread_title_qualify', |
||
| 502 | 'thread_id', |
||
| 503 | get_lang('Forum'), |
||
| 504 | ); |
||
| 505 | $table_evaluated[LINK_ATTENDANCE] = array( |
||
| 506 | TABLE_ATTENDANCE, |
||
| 507 | 'attendance_title_qualify', |
||
| 508 | 'id', |
||
| 509 | get_lang('Attendance'), |
||
| 510 | ); |
||
| 511 | $table_evaluated[LINK_SURVEY] = array( |
||
| 512 | TABLE_SURVEY, |
||
| 513 | 'code', |
||
| 514 | 'survey_id', |
||
| 515 | get_lang('Survey'), |
||
| 516 | ); |
||
| 517 | |||
| 518 | return $table_evaluated; |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @param Category $cat |
||
| 523 | * @param $users |
||
| 524 | * @param $alleval |
||
| 525 | * @param $alllinks |
||
| 526 | * @param $params |
||
| 527 | * @param null $mainCourseCategory |
||
| 528 | * @return array |
||
| 529 | */ |
||
| 530 | public static function get_printable_data($cat, $users, $alleval, $alllinks, $params, $mainCourseCategory = null) |
||
| 531 | { |
||
| 532 | $datagen = new FlatViewDataGenerator( |
||
| 533 | $users, |
||
| 534 | $alleval, |
||
| 535 | $alllinks, |
||
| 536 | $params, |
||
| 537 | $mainCourseCategory |
||
| 538 | ); |
||
| 539 | |||
| 540 | $offset = isset($_GET['offset']) ? $_GET['offset'] : '0'; |
||
| 541 | $offset = intval($offset); |
||
| 542 | |||
| 543 | // step 2: generate rows: students |
||
| 544 | $datagen->category = $cat; |
||
| 545 | |||
| 546 | $count = (($offset + 10) > $datagen->get_total_items_count()) ? ($datagen->get_total_items_count() - $offset) : GRADEBOOK_ITEM_LIMIT; |
||
| 547 | $header_names = $datagen->get_header_names($offset, $count, true); |
||
| 548 | $data_array = $datagen->get_data( |
||
| 549 | FlatViewDataGenerator::FVDG_SORT_LASTNAME, |
||
| 550 | 0, |
||
| 551 | null, |
||
| 552 | $offset, |
||
| 553 | $count, |
||
| 554 | true, |
||
| 555 | true |
||
| 556 | ); |
||
| 557 | |||
| 558 | $result = array(); |
||
| 559 | foreach ($data_array as $data) { |
||
| 560 | $result[] = array_slice($data, 1); |
||
| 561 | } |
||
| 562 | $return = array($header_names, $result); |
||
| 563 | |||
| 564 | return $return; |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * XML-parser: handle character data |
||
| 569 | */ |
||
| 570 | public static function character_data($parser, $data) |
||
| 571 | { |
||
| 572 | global $current_value; |
||
| 573 | $current_value = $data; |
||
| 574 | } |
||
| 575 | |||
| 576 | /** |
||
| 577 | * XML-parser: handle end of element |
||
| 578 | */ |
||
| 579 | public static function element_end($parser, $data) |
||
| 580 | { |
||
| 581 | global $user; |
||
| 582 | global $users; |
||
| 583 | global $current_value; |
||
| 584 | switch ($data) { |
||
| 585 | case 'Result': |
||
| 586 | $users[] = $user; |
||
| 587 | break; |
||
| 588 | default: |
||
| 589 | $user[$data] = $current_value; |
||
| 590 | break; |
||
| 591 | } |
||
| 592 | } |
||
| 593 | |||
| 594 | /** |
||
| 595 | * XML-parser: handle start of element |
||
| 596 | */ |
||
| 597 | public static function element_start($parser, $data) |
||
| 598 | { |
||
| 599 | global $user; |
||
| 600 | global $current_tag; |
||
| 601 | switch ($data) { |
||
| 602 | case 'Result': |
||
| 603 | $user = array(); |
||
| 604 | break; |
||
| 605 | default: |
||
| 606 | $current_tag = $data; |
||
| 607 | } |
||
| 608 | } |
||
| 609 | |||
| 610 | public static function overwritescore($resid, $importscore, $eval_max) |
||
| 611 | { |
||
| 612 | $result = Result::load($resid); |
||
| 613 | if ($importscore > $eval_max) { |
||
| 614 | header('Location: gradebook_view_result.php?selecteval='.Security::remove_XSS($_GET['selecteval']).'&overwritemax='); |
||
| 615 | exit; |
||
| 616 | } |
||
| 617 | $result[0]->set_score($importscore); |
||
| 618 | $result[0]->save(); |
||
| 619 | unset($result); |
||
| 620 | } |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Read the XML-file |
||
| 624 | * @param string $file Path to the XML-file |
||
| 625 | * @return array All user information read from the file |
||
| 626 | */ |
||
| 627 | View Code Duplication | public static function parse_xml_data($file) |
|
| 628 | { |
||
| 629 | global $current_tag; |
||
| 630 | global $current_value; |
||
| 631 | global $user; |
||
| 632 | global $users; |
||
| 633 | $users = array(); |
||
| 634 | $parser = xml_parser_create(); |
||
| 635 | xml_set_element_handler($parser, 'element_start', 'element_end'); |
||
| 636 | xml_set_character_data_handler($parser, "character_data"); |
||
| 637 | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); |
||
| 638 | xml_parse($parser, file_get_contents($file)); |
||
| 639 | xml_parser_free($parser); |
||
| 640 | return $users; |
||
| 641 | } |
||
| 642 | |||
| 643 | /** |
||
| 644 | * register user info about certificate |
||
| 645 | * @param int $cat_id The category id |
||
| 646 | * @param int $user_id The user id |
||
| 647 | * @param float $score_certificate The score obtained for certified |
||
| 648 | * @param string $date_certificate The date when you obtained the certificate |
||
| 649 | * |
||
| 650 | * @return void |
||
| 651 | */ |
||
| 652 | public static function registerUserInfoAboutCertificate( |
||
| 653 | $cat_id, |
||
| 654 | $user_id, |
||
| 655 | $score_certificate, |
||
| 656 | $date_certificate |
||
| 657 | ) { |
||
| 658 | $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
||
| 659 | $sql = 'SELECT COUNT(id) as count |
||
| 660 | FROM ' . $table.' gc |
||
| 661 | WHERE gc.cat_id="' . intval($cat_id).'" AND user_id="'.intval($user_id).'" '; |
||
| 662 | $rs_exist = Database::query($sql); |
||
| 663 | $row = Database::fetch_array($rs_exist); |
||
| 664 | if ($row['count'] == 0) { |
||
| 665 | $params = [ |
||
| 666 | 'cat_id' => $cat_id, |
||
| 667 | 'user_id' => $user_id, |
||
| 668 | 'score_certificate' => $score_certificate, |
||
| 669 | 'created_at' => $date_certificate |
||
| 670 | ]; |
||
| 671 | Database::insert($table, $params); |
||
| 672 | } |
||
| 673 | } |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Get date of user certificate |
||
| 677 | * @param int $cat_id The category id |
||
| 678 | * @param int $user_id The user id |
||
| 679 | * @return Datetime The date when you obtained the certificate |
||
| 680 | */ |
||
| 681 | public static function get_certificate_by_user_id($cat_id, $user_id) |
||
| 682 | { |
||
| 683 | $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
||
| 684 | $sql = 'SELECT * FROM '.$table_certificate.' |
||
| 685 | WHERE cat_id="' . intval($cat_id).'" AND user_id="'.intval($user_id).'"'; |
||
| 686 | |||
| 687 | $result = Database::query($sql); |
||
| 688 | $row = Database::fetch_array($result, 'ASSOC'); |
||
| 689 | |||
| 690 | return $row; |
||
| 691 | } |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Get list of users certificates |
||
| 695 | * @param int $cat_id The category id |
||
| 696 | * @param array $userList Only users in this list |
||
| 697 | * @return array |
||
| 698 | */ |
||
| 699 | public static function get_list_users_certificates($cat_id = null, $userList = array()) |
||
| 700 | { |
||
| 701 | $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
||
| 702 | $table_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 703 | $sql = 'SELECT DISTINCT u.user_id, u.lastname, u.firstname, u.username |
||
| 704 | FROM ' . $table_user.' u |
||
| 705 | INNER JOIN ' . $table_certificate.' gc |
||
| 706 | ON u.user_id=gc.user_id '; |
||
| 707 | View Code Duplication | if (!is_null($cat_id) && $cat_id > 0) { |
|
| 708 | $sql .= ' WHERE cat_id='.intval($cat_id); |
||
| 709 | } |
||
| 710 | if (!empty($userList)) { |
||
| 711 | $userList = array_map('intval', $userList); |
||
| 712 | $userListCondition = implode("','", $userList); |
||
| 713 | $sql .= " AND u.user_id IN ('$userListCondition')"; |
||
| 714 | } |
||
| 715 | $sql .= ' ORDER BY u.firstname'; |
||
| 716 | $rs = Database::query($sql); |
||
| 717 | |||
| 718 | $list_users = array(); |
||
| 719 | while ($row = Database::fetch_array($rs)) { |
||
| 720 | $list_users[] = $row; |
||
| 721 | } |
||
| 722 | |||
| 723 | return $list_users; |
||
| 724 | } |
||
| 725 | |||
| 726 | /** |
||
| 727 | * Gets the certificate list by user id |
||
| 728 | * @param int $user_id The user id |
||
| 729 | * @param int $cat_id The category id |
||
| 730 | * @return array |
||
| 731 | */ |
||
| 732 | public static function get_list_gradebook_certificates_by_user_id($user_id, $cat_id = null) |
||
| 733 | { |
||
| 734 | $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
||
| 735 | $sql = 'SELECT |
||
| 736 | gc.score_certificate, |
||
| 737 | gc.created_at, |
||
| 738 | gc.path_certificate, |
||
| 739 | gc.cat_id, |
||
| 740 | gc.user_id, |
||
| 741 | gc.id |
||
| 742 | FROM '.$table_certificate.' gc |
||
| 743 | WHERE gc.user_id="' . intval($user_id).'" '; |
||
| 744 | View Code Duplication | if (!is_null($cat_id) && $cat_id > 0) { |
|
| 745 | $sql .= ' AND cat_id='.intval($cat_id); |
||
| 746 | } |
||
| 747 | |||
| 748 | $rs = Database::query($sql); |
||
| 749 | $list_certificate = array(); |
||
| 750 | while ($row = Database::fetch_array($rs)) { |
||
| 751 | $list_certificate[] = $row; |
||
| 752 | } |
||
| 753 | return $list_certificate; |
||
| 754 | } |
||
| 755 | |||
| 756 | /** |
||
| 757 | * @param int $user_id |
||
| 758 | * @param string $course_code |
||
| 759 | * @param int $sessionId |
||
| 760 | * @param bool $is_preview |
||
| 761 | * @param bool $hide_print_button |
||
| 762 | * |
||
| 763 | * @return array |
||
| 764 | */ |
||
| 765 | public static function get_user_certificate_content( |
||
| 766 | $user_id, |
||
| 767 | $course_code, |
||
| 768 | $sessionId, |
||
| 769 | $is_preview = false, |
||
| 770 | $hide_print_button = false |
||
| 771 | ) { |
||
| 772 | // Generate document HTML |
||
| 773 | $content_html = DocumentManager::replace_user_info_into_html( |
||
| 774 | $user_id, |
||
| 775 | $course_code, |
||
| 776 | $sessionId, |
||
| 777 | $is_preview |
||
| 778 | ); |
||
| 779 | |||
| 780 | $new_content_html = isset($content_html['content']) ? $content_html['content'] : null; |
||
| 781 | $variables = isset($content_html['variables']) ? $content_html['variables'] : null; |
||
| 782 | $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path($course_code).'/document/images/gallery'; |
||
| 783 | $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html); |
||
| 784 | |||
| 785 | $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document'; |
||
| 786 | $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html); |
||
| 787 | $new_content_html = str_replace(SYS_CODE_PATH.'img/', api_get_path(WEB_IMG_PATH), $new_content_html); |
||
| 788 | |||
| 789 | //add print header |
||
| 790 | if (!$hide_print_button) { |
||
| 791 | $print = '<style>#print_div { |
||
| 792 | padding:4px;border: 0 none;position: absolute;top: 0px;right: 0px; |
||
| 793 | } |
||
| 794 | @media print { |
||
| 795 | #print_div { |
||
| 796 | display: none !important; |
||
| 797 | } |
||
| 798 | } |
||
| 799 | </style>'; |
||
| 800 | |||
| 801 | $print .= Display::div( |
||
| 802 | Display::url( |
||
| 803 | Display::return_icon('printmgr.gif', get_lang('Print')), |
||
| 804 | 'javascript:void()', |
||
| 805 | ['onclick' => 'window.print();'] |
||
| 806 | ), |
||
| 807 | ['id' => 'print_div'] |
||
| 808 | ); |
||
| 809 | $print .= '</html>'; |
||
| 810 | $new_content_html = str_replace('</html>', $print, $new_content_html); |
||
| 811 | } |
||
| 812 | |||
| 813 | return [ |
||
| 814 | 'content' => $new_content_html, |
||
| 815 | 'variables' => $variables |
||
| 816 | ]; |
||
| 817 | } |
||
| 818 | |||
| 819 | /** |
||
| 820 | * @param int $courseId |
||
| 821 | * @param int $gradebook_model_id |
||
| 822 | * @return mixed |
||
| 823 | */ |
||
| 824 | public static function createDefaultCourseGradebook($courseId = 0, $gradebook_model_id = 0) |
||
| 825 | { |
||
| 826 | if (api_is_allowed_to_edit(true, true)) { |
||
| 827 | if (!isset($courseId) || empty($courseId)) { |
||
| 828 | $courseId = api_get_course_int_id(); |
||
| 829 | } |
||
| 830 | |||
| 831 | $courseInfo = api_get_course_info_by_id($courseId); |
||
| 832 | $session_id = api_get_session_id(); |
||
| 833 | |||
| 834 | $t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); |
||
| 835 | $sql = "SELECT * FROM $t WHERE c_id = '" . Database::escape_string($courseId) . "' "; |
||
| 836 | if (!empty($session_id)) { |
||
| 837 | $sql .= " AND session_id = " . (int) $session_id; |
||
| 838 | } else { |
||
| 839 | $sql .= " AND (session_id IS NULL OR session_id = 0) "; |
||
| 840 | } |
||
| 841 | $sql .= " ORDER BY id"; |
||
| 842 | $res = Database::query($sql); |
||
| 843 | $course_code = $courseInfo['code']; |
||
| 844 | if (Database::num_rows($res) < 1) { |
||
| 845 | //there is no unique category for this course+session combination, |
||
| 846 | $cat = new Category(); |
||
| 847 | View Code Duplication | if (!empty($session_id)) { |
|
| 848 | $my_session_id = api_get_session_id(); |
||
| 849 | $s_name = api_get_session_name($my_session_id); |
||
| 850 | $cat->set_name($course_code . ' - ' . get_lang('Session') . ' ' . $s_name); |
||
| 851 | $cat->set_session_id($session_id); |
||
| 852 | } else { |
||
| 853 | $cat->set_name($course_code); |
||
| 854 | } |
||
| 855 | $cat->set_course_code($course_code); |
||
| 856 | $cat->set_description(null); |
||
| 857 | $cat->set_user_id(api_get_user_id()); |
||
| 858 | $cat->set_parent_id(0); |
||
| 859 | $default_weight_setting = api_get_setting('gradebook_default_weight'); |
||
| 860 | $default_weight = isset($default_weight_setting) && !empty($default_weight_setting) ? $default_weight_setting : 100; |
||
| 861 | $cat->set_weight($default_weight); |
||
| 862 | $cat->set_grade_model_id($gradebook_model_id); |
||
| 863 | $cat->set_certificate_min_score(75); |
||
| 864 | $cat->set_visible(0); |
||
| 865 | $cat->add(); |
||
| 866 | $category_id = $cat->get_id(); |
||
| 867 | unset($cat); |
||
| 868 | } else { |
||
| 869 | $row = Database::fetch_array($res); |
||
| 870 | $category_id = $row['id']; |
||
| 871 | } |
||
| 872 | |||
| 873 | return $category_id; |
||
| 874 | } |
||
| 875 | |||
| 876 | return false; |
||
| 877 | } |
||
| 878 | |||
| 879 | /** |
||
| 880 | * @param FormValidator $form |
||
| 881 | */ |
||
| 882 | public static function load_gradebook_select_in_tool($form) |
||
| 883 | { |
||
| 884 | $course_code = api_get_course_id(); |
||
| 885 | $session_id = api_get_session_id(); |
||
| 886 | |||
| 887 | self::createDefaultCourseGradebook(); |
||
| 888 | |||
| 889 | // Cat list |
||
| 890 | $all_categories = Category::load(null, null, $course_code, null, null, $session_id, false); |
||
| 891 | $select_gradebook = $form->addElement('select', 'category_id', get_lang('SelectGradebook')); |
||
| 892 | |||
| 893 | if (!empty($all_categories)) { |
||
| 894 | foreach ($all_categories as $my_cat) { |
||
| 895 | View Code Duplication | if ($my_cat->get_course_code() == api_get_course_id()) { |
|
| 896 | $grade_model_id = $my_cat->get_grade_model_id(); |
||
| 897 | if (empty($grade_model_id)) { |
||
| 898 | if ($my_cat->get_parent_id() == 0) { |
||
| 899 | //$default_weight = $my_cat->get_weight(); |
||
| 900 | $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); |
||
| 901 | $cats_added[] = $my_cat->get_id(); |
||
| 902 | } else { |
||
| 903 | $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); |
||
| 904 | $cats_added[] = $my_cat->get_id(); |
||
| 905 | } |
||
| 906 | } else { |
||
| 907 | $select_gradebook->addoption(get_lang('Select'), 0); |
||
| 908 | } |
||
| 909 | } |
||
| 910 | } |
||
| 911 | } |
||
| 912 | } |
||
| 913 | |||
| 914 | /** |
||
| 915 | * @param FlatViewTable $flatviewtable |
||
| 916 | * @param Category $cat |
||
| 917 | * @param $users |
||
| 918 | * @param $alleval |
||
| 919 | * @param $alllinks |
||
| 920 | * @param array $params |
||
| 921 | * @param null $mainCourseCategory |
||
| 922 | */ |
||
| 923 | public static function export_pdf_flatview( |
||
| 924 | $flatviewtable, |
||
| 925 | $cat, |
||
| 926 | $users, |
||
| 927 | $alleval, |
||
| 928 | $alllinks, |
||
| 929 | $params = array(), |
||
| 930 | $mainCourseCategory = null |
||
| 931 | ) { |
||
| 932 | // Getting data |
||
| 933 | $printable_data = self::get_printable_data( |
||
| 934 | $cat[0], |
||
| 935 | $users, |
||
| 936 | $alleval, |
||
| 937 | $alllinks, |
||
| 938 | $params, |
||
| 939 | $mainCourseCategory |
||
| 940 | ); |
||
| 941 | |||
| 942 | // HTML report creation first |
||
| 943 | $course_code = trim($cat[0]->get_course_code()); |
||
| 944 | |||
| 945 | $displayscore = ScoreDisplay::instance(); |
||
| 946 | $customDisplays = $displayscore->get_custom_score_display_settings(); |
||
| 947 | |||
| 948 | $total = array(); |
||
| 949 | if (is_array($customDisplays) && count(($customDisplays))) { |
||
| 950 | foreach ($customDisplays as $custom) { |
||
| 951 | $total[$custom['display']] = 0; |
||
| 952 | } |
||
| 953 | $user_results = $flatviewtable->datagen->get_data_to_graph2(false); |
||
| 954 | foreach ($user_results as $user_result) { |
||
| 955 | $item = $user_result[count($user_result) - 1]; |
||
| 956 | $customTag = isset($item[1]) ? strip_tags($item[1]) : ''; |
||
| 957 | $total[$customTag]++; |
||
| 958 | } |
||
| 959 | } |
||
| 960 | |||
| 961 | $parent_id = $cat[0]->get_parent_id(); |
||
| 962 | if (isset($cat[0]) && isset($parent_id)) { |
||
| 963 | if ($parent_id == 0) { |
||
| 964 | $grade_model_id = $cat[0]->get_grade_model_id(); |
||
| 965 | } else { |
||
| 966 | $parent_cat = Category::load($parent_id); |
||
| 967 | $grade_model_id = $parent_cat[0]->get_grade_model_id(); |
||
| 968 | } |
||
| 969 | } |
||
| 970 | |||
| 971 | $use_grade_model = true; |
||
| 972 | if (empty($grade_model_id) || $grade_model_id == -1) { |
||
| 973 | $use_grade_model = false; |
||
| 974 | } |
||
| 975 | |||
| 976 | if ($use_grade_model) { |
||
| 977 | if ($parent_id == 0) { |
||
| 978 | $title = api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed'); |
||
| 979 | } else { |
||
| 980 | $title = api_strtoupper(get_lang('Average')).'<br />'.$cat[0]->get_description().' - ('.$cat[0]->get_name().')'; |
||
| 981 | } |
||
| 982 | } else { |
||
| 983 | if ($parent_id == 0) { |
||
| 984 | $title = api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed'); |
||
| 985 | } else { |
||
| 986 | $title = api_strtoupper(get_lang('Average')); |
||
| 987 | } |
||
| 988 | } |
||
| 989 | |||
| 990 | $columns = count($printable_data[0]); |
||
| 991 | $has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0; |
||
| 992 | |||
| 993 | $table = new HTML_Table(array('class' => 'data_table')); |
||
| 994 | $row = 0; |
||
| 995 | $column = 0; |
||
| 996 | $table->setHeaderContents($row, $column, get_lang('NumberAbbreviation')); |
||
| 997 | $column++; |
||
| 998 | foreach ($printable_data[0] as $printable_data_cell) { |
||
| 999 | if (!is_array($printable_data_cell)) { |
||
| 1000 | $printable_data_cell = strip_tags($printable_data_cell); |
||
| 1001 | } |
||
| 1002 | $table->setHeaderContents($row, $column, $printable_data_cell); |
||
| 1003 | $column++; |
||
| 1004 | } |
||
| 1005 | $row++; |
||
| 1006 | |||
| 1007 | if ($has_data) { |
||
| 1008 | $counter = 1; |
||
| 1009 | foreach ($printable_data[1] as &$printable_data_row) { |
||
| 1010 | $column = 0; |
||
| 1011 | $table->setCellContents($row, $column, $counter); |
||
| 1012 | $table->updateCellAttributes($row, $column, 'align="center"'); |
||
| 1013 | $column++; |
||
| 1014 | $counter++; |
||
| 1015 | |||
| 1016 | foreach ($printable_data_row as $key => &$printable_data_cell) { |
||
| 1017 | $attributes = array(); |
||
| 1018 | $attributes['align'] = 'center'; |
||
| 1019 | $attributes['style'] = null; |
||
| 1020 | |||
| 1021 | if ($key === 'name') { |
||
| 1022 | $attributes['align'] = 'left'; |
||
| 1023 | } |
||
| 1024 | if ($key === 'total') { |
||
| 1025 | $attributes['style'] = 'font-weight:bold'; |
||
| 1026 | } |
||
| 1027 | $table->setCellContents($row, $column, $printable_data_cell); |
||
| 1028 | $table->updateCellAttributes($row, $column, $attributes); |
||
| 1029 | $column++; |
||
| 1030 | } |
||
| 1031 | $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); |
||
| 1032 | $row++; |
||
| 1033 | } |
||
| 1034 | } else { |
||
| 1035 | $column = 0; |
||
| 1036 | $table->setCellContents($row, $column, get_lang('NoResults')); |
||
| 1037 | $table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"'); |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | $pdfParams = array( |
||
| 1041 | 'filename' => get_lang('FlatView').'_'.api_get_utc_datetime(), |
||
| 1042 | 'pdf_title' => $title, |
||
| 1043 | 'course_code' => $course_code, |
||
| 1044 | 'add_signatures' => ['Drh', 'Teacher', 'Date'] |
||
| 1045 | ); |
||
| 1046 | |||
| 1047 | $page_format = $params['orientation'] == 'landscape' ? 'A4-L' : 'A4'; |
||
| 1048 | ob_start(); |
||
| 1049 | $pdf = new PDF($page_format, $page_format, $pdfParams); |
||
| 1050 | $pdf->html_to_pdf_with_template($flatviewtable->return_table()); |
||
| 1051 | $content = ob_get_contents(); |
||
| 1052 | ob_end_clean(); |
||
| 1053 | echo $content; |
||
| 1054 | exit; |
||
| 1055 | } |
||
| 1056 | |||
| 1057 | /** |
||
| 1058 | * @param string[] $list_values |
||
| 1059 | * @return string |
||
| 1060 | */ |
||
| 1061 | public static function score_badges($list_values) |
||
| 1062 | { |
||
| 1063 | $counter = 1; |
||
| 1064 | $badges = array(); |
||
| 1065 | foreach ($list_values as $value) { |
||
| 1066 | $class = 'warning'; |
||
| 1067 | if ($counter == 1) { |
||
| 1068 | $class = 'success'; |
||
| 1069 | } |
||
| 1070 | $counter++; |
||
| 1071 | $badges[] = Display::badge($value, $class); |
||
| 1072 | } |
||
| 1073 | |||
| 1074 | return Display::badge_group($badges); |
||
| 1075 | } |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * returns users within a course given by param |
||
| 1079 | * @param string $courseCode |
||
| 1080 | * @return array |
||
| 1081 | */ |
||
| 1082 | public static function get_users_in_course($courseCode) |
||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * @param Doctrine\DBAL\Driver\Statement|null $result |
||
| 1121 | * @return array |
||
| 1122 | */ |
||
| 1123 | public static function get_user_array_from_sql_result($result) |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * @param array $evals |
||
| 1142 | * @param array $links |
||
| 1143 | * @return array |
||
| 1144 | */ |
||
| 1145 | public static function get_all_users($evals = array(), $links = array()) |
||
| 1146 | { |
||
| 1147 | $coursecodes = array(); |
||
| 1148 | |||
| 1149 | // By default add all user in course |
||
| 1150 | $coursecodes[api_get_course_id()] = '1'; |
||
| 1151 | $users = self::get_users_in_course(api_get_course_id()); |
||
| 1152 | |||
| 1153 | foreach ($evals as $eval) { |
||
| 1154 | $coursecode = $eval->get_course_code(); |
||
| 1155 | // evaluation in course |
||
| 1156 | if (isset($coursecode) && !empty($coursecode)) { |
||
| 1157 | View Code Duplication | if (!array_key_exists($coursecode, $coursecodes)) { |
|
| 1158 | $coursecodes[$coursecode] = '1'; |
||
| 1159 | $users = array_merge($users, self::get_users_in_course($coursecode)); |
||
| 1160 | } |
||
| 1161 | } else { |
||
| 1162 | // course independent evaluation |
||
| 1163 | $tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 1164 | $tbl_res = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
||
| 1165 | |||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Search students matching a given last name and/or first name |
||
| 1196 | * @author Bert Steppé |
||
| 1197 | */ |
||
| 1198 | public static function find_students($mask = '') |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * @param int $linkId |
||
| 1243 | * @param float $weight |
||
| 1244 | */ |
||
| 1245 | public static function updateLinkWeight($linkId, $name, $weight) |
||
| 1304 | |||
| 1305 | /** |
||
| 1306 | * @param int $id |
||
| 1307 | * @param float $weight |
||
| 1308 | */ |
||
| 1309 | View Code Duplication | public static function updateEvaluationWeight($id, $weight) |
|
| 1320 | |||
| 1321 | /** |
||
| 1322 | * |
||
| 1323 | * Get the achieved certificates for a user in courses |
||
| 1324 | * @param int $userId The user id |
||
| 1325 | * @param bool $includeNonPublicCertificates Whether include the non-plublic certificates |
||
| 1326 | * @return array |
||
| 1327 | */ |
||
| 1328 | public static function getUserCertificatesInCourses($userId, $includeNonPublicCertificates = true) |
||
| 1369 | |||
| 1370 | /** |
||
| 1371 | * Get the achieved certificates for a user in course sessions |
||
| 1372 | * @param int $userId The user id |
||
| 1373 | * @param bool $includeNonPublicCertificates Whether include the non-public certificates |
||
| 1374 | * @return array |
||
| 1375 | */ |
||
| 1376 | public static function getUserCertificatesInSessions($userId, $includeNonPublicCertificates = true) |
||
| 1433 | |||
| 1434 | /** |
||
| 1435 | * @param int $userId |
||
| 1436 | * @param array $cats |
||
| 1437 | * @param bool $saveToFile |
||
| 1438 | * @param bool $saveToHtmlFile |
||
| 1439 | * @param array $studentList |
||
| 1440 | * @param PDF $pdf |
||
| 1441 | * |
||
| 1442 | * @return string |
||
| 1443 | */ |
||
| 1444 | public static function generateTable( |
||
| 1546 | } |
||
| 1547 |
This check looks for references to static members where there are spaces between the name of the type and the actual member.
An example:
will actually work, but is not very readable.