Forums / Developer / Sort node list by float attribute: hack or new contribution? / Comment47905
Guillaume Kulakowski
Thursday 22 May 2008 3:00:59 am
Better than a kernel hack, you can create a datatype who extends eZFloatType like that :
<?php /** * classe extendedFloatType similaire à ezFloatType mais avec la possibilitée de trier. */ include_once( "kernel/classes/datatypes/ezfloat/ezfloattype.php" ); class extendedFloatType extends eZFloatType { const DATA_TYPE_STRING = "extendedfloat"; function extendedFloatType() { $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', "Float", 'Datatype name' )." 2", array( 'serialize_supported' => true, 'object_serialize_map' => array( 'data_float' => 'value' ) ) ); $this->FloatValidator = new eZFloatValidator(); } /*! \return true if the datatype can be indexed */ function isIndexable() { return true; } function sortKey( $contentObjectAttribute ) { $intPrice = (int)($contentObjectAttribute->attribute( 'data_float' ) * 100.00); return $intPrice; } /*! \reimp */ function sortKeyType() { return 'int'; } } eZDataType::register( extendedFloatType::DATA_TYPE_STRING, "extendedFloatType" ); ?>
My blog : http://www.llaumgui.com (not in eZ Publish ;-)) eZC on RHEL : http://blog.famillecollet.com/pages/Config-en eZC on Fedora : just "yum install php-channel-ezc"