]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/web/class_WebFormHelper.php
User profile form added
[shipsimu.git] / inc / classes / main / helper / web / class_WebFormHelper.php
index 293a6fc34c14efaeb9a4f85a00cee7e5026d3727..5debdda12b3dc07c83cd3350cd837b71126e1bb4 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class WebFormHelper extends BaseHelper {
+       /**
+        * Instance to the class which provides field values
+        */
+       private $valueInstance = null;
+
        /**
         * Wether the form tag is opened (keep at false or else your forms will
         * never work!)
@@ -98,6 +103,24 @@ class WebFormHelper extends BaseHelper {
                return $helperInstance;
        }
 
+       /**
+        * Pre-fetches field default values from the given registry key instance into this class
+        *
+        * @param       $registryKey
+        * @return      void
+        * @throws      NullPointerException    If an instance from registry is null
+        */
+       public function prefetchFieldValues ($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
+       }
+
        /**
         * Add the form tag or close it an already opened form tag
         *
@@ -164,8 +187,8 @@ class WebFormHelper extends BaseHelper {
         * Add a text input tag to the form or throw an exception if it is not yet
         * opened. The field's name will be set as id.
         *
-        * @param       $fieldName                      Input field name
-        * @param       $fieldValue                     Input default value (default: empty)
+        * @param       $fieldName              Input field name
+        * @param       $fieldValue             Input default value (default: empty)
         * @return      void
         * @throws      FormClosedException             If the form is not yet opened
         */
@@ -187,6 +210,21 @@ class WebFormHelper extends BaseHelper {
                $this->addContent($inputContent);
        }
 
+       /**
+        * Add a text input tag to the form with pre-loaded default value
+        *
+        * @param       $fieldName      Input field name
+        * @return      void
+        */
+       public function addInputTextFieldWithDefault ($fieldName) {
+               // Get the value from instance
+               $fieldValue = call_user_func_array(array($this->valueInstance, "getField"), array($fieldName));
+               //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."<br />\n";
+
+               // Add the text field
+               $this->addInputTextField($fieldName, $fieldValue);
+       }
+
        /**
         * Add a password input tag to the form or throw an exception if it is not
         * yet opened. The field's name will be set as id.
@@ -607,6 +645,36 @@ class WebFormHelper extends BaseHelper {
                return $isAllowed;
        }
 
+       /**
+        * Checks wether the email address change must be confirmed
+        *
+        * @return      $requireConfirm         Wether email change must be confirmed
+        */
+       public function ifEmailChangeRequireConfirmation () {
+               $requireConfirm = ($this->getConfigInstance()->readConfig('email_change_confirmation') == "Y");
+               return $requireConfirm;
+       }
+
+       /**
+        * Checks wether the rules has been updated
+        *
+        * @return      $rulesUpdated   Wether rules has been updated
+        */
+       public function ifRulesHaveChanged () {
+               /* @TODO Implement check if rules have been changed */
+               return false;
+       }
+
+       /**
+        * Checks wether email change is allowed
+        *
+        * @return      $emailChange    Wether changing email address is allowed
+        */
+       public function ifEmailChangeAllowed () {
+               $emailChange = ($this->getConfigInstance()->readConfig('email_change_allowed') == "Y");
+               return $emailChange;
+       }
+
        /**
         * Flushs the content out (not yet secured against open forms, etc.!) or
         * throw an exception if it is not yet closed
@@ -624,6 +692,20 @@ class WebFormHelper extends BaseHelper {
                // Send content to template engine
                $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent());
        }
+
+       /**
+        * 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]