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