added new class mod_roomReservationControl (a abstract class for user defined control...
authorrohieb <devnull@localhost>
Fri, 25 Jul 2008 02:33:27 +0000 (04:33 +0200)
committerrohieb <devnull@localhost>
Fri, 25 Jul 2008 02:33:27 +0000 (04:33 +0200)
includes/mod_roomReservationControl.inc [new file with mode: 0644]
includes/mod_roomReservationTimesliceListBox.inc

diff --git a/includes/mod_roomReservationControl.inc b/includes/mod_roomReservationControl.inc
new file mode 100644 (file)
index 0000000..3806137
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+/**\r
+ * @file mod_roomReservationControl.inc\r
+ * Class that represents an abstract control\r
+ * @author Roland Hieber (roland.hieber@wilhelm-gym.net)\r
+ * @date 25.07.2008\r
+ * \r
+ * Copyright © 2007 Roland Hieber\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ * THE SOFTWARE.\r
+ */\r
+\r
+/** @todo document */
+abstract class mod_roomReservationControl {
+  /** (array of strings) Errors that occur while processing the form */ 
+  protected $asMessages;
+  /** (mod_roomReservationConfig) Reference to the configuration object */
+  protected $oCfg;
+  
+  /***************************************************************************/
+  /**
+   * @name Constructor
+   * @{
+   * Constructor
+   * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
+   *  configuration
+   * @return mod_roomReservationBookingTable
+   */
+  public function __construct(mod_roomReservationConfig &$oCfg) {
+    rrAddCss(".blue .treeview .err { color:red !important; }");
+    $this->oCfg = $oCfg;
+    $this->processRequestVariables();
+  }
+  /***************************************************************************/
+  /**
+   * @}
+   * @name Initialization
+   * @{
+   */
+
+  /**
+   * Process the REQUEST variables and preset the some variables
+   * @return void
+   */
+  protected function processRequestVariables() { }
+  
+  /***************************************************************************/
+  /**
+   * @}
+   * @name Output
+   * @{
+   */
+
+  /**
+   * Get the messages that have been produced. Returns HTML.
+   * @return string
+   */
+  protected function getMessages() {
+    if(count($this->asMessages) > 0) {
+      return sprintf("<div class='err'>%s</p>\n",
+        nl2br(q(join("\n", $this->asMessages))));
+    }
+  }
+
+  /**
+   * Show the beginning of the control.
+   * @return void
+   */
+  protected function beginShow() { }
+  
+  /**
+   * Show the control. Override this function to print your HTML code.
+   * @return void
+   */
+  protected abstract function doShow();
+  
+  /**
+   * Show the end of the control.
+   * @return void
+   */
+  protected function endShow() { }
+
+  /**
+   * Show the full control. You don't need to override this function. Instead,
+   * override doShow(). 
+   * @return void
+   */
+  public function show() {
+    $this->beginShow();
+    $this->doShow();
+    $this->endShow();
+  }
+}
+?>
\ No newline at end of file
index 595ed61..6928a33 100644 (file)
@@ -27,6 +27,7 @@
  */\r
 
 require_once("ctrl.inc");
+require_once("mod_room-reservation/mod_roomReservationControl.inc");
 require_once("mod_room-reservation/mod_roomReservationTimeslice.inc");
 
 /*****************************************************************************/
@@ -48,10 +49,8 @@ define("MOD_ROOM_RESERVATION_TLB_ACTION_DELETE", 2);
 /** @} */
 \r
 /** @todo document, add a delete confirmation */
-class mod_roomReservationTimesliceListBox /* extends mclControl */ {
+class mod_roomReservationTimesliceListBox  extends mod_roomReservationControl {
   
-  /** (mod_roomReservationConfig) Reference to the configuration object */
-  protected $oCfg;
   /** 
    * (constant) The action to be done (GET data).
    * See @ref timeslicelistbox_actions.
@@ -61,8 +60,6 @@ class mod_roomReservationTimesliceListBox /* extends mclControl */ {
   protected $sNewBegin;
   /** (string) The ending for a new timeslice (GET data) */
   protected $sNewEnd;
-  /** (array of strings) Errors that occur while processing the form */ 
-  protected $asFormErrors;
   
   /***************************************************************************/
   /**
@@ -71,12 +68,10 @@ class mod_roomReservationTimesliceListBox /* extends mclControl */ {
    * Constructor
    * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
    *  configuration
-   * @return mod_roomReservationBookingTable
+   * @return mod_roomReservationTimesliceListBox
    */
   public function __construct(mod_roomReservationConfig &$oCfg) {
-    $this->oCfg = $oCfg;
-   
-    $this->processRequestVariables();
+    parent::__construct($oCfg);
   }
  
   /***************************************************************************/
@@ -118,12 +113,12 @@ class mod_roomReservationTimesliceListBox /* extends mclControl */ {
       
       // Note: we want to handle the timestamps in GMT format, hence the "+0000"
       if(strtotime($this->getNewBegin()." +0000") === false) {
-        $this->asFormErrors[] = _c("room-reservation:The beginning time is ".
+        $this->asMessages[] = _c("room-reservation:The beginning time is ".
                "invalid.");
         $bErrors = true;
       }
       if(strtotime($this->getNewEnd()." +0000") === false) {
-        $this->asFormErrors[] = _c("room-reservation:The ending time is ".
+        $this->asMessages[] = _c("room-reservation:The ending time is ".
                "invalid.");
         $bErrors = true;
       }
@@ -137,7 +132,7 @@ class mod_roomReservationTimesliceListBox /* extends mclControl */ {
           $this->setNewBegin("");
           $this->setNewEnd("");
         } catch(Exception $e) {
-          $this->asFormErrors[] = $e->getMessage();
+          $this->asMessages[] = $e->getMessage();
         }
       }
       
@@ -210,20 +205,22 @@ class mod_roomReservationTimesliceListBox /* extends mclControl */ {
    */
   
   /**
-   * Show the control
+   * Actually show the control
    * @return void
    */
-  public function show() {
+  public function doShow() {
     TreeView(array(_c("room-reservation:Begin"), _c("room-reservation:End")));
 
     // addition form
     printf("<form method='get'>");
     hidden("mod_roomReservationTimesliceListBox[action]", "add");
     TreeViewTitle(_("Add"));
-    if(count($this->asFormErrors) > 0) {
-      TreeViewLine(sprintf("<div class='err' style='color:red;'>%s</div>", 
-        nl2br(q(trim(join("\n", $this->asFormErrors))))));
+    
+    $sMessages = $this->getMessages();
+    if(trim($sMessages) != "") {
+      TreeViewLine($sMessages);
     }
+    
     TreeViewLine(array(sprintf("<%s name='mod_roomReservationTimesliceListBox".
        "[begin]' value='%s' size='8'/>", $GLOBALS["stdedt"], 
       $this->getNewBegin()), sprintf("<%s name='".
This page took 0.030004 seconds and 4 git commands to generate.