From 747000f7767a7e76ded739963d6d6d91b740e7f7 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 14 Jan 2019 15:35:41 +0100 Subject: [PATCH] Add LP icon code see BT#15162 --- main/lp/learnpath.class.php | 117 ++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index c3e8dd4e59..94690b2f9d 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -13982,6 +13982,64 @@ EOD; return (int) $row['total']; } + /** + * In order to use the lp icon option you need to create the "lp_icon" LP extra field + * and put the images in. + * + * @return array + */ + public static function getIconSelect() + { + $theme = api_get_visual_theme(); + $path = api_get_path(SYS_PUBLIC_PATH).'css/themes/'.$theme.'/lp_icons/'; + $icons = ['' => get_lang('SelectAnOption')]; + + if (is_dir($path)) { + $finder = new Finder(); + $finder->files()->in($path); + $allowedExtensions = ['jpeg', 'jpg', 'png']; + /** @var SplFileInfo $file */ + foreach ($finder as $file) { + if (in_array(strtolower($file->getExtension()), $allowedExtensions)) { + $icons[$file->getFilename()] = $file->getFilename(); + } + } + } + + return $icons; + } + + /** + * @param int $lpId + * + * @return string + */ + public static function getSelectedIcon($lpId) + { + $extraFieldValue = new ExtraFieldValue('lp'); + $lpIcon = $extraFieldValue->get_values_by_handler_and_field_variable($lpId, 'lp_icon'); + $icon = ''; + if (!empty($lpIcon) && isset($lpIcon['value'])) { + $icon = $lpIcon['value']; + } + + return $icon; + } + + public static function getSelectedIconHtml($lpId) + { + $icon = self::getSelectedIcon($lpId); + + if (empty($icon)) { + return ''; + } + + $theme = api_get_visual_theme(); + $path = api_get_path(WEB_PUBLIC_PATH).'css/themes/'.$theme.'/lp_icons/'.$icon; + + return Display::img($path); + } + /** * Get the depth level of LP item. * @@ -14086,63 +14144,4 @@ EOD; return ''; } - - /** - * In order to use the lp icon option you need to create the "lp_icon" LP extra field - * and put the images in - * - * @return array - */ - public static function getIconSelect() - { - $theme = api_get_visual_theme(); - $path = api_get_path(SYS_PUBLIC_PATH).'css/themes/'.$theme.'/lp_icons/'; - $icons = ['' => get_lang('SelectAnOption')]; - - if (is_dir($path)) { - $finder = new Finder(); - $finder->files()->in($path); - $allowedExtensions = ['jpeg', 'jpg', 'png']; - /** @var SplFileInfo $file */ - foreach ($finder as $file) { - if (in_array(strtolower($file->getExtension()), $allowedExtensions)) { - $icons[$file->getFilename()] = $file->getFilename(); - } - } - } - - return $icons; - } - - /** - * @param int $lpId - * - * @return string - */ - public static function getSelectedIcon($lpId) - { - $extraFieldValue = new ExtraFieldValue('lp'); - $lpIcon = $extraFieldValue->get_values_by_handler_and_field_variable($lpId, 'lp_icon'); - $icon = ''; - if (!empty($lpIcon) && isset($lpIcon['value'])) { - $icon = $lpIcon['value']; - } - - return $icon; - } - - public static function getSelectedIconHtml($lpId) - { - $icon = self::getSelectedIcon($lpId); - - if (empty($icon)) { - return ''; - } - - $theme = api_get_visual_theme(); - $path = api_get_path(WEB_PUBLIC_PATH).'css/themes/'.$theme.'/lp_icons/'.$icon; - - return Display::img($path); - - } }