This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Charles Marion
committed
Mar 9, 2011
1 parent
39a752c
commit a2a1a94
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
?> |