<?php
namespace App\Smarty\Functions; class DepartmentLabel { static public function create($params, $smarty) { $defaultOutput = ''; if ($params['default']) { $defaultOutput = $params['default']; } if (is_object($params['ref']) and get_class($params['ref'])=='Entity\Department') { $department = $params['ref']; } elseif ( is_numeric($params['ref']) and $params['ref']>0 ) { $department = \Entity\Department::select($params['ref']); if (!$department->recordExists()) { return $defaultOutput; } } else { return $defaultOutput; } if ($params['assign']) { $smarty->assign($params['assign'], $department); return ''; } if (!$params['format']) { return $department->name ? $department->name : $defaultOutput; } else { $replaceArray = []; $replaceArray['%name%'] = $department->name; $replaceArray['%code%'] = $department->code; return str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); } } }