ez projects / sortobjectsoperators / forum / general / additional code
You need to be logged in to post messages in the forums. New users may register here.
|
Member since: Posts: 10 |
Thursday 09 February 2012 12:09:07 am Hey, great extension, thank you very much!
Arne Bakkebø is right with extended_sort I think, but I like this one =) Maybe you are interested to add my little extension to yours to sort by price: case 'sort_key': $objectA = self::getObjectAttributeSortKey( $objectA, $attributeName ); $objectB = self::getObjectAttributeSortKey( $objectB, $attributeName ); $objectAAttributeValue = ''; $objectBAttributeValue = ''; // if price is gt... (sort_key_int) if ( $objectA > $objectB ) { // Making ObjectA to be less than ObjectB // Jumping to comparing function $objectAAttributeValue = 'a'; $objectBAttributeValue = 'b'; } else { $objectAAttributeValue = 'b'; $objectBAttributeValue = 'a'; } break; public static function getObjectAttributeSortKey( $object, $attributeName ) { $attribute = self::getObjectAttribute( $object, $attributeName ); //sort_key_int sometimes has a difference from 1, maybe a bug... //return $attribute->SortKeyInt; $Price = sprintf ( '%01.2f', $attribute->DataFloat ); $PriceInt = (int) str_replace(',','',str_replace('.','',str_replace(' ','',$Price))); return $PriceInt; } {def $sorted_children = get_sorted_objects( $children_arr, array( array( false(), array( 'sort_key', 'price' ) ) ))} best regards scrieler |
|
Member since: Posts: 2 |
Thursday 09 February 2012 8:38:25 am I think you were talking about "typed" sorting, right? Maybe it is worth to add attribute value's type specificator. Will think how to manage that.
Thanks for idea :) Web developer, GPI S.p.A. |
You need to be logged in to post messages in the forums. New users may register here.