Add LP icon code see BT#15162

pull/2798/head
Julio Montoya 7 years ago
parent d9e1b86e81
commit 747000f776
  1. 117
      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);
}
}

Loading…
Cancel
Save