<?php
namespace App\Smarty\Functions; class ImportedServiceLabel { static public function create($params, $smarty) { $defaultOutput = ''; if ($params['default']) { $defaultOutput = $params['default']; } if (is_object($params['ref']) and get_class($params['ref'])=='Entity\ImportedService') { $service = $params['ref']; } elseif ( is_numeric($params['ref']) and $params['ref']>0 ) { $service = \Entity\ImportedService::select($params['ref']); if (!$service->recordExists()) { return $defaultOutput; } } else { return $defaultOutput; } if ($params['assign']) { $smarty->assign($params['assign'], $service); return ''; } if (!$params['format']) { if ($params['hideLink']) return ($service->getId()?sprintf("#%s", $service->getId()):$defaultOutput); else { return sprintf("<span class=\"remoteLoadLink\" onclick=\"RemoteLoad.loadEntity(this, '%s', '%s');\">%s</span>", 'importedService', $service->getId(), ($service->getId()?sprintf("#%s", $service->getId()):$defaultOutput)); } } else { $replaceArray = []; $replaceArray['%idServiceExtSys%'] = $service->idServiceExtSys; $replaceArray['%offerConfirmationNumber%'] = $service->offerConfirmationNumber; $replaceArray['%offerExternalSystemReservationId%'] = $service->offerExternalSystemReservationId; $replaceArray['%offerExternalSystemReservationDate%'] = $service->offerExternalSystemReservationDate; if ($params['hideLink']) return str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); else { $defaultOutput = str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); return sprintf("<span class=\"remoteLoadLink\" onclick=\"RemoteLoad.loadEntity(this, '%s', '%s');\">%s</span>", 'importedService', $service->getId(), $defaultOutput); } } } }