Add rider rating average computation #730
This commit is contained in:
parent
c2c4be8b7b
commit
33e6994aaa
2 changed files with 16 additions and 2 deletions
|
|
@ -230,7 +230,10 @@ class RiderController extends ApiController
|
|||
$this->em->persist($rating);
|
||||
$this->em->flush();
|
||||
|
||||
// TODO: set average rating in rider entity
|
||||
// TODO: preliminary rating computation on the entity for now
|
||||
$rider->updateRatingAverage();
|
||||
$this->em->persist($rider);
|
||||
$this->em->flush();
|
||||
|
||||
// response
|
||||
return new ApiResponse();
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class Rider
|
|||
|
||||
// current rating of rider
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
protected $curr_rating;
|
||||
|
||||
|
|
@ -241,6 +241,17 @@ class Rider
|
|||
return $this->image_file;
|
||||
}
|
||||
|
||||
public function updateRatingAverage()
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->ratings as $rating) {
|
||||
$total += $rating->getRating();
|
||||
}
|
||||
|
||||
$this->setCurrentRating(round($total / $this->ratings->count(), 2));
|
||||
}
|
||||
|
||||
public function setCurrentRating($rating)
|
||||
{
|
||||
$this->curr_rating = $rating;
|
||||
|
|
|
|||
Loading…
Reference in a new issue