mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-09 11:08:34 +01:00
add photos in category banner (#28221)
This commit is contained in:
@@ -1645,6 +1645,36 @@ class Categorie extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return if at least one photo is available
|
||||||
|
*
|
||||||
|
* @param string $sdir Directory to scan
|
||||||
|
* @return boolean True if at least one photo is available, False if not
|
||||||
|
*/
|
||||||
|
public function isAnyPhotoAvailable($sdir)
|
||||||
|
{
|
||||||
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
||||||
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
|
||||||
|
|
||||||
|
$sdir .= '/' . get_exdir($this->id, 2, 0, 0, $this, 'category') . $this->id . "/photos/";
|
||||||
|
|
||||||
|
$dir_osencoded = dol_osencode($sdir);
|
||||||
|
if (file_exists($dir_osencoded)) {
|
||||||
|
$handle = opendir($dir_osencoded);
|
||||||
|
if (is_resource($handle)) {
|
||||||
|
while (($file = readdir($handle)) !== false) {
|
||||||
|
if (!utf8_check($file)) {
|
||||||
|
$file = mb_convert_encoding($file, 'UTF-8', 'ISO-8859-1'); // To be sure data is stored in UTF8 in memory
|
||||||
|
}
|
||||||
|
if (dol_is_file($sdir . $file) && image_format_supported($file) >= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getTooltipContentArray
|
* getTooltipContentArray
|
||||||
* @param array $params params to construct tooltip data
|
* @param array $params params to construct tooltip data
|
||||||
@@ -1755,7 +1785,7 @@ class Categorie extends CommonObject
|
|||||||
if (file_exists($dir)) {
|
if (file_exists($dir)) {
|
||||||
if (is_array($file['name']) && count($file['name']) > 0) {
|
if (is_array($file['name']) && count($file['name']) > 0) {
|
||||||
$nbfile = count($file['name']);
|
$nbfile = count($file['name']);
|
||||||
for ($i = 0; $i <= $nbfile; $i++) {
|
for ($i = 0; $i < $nbfile; $i++) {
|
||||||
$originImage = $dir.$file['name'][$i];
|
$originImage = $dir.$file['name'][$i];
|
||||||
|
|
||||||
// Cree fichier en taille origine
|
// Cree fichier en taille origine
|
||||||
|
|||||||
@@ -9051,7 +9051,8 @@ abstract class CommonObject
|
|||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$file = ''; $originalfile = '';
|
$file = '';
|
||||||
|
$originalfile = '';
|
||||||
$newmodulepart = $modulepart;
|
$newmodulepart = $modulepart;
|
||||||
if ($modulepart == 'unknown' && !empty($this->module)) {
|
if ($modulepart == 'unknown' && !empty($this->module)) {
|
||||||
$newmodulepart = $this->module;
|
$newmodulepart = $this->module;
|
||||||
@@ -9124,6 +9125,10 @@ abstract class CommonObject
|
|||||||
$pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/";
|
$pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($modulepart == 'category') {
|
||||||
|
$dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/";
|
||||||
|
$pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/";
|
||||||
|
}
|
||||||
|
|
||||||
// Defined relative dir to DOL_DATA_ROOT
|
// Defined relative dir to DOL_DATA_ROOT
|
||||||
$relativedir = '';
|
$relativedir = '';
|
||||||
|
|||||||
@@ -2414,6 +2414,26 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
|
|||||||
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" title="'.dol_escape_htmltag($langs->trans("UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv("Documents"))).'" alt="No photo"'.($width ? ' style="width: '.$width.'px"' : '').' src="'.DOL_URL_ROOT.$nophoto.'"></div>';
|
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" title="'.dol_escape_htmltag($langs->trans("UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv("Documents"))).'" alt="No photo"'.($width ? ' style="width: '.$width.'px"' : '').' src="'.DOL_URL_ROOT.$nophoto.'"></div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} elseif ($object->element == 'category') {
|
||||||
|
/** @var Categorie $object */
|
||||||
|
$width = 80;
|
||||||
|
$cssclass = 'photowithmargin photoref';
|
||||||
|
$showimage = $object->isAnyPhotoAvailable($conf->categorie->multidir_output[$entity]);
|
||||||
|
$maxvisiblephotos = getDolGlobalInt('CATEGORY_MAX_VISIBLE_PHOTO', 5);
|
||||||
|
if ($conf->browser->layout == 'phone') {
|
||||||
|
$maxvisiblephotos = 1;
|
||||||
|
}
|
||||||
|
if ($showimage) {
|
||||||
|
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos('category', $conf->categorie->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0, '').'</div>';
|
||||||
|
} else {
|
||||||
|
if (getDolGlobalString('CATEGORY_NODISPLAYIFNOPHOTO')) {
|
||||||
|
$nophoto = '';
|
||||||
|
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
|
||||||
|
} else { // Show no photo link
|
||||||
|
$nophoto = '/public/theme/common/nophoto.png';
|
||||||
|
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" title="'.dol_escape_htmltag($langs->trans("UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv("Documents"))).'" alt="No photo"'.($width ? ' style="width: '.$width.'px"' : '').' src="'.DOL_URL_ROOT.$nophoto.'"></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
} elseif ($object->element == 'bom') {
|
} elseif ($object->element == 'bom') {
|
||||||
/** @var Bom $object */
|
/** @var Bom $object */
|
||||||
$width = 80;
|
$width = 80;
|
||||||
@@ -2437,6 +2457,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
|
|||||||
} elseif ($object->element == 'ticket') {
|
} elseif ($object->element == 'ticket') {
|
||||||
$width = 80;
|
$width = 80;
|
||||||
$cssclass = 'photoref';
|
$cssclass = 'photoref';
|
||||||
|
/** @var Ticket $object */
|
||||||
$showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].'/'.$object->ref);
|
$showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].'/'.$object->ref);
|
||||||
$maxvisiblephotos = getDolGlobalInt('TICKET_MAX_VISIBLE_PHOTO', 2);
|
$maxvisiblephotos = getDolGlobalInt('TICKET_MAX_VISIBLE_PHOTO', 2);
|
||||||
if ($conf->browser->layout == 'phone') {
|
if ($conf->browser->layout == 'phone') {
|
||||||
|
|||||||
Reference in New Issue
Block a user