Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
BUG: git
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Marion committed Mar 9, 2011
1 parent 39a752c commit a2a1a94
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions application/controllers/components/SortdaoComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/** Sort Daos*/
class SortdaoComponent extends AppComponent
{
public $field='';
public $order='asc';

/* sort daos*/
public function sortByDate($a,$b)
{
if($this->field==''||!isset($a->{$this->field}))
{
throw new Zend_Exception("Error field.");
}
$a_t = strtotime( $a->{$this->field} ) ;
$b_t = strtotime( $b->{$this->field} ) ;

if( $a_t == $b_t )
return 0 ;

if($this->order=='asc')
{
return ($a_t > $b_t ) ? -1 : 1;
}
else
{
return ($a_t > $b_t ) ? 1 : -1;
}
}//end sortByDate

/** sort by name*/
public function sortByName($a,$b)
{
if($this->field==''||!isset($a->{$this->field}))
{
throw new Zend_Exception("Error field.");
}
$a_n = strtolower($a->{$this->field}) ;
$b_n = strtolower($b->{$this->field}) ;

if( $a_n == $b_n )
return 0 ;

if($this->order=='asc')
{
return ($a_n < $b_n) ? -1 : 1;
}
else
{
return ($a_n < $b_n ) ? 1 : -1;
}
}//end sortByDate


public function arrayUniqueDao($array, $keep_key_assoc = false)
{
$duplicate_keys = array();
$tmp = array();

foreach ($array as $key=>$val)
{
// convert objects to arrays, in_array() does not support objects
if (is_object($val))
$val = (array)$val;

if (!in_array($val, $tmp))
$tmp[] = $val;
else
$duplicate_keys[] = $key;
}

foreach ($duplicate_keys as $key)
unset($array[$key]);

return $keep_key_assoc ? $array : array_values($array);
}
} // end class
?>

0 comments on commit a2a1a94

Please sign in to comment.