فهرست منبع

Minor - format code

jmontoyaa 7 سال پیش
والد
کامیت
8f8d3f9cb8
2فایلهای تغییر یافته به همراه127 افزوده شده و 113 حذف شده
  1. 30 15
      main/inc/lib/system/session.class.php
  2. 97 98
      main/inc/lib/table_sort.class.php

+ 30 - 15
main/inc/lib/system/session.class.php

@@ -13,18 +13,29 @@ namespace System;
  */
 class Session implements \ArrayAccess
 {
-
-    static function read($variable, $default = null)
+    /**
+     * @param string $variable
+     * @param null $default
+     * @return null
+     */
+    public static function read($variable, $default = null)
     {
         return isset($_SESSION[$variable]) ? $_SESSION[$variable] : $default;
     }
 
-    static function write($variable, $value)
+    /**
+     * @param string $variable
+     * @param string $value
+     */
+    public static function write($variable, $value)
     {
         $_SESSION[$variable] = $value;
     }
 
-    static function erase($variable)
+    /**
+     * @param string $variable
+     */
+    public static function erase($variable)
     {
         $variable = (string) $variable;
         if (isset($GLOBALS[$variable])) {
@@ -41,19 +52,22 @@ class Session implements \ArrayAccess
      * @param string $variable
      * @return mixed value
      */
-    static function has($variable)
+    public static function has($variable)
     {
         return isset($_SESSION[$variable]);
     }
 
-    static function clear()
+    /**
+     * Clear session
+     */
+    public static function clear()
     {
         session_regenerate_id();
         session_unset();
         $_SESSION = array();
     }
 
-    static function destroy()
+    public static function destroy()
     {
         session_unset();
         $_SESSION = array();
@@ -63,7 +77,6 @@ class Session implements \ArrayAccess
     /*
      * ArrayAccess
      */
-
     public function offsetExists($offset)
     {
         return isset($_SESSION[$offset]);
@@ -92,15 +105,17 @@ class Session implements \ArrayAccess
     }
 
     /**
-     * Magical methods
-     *
+     * @param string $name
      */
-
     public function __unset($name)
     {
         unset($_SESSION[$name]);
     }
 
+    /**
+     * @param string $name
+     * @return mixed
+     */
     public function __isset($name)
     {
         return self::has($name);
@@ -111,10 +126,10 @@ class Session implements \ArrayAccess
      * If offset does not exists returns null. Do not trigger a warning.
      *
      * @param string $name
-     * @return any
+     * @return mixed
      *
      */
-    function __get($name)
+    public function __get($name)
     {
         return self::read($name);
     }
@@ -122,9 +137,9 @@ class Session implements \ArrayAccess
     /**
      *
      * @param string $name
-     * @param any $value
+     * @param mixed $value
      */
-    function __set($name, $value)
+    public function __set($name, $value)
     {
         self::write($name, $value);
     }

+ 97 - 98
main/inc/lib/table_sort.class.php

@@ -1,9 +1,10 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
- *	This is a library with some functions to sort tabular data
+ * This is a library with some functions to sort tabular data
  *
- *	@package chamilo.library
+ * @package chamilo.library
  */
 
 define('SORT_DATE', 3);
@@ -24,7 +25,7 @@ class TableSort
     * @return array The sorted dataset
     * @author bart.mollet@hogent.be
     */
-	public static function sort_table($data, $column = 0, $direction = SORT_ASC, $type = SORT_REGULAR)
+    public static function sort_table($data, $column = 0, $direction = SORT_ASC, $type = SORT_REGULAR)
     {
         if (!is_array($data) || empty($data)) {
             return array();
@@ -73,18 +74,18 @@ class TableSort
         return $data;
     }
 
-	/**
-	 * Sorts 2-dimensional table. It is possile changing the columns that will be shown and the way that the columns are to be sorted.
-	 * @param array $data The data to be sorted.
-	 * @param int $column The column on which the data should be sorted (default = 0)
-	 * @param string $direction The direction to sort (SORT_ASC (default) orSORT_DESC)
-	 * @param array $column_show The columns that we will show in the table i.e: $column_show = array('1','0','1') we will show the 1st and the 3th column.
-	 * @param array $column_order Changes how the columns will be sorted ie. $column_order = array('0','3','2','3') The column [1] will be sorted like the column [3]
-	 * @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_DATE, SORT_IMAGE)
-	 * @return array The sorted dataset
-	 * @author bart.mollet@hogent.be
-	 */
-	public static function sort_table_config(
+    /**
+     * Sorts 2-dimensional table. It is possile changing the columns that will be shown and the way that the columns are to be sorted.
+     * @param array $data The data to be sorted.
+     * @param int $column The column on which the data should be sorted (default = 0)
+     * @param string $direction The direction to sort (SORT_ASC (default) orSORT_DESC)
+     * @param array $column_show The columns that we will show in the table i.e: $column_show = array('1','0','1') we will show the 1st and the 3th column.
+     * @param array $column_order Changes how the columns will be sorted ie. $column_order = array('0','3','2','3') The column [1] will be sorted like the column [3]
+     * @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_DATE, SORT_IMAGE)
+     * @return array The sorted dataset
+     * @author bart.mollet@hogent.be
+     */
+    public static function sort_table_config(
         $data,
         $column = 0,
         $direction = SORT_ASC,
@@ -132,9 +133,9 @@ class TableSort
             if (!empty($data)) {
                 foreach ($data as $document) {
                     if ($document['type'] == 'folder') {
-                      $docs_to_sort[$document['id']]   = api_strtolower($document['name']);
+                        $docs_to_sort[$document['id']] = api_strtolower($document['name']);
                     } else {
-                      $folder_to_sort[$document['id']] = api_strtolower($document['name']);
+                        $folder_to_sort[$document['id']] = api_strtolower($document['name']);
                     }
                     $new_data[$document['id']] = $document;
                 }
@@ -175,7 +176,6 @@ class TableSort
             }
         } else {
             $compare_operator = $direction == SORT_ASC ? '>' : '<=';
-
             switch ($type) {
                 case SORT_NUMERIC:
                     $compare_function = 'return strip_tags($a['.$column.']) '.$compare_operator.' strip_tags($b['.$column.']);';
@@ -196,91 +196,90 @@ class TableSort
             usort($data, create_function('$a, $b', $compare_function));
         }
 
-		if (is_array($column_show) && !empty($column_show)) {
-
-			// We show only the columns data that were set up on the $column_show array
-			$new_order_data = array();
-			$count_data = count($data);
-			$count_column_show = count($column_show);
-			for ($j = 0; $j < $count_data; $j++) {
-				$k = 0;
-				for ($i = 0; $i < $count_column_show; $i++) {
-					if ($column_show[$i]) {
-						$new_order_data[$j][$k] = $data[$j][$i];
-					}
-					$k++;
-				}
-			}
-			// Replace the multi-arrays
-			$data = $new_order_data;
-		}
+        if (is_array($column_show) && !empty($column_show)) {
+            // We show only the columns data that were set up on the $column_show array
+            $new_order_data = array();
+            $count_data = count($data);
+            $count_column_show = count($column_show);
+            for ($j = 0; $j < $count_data; $j++) {
+                $k = 0;
+                for ($i = 0; $i < $count_column_show; $i++) {
+                    if ($column_show[$i]) {
+                        $new_order_data[$j][$k] = $data[$j][$i];
+                    }
+                    $k++;
+                }
+            }
+            // Replace the multi-arrays
+            $data = $new_order_data;
+        }
 
-		return $data;
-	}
+        return $data;
+    }
 
-	/**
-	 * Checks whether a column of a 2D-array contains only numeric values
-	 * @param array $data		The data-array
-	 * @param int $column		The index of the column to check
-	 * @return bool				TRUE if column contains only dates, FALSE otherwise
-	 * @todo Take locale into account (eg decimal point or comma ?)
-	 * @author bart.mollet@hogent.be
-	 */
-	private static function is_numeric_column(& $data, $column)
+    /**
+     * Checks whether a column of a 2D-array contains only numeric values
+     * @param array $data The data-array
+     * @param int $column The index of the column to check
+     * @return bool TRUE if column contains only dates, FALSE otherwise
+     * @todo Take locale into account (eg decimal point or comma ?)
+     * @author bart.mollet@hogent.be
+     */
+    private static function is_numeric_column(& $data, $column)
     {
-		$is_numeric = true;
-		foreach ($data as $index => & $row) {
-			$is_numeric &= is_numeric(strip_tags($row[$column]));
-			if (!$is_numeric) {
-				break;
-			}
-		}
-		return $is_numeric;
-	}
+        $is_numeric = true;
+        foreach ($data as $index => & $row) {
+            $is_numeric &= is_numeric(strip_tags($row[$column]));
+            if (!$is_numeric) {
+                break;
+            }
+        }
+        return $is_numeric;
+    }
 
-	/**
-	 * Checks whether a column of a 2D-array contains only dates (GNU date syntax)
-	 * @param array $data		The data-array
-	 * @param int $column		The index of the column to check
-	 * @return bool				TRUE if column contains only dates, FALSE otherwise
-	 * @author bart.mollet@hogent.be
-	 */
-	private static function is_date_column(& $data, $column)
+    /**
+     * Checks whether a column of a 2D-array contains only dates (GNU date syntax)
+     * @param array $data The data-array
+     * @param int $column The index of the column to check
+     * @return bool TRUE if column contains only dates, FALSE otherwise
+     * @author bart.mollet@hogent.be
+     */
+    private static function is_date_column(& $data, $column)
     {
-		$is_date = true;
-		foreach ($data as $index => & $row) {
-			if (strlen(strip_tags($row[$column])) != 0) {
-				$check_date = strtotime(strip_tags($row[$column]));
-				// strtotime Returns a timestamp on success, FALSE otherwise.
-				// Previous to PHP 5.1.0, this function would return -1 on failure.
-				$is_date &= ($check_date != -1 && $check_date);
-			} else {
-				$is_date &= false;
-			}
-			if (!$is_date) {
-				break;
-			}
-		}
-		return $is_date;
-	}
+        $is_date = true;
+        foreach ($data as $index => & $row) {
+            if (strlen(strip_tags($row[$column])) != 0) {
+                $check_date = strtotime(strip_tags($row[$column]));
+                // strtotime Returns a timestamp on success, FALSE otherwise.
+                // Previous to PHP 5.1.0, this function would return -1 on failure.
+                $is_date &= ($check_date != -1 && $check_date);
+            } else {
+                $is_date &= false;
+            }
+            if (!$is_date) {
+                break;
+            }
+        }
+        return $is_date;
+    }
 
-	/**
-	 * Checks whether a column of a 2D-array contains only images (<img src="path/file.ext" alt=".."/>)
-	 * @param array $data		The data-array
-	 * @param int $column		The index of the column to check
-	 * @return bool				TRUE if column contains only images, FALSE otherwise
-	 * @author bart.mollet@hogent.be
-	 */
-	private static function is_image_column(& $data, $column)
+    /**
+     * Checks whether a column of a 2D-array contains only images (<img src="path/file.ext" alt=".."/>)
+     * @param array $data The data-array
+     * @param int $column The index of the column to check
+     * @return bool TRUE if column contains only images, FALSE otherwise
+     * @author bart.mollet@hogent.be
+     */
+    private static function is_image_column(& $data, $column)
     {
-		$is_image = true;
-		foreach ($data as $index => & $row) {
-			$is_image &= strlen(trim(strip_tags($row[$column], '<img>'))) > 0; // at least one img-tag
-			$is_image &= strlen(trim(strip_tags($row[$column]))) == 0; // and no text outside attribute-values
-			if (!$is_image) {
-				break;
-			}
-		}
-		return $is_image;
-	}
+        $is_image = true;
+        foreach ($data as $index => & $row) {
+            $is_image &= strlen(trim(strip_tags($row[$column], '<img>'))) > 0; // at least one img-tag
+            $is_image &= strlen(trim(strip_tags($row[$column]))) == 0; // and no text outside attribute-values
+            if (!$is_image) {
+                break;
+            }
+        }
+        return $is_image;
+    }
 }