function deleteStoredObjectAttribute($contentObjectAttribute, $version = null)
 {
     // Remove all ratings associated with thes objectAttribute;
     if ($version == null) {
         ezsrRatingObject::removeByObjectId($contentObjectAttribute->attribute('contentobject_id'), $contentObjectAttribute->attribute('id'));
         ezsrRatingDataObject::removeByObjectId($contentObjectAttribute->attribute('contentobject_id'), $contentObjectAttribute->attribute('id'));
     }
 }
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         case 'fetch_starrating_data':
             $ret = ezsrRatingDataObject::fetchByConds($namedParameters['params']);
             break;
         case 'fetch_starrating_stats':
             $ret = ezsrRatingObject::stats($namedParameters['object_id']);
             break;
         case 'fetch_by_starrating':
             $ret = ezsrRatingObject::fetchNodeByRating($namedParameters['params']);
             break;
     }
     $operatorValue = $ret;
 }
    /**
     * Check if user has rated.
     *
     * @param array $args ( 0 => contentobject_id,  1 => contentobjectattribute_id )
     * @return bool|null (null if params are wrong)
     */
    public static function user_has_rated( $args )
    {
        if ( !isset( $args[1] ) || !is_numeric( $args[0] ) || !is_numeric( $args[1] ) )
            return null;

        $rateDataObj = ezsrRatingDataObject::create( array( 'contentobject_id' => $args[0],
                                                    'contentobject_attribute_id' =>  $args[1]
        ));

        return $rateDataObj->userHasRated();
    }
 /**
  * Update rating_average and rating_count from rating data.
  * Note: Does not store the change!
  * 
  * @return bool False if no rating data was returned so no updates could be done
  */
 function updateFromRatingData()
 {
     $custom = array(array('operation' => 'count( id )', 'name' => 'rating_count'), array('operation' => 'avg( rating )', 'name' => 'rating_average'));
     $cond = array('contentobject_id' => $this->attribute('contentobject_id'), 'contentobject_attribute_id' => $this->attribute('contentobject_attribute_id'));
     $data = self::fetchObjectList(ezsrRatingDataObject::definition(), array(), $cond, null, null, false, false, $custom);
     if (isset($data[0]['rating_average'])) {
         $this->setAttribute('rating_average', $data[0]['rating_average']);
         $this->setAttribute('rating_count', $data[0]['rating_count']);
         return true;
     }
     return false;
 }