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 CourseHome 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 CourseHome, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class CourseHome |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Gets the html content to show in the 3 column view |
||
| 14 | * @param string $cat |
||
| 15 | * @param int $userId |
||
| 16 | * @return string |
||
| 17 | */ |
||
| 18 | public static function show_tool_3column($cat, $userId = null) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Displays the tools of a certain category. |
||
| 226 | * |
||
| 227 | * @return void |
||
| 228 | * @param string $course_tool_category contains the category of tools to display: |
||
| 229 | * "Public", "PublicButHide", "courseAdmin", "claroAdmin" |
||
| 230 | */ |
||
| 231 | public static function show_tool_2column($course_tool_category) |
||
| 232 | { |
||
| 233 | $html = ''; |
||
| 234 | $web_code_path = api_get_path(WEB_CODE_PATH); |
||
| 235 | $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); |
||
| 236 | |||
| 237 | $course_id = api_get_course_int_id(); |
||
| 238 | |||
| 239 | switch ($course_tool_category) { |
||
| 240 | View Code Duplication | case TOOL_PUBLIC: |
|
| 241 | $condition_display_tools = ' WHERE c_id = '.$course_id.' AND visibility = 1 '; |
||
| 242 | if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') { |
||
| 243 | $condition_display_tools = ' WHERE c_id = '.$course_id.' AND (visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'")) '; |
||
| 244 | } |
||
| 245 | $result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id"); |
||
| 246 | $col_link = "##003399"; |
||
| 247 | break; |
||
| 248 | case TOOL_PUBLIC_BUT_HIDDEN: |
||
| 249 | $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility=0 AND admin=0 ORDER BY id"); |
||
| 250 | $col_link = "##808080"; |
||
| 251 | break; |
||
| 252 | case TOOL_COURSE_ADMIN: |
||
| 253 | $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND admin=1 AND visibility != 2 ORDER BY id"); |
||
| 254 | $col_link = "##003399"; |
||
| 255 | break; |
||
| 256 | case TOOL_PLATFORM_ADMIN: |
||
| 257 | $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility = 2 ORDER BY id"); |
||
| 258 | $col_link = "##003399"; |
||
| 259 | } |
||
| 260 | $i = 0; |
||
| 261 | |||
| 262 | // Grabbing all the tools from $course_tool_table |
||
| 263 | while ($temp_row = Database::fetch_array($result)) { |
||
| 264 | if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') { |
||
| 265 | $temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']); |
||
| 266 | } |
||
| 267 | $all_tools_list[] = $temp_row; |
||
| 268 | } |
||
| 269 | |||
| 270 | // Grabbing all the links that have the property on_homepage set to 1 |
||
| 271 | $course_link_table = Database::get_course_table(TABLE_LINK); |
||
| 272 | $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||
| 273 | |||
| 274 | switch ($course_tool_category) { |
||
| 275 | case TOOL_PUBLIC: |
||
| 276 | $sql_links = "SELECT tl.*, tip.visibility |
||
| 277 | FROM $course_link_table tl |
||
| 278 | LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id |
||
| 279 | WHERE tl.on_homepage='1' AND tip.visibility = 1"; |
||
| 280 | break; |
||
| 281 | case TOOL_PUBLIC_BUT_HIDDEN: |
||
| 282 | $sql_links = "SELECT tl.*, tip.visibility |
||
| 283 | FROM $course_link_table tl |
||
| 284 | LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id |
||
| 285 | WHERE tl.on_homepage='1' AND tip.visibility = 0"; |
||
| 286 | |||
| 287 | break; |
||
| 288 | default: |
||
| 289 | $sql_links = null; |
||
| 290 | break; |
||
| 291 | } |
||
| 292 | if ($sql_links != null) { |
||
| 293 | $properties = array(); |
||
| 294 | $result_links = Database::query($sql_links); |
||
| 295 | View Code Duplication | while ($links_row = Database::fetch_array($result_links)) { |
|
| 296 | unset($properties); |
||
| 297 | $properties['name'] = $links_row['title']; |
||
| 298 | $properties['link'] = $links_row['url']; |
||
| 299 | $properties['visibility'] = $links_row['visibility']; |
||
| 300 | $properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif'; |
||
| 301 | $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id']; |
||
| 302 | $all_tools_list[] = $properties; |
||
| 303 | } |
||
| 304 | } |
||
| 305 | if (isset($all_tools_list)) { |
||
| 306 | $lnk = array(); |
||
| 307 | foreach ($all_tools_list as & $tool) { |
||
| 308 | View Code Duplication | if ($tool['image'] == 'scormbuilder.gif') { |
|
| 309 | // check if the published learnpath is visible for student |
||
| 310 | $published_lp_id = self::get_published_lp_id_from_link($tool['link']); |
||
| 311 | |||
| 312 | if (!api_is_allowed_to_edit(null, true) && |
||
| 313 | !learnpath::is_lp_visible_for_student( |
||
| 314 | $published_lp_id, |
||
| 315 | api_get_user_id(), |
||
| 316 | api_get_course_id(), |
||
| 317 | api_get_session_id() |
||
| 318 | ) |
||
| 319 | ) { |
||
| 320 | continue; |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | View Code Duplication | if (api_get_session_id() != 0 && |
|
| 325 | in_array($tool['name'], array('course_maintenance', 'course_setting')) |
||
| 326 | ) { |
||
| 327 | continue; |
||
| 328 | } |
||
| 329 | |||
| 330 | if (!($i % 2)) { |
||
| 331 | $html .= "<tr valign=\"top\">"; |
||
| 332 | } |
||
| 333 | |||
| 334 | // NOTE : Table contains only the image file name, not full path |
||
| 335 | View Code Duplication | if (stripos($tool['link'], 'http://') === false && |
|
| 336 | stripos($tool['link'], 'https://') === false && |
||
| 337 | stripos($tool['link'], 'ftp://') === false |
||
| 338 | ) { |
||
| 339 | $tool['link'] = $web_code_path.$tool['link']; |
||
| 340 | } |
||
| 341 | $class = ''; |
||
| 342 | if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) { |
||
| 343 | $class = 'class="text-muted"'; |
||
| 344 | } |
||
| 345 | $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; |
||
| 346 | |||
| 347 | $tool['link'] = $tool['link']; |
||
| 348 | $html .= '<td width="50%" height="30">'; |
||
| 349 | |||
| 350 | if (strpos($tool['name'], 'visio_') !== false) { |
||
| 351 | $html .= '<a '.$class.' href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['image'] == 'external_na.gif') ? '' : $qm_or_amp.api_get_cidreq()).'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'">'; |
||
| 352 | } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { |
||
| 353 | $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).$qm_or_amp.api_get_cidreq().'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'" '.$class.'>'; |
||
| 354 | } else { |
||
| 355 | $html .= '<a href="'.htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['image'] == 'external_na.gif') ? '' : $qm_or_amp.api_get_cidreq()).'" target="'.$tool['target'].'" '.$class.'>'; |
||
| 356 | } |
||
| 357 | |||
| 358 | $tool_name = self::translate_tool_name($tool); |
||
| 359 | $html .= Display::return_icon( |
||
| 360 | $tool['image'], |
||
| 361 | $tool_name, |
||
| 362 | array(), |
||
| 363 | null, |
||
| 364 | ICON_SIZE_MEDIUM |
||
| 365 | ).' '.$tool_name.'</a>'; |
||
| 366 | |||
| 367 | // This part displays the links to hide or remove a tool. |
||
| 368 | // These links are only visible by the course manager. |
||
| 369 | unset($lnk); |
||
| 370 | if (api_is_allowed_to_edit(null, true) && !api_is_coach()) { |
||
| 371 | View Code Duplication | if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) { |
|
| 372 | $link['name'] = Display::returnFontAwesomeIcon('minus'); |
||
| 373 | $link['title'] = get_lang('Deactivate'); |
||
| 374 | $link['cmd'] = 'hide=yes'; |
||
| 375 | $lnk[] = $link; |
||
| 376 | } |
||
| 377 | |||
| 378 | View Code Duplication | if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) { |
|
| 379 | //$link['name'] = Display::return_icon('add.gif', get_lang('Activate')); |
||
| 380 | $link['name'] = Display::returnFontAwesomeIcon('plus'); |
||
| 381 | $link['title'] = get_lang('Activate'); |
||
| 382 | $link['cmd'] = 'restore=yes'; |
||
| 383 | $lnk[] = $link; |
||
| 384 | |||
| 385 | if ($tool['added_tool'] == 1) { |
||
| 386 | //$link['name'] = Display::return_icon('delete.gif', get_lang('Remove')); |
||
| 387 | $link['name'] = Display::returnFontAwesomeIcon('trash'); |
||
| 388 | $link['title'] = get_lang('Remove'); |
||
| 389 | $link['cmd'] = 'remove=yes'; |
||
| 390 | $lnk[] = $link; |
||
| 391 | } |
||
| 392 | } |
||
| 393 | if (isset($tool['adminlink'])) { |
||
| 394 | $html .= '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>'; |
||
| 395 | } |
||
| 396 | } |
||
| 397 | if (api_is_platform_admin() && !api_is_coach()) { |
||
| 398 | View Code Duplication | if ($tool['visibility'] == 2) { |
|
| 399 | $link['name'] = Display::returnFontAwesomeIcon('undo'); |
||
| 400 | $link['title'] = get_lang('Activate'); |
||
| 401 | $link['cmd'] = 'hide=yes'; |
||
| 402 | $lnk[] = $link; |
||
| 403 | |||
| 404 | if ($tool['added_tool'] == 1) { |
||
| 405 | $link['name'] = get_lang('Delete'); |
||
| 406 | $link['cmd'] = 'askDelete=yes'; |
||
| 407 | $lnk[] = $link; |
||
| 408 | } |
||
| 409 | } |
||
| 410 | View Code Duplication | if ($tool['visibility'] == 0 && $tool['added_tool'] == 0) { |
|
| 411 | $link['name'] = Display::returnFontAwesomeIcon('trash'); |
||
| 412 | $link['title'] = get_lang('Remove'); |
||
| 413 | $link['cmd'] = 'remove=yes'; |
||
| 414 | $lnk[] = $link; |
||
| 415 | } |
||
| 416 | } |
||
| 417 | if (is_array($lnk)) { |
||
| 418 | $html .= '<div class="pull-right">'; |
||
| 419 | $html .= '<div class="btn-options">'; |
||
| 420 | $html .= '<div class="btn-group btn-group-sm" role="group">'; |
||
| 421 | View Code Duplication | foreach ($lnk as & $this_link) { |
|
| 422 | if (!isset($tool['adminlink'])) { |
||
| 423 | $html .= '<a class="btn btn-default" title='.$this_link['title'].' href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['id'].'&'.$this_link['cmd'].'">'.$this_link['name'].'</a>'; |
||
| 424 | } |
||
| 425 | } |
||
| 426 | $html .= '</div>'; |
||
| 427 | $html .= '</div>'; |
||
| 428 | $html .= '</div>'; |
||
| 429 | } |
||
| 430 | $html .= "</td>"; |
||
| 431 | |||
| 432 | if ($i % 2) { |
||
| 433 | $html .= "</tr>"; |
||
| 434 | } |
||
| 435 | |||
| 436 | $i++; |
||
| 437 | } |
||
| 438 | } |
||
| 439 | |||
| 440 | if ($i % 2) { |
||
| 441 | $html .= "<td width=\"50%\"> </td></tr>"; |
||
| 442 | } |
||
| 443 | |||
| 444 | return $html; |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Gets the tools of a certain category. Returns an array expected |
||
| 449 | * by show_tools_category() |
||
| 450 | * @param string $course_tool_category contains the category of tools to |
||
| 451 | * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin" |
||
| 452 | * @param int $courseId Optional |
||
| 453 | * @param int $sessionId Optional |
||
| 454 | * @return array |
||
| 455 | */ |
||
| 456 | public static function get_tools_category($course_tool_category, $courseId = 0, $sessionId = 0) |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Displays the tools of a certain category. |
||
| 709 | * @param $urlGenerator |
||
| 710 | * @param array $all_tools_list List of tools as returned by get_tools_category() |
||
| 711 | * @param bool $rows |
||
| 712 | * |
||
| 713 | * @return string |
||
| 714 | */ |
||
| 715 | public static function show_tools_category($urlGenerator, $all_tools_list, $rows = false) |
||
| 716 | { |
||
| 717 | $_user = api_get_user_info(); |
||
| 718 | $web_code_path = api_get_path(WEB_CODE_PATH); |
||
| 719 | $session_id = api_get_session_id(); |
||
| 720 | $is_platform_admin = api_is_platform_admin(); |
||
| 721 | $theme = api_get_setting('homepage_view'); |
||
| 722 | |||
| 723 | if ($theme === 'vertical_activity') { |
||
| 724 | //ordering by get_lang name |
||
| 725 | $order_tool_list = array(); |
||
| 726 | if (is_array($all_tools_list) && count($all_tools_list) > 0) { |
||
| 727 | foreach ($all_tools_list as $key => $new_tool) { |
||
| 728 | $tool_name = self::translate_tool_name($new_tool); |
||
| 729 | $order_tool_list [$key] = $tool_name; |
||
| 730 | } |
||
| 731 | natsort($order_tool_list); |
||
| 732 | $my_temp_tool_array = array(); |
||
| 733 | foreach ($order_tool_list as $key => $new_tool) { |
||
| 734 | $my_temp_tool_array[] = $all_tools_list[$key]; |
||
| 735 | } |
||
| 736 | $all_tools_list = $my_temp_tool_array; |
||
| 737 | } else { |
||
| 738 | $all_tools_list = array(); |
||
| 739 | } |
||
| 740 | } |
||
| 741 | $web_code_path = api_get_path(WEB_CODE_PATH); |
||
| 742 | $session_id = api_get_session_id(); |
||
| 743 | $is_platform_admin = api_is_platform_admin(); |
||
| 744 | $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session'); |
||
| 745 | |||
| 746 | if ($session_id == 0) { |
||
| 747 | $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin(); |
||
| 748 | } else { |
||
| 749 | $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach(); |
||
| 750 | if ($allowEditionInSession) { |
||
| 751 | $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_coach($session_id, api_get_course_int_id()); |
||
| 752 | } |
||
| 753 | } |
||
| 754 | |||
| 755 | $i = 0; |
||
| 756 | $items = array(); |
||
| 757 | $app_plugin = new AppPlugin(); |
||
| 758 | |||
| 759 | $toolChain = \Chamilo\CoreBundle\Framework\Container::getToolChain(); |
||
| 760 | |||
| 761 | if (isset($all_tools_list)) { |
||
| 762 | $lnk = ''; |
||
| 763 | |||
| 764 | foreach ($all_tools_list as & $tool) { |
||
| 765 | $item = array(); |
||
| 766 | $studentview = false; |
||
| 767 | |||
| 768 | // Using tool chain to load links instead of loading link from the database. |
||
| 769 | $toolObject = $toolChain->getToolFromName($tool['name']); |
||
| 770 | if ($toolObject) { |
||
| 771 | $tool['link'] = $toolObject->getLink(); |
||
| 772 | } |
||
| 773 | |||
| 774 | $tool['original_link'] = $tool['link']; |
||
| 775 | |||
| 776 | if ($tool['image'] == 'scormbuilder.gif') { |
||
| 777 | // check if the published learnpath is visible for student |
||
| 778 | $published_lp_id = self::get_published_lp_id_from_link($tool['link']); |
||
| 779 | if (api_is_allowed_to_edit(null, true)) { |
||
| 780 | $studentview = true; |
||
| 781 | } |
||
| 782 | if (!api_is_allowed_to_edit(null, true) && |
||
| 783 | !learnpath::is_lp_visible_for_student( |
||
| 784 | $published_lp_id, |
||
| 785 | api_get_user_id(), |
||
| 786 | api_get_course_id(), |
||
| 787 | api_get_session_id() |
||
| 788 | ) |
||
| 789 | ) { |
||
| 790 | continue; |
||
| 791 | } |
||
| 792 | } |
||
| 793 | |||
| 794 | if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) { |
||
| 795 | continue; |
||
| 796 | } |
||
| 797 | |||
| 798 | // This part displays the links to hide or remove a tool. |
||
| 799 | // These links are only visible by the course manager. |
||
| 800 | unset($lnk); |
||
| 801 | |||
| 802 | $item['extra'] = null; |
||
| 803 | $toolAdmin = isset($tool['admin']) ? $tool['admin'] : ''; |
||
| 804 | |||
| 805 | if ($is_allowed_to_edit) { |
||
| 806 | if (empty($session_id)) { |
||
| 807 | if (isset($tool['id'])) { |
||
| 808 | View Code Duplication | if ($tool['visibility'] == '1' && $toolAdmin != '1') { |
|
| 809 | $link['name'] = Display::return_icon( |
||
| 810 | 'visible.png', |
||
| 811 | get_lang('Deactivate'), |
||
| 812 | array('id' => 'linktool_'.$tool['id']), |
||
| 813 | ICON_SIZE_SMALL, |
||
| 814 | false |
||
| 815 | ); |
||
| 816 | $link['cmd'] = 'hide=yes'; |
||
| 817 | $lnk[] = $link; |
||
| 818 | } |
||
| 819 | View Code Duplication | if ($tool['visibility'] == '0' && $toolAdmin != '1') { |
|
| 820 | $link['name'] = Display::return_icon( |
||
| 821 | 'invisible.png', |
||
| 822 | get_lang('Activate'), |
||
| 823 | array('id' => 'linktool_'.$tool['id']), |
||
| 824 | ICON_SIZE_SMALL, |
||
| 825 | false |
||
| 826 | ); |
||
| 827 | $link['cmd'] = 'restore=yes'; |
||
| 828 | $lnk[] = $link; |
||
| 829 | } |
||
| 830 | } |
||
| 831 | } elseif ($allowEditionInSession) { |
||
| 832 | $criteria = [ |
||
| 833 | 'cId' => api_get_course_int_id(), |
||
| 834 | 'name' => $tool['name'], |
||
| 835 | 'sessionId' => $session_id |
||
| 836 | ]; |
||
| 837 | /** @var CTool $tool */ |
||
| 838 | $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria); |
||
| 839 | if ($toolObj) { |
||
| 840 | $visibility = $toolObj->getVisibility(); |
||
| 841 | switch ($visibility) { |
||
| 842 | View Code Duplication | case '0': |
|
| 843 | $link['name'] = Display::return_icon( |
||
| 844 | 'invisible.png', |
||
| 845 | get_lang('Activate'), |
||
| 846 | array('id' => 'linktool_'.$tool['id']), |
||
| 847 | ICON_SIZE_SMALL, |
||
| 848 | false |
||
| 849 | ); |
||
| 850 | $link['cmd'] = 'restore=yes'; |
||
| 851 | $lnk[] = $link; |
||
| 852 | break; |
||
| 853 | View Code Duplication | case '1': |
|
| 854 | $link['name'] = Display::return_icon( |
||
| 855 | 'visible.png', |
||
| 856 | get_lang('Deactivate'), |
||
| 857 | array('id' => 'linktool_'.$tool['id']), |
||
| 858 | ICON_SIZE_SMALL, |
||
| 859 | false |
||
| 860 | ); |
||
| 861 | $link['cmd'] = 'hide=yes'; |
||
| 862 | $lnk[] = $link; |
||
| 863 | break; |
||
| 864 | } |
||
| 865 | View Code Duplication | } else { |
|
| 866 | $link['name'] = Display::return_icon( |
||
| 867 | 'visible.png', |
||
| 868 | get_lang('Deactivate'), |
||
| 869 | array('id' => 'linktool_'.$tool['id']), |
||
| 870 | ICON_SIZE_SMALL, |
||
| 871 | false |
||
| 872 | ); |
||
| 873 | $link['cmd'] = 'hide=yes'; |
||
| 874 | $lnk[] = $link; |
||
| 875 | } |
||
| 876 | } |
||
| 877 | if (!empty($tool['adminlink'])) { |
||
| 878 | $item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>'; |
||
| 879 | } |
||
| 880 | } |
||
| 881 | |||
| 882 | // Both checks are necessary as is_platform_admin doesn't take student view into account |
||
| 883 | if ($is_platform_admin && $is_allowed_to_edit) { |
||
| 884 | if ($toolAdmin != '1') { |
||
| 885 | $link['cmd'] = 'hide=yes'; |
||
| 886 | } |
||
| 887 | } |
||
| 888 | |||
| 889 | $item['visibility'] = null; |
||
| 890 | if (isset($lnk) && is_array($lnk)) { |
||
| 891 | View Code Duplication | foreach ($lnk as $this_link) { |
|
| 892 | if (empty($tool['adminlink'])) { |
||
| 893 | $item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['id'].'&'.$this_link['cmd'].'">'. |
||
| 894 | $this_link['name'].'</a>'; |
||
| 895 | } |
||
| 896 | } |
||
| 897 | } else { |
||
| 898 | $item['visibility'] .= ''; |
||
| 899 | } |
||
| 900 | |||
| 901 | // NOTE : Table contains only the image file name, not full path |
||
| 902 | View Code Duplication | if (stripos($tool['link'], 'http://') === false && |
|
| 903 | stripos($tool['link'], 'https://') === false && |
||
| 904 | stripos($tool['link'], 'ftp://') === false |
||
| 905 | ) { |
||
| 906 | $tool['link'] = $web_code_path.$tool['link']; |
||
| 907 | } |
||
| 908 | |||
| 909 | if ($tool['visibility'] == '0' && $toolAdmin != '1') { |
||
| 910 | $class = 'text-muted'; |
||
| 911 | $info = pathinfo($tool['image']); |
||
| 912 | $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index" |
||
| 913 | $tool['image'] = $basename.'_na.'.$info['extension']; |
||
| 914 | } else { |
||
| 915 | $class = ''; |
||
| 916 | } |
||
| 917 | |||
| 918 | $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; |
||
| 919 | // If it's a link, we don't add the cidReq |
||
| 920 | |||
| 921 | if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') { |
||
| 922 | $tool['link'] = $tool['link'].$qm_or_amp; |
||
| 923 | } else { |
||
| 924 | $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq(); |
||
| 925 | } |
||
| 926 | |||
| 927 | $tool_link_params = array(); |
||
| 928 | $toolId = isset($tool["id"]) ? $tool["id"] : null; |
||
| 929 | |||
| 930 | //@todo this visio stuff should be removed |
||
| 931 | if (strpos($tool['name'], 'visio_') !== false) { |
||
| 932 | $tool_link_params = array( |
||
| 933 | 'id' => 'tooldesc_'.$toolId, |
||
| 934 | 'href' => '"javascript: void(0);"', |
||
| 935 | 'class' => $class, |
||
| 936 | 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', |
||
| 937 | 'target' => $tool['target'] |
||
| 938 | ); |
||
| 939 | } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { |
||
| 940 | $tool_link_params = array( |
||
| 941 | 'id' => 'tooldesc_'.$toolId, |
||
| 942 | 'class' => $class, |
||
| 943 | 'href' => 'javascript: void(0);', |
||
| 944 | 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows |
||
| 945 | 'target' => $tool['target'] |
||
| 946 | ); |
||
| 947 | } else { |
||
| 948 | $tool_link_params = array( |
||
| 949 | 'id' => 'tooldesc_'.$toolId, |
||
| 950 | 'href' => $tool['link'], |
||
| 951 | 'class' => $class, |
||
| 952 | 'target' => $tool['target'] |
||
| 953 | ); |
||
| 954 | } |
||
| 955 | |||
| 956 | $tool_name = self::translate_tool_name($tool); |
||
|
|
|||
| 957 | |||
| 958 | // Including Courses Plugins |
||
| 959 | // Creating title and the link |
||
| 960 | if (isset($tool['category']) && $tool['category'] == 'plugin') { |
||
| 961 | $plugin_info = $app_plugin->getPluginInfo($tool['name']); |
||
| 962 | if (isset($plugin_info) && isset($plugin_info['title'])) { |
||
| 963 | $tool_name = $plugin_info['title']; |
||
| 964 | } |
||
| 965 | |||
| 966 | View Code Duplication | if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) && |
|
| 967 | !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) { |
||
| 968 | $tool['image'] = 'plugins.png'; |
||
| 969 | } |
||
| 970 | $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq(); |
||
| 971 | } |
||
| 972 | |||
| 973 | $icon = Display::return_icon( |
||
| 974 | $tool['image'], |
||
| 975 | $tool_name, |
||
| 976 | array('class' => 'tool-icon', 'id' => 'toolimage_'.$toolId), |
||
| 977 | ICON_SIZE_BIG, |
||
| 978 | false |
||
| 979 | ); |
||
| 980 | |||
| 981 | /*if (!empty($tool['custom_icon'])) { |
||
| 982 | $image = self::getCustomWebIconPath().$tool['custom_icon']; |
||
| 983 | $icon = Display::img( |
||
| 984 | $image, |
||
| 985 | $tool['description'], |
||
| 986 | array( |
||
| 987 | 'class' => 'tool-icon', |
||
| 988 | 'id' => 'toolimage_'.$tool['id'] |
||
| 989 | ) |
||
| 990 | ); |
||
| 991 | }*/ |
||
| 992 | |||
| 993 | // Validation when belongs to a session |
||
| 994 | $session_img = api_get_session_image($tool['session_id'], (!empty($_user['status']) ? $_user['status'] : '')); |
||
| 995 | if ($studentview) { |
||
| 996 | $tool_link_params['href'] .= '&isStudentView=true'; |
||
| 997 | } |
||
| 998 | $item['url_params'] = $tool_link_params; |
||
| 999 | $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); |
||
| 1000 | $item['tool'] = $tool; |
||
| 1001 | $item['name'] = $tool_name; |
||
| 1002 | $tool_link_params['id'] = 'is'.$tool_link_params['id']; |
||
| 1003 | $item['link'] = Display::url( |
||
| 1004 | $tool_name.$session_img, |
||
| 1005 | $tool_link_params['href'], |
||
| 1006 | $tool_link_params |
||
| 1007 | ); |
||
| 1008 | |||
| 1009 | $items[] = $item; |
||
| 1010 | |||
| 1011 | $i++; |
||
| 1012 | } // end of foreach |
||
| 1013 | } |
||
| 1014 | |||
| 1015 | $i = 0; |
||
| 1016 | $html = ''; |
||
| 1017 | |||
| 1018 | if (!empty($items)) { |
||
| 1019 | foreach ($items as $item) { |
||
| 1020 | switch ($theme) { |
||
| 1021 | case 'activity_big': |
||
| 1022 | $data = ''; |
||
| 1023 | $html .= '<div class="col-xs-6 col-md-3 course-tool">'; |
||
| 1024 | $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png'; |
||
| 1025 | $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null; |
||
| 1026 | |||
| 1027 | if (isset($item['tool']['custom_image'])) { |
||
| 1028 | $original_image = Display::img( |
||
| 1029 | $item['tool']['custom_image'], |
||
| 1030 | $item['name'], |
||
| 1031 | array('id' => 'toolimage_'.$toolId) |
||
| 1032 | ); |
||
| 1033 | } elseif (isset($item['tool']['custom_icon']) && |
||
| 1034 | !empty($item['tool']['custom_icon']) |
||
| 1035 | ) { |
||
| 1036 | $customIcon = $item['tool']['custom_icon']; |
||
| 1037 | if ($item['tool']['visibility'] == '0') { |
||
| 1038 | $fileInfo = pathinfo($item['tool']['custom_icon']); |
||
| 1039 | $customIcon = self::getDisableIcon($item['tool']['custom_icon']); |
||
| 1040 | } |
||
| 1041 | $original_image = Display::img( |
||
| 1042 | self::getCustomWebIconPath().$customIcon, |
||
| 1043 | $item['name'], |
||
| 1044 | array('id' => 'toolimage_'.$toolId) |
||
| 1045 | ); |
||
| 1046 | } else { |
||
| 1047 | $original_image = Display::return_icon( |
||
| 1048 | $image, |
||
| 1049 | $item['name'], |
||
| 1050 | array('id' => 'toolimage_'.$toolId), |
||
| 1051 | ICON_SIZE_BIG, |
||
| 1052 | false |
||
| 1053 | ); |
||
| 1054 | } |
||
| 1055 | |||
| 1056 | $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']); |
||
| 1057 | $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection |
||
| 1058 | $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content')); |
||
| 1059 | $html .= '</div>'; |
||
| 1060 | |||
| 1061 | break; |
||
| 1062 | case 'activity': |
||
| 1063 | $html .= '<div class="offset2 col-md-4 course-tool">'; |
||
| 1064 | $html .= $item['extra']; |
||
| 1065 | $html .= $item['visibility']; |
||
| 1066 | $html .= $item['icon']; |
||
| 1067 | $html .= $item['link']; |
||
| 1068 | $html .= '</div>'; |
||
| 1069 | break; |
||
| 1070 | case 'vertical_activity': |
||
| 1071 | if ($i == 0) { |
||
| 1072 | $html .= '<ul>'; |
||
| 1073 | } |
||
| 1074 | $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png'; |
||
| 1075 | $original_image = Display::return_icon( |
||
| 1076 | $image, |
||
| 1077 | $item['name'], |
||
| 1078 | array('id' => 'toolimage_'.$item['tool']['id']), |
||
| 1079 | ICON_SIZE_SMALL, |
||
| 1080 | false |
||
| 1081 | ); |
||
| 1082 | $html .= '<li class="course-tool">'; |
||
| 1083 | $html .= $item['extra']; |
||
| 1084 | $html .= $item['visibility']; |
||
| 1085 | $url = Display::url($original_image, $item['url_params']['href'], $item['url_params']); |
||
| 1086 | $html .= $url; |
||
| 1087 | $html .= $item['link']; |
||
| 1088 | $html .= '</li>'; |
||
| 1089 | |||
| 1090 | if ($i == count($items) - 1) { |
||
| 1091 | $html .= '</ul>'; |
||
| 1092 | } |
||
| 1093 | break; |
||
| 1094 | } |
||
| 1095 | $i++; |
||
| 1096 | } |
||
| 1097 | } |
||
| 1098 | |||
| 1099 | return array( |
||
| 1100 | 'content' => $html, |
||
| 1101 | 'tool_list' => $items |
||
| 1102 | ); |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * Shows the general data for a particular meeting |
||
| 1107 | * |
||
| 1108 | * @param id session id |
||
| 1109 | * @return string session data |
||
| 1110 | */ |
||
| 1111 | public static function show_session_data($id_session) |
||
| 1153 | |||
| 1154 | /** |
||
| 1155 | * Retrieves the name-field within a tool-record and translates it on necessity. |
||
| 1156 | * @param array $tool The input record. |
||
| 1157 | * @return string Returns the name of the corresponding tool. |
||
| 1158 | */ |
||
| 1159 | public static function translate_tool_name(& $tool) |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Get published learning path id from link inside course home |
||
| 1191 | * @param string Link to published lp |
||
| 1192 | * @return int Learning path id |
||
| 1193 | */ |
||
| 1194 | public static function get_published_lp_id_from_link($published_lp_link) |
||
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Get published learning path category from link inside course home |
||
| 1210 | * @param string $link |
||
| 1211 | * @return CLpCategory |
||
| 1212 | */ |
||
| 1213 | public static function getPublishedLpCategoryFromLink($link) |
||
| 1226 | |||
| 1227 | /** |
||
| 1228 | * @param bool $include_admin_tools |
||
| 1229 | * @return array |
||
| 1230 | */ |
||
| 1231 | public static function get_navigation_items($include_admin_tools = false) |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Show a navigation menu |
||
| 1306 | */ |
||
| 1307 | public static function show_navigation_menu() |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Show a toolbar with shortcuts to the course tool |
||
| 1385 | * @param int $orientation |
||
| 1386 | * |
||
| 1387 | * @return string |
||
| 1388 | */ |
||
| 1389 | public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL) |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * List course homepage tools from authoring and interaction sections |
||
| 1451 | * @param int $courseId The course ID (guessed from context if not provided) |
||
| 1452 | * @param int $sessionId The session ID (guessed from context if not provided) |
||
| 1453 | * @return array List of all tools data from the c_tools table |
||
| 1454 | */ |
||
| 1455 | public static function toolsIconsAction($courseId = null, $sessionId = null) |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * @param int $editIcon |
||
| 1489 | * @return array |
||
| 1490 | */ |
||
| 1491 | View Code Duplication | public static function getTool($editIcon) |
|
| 1503 | |||
| 1504 | /** |
||
| 1505 | * @return string |
||
| 1506 | */ |
||
| 1507 | public static function getCustomSysIconPath() |
||
| 1517 | |||
| 1518 | /** |
||
| 1519 | * @return string |
||
| 1520 | */ |
||
| 1521 | public static function getCustomWebIconPath() |
||
| 1528 | |||
| 1529 | /** |
||
| 1530 | * @param string $icon |
||
| 1531 | * @return string |
||
| 1532 | */ |
||
| 1533 | public static function getDisableIcon($icon) |
||
| 1539 | |||
| 1540 | /** |
||
| 1541 | * @param int $id |
||
| 1542 | * @param array $values |
||
| 1543 | */ |
||
| 1544 | public static function updateTool($id, $values) |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * @param int $id |
||
| 1600 | */ |
||
| 1601 | public static function deleteIcon($id) |
||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * @param string $text |
||
| 1638 | * @param array $toolList |
||
| 1639 | * @return string |
||
| 1640 | */ |
||
| 1641 | public static function replaceTextWithToolUrls($text, $toolList) |
||
| 1665 | |||
| 1666 | /** |
||
| 1667 | * Available tools |
||
| 1668 | * @return array |
||
| 1669 | */ |
||
| 1670 | public static function availableTools() |
||
| 1696 | } |
||
| 1697 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.