Przeglądaj źródła

Refactor code, remove repetitive code into a single function

Julio 6 lat temu
rodzic
commit
ddac454615

+ 1 - 22
main/inc/lib/formvalidator/Element/DatePicker.php

@@ -80,28 +80,7 @@ class DatePicker extends HTML_QuickForm_text
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
-
-        if (empty($size)) {
-            $sizeTemp = $this->getInputSize();
-            if (empty($size)) {
-                $sizeTemp = 8;
-            }
-            $size = [2, $sizeTemp, 2];
-        } else {
-            if (is_array($size)) {
-                if (count($size) != 3) {
-                    $sizeTemp = $this->getInputSize();
-                    if (empty($size)) {
-                        $sizeTemp = 8;
-                    }
-                    $size = [2, $sizeTemp, 2];
-                }
-                // else just keep the $size array as received
-            } else {
-                $size = [2, (int) $size, 2];
-            }
-        }
+        $size = $this->calculateSize();
 
         switch ($layout) {
             case FormValidator::LAYOUT_INLINE:

+ 1 - 22
main/inc/lib/formvalidator/Element/DateTimePicker.php

@@ -79,28 +79,7 @@ class DateTimePicker extends HTML_QuickForm_text
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
-
-        if (empty($size)) {
-            $sizeTemp = $this->getInputSize();
-            if (empty($size)) {
-                $sizeTemp = 8;
-            }
-            $size = [2, $sizeTemp, 2];
-        } else {
-            if (is_array($size)) {
-                if (count($size) != 3) {
-                    $sizeTemp = $this->getInputSize();
-                    if (empty($size)) {
-                        $sizeTemp = 8;
-                    }
-                    $size = [2, $sizeTemp, 2];
-                }
-                // else just keep the $size array as received
-            } else {
-                $size = [2, (int) $size, 2];
-            }
-        }
+        $size = $this->calculateSize();
 
         switch ($layout) {
             case FormValidator::LAYOUT_INLINE:

+ 1 - 23
main/inc/lib/formvalidator/Element/DateTimeRangePicker.php

@@ -53,29 +53,7 @@ class DateTimeRangePicker extends DateRangePicker
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
-
-        if (empty($size)) {
-            $sizeTemp = $this->getInputSize();
-            if (empty($size)) {
-                $sizeTemp = 8;
-            }
-            $size = [2, $sizeTemp, 2];
-        } else {
-            if (is_array($size)) {
-                if (count($size) != 3) {
-                    $sizeTemp = $this->getInputSize();
-                    if (empty($size)) {
-                        $sizeTemp = 8;
-                    }
-                    $size = [2, $sizeTemp, 2];
-                }
-                // else just keep the $size array as received
-            } else {
-                $size = [2, (int) $size, 2];
-            }
-        }
-
+        $size = $this->calculateSize();
         $id = $this->getAttribute('id');
 
         switch ($layout) {

+ 1 - 16
main/inc/lib/pear/HTML/QuickForm/button.php

@@ -210,24 +210,9 @@ class HTML_QuickForm_button extends HTML_QuickForm_input
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
+        $size = $this->calculateSize();
         $attributes = $this->getAttributes();
 
-        if (empty($size)) {
-            $size = array(2, 8, 2);
-        } else {
-            if (is_array($size)) {
-                if (count($size) == 1) {
-                    $size = array(2, intval($size[0]), 2);
-                } elseif (count($size) != 3) {
-                    $size = array(2, 8, 2);
-                }
-                // else just keep the $size array as received
-            } else {
-                $size = array(2, intval($size), 2);
-            }
-        }
-
         switch ($layout) {
             case FormValidator::LAYOUT_INLINE:
                 return '

+ 1 - 16
main/inc/lib/pear/HTML/QuickForm/checkbox.php

@@ -163,22 +163,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
-
-        if (empty($size)) {
-            $size = array(2, 8, 2);
-        } else {
-            if (is_array($size)) {
-                if (count($size) == 1) {
-                    $size = array(2, intval($size[0]), 2);
-                } elseif (count($size) != 3) {
-                    $size = array(2, 8, 2);
-                }
-                // else just keep the $size array as received
-            } else {
-                $size = array(2, intval($size), 2);
-            }
-        }
+        $size = $this->calculateSize();
 
         switch ($layout) {
             case FormValidator::LAYOUT_INLINE:

+ 50 - 0
main/inc/lib/pear/HTML/QuickForm/element.php

@@ -39,6 +39,7 @@ class HTML_QuickForm_element extends HTML_Common
     private $icon;
     private $template;
     private $customFrozenTemplate = '';
+    protected $inputSize;
 
     /**
      * Label of the field
@@ -584,4 +585,53 @@ class HTML_QuickForm_element extends HTML_Common
 
         return $this;
     }
+
+
+
+    /**
+     * @return null
+     */
+    public function getInputSize()
+    {
+        return $this->inputSize;
+    }
+
+    /**
+     * @param null $inputSize
+     */
+    public function setInputSize($inputSize)
+    {
+        $this->inputSize = $inputSize;
+    }
+
+    /**
+     * @return array|null
+     */
+    public function calculateSize()
+    {
+        $size = $this->getColumnsSize();
+
+        if (empty($size)) {
+            $sizeTemp = $this->getInputSize();
+            if (empty($size)) {
+                $sizeTemp = 8;
+            }
+            $size = array(2, $sizeTemp, 2);
+        } else {
+            if (is_array($size)) {
+                if (count($size) != 3) {
+                    $sizeTemp = $this->getInputSize();
+                    if (empty($size)) {
+                        $sizeTemp = 8;
+                    }
+                    $size = array(2, $sizeTemp, 2);
+                }
+            } else {
+                // else just keep the $size array as received
+                $size = array(2, (int) $size, 2);
+            }
+        }
+
+        return $size;
+    }
 }

+ 1 - 16
main/inc/lib/pear/HTML/QuickForm/group.php

@@ -536,22 +536,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
-
-        if (empty($size)) {
-            $size = array(2, 8, 2);
-        } else {
-            if (is_array($size)) {
-                if (count($size) == 1) {
-                    $size = array(2, intval($size[0]), 2);
-                } elseif (count($size) != 3) {
-                    $size = array(2, 8, 2);
-                }
-                // else just keep the $size array as received
-            } else {
-                $size = array(2, intval($size), 2);
-            }
-        }
+        $size = $this->calculateSize();
 
         switch ($layout) {
             case FormValidator::LAYOUT_INLINE:

+ 0 - 50
main/inc/lib/pear/HTML/QuickForm/input.php

@@ -33,8 +33,6 @@
  */
 class HTML_QuickForm_input extends HTML_QuickForm_element
 {
-    protected $inputSize;
-
     /**
      * Class constructor
      *
@@ -114,54 +112,6 @@ class HTML_QuickForm_input extends HTML_QuickForm_element
         return $this->getAttribute('value');
     }
 
-
-    /**
-     * @return null
-     */
-    public function getInputSize()
-    {
-        return $this->inputSize;
-    }
-
-    /**
-     * @param null $inputSize
-     */
-    public function setInputSize($inputSize)
-    {
-        $this->inputSize = $inputSize;
-    }
-
-    /**
-     * @return array|null
-     */
-    public function calculateSize()
-    {
-        $size = $this->getColumnsSize();
-
-        if (empty($size)) {
-            $sizeTemp = $this->getInputSize();
-            if (empty($size)) {
-                $sizeTemp = 8;
-            }
-            $size = array(2, $sizeTemp, 2);
-        } else {
-            if (is_array($size)) {
-                if (count($size) != 3) {
-                    $sizeTemp = $this->getInputSize();
-                    if (empty($size)) {
-                        $sizeTemp = 8;
-                    }
-                    $size = array(2, $sizeTemp, 2);
-                }
-            } else {
-                // else just keep the $size array as received
-                $size = array(2, (int) $size, 2);
-            }
-        }
-
-        return $size;
-    }
-
     /**
      * Returns the input field in HTML
      *

+ 1 - 16
main/inc/lib/pear/HTML/QuickForm/select.php

@@ -586,22 +586,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
-
-        if (empty($size)) {
-            $size = array(2, 8, 2);
-        } else {
-            if (is_array($size)) {
-                if (count($size) == 1) {
-                    $size = array(2, intval($size[0]), 2);
-                } elseif (count($size) != 3) {
-                    $size = array(2, 8, 2);
-                }
-                // else just keep the $size array as received
-            } else {
-                $size = array(2, intval($size), 2);
-            }
-        }
+        $size = $this->calculateSize();
 
         switch ($layout) {
             case FormValidator::LAYOUT_INLINE: