Add an option to group divisional results by prize so all the HMs are first, then bronze, etc. (based on the order of the prizes of the first divsional award encountered).

Won't work quite right if the first divsional award doesn't have any winners for a prize.wq
This commit is contained in:
dave 2010-04-10 07:09:07 +00:00
parent 02244937d2
commit 37ae79c363
2 changed files with 80 additions and 33 deletions

View File

@ -19,6 +19,7 @@
else $show_unawarded_prizes="no";
$show_pronunciation= ($_GET['show_pronunciation'] == 'on') ? TRUE : FALSE;
$group_by_prize= ($_GET['group_by_prize'] == 'on') ? true : false;
if(is_array($_GET['show_category'])) {
$show_category = array();
@ -74,11 +75,17 @@ if(!$scriptformat) $scriptformat="default";
ORDER BY awards_order");
echo mysql_error();
// echo "<pre>";
if(mysql_num_rows($q)) {
while($r=mysql_fetch_object($q)) {
if(!mysql_num_rows($q)) {
$rep->output();
exit;
}
$awards = array();
$pq=mysql_query("SELECT
while($r=mysql_fetch_object($q)) {
$pq=mysql_query("SELECT
award_prizes.prize,
award_prizes.number,
award_prizes.id,
@ -94,7 +101,7 @@ if(!$scriptformat) $scriptformat="default";
LEFT JOIN winners ON winners.awards_prizes_id=award_prizes.id
LEFT JOIN projects ON projects.id=winners.projects_id
WHERE
award_awards_id='$r->id'
award_awards_id='{$r->id}'
AND award_prizes.year='$foryear'
AND award_prizes.excludefromac='0'
AND ($and_categories)
@ -103,42 +110,81 @@ if(!$scriptformat) $scriptformat="default";
projects.projectnumber");
echo mysql_error();
if($show_unawarded_awards=="no") {
$skipAward=true;
while($pr=mysql_fetch_object($pq)) {
if($pr->projectnumber) {
$skipAward=false;
$r->winners = array();
while($w = mysql_fetch_object($pq)) {
if($r->type == 'Divisional' && $group_by_prize==true) {
/* Search awards for an award name that matches this prize */
$found = false;
foreach($awards as &$p_award) {
if($p_award->name == $w->prize) {
/* Match! Set the prize name to the award name,
* and add the prize to the award */
$w->prize = $r->name;
$p_award->winners[] = $w;
$found = true;
// echo "Add to award {$p_award->name}: "; print_r($w);
break;
}
}
if($skipAward) {
continue;
if($found == false) {
/* Make a new award and set it equal to the prize name */
$n = $r->name;
$new_award = clone($r);
$new_award->name = $w->prize;
/* Now add the prize with the award's name */
$w->prize = $n;
$new_award->winners[] = $w;
$awards[] = $new_award;
// echo "Create Award:"; print_r($new_award);
}
mysql_data_seek($pq, 0);
} else {
// echo "Add non-div winner\n";
$r->winners[] = $w;
}
if($scriptformat=="formatted")
$rep->newPage();
}
if($scriptformat=="default")
$rep->heading("$r->name ($r->type)");
if($scriptformat=="formatted") {
$rep->setFontBold();
$rep->addText("$r->name ($r->type)");
$rep->setFontNormal();
}
if($r->type!="Divisional")
$rep->addText(i18n("Sponsored by: %1",array($r->organization)));
if($r->presenter)
$rep->addText(i18n("Presented by: %1",array($r->presenter)));
if($r->description)
$rep->addText(i18n("Description: %1",array($r->description)));
if($show_criteria)
$rep->addText(i18n("Criteria: %1",array($r->criteria)));
if($show_unawarded_awards=="no" && count($r->winners) == 0) {
/* No winners */
continue;
}
if($scriptformat=="formatted") $rep->nextline();
$prevprizeid=-1;
while($pr=mysql_fetch_object($pq)) {
if($r->type == 'Divisional' && $group_by_prize == true) {
/* Do nothing */
} else {
$awards[] = $r;
}
}
// echo '<pre>'; print_r($awards);
foreach($awards as $r) {
if($scriptformat=="formatted")
$rep->newPage();
if($scriptformat=="default")
$rep->heading("$r->name ($r->type)");
if($scriptformat=="formatted") {
$rep->setFontBold();
$rep->addText("$r->name ($r->type)");
$rep->setFontNormal();
}
if($r->type!="Divisional")
$rep->addText(i18n("Sponsored by: %1",array($r->organization)));
if($r->presenter)
$rep->addText(i18n("Presented by: %1",array($r->presenter)));
if($r->description)
$rep->addText(i18n("Description: %1",array($r->description)));
if($show_criteria)
$rep->addText(i18n("Criteria: %1",array($r->criteria)));
if($scriptformat=="formatted") $rep->nextline();
$prevprizeid=-1;
foreach($r->winners as $pr) {
if($pr->projectnumber || $show_unawarded_prizes=="yes") {
if($prevprizeid!=$pr->id) {
$prizetext=$pr->prize;
@ -232,6 +278,5 @@ if(!$scriptformat) $scriptformat="default";
$rep->nextLine();
}
}
$rep->output();
?>

View File

@ -87,6 +87,8 @@
echo "<td><input name=\"show_criteria\" type=\"checkbox\" ".($config['reports_show_criteria'] == 'yes' ? "checked" : "")." value=\"on\"/></td></tr>";
echo "<tr><td ><b>".i18n("Show student name pronunciation").":</b></td>";
echo "<td><input name=\"show_pronunciation\" type=\"checkbox\" /></td></tr>";
echo "<tr><td width=\"30%\"><b>".i18n("Group divisional results by Prize (instead of Award Name). This groups all the honourable mentions in all divisions together, all the bronzes together, etc."). ":</b></td>";
echo "<td><input name=\"group_by_prize\" type=\"checkbox\" /></td></tr>";
echo "<tr><td><b>".i18n("Include the following age categories").":</b></td>";
echo "<td>";