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