Yii - GridView中的评级百分比

So, I finally have a progress bar in my GridView, thanks to the BootProgressColumn. However, I have a rating system, and I'd like to show the percentage inside the progress bar. I can set it the hard way in the columns array, but that'll be for all the rows.

$rawData = Item::model()->findAllByAttributes(array('special_id' => $specialId));
$dataProvider = new CArrayDataProvider($rawData, array());

The GridView:

'dataProvider' => $dataProvider,
'columns' => array(
 array(
  'class' => 'application.components.BootProgressColumn',
  'name' => 'Rating',
  'animated' => true,
  'striped' => true,
  'percent' => '44',
 ),
)

Now, how do I get the sum of all columns where each respective $data->id matches rows in the Rating model?

$countRatings = count(Rating::model()->findAllByAttributes(array('item_id' => $data->id));

But what to do for sum? And how to divide sum by count? That all having done, how to get it in each column? Or would it be best to just create a table by myself?

If I understand your question well, you want to get the average rates for each item, here is what you can do:

in the Item model create the relation avgRating:

public function relations()
{
    return array(
        'avgRating' => array(self::STAT, 'Item', 'item_id', 'group' => 'item_id', 'select' => 'ROUND(AVG(rate),1)'),
    );
}

and then you can call this for each item to get the rating in your table:

'dataProvider' => $dataProvider,
   'columns' => array(
    array(
      'class' => 'application.components.BootProgressColumn',
      'name' => 'Rating',
      'animated' => true,
      'striped' => true,
      'percent' => '$data->avgRating',
    ),
)