From 8f1955a18236dd8d67696695618d83c88ce420b5 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 31 May 2017 17:44:20 -0500 Subject: [PATCH] Improve code for show course tool items - refs BT#12756 Improve code for show course tool items - refs BT#12756 Fix fatall error about CourseHome::formatToolItems - refs BT#12756 --- main/inc/lib/course_home.lib.php | 170 +++++++++++++++++-------------- 1 file changed, 95 insertions(+), 75 deletions(-) diff --git a/main/inc/lib/course_home.lib.php b/main/inc/lib/course_home.lib.php index cbe15bae08..874ea64d02 100755 --- a/main/inc/lib/course_home.lib.php +++ b/main/inc/lib/course_home.lib.php @@ -996,87 +996,107 @@ class CourseHome } // end of foreach } - $i = 0; + return self::formatToolItems($items); + } + + /** + * Get buttons to course tools + * @param array $items + * @return string + */ + public static function formatToolItems(array $items) + { + $theme = api_get_setting('homepage_view'); $html = ''; - if (!empty($items)) { - foreach ($items as $item) { - switch ($theme) { - case 'activity_big': - $data = ''; - $html .= '
'; - $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png'; - $toolIid = isset($item['tool']['iid']) ? $item['tool']['iid'] : null; - - if (isset($item['tool']['custom_image'])) { - $original_image = Display::img( - $item['tool']['custom_image'], - $item['name'], - array('id' => 'toolimage_'.$toolIid) - ); - } elseif (isset($item['tool']['custom_icon']) && - !empty($item['tool']['custom_icon']) - ) { - $customIcon = $item['tool']['custom_icon']; - if ($item['tool']['visibility'] == '0') { - $customIcon = self::getDisableIcon($item['tool']['custom_icon']); - } - $original_image = Display::img( - self::getCustomWebIconPath().$customIcon, - $item['name'], - array('id' => 'toolimage_'.$toolIid) - ); - } else { - $original_image = Display::return_icon( - $image, - $item['name'], - array('id' => 'toolimage_'.$toolIid), - ICON_SIZE_BIG, - false - ); - } + if (empty($items)) { + return $html; + } - $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']); - $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection - $html .= Display::div('

'.$item['visibility'].$item['extra'].$item['link'].'

', array('class' => 'content')); - $html .= '
'; - - break; - case 'activity': - $html .= '
'; - $html .= $item['extra']; - $html .= $item['visibility']; - $html .= $item['icon']; - $html .= $item['link']; - $html .= '
'; - break; - case 'vertical_activity': - if ($i == 0) { - $html .= ''; - } - break; + $image, + $item['name'], + array('id' => 'toolimage_'.$toolIid), + ICON_SIZE_BIG, + false + ); + } + + $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']); + + $html .= '
' + .Display::div($data, array('class' => 'big_icon')) + .Display::div( + '

'.$item['visibility'].$item['extra'].$item['link'].'

', + array('class' => 'content') + ) + .'
'; } - $i++; - } + break; + case 'activity': + foreach ($items as $item) { + $html .= '
' + .$item['extra'] + .$item['visibility'] + .$item['icon'] + .$item['link'] + .'
'; + } + break; + case 'vertical_activity': + $i = 0; + foreach ($items as $item) { + $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png'; + $original_image = Display::return_icon( + $image, + $item['name'], + array('id' => 'toolimage_'.$item['tool']['iid']), + ICON_SIZE_SMALL, + false + ); + + if ($i == 0) { + $html .= ''; + } + + $i++; + } + break; } return $html;