The examples on this site are currently tested to work on Phalcon V3.4 and Phalcon Devtools V3.2 Some issues may arise when using later versions.

Please get in touch or post a comment below the post if you encounter a problem.

In order to drill down on the ratings behind the average we need a simple page which will show a list of ratings for a given court. To achieve this we need a controller action which will find all the ratings for a given court and a corresponding view which will present the information.

Modify the file /app/controllers/CourtratingController.php and add the following function

public function showRatingsAction($id)
{
	 $this->view->courtratings = Courtrating::findByCourtid($id);
}

Now create the following corresponding view. Save the following code to a new file called /app/views/courtrating/showRatings.phtml

<div class="page-header">
    <h1>Court Ratings</h1>
</div>
<?php echo $this->getContent(); ?>
<div class="row">
    <table class="table table-bordered">
        <thead>
            <tr>
		<th>Id</th>
		<th>Rating</th>
		<th>Comment</th>
		<th>CreatedAt</th>
            </tr>
        </thead>
        <tbody>
        <?php foreach ($courtratings as $courtrating): ?>
            <tr>
                <td><?php echo $courtrating->getId() ?></td>
		<td><?php echo $courtrating->getRating() ?></td>
		<td><?php echo $courtrating->getComment() ?></td>
	        <td><?php echo $courtrating->getCreatedat() ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>

Now a visit to http://localhost/tennisClub/courtrating/showRatings/3 will show a list of ratings for court number 3. To tie this back into the court search page and allow for a drill-down capability modify the file /app/views/court/search.phtml

Replace the <td>...</td> element and enclosed code which displays the average rating column with the following code which wraps an anchor tag around the average star rating figure.

<td>
    <?php $avgRating =  $court->getAverageRating();?>
    <?php echo $this->tag->linkTo(["CourtRating/showRatings/" . $court->getId(), "$avgRating"]);?>
</td>

Now when a user clicks on the figure for the average star rating they will see the following list of ratings for that court.