<?php
namespace App\Smarty\Functions; class BankLabel { static public function create($params, $smarty) { $defaultOutput = ''; if ($params['default']) { $defaultOutput = $params['default']; } if (is_object($params['ref']) and get_class($params['ref'])=='Entity\Bank') { $bank = $params['ref']; } elseif ( is_numeric($params['ref']) and $params['ref']>0 ) { $bank = \Entity\Bank::select($params['ref']); if (!$bank->recordExists()) { return $defaultOutput; } } else { return $defaultOutput; } if ($params['assign']) { $smarty->assign($params['assign'], $bank); return ''; } if (!$params['format']) { if ($params['hideLink']) { return $bank->name ? $bank->name : $defaultOutput; } else { return sprintf("<span class=\"remoteLoadLink\" onclick=\"RemoteLoad.loadEntity(this, '%s', '%s');\">%s</span>", 'bank', $bank->getId(), ($bank->name ? $bank->name : $defaultOutput) ); } } else { $replaceArray = []; $replaceArray['%name%'] = $bank->name; $replaceArray['%name2%'] = $bank->name2; $replaceArray['%nameStandard%'] = $bank->nameStandard; $replaceArray['%nameLocal%'] = $bank->nameLocal; $replaceArray['%code%'] = $bank->code; return str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); } } }