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