Commit 16159bb9 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2595 The code should follow code guidelines

parent 3dc68d99
<?php <?php
/* /*
This code is part of FusionDirectory (http://www.fusiondirectory.org/) This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier Copyright (C) 2003-2010 Cajus Pollmeier
...@@ -38,25 +37,26 @@ class departmentSortIterator implements Iterator { ...@@ -38,25 +37,26 @@ class departmentSortIterator implements Iterator {
* *
* \param $direction Direction * \param $direction Direction
*/ */
public function __construct($data, $direction) { public function __construct($data, $direction)
{
function depSort($ao, $bo) { function depSort($ao, $bo)
{
// Override sort attribute from data if needed // Override sort attribute from data if needed
$attribute_a= $ao['sort-attribute']; $attribute_a = $ao['sort-attribute'];
$attribute_b= $bo['sort-attribute']; $attribute_b = $bo['sort-attribute'];
// Extract values from ao and bo // Extract values from ao and bo
$a= $b= ""; $a = $b = "";
if (isset($ao[$attribute_a])) { if (isset($ao[$attribute_a])) {
$a= $ao[$attribute_a]; $a = $ao[$attribute_a];
if (is_array($a)) { if (is_array($a)) {
$a= $a[0]; $a = $a[0];
} }
} }
if (isset($bo[$attribute_b])) { if (isset($bo[$attribute_b])) {
$b= $bo[$attribute_b]; $b = $bo[$attribute_b];
if (is_array($b)) { if (is_array($b)) {
$b= $b[0]; $b = $b[0];
} }
} }
...@@ -69,9 +69,9 @@ class departmentSortIterator implements Iterator { ...@@ -69,9 +69,9 @@ class departmentSortIterator implements Iterator {
// Invert if direction is set // Invert if direction is set
if ($direction) { if ($direction) {
$this->data= array_reverse($data, true); $this->data = array_reverse($data, TRUE);
} else { } else {
$this->data= $data; $this->data = $data;
} }
} }
...@@ -80,7 +80,8 @@ class departmentSortIterator implements Iterator { ...@@ -80,7 +80,8 @@ class departmentSortIterator implements Iterator {
* *
* \return the first element of the array * \return the first element of the array
*/ */
function rewind() { function rewind()
{
return reset($this->data); return reset($this->data);
} }
...@@ -89,7 +90,8 @@ class departmentSortIterator implements Iterator { ...@@ -89,7 +90,8 @@ class departmentSortIterator implements Iterator {
* *
* \return The current element pointed by array pointer * \return The current element pointed by array pointer
*/ */
function current() { function current()
{
return current($this->data); return current($this->data);
} }
...@@ -98,7 +100,8 @@ class departmentSortIterator implements Iterator { ...@@ -98,7 +100,8 @@ class departmentSortIterator implements Iterator {
* *
* \return the key element of the array * \return the key element of the array
*/ */
function key() { function key()
{
return key($this->data); return key($this->data);
} }
...@@ -107,7 +110,8 @@ class departmentSortIterator implements Iterator { ...@@ -107,7 +110,8 @@ class departmentSortIterator implements Iterator {
* *
* \return The next element pointed by array pointer * \return The next element pointed by array pointer
*/ */
function next() { function next()
{
return next($this->data); return next($this->data);
} }
...@@ -116,9 +120,9 @@ class departmentSortIterator implements Iterator { ...@@ -116,9 +120,9 @@ class departmentSortIterator implements Iterator {
* *
* \return TRUE if the array is valid, return FALSE otherwise * \return TRUE if the array is valid, return FALSE otherwise
*/ */
function valid() { function valid()
return key($this->data) !== null; {
return (key($this->data) !== NULL);
} }
} }
?> ?>
<?php <?php
/* /*
This code is part of FusionDirectory (http://www.fusiondirectory.org/) This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier Copyright (C) 2003-2010 Cajus Pollmeier
...@@ -43,29 +42,31 @@ class listingSortIterator implements Iterator { ...@@ -43,29 +42,31 @@ class listingSortIterator implements Iterator {
* *
* \param string $type * \param string $type
*/ */
public function __construct($data, $direction, $attribute, $type= "string") { public function __construct($data, $direction, $attribute, $type = "string")
{
global $_sortAttribute; global $_sortAttribute;
global $_sortType; global $_sortType;
$_sortAttribute= $attribute; $_sortAttribute = $attribute;
$_sortType= $type; $_sortType = $type;
// Inline function to // Inline function to
function attrSort($ao, $bo) { function attrSort($ao, $bo)
{
global $_sortAttribute; global $_sortAttribute;
global $_sortType; global $_sortType;
// Extract values from ao and bo // Extract values from ao and bo
$a= $b= ""; $a = $b = "";
if (isset($ao[$_sortAttribute])) { if (isset($ao[$_sortAttribute])) {
$a= $ao[$_sortAttribute]; $a = $ao[$_sortAttribute];
if (is_array($a)) { if (is_array($a)) {
$a= $a[0]; $a = $a[0];
} }
} }
if (isset($bo[$_sortAttribute])) { if (isset($bo[$_sortAttribute])) {
$b= $bo[$_sortAttribute]; $b = $bo[$_sortAttribute];
if (is_array($b)) { if (is_array($b)) {
$b= $b[0]; $b = $b[0];
} }
} }
...@@ -79,16 +80,16 @@ class listingSortIterator implements Iterator { ...@@ -79,16 +80,16 @@ class listingSortIterator implements Iterator {
case 'date': case 'date':
if ($a == "") { if ($a == "") {
$a= "31.12.0000"; $a = "31.12.0000";
} }
if ($b == "") { if ($b == "") {
$b= "31.12.0000"; $b = "31.12.0000";
} }
list($d, $m, $y)= explode('.', $a); list($d, $m, $y) = explode('.', $a);
$a= (int)sprintf("%04d%02d%02d", $y, $m, $d); $a = (int)sprintf("%04d%02d%02d", $y, $m, $d);
list($d, $m, $y)= explode('.', $b); list($d, $m, $y) = explode('.', $b);
$b= (int)sprintf("%04d%02d%02d", $y, $m, $d); $b = (int)sprintf("%04d%02d%02d", $y, $m, $d);
return $b-$a; return $b - $a;
// Sort for string by default // Sort for string by default
default: default:
...@@ -103,9 +104,9 @@ class listingSortIterator implements Iterator { ...@@ -103,9 +104,9 @@ class listingSortIterator implements Iterator {
// Invert if direction is set // Invert if direction is set
if ($direction) { if ($direction) {
$this->data= array_reverse($data, true); $this->data = array_reverse($data, TRUE);
} else { } else {
$this->data= $data; $this->data = $data;
} }
} }
...@@ -114,7 +115,8 @@ class listingSortIterator implements Iterator { ...@@ -114,7 +115,8 @@ class listingSortIterator implements Iterator {
* *
* \return the first element of the array * \return the first element of the array
*/ */
function rewind() { function rewind()
{
return reset($this->data); return reset($this->data);
} }
...@@ -123,7 +125,8 @@ class listingSortIterator implements Iterator { ...@@ -123,7 +125,8 @@ class listingSortIterator implements Iterator {
* *
* \return The current element pointed by array pointer * \return The current element pointed by array pointer
*/ */
function current() { function current()
{
return current($this->data); return current($this->data);
} }
...@@ -132,7 +135,8 @@ class listingSortIterator implements Iterator { ...@@ -132,7 +135,8 @@ class listingSortIterator implements Iterator {
* *
* \return the key element of the array * \return the key element of the array
*/ */
function key() { function key()
{
return key($this->data); return key($this->data);
} }
...@@ -141,7 +145,8 @@ class listingSortIterator implements Iterator { ...@@ -141,7 +145,8 @@ class listingSortIterator implements Iterator {
* *
* \return The next element pointed by array pointer * \return The next element pointed by array pointer
*/ */
function next() { function next()
{
return next($this->data); return next($this->data);
} }
...@@ -150,9 +155,9 @@ class listingSortIterator implements Iterator { ...@@ -150,9 +155,9 @@ class listingSortIterator implements Iterator {
* *
* \return TRUE if the array is valid, return FALSE otherwise * \return TRUE if the array is valid, return FALSE otherwise
*/ */
function valid() { function valid()
return key($this->data) !== null; {
return (key($this->data) !== NULL);
} }
} }
?> ?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment