Merged revisions 47454 via svnmerge from

http://svn.silverstripe.com/open/modules/sapphire/branches/2.2.1asfonz

........
  r47454 | jshipman | 2007-12-21 13:36:38 +1300 (Fri, 21 Dec 2007) | 1 line
........


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@48536 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-01-24 00:12:02 +00:00
parent 08a5d49c66
commit a356bf9181
2 changed files with 53 additions and 0 deletions

View File

@ -833,6 +833,56 @@ class DataObjectSet extends ViewableData implements Iterator {
}
}
/**
* Adds ranking field to the dataobjects according to current ordering of dataobjects
* @param string $duplicatevalue the field being compared (used to check for equal ranks). Equals are excluded if null.
* @param boolean $skipduplicates skip the next number if there are equal ranks eg 1st equal, 1st equal, 3rd, 4th
*/
public function addRankings($field = 'ID', $skipduplicates = false){
//do a sort by duplicate value?
//suffixes of number values
$count = 1;
if($this->items){
$previous = null;
foreach($this->items as $key => $item){
//check if current item field value equals the next
if($item->$field == $previous->$field){
}
$item->Ranking = $this->convertIntToRank($count);
$count++;
}
}
}
/**
* Helperfunction for converting ints to rank values.
* Should we move this to Int or somthing and just use in the template? The problem this poses is having "equal" values eg "1st equal"
* @param
*/
private function convertIntToRank($value){
$rankconv = array(
11 => "th",
12 => "th",
13 => "th",
1=> "st",
2 => "nd",
3 => "rd",
);
//if the value ends with any of $rankconv, then add that suffix
foreach($rankconv as $key => $val){
if(ereg($key."$",$value)){
return $value.$val;
}
}
return $value."th";
}
/**
* Remove duplicates from this set based on the dataobjects ID.
* Assumes all items contained in the set all have IDs.

View File

@ -43,6 +43,9 @@ class Int extends DBField {
function Nice() {
return sprintf( '%d', $this->value );
}
}
?>