]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/class_BaseHelper.php
More conventions than code added:
[shipsimu.git] / inc / classes / main / helper / class_BaseHelper.php
index adb1f0145301e409b01635409bb13bf355516fb2..bd27e03df04ed591089896ac4e9908d5a4505aa4 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @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
  *
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseHelper extends BaseFrameworkSystem {
-       // Exception constants
-       const EXCEPTION_XML_PARSER_ERROR  = 0x1e0;
-       const EXCEPTION_XML_NODE_UNKNOWN  = 0x1e1;
-       const EXCEPTION_XML_NODE_MISMATCH = 0x1e2;
-
        /**
         * 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
         *
@@ -65,6 +70,77 @@ class BaseHelper extends BaseFrameworkSystem {
        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]