<?php
namespace App\Smarty\Functions; class CashBookDocumentLabel { static public function create($params, $smarty) { $defaultOutput = ''; if ($params['default']) { $defaultOutput = $params['default']; } if (is_object($params['ref']) and get_class($params['ref'])=='Entity\CashBookDocument') { $cashBookDocument = $params['ref']; } elseif ( is_numeric($params['ref']) and $params['ref']>0 ) { $cashBookDocument = \Entity\CashBookDocument::select($params['ref']); if (!$cashBookDocument->recordExists()) { return $defaultOutput; } } else { return $defaultOutput; } if ($params['assign']) { $smarty->assign($params['assign'], $cashBookDocument); return ''; } if (!$params['format']) { $title = "#{$cashBookDocument->getId()}"; } else { $replaceArray = []; $replaceArray['%number%'] = $cashBookDocument->number." / ".\Engine\DateTime::createFromIsoDate($cashBookDocument->date)->formatDateStd(); $title = str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); } if ($params['hideLink']) { return $title; } else { return sprintf("<span class=\"remoteLoadLink\" onclick=\"RemoteLoad.loadEntity(this, '%s', '%s')\">%s</span>", 'cashBookDocument', $cashBookDocument->getId(), $title); } } }