<?php
namespace App\Smarty\Functions; class SupplierLabel { static public function create($params, $smarty) { $defaultOutput = ''; if ($params['default']) { $defaultOutput = $params['default']; } if (is_object($params['ref']) and get_class($params['ref'])=='Entity\Supplier') { $supp = $params['ref']; } elseif ( is_numeric($params['ref']) and $params['ref']>0 ) { $supp = \Entity\Supplier::select($params['ref']); if (!$supp->recordExists()) { return $defaultOutput; } } else { return $defaultOutput; } if ($params['assign']) { $smarty->assign($params['assign'], $supp); return ''; } if (!$params['format']) { $display = ''; if ($supp->alias) { $display = $supp->alias; } if (!$display) { $display = $defaultOutput; } if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Partners/Suppliers-remoteDetails') && !$params['hideLink']) { return sprintf("<span class=\"remoteLoadLink\" onclick=\"RemoteLoad.load(this, MVC.appUrl('RemoteData/InfoBox', '%s', { 'id': '%s'}), null); return false;\">%s</span>", 'supplier', $supp->getId(), $display); } else { return $display; } } else { $replaceArray = []; $replaceArray['%alias%']=$supp->alias; $replaceArray['%company%']=$supp->company; $replaceArray['%companyFull%']=trim($supp->companyPrefix.' '.$supp->company.' '.$supp->companySuffix); return str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); } } }