public function testPerformanceTest() { $objLang = class_lang::getInstance(); $arrParameters = array("lorem", "ipsum", "dolor", "sit", "amet"); $strPropertyRaw = "lorem {0} ipsum {1} dolor {2} sit {3} amet {4} {0}"; $intStart = microtime(true); for ($intI = 0; $intI <= 100; $intI++) { $strProperty = $strPropertyRaw; foreach ($arrParameters as $intKey => $strParameter) { $strProperty = uniStrReplace("{" . $intKey . "}", $strParameter, $strProperty); } $this->assertEquals($strProperty, "lorem lorem ipsum ipsum dolor dolor sit sit amet amet lorem"); } $intEnd = microtime(true); echo "uniStrReplace: " . ($intEnd - $intStart) . " sec\n"; $intStart = microtime(true); for ($intI = 0; $intI <= 100; $intI++) { $strProperty = uniStrReplace(array_map(function ($i) { return "{" . $i . "}"; }, array_keys($arrParameters)), $arrParameters, $strPropertyRaw); $this->assertEquals($strProperty, "lorem lorem ipsum ipsum dolor dolor sit sit amet amet lorem"); } $intEnd = microtime(true); echo "array based uniStrReplace: " . ($intEnd - $intStart) . " sec\n"; $intStart = microtime(true); for ($intI = 0; $intI <= 100; $intI++) { $strProperty = preg_replace_callback("/{(\\d)}/", function ($hit) use($arrParameters) { return $arrParameters[$hit[1]]; }, $strPropertyRaw); $this->assertEquals($strProperty, "lorem lorem ipsum ipsum dolor dolor sit sit amet amet lorem"); } $intEnd = microtime(true); echo "preg_replace based : " . ($intEnd - $intStart) . " sec\n"; $intStart = microtime(true); for ($intI = 0; $intI <= 100; $intI++) { $strProperty = $objLang->replaceParams($strPropertyRaw, $arrParameters); $this->assertEquals($strProperty, "lorem lorem ipsum ipsum dolor dolor sit sit amet amet lorem"); } $intEnd = microtime(true); echo "current implementation : " . ($intEnd - $intStart) . " sec\n"; }
/** * @param string $strTargetURI If you pass null, no form-tags will be rendered. * @param int $intButtonConfig a list of buttons to attach to the end of the form. if you need more then the obligatory save-button, * pass them combined by a bitwise or, e.g. class_admin_formgenerator::BIT_BUTTON_SAVE | class_admin_formgenerator::$BIT_BUTTON_CANCEL * * @throws class_exception * @return string */ public function renderForm($strTargetURI, $intButtonConfig = 2) { $strReturn = ""; //add a hidden systemid-field if ($this->objSourceobject != null) { $objField = new class_formentry_hidden($this->strFormname, "systemid"); $objField->setStrEntryName("systemid")->setStrValue($this->objSourceobject->getSystemid())->setObjValidator(new class_systemid_validator()); $this->addField($objField); } $objToolkit = class_carrier::getInstance()->getObjToolkit("admin"); if ($strTargetURI !== null) { $strReturn .= $objToolkit->formHeader($strTargetURI, "", $this->strFormEncoding, $this->strOnSubmit); } $strReturn .= $objToolkit->getValidationErrors($this); $strHidden = ""; foreach ($this->arrFields as $objOneField) { if (in_array($objOneField->getStrEntryName(), $this->arrHiddenElements)) { $strHidden .= $objOneField->renderField(); } else { $strReturn .= $objOneField->renderField(); } } if ($strHidden != "") { $strReturn .= $objToolkit->formOptionalElementsWrapper($strHidden, $this->strHiddenGroupTitle, $this->bitHiddenElementsVisible); } if ($intButtonConfig & self::BIT_BUTTON_SUBMIT) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_submit", "system"), "submitbtn"); } if ($intButtonConfig & self::BIT_BUTTON_SAVE) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_save", "system"), "submitbtn"); } if ($intButtonConfig & self::BIT_BUTTON_CANCEL) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_cancel", "system"), "cancelbtn"); } if ($intButtonConfig & self::BIT_BUTTON_CLOSE) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_close", "system"), "closebtn"); } if ($intButtonConfig & self::BIT_BUTTON_DELETE) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_delete", "system"), "deletebtn"); } if ($intButtonConfig & self::BIT_BUTTON_RESET) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_reset", "system"), "reset", "", "cancelbutton"); } if ($intButtonConfig & self::BIT_BUTTON_CONTINUE) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_continue", "system"), "continuebtn"); } if ($intButtonConfig & self::BIT_BUTTON_BACK) { $strReturn .= $objToolkit->formInputSubmit(class_lang::getInstance()->getLang("commons_back", "system"), "backbtn"); } if ($strTargetURI !== null) { $strReturn .= $objToolkit->formClose(); } if (count($this->arrFields) > 0) { reset($this->arrFields); do { $objField = current($this->arrFields); if (!$objField instanceof class_formentry_hidden && !$objField instanceof class_formentry_plaintext && !$objField instanceof class_formentry_headline && !$objField instanceof class_formentry_divider) { $strReturn .= $objToolkit->setBrowserFocus($objField->getStrEntryName()); break; } } while (next($this->arrFields) !== false); } //lock the record to avoid multiple edit-sessions - if in edit mode if ($this->objSourceobject != null && method_exists($this->objSourceobject, "getLockManager")) { $bitSkip = false; if ($this->getField("mode") != null && $this->getField("mode")->getStrValue() == "new") { $bitSkip = true; } if (!$bitSkip && !validateSystemid($this->objSourceobject->getSystemid())) { $bitSkip = true; } if (!$bitSkip) { if ($this->objSourceobject->getLockManager()->isAccessibleForCurrentUser()) { $this->objSourceobject->getLockManager()->lockRecord(); } else { $objUser = new class_module_user_user($this->objSourceobject->getLockManager()->getLockId()); throw new class_exception("Current record is already locked by user '" . $objUser->getStrDisplayName() . "'.\nCannot be locked for the current user", class_exception::$level_ERROR); } } } return $strReturn; }
/** * Generates a list of errors found by the form-validation * * @param class_admin_controller|class_admin_formgenerator $objCalling * @param string $strTargetAction * * @return string */ public function getValidationErrors($objCalling, $strTargetAction = null) { $strRendercode = ""; //render mandatory fields? if (method_exists($objCalling, "getRequiredFields") && is_callable(array($objCalling, "getRequiredFields"))) { if ($objCalling instanceof class_admin_formgenerator) { $arrFields = $objCalling->getRequiredFields(); } else { $strTempAction = $objCalling->getAction(); $objCalling->setAction($strTargetAction); $arrFields = $objCalling->getRequiredFields(); $objCalling->setAction($strTempAction); } if (count($arrFields) > 0) { $strRendercode .= "<script type=\"text/javascript\">\$(document).ready(function () {\r\n KAJONA.admin.forms.renderMandatoryFields(["; foreach ($arrFields as $strName => $strType) { $strRendercode .= "[ '" . $strName . "', '" . $strType . "' ], "; } $strRendercode .= " [] ]); });</script>"; } } $arrErrors = method_exists($objCalling, "getValidationErrors") ? $objCalling->getValidationErrors() : array(); if (count($arrErrors) == 0) { return $strRendercode; } $strTemplateID = $this->objTemplate->readTemplate("/elements.tpl", "error_container"); $strTemplateRowID = $this->objTemplate->readTemplate("/elements.tpl", "error_row"); $strRows = ""; $strRendercode .= "<script type=\"text/javascript\">\$(document).ready(function () {\r\n KAJONA.admin.forms.renderMissingMandatoryFields(["; foreach ($arrErrors as $strKey => $arrOneErrors) { foreach ($arrOneErrors as $strOneError) { $strRows .= $this->objTemplate->fillTemplate(array("field_errortext" => $strOneError), $strTemplateRowID); $strRendercode .= "[ '" . $strKey . "' ], "; } } $strRendercode .= " [] ]); });</script>"; $arrTemplate = array(); $arrTemplate["errorrows"] = $strRows; $arrTemplate["errorintro"] = class_lang::getInstance()->getLang("errorintro", "system"); return $this->objTemplate->fillTemplate($arrTemplate, $strTemplateID) . $strRendercode; }
/** * Managing access to the text object. Use ONLY this method to * get an instance! * * @return class_lang */ public function getObjLang() { //Do we have to generate the object? if ($this->objLang == null) { $this->objLang = class_lang::getInstance(); } return $this->objLang; }