Hi there! I hope someone can help me.
I would like to create a top ten Guides to show on a GuideHolder page. Following the Form documentation I've created the GuideReviewSubmission object. Then the page type GuidePage. I would like to show for each PageGuide its poll "Percentage" from the higher to the lower.
But I have some problem with the following script because I am not able to merge the two ArrayLists or associate one to the other for each GuidePage.
<?php
class GuideHolder extends Page {
private static $allowed_children = array('GuidePage');
}
class GuideHolder_Controller extends Page_Controller {
public function topTenGuides() {
$submissions = new GroupedList(GuideReviewSubmission::get());
$guides = GuidePage::get();
$topGuides = new ArrayList();
$list = new ArrayList();
foreach($submissions->groupBy('Guide') as $guideName => $guideSubmissions) {
$guideTot = $guideSubmissions->Count();
$totalReview = 0;
foreach ($guideSubmissions as $value) {
$totalReview = ($value->Review + $totalReview);
}
$percentage = (int) ($totalReview / $guideTot * 20);
$list->push(new ArrayData(array(
'Guide' => $guideName,
'Percentage' => $percentage,
'Total' => $guideTot
)));
}
$list = $list->sort('Percentage', 'DESC');
foreach ($list as $eachGuideResult) {
foreach ($guides as $allTheGuides) {
if ($eachGuideResult->Guide == $allTheGuides->Title) {
$topGuides->merge($allTheGuides , $eachGuideResult);
}
}
}
return $topGuides;
}
$topGuides->merge($allTheGuides , $eachGuideResult); seems to do not work because the result is only the list of the PageGuides and it doesn't give the Poll result (Percentage).
If I change it with
$topGuides->push($allTheGuides);
$topGuides->push($eachGuideResult);
the records are of course duplicated.
Here is the template code
<% loop $topTenGuides %>
<h1>$Title</h1>
<div id="GuideResult">
<div class="space"><div class="bar" style="width:$Percentage%"> </div></div>
</div>
<p>$Content.FirstParagraph</P>
<% end_loop %>
I am not an expert of PHP, can someone help me?
Thanks in advance!!