/** * @param array $data * @return \Shopware\Bundle\StoreFrontBundle\Struct\Product\VoteAverage */ public function hydrateAverage(array $data) { $struct = new Struct\Product\VoteAverage(); $points = 0; $total = 0; foreach ($data as $row) { $points += $row['points'] * $row['total']; $total += $row['total']; } $this->sortByPointsDescending($data); $struct->setAverage($points / $total * 2); $struct->setCount($total); $struct->setPointCount($data); return $struct; }
/** * @param StoreFrontBundle\Struct\Product\VoteAverage $average * @return array */ public function convertVoteAverageStruct(StoreFrontBundle\Struct\Product\VoteAverage $average) { $data = array('average' => round($average->getAverage()), 'count' => $average->getCount(), 'pointCount' => $average->getPointCount()); $data['attributes'] = $average->getAttributes(); /** @deprecated averange value, use average instead */ $data['averange'] = $data['average']; return $data; }