Path

ez projects / starrating / forum / general / oracle/postgres compat


oracle/postgres compat

You need to be logged in to post messages in the forums. New users may register here.

Gaetano Giunta

Member since:
09 January 2008

Posts: 241

Thursday 18 June 2009 10:23:13 am

The sql function to calculate standard deviation is different depending on db type.

Use this code to fix:



 static function stats($ContentObjectAttributeID)


 {


   if (isset($GLOBALS['ratings']['stats'][$ContentObjectAttributeID]))


   {


     $return =& $GLOBALS['ratings']['stats'][$ContentObjectAttributeID];


   }


   else


   {


     // G. Giunta: use different std deviation function depending on db type


     $db = eZDB::instance();


     $type = $db->databaseName();


     if ( $type == 'mysql' )


     {


         $stddev = 'std';


     }


     else


     {


       $stddev = 'stddev';


     }


     $custom = array( array( 'operation' => 'count( id )',


                             'name'     => 'count' ) ,


                      array( 'operation' => 'avg( rating )',


                             'name'     => 'average' ),


                      array( 'operation' => $stddev . '( rating )',


                             'name'     => 'std' ));


     $cond=array( 'contentobject_attribute_id' => $ContentObjectAttributeID );


     $return = starrating::fetchObjectList(starrating::definition(), array(), $cond, null, null, false, false, $custom );


     if (is_array($return))


       $return = $return[0];


     $GLOBALS['ratings']['stats'][$ContentObjectAttributeID] =& $return;


   }


   return $return;


 }


Principal Consultant International Business
Member of the Community Project Board

Up

You need to be logged in to post messages in the forums. New users may register here.