* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class BaseHelper extends BaseFrameworkSystem { /** * Rendered content created by the helper class */ private $content = ""; /** * Instance to the class which provides field values */ private $valueInstance = null; // Exception constants const EXCEPTION_XML_PARSER_ERROR = 0x1e0; const EXCEPTION_XML_NODE_UNKNOWN = 0x1e1; const EXCEPTION_XML_NODE_MISMATCH = 0x1e2; /** * Protected constructor * * @param $className Real name of the class * @return void */ protected function __construct ($className) { // Call parent constructor parent::__construct($className); // Clean up a little $this->removeNumberFormaters(); $this->removeSystemArray(); } /** * Add content * * @param $newContent New content to add * @return void */ protected final function addContent ($newContent) { $this->content .= (string) trim($newContent)."\r\n"; } /** * Getter for content * * @return $content The rendered content by this helper */ protected final function getContent () { return $this->content; } /** * Assigns a field from the value instance with a template variable * * @param $fieldName Name of the field to assign * @return void */ public function assignField ($fieldName) { // Get the value from value instance $fieldValue = $this->getField($fieldName); // Add a group $this->getTemplateInstance()->setVariableGroup('values'); // Assign it with a template variable $this->getTemplateInstance()->addGroupVariable($fieldName, $fieldValue); } /** * Assigns a field from the value instance with a template variable but * parses its content through a given filter method of the value instance * * @param $fieldName Name of the field to assign * @param $filterMethod Method name to call of the value instance * @return void */ public function assignFieldWithFilter ($fieldName, $filterMethod) { // Get the value $fieldValue = $this->getField($fieldName); // Now filter it through the value through the filter method $filteredValue = call_user_func_array(array($this->valueInstance, "doFilter" . ucfirst($filterMethod)), array($fieldValue)); // Add a group $this->getTemplateInstance()->setVariableGroup('values'); // Assign it with a template variable $this->getTemplateInstance()->addGroupVariable($fieldName, $fieldValue); } /** * Pre-fetches field default values from the given registry key instance into this class * * @param $registryKey Registry key which holds an object with values * @return void * @throws NullPointerException If an instance from registry is null */ public function prefetchValueInstance ($registryKey) { // Get the required instance $this->valueInstance = Registry::getRegistry()->getInstance($registryKey); // Is the instance valid? if (is_null($this->valueInstance)) { // Throw an exception throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } // END - if } /** * Getter for direct field values * * @param $fieldName Name of the field we shall fetch * @return $fieldValue Value from field */ public function getField ($fieldName) { // Get the field value $fieldValue = call_user_func_array(array($this->valueInstance, 'getField'), array($fieldName)); // Return it return $fieldValue; } } // [EOF] ?>