add count of Stations for each Character group (implements #139)

This commit is contained in:
oliver 2016-02-02 10:02:17 +01:00
commit 5ad86c811a
5 changed files with 68 additions and 19 deletions

View file

@ -118,8 +118,16 @@
} }
} }
// Get Character groups-groups // Get Character groups
$groups = $this->Charactergroups->getGroupsForQuest($quest['id']); $groups = $this->Charactergroups->getGroupsForQuest($quest['id']);
foreach($groups as &$group)
{
// Get count of solved Stations
$group['stations'] = $this->Charactergroupsqueststations->getSolvedStationsForQuestAndGroup(
$quest['id'],
$group['id']
);
}
// Get uploads // Get uploads
$uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']); $uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
@ -172,6 +180,14 @@
// Get Character groups // Get Character groups
$groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']); $groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']);
foreach($groups as &$group)
{
// Get count of solved Stations
$group['stations'] = $this->Charactergroupsqueststations->getSolvedStationsForQuestAndGroup(
$quest['id'],
$group['id']
);
}
// Get allowed mimetypes // Get allowed mimetypes
$mimetypes = \nre\configs\AppConfig::$mimetypes['charactergroupsquests']; $mimetypes = \nre\configs\AppConfig::$mimetypes['charactergroupsquests'];

View file

@ -98,7 +98,7 @@
$stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']);
} }
elseif(!is_null($charactergroup)) { elseif(!is_null($charactergroup)) {
$stations = $this->Charactergroupsqueststations->getStationsForQuestAndGroup($quest['id'], $charactergroup['id']); $stations = $this->Charactergroupsqueststations->getEnteredStationsForQuestAndGroup($quest['id'], $charactergroup['id']);
} }

View file

@ -131,28 +131,30 @@
/** /**
* Get all Stations for a Character groups Quest and a Character group. * Get all Stations for a Character groups Quest that have been entered
* by a Character group.
* *
* @param int $questId ID of Character groups Quest * @param int $questId ID of Character groups Quest
* @param int $groupId ID of Character group * @param int $groupId ID of Character group
* @return array List of Station * @return array List of Station
*/ */
public function getStationsForQuestAndGroup($questId, $groupId) private function getEnteredStationsForQuestAndGroup($questId, $groupId)
{ {
return $this->db->query( return $this->getStationsForQuestAndGroup($questId, $groupId, self::STATUS_ENTERED);
'SELECT charactergroupsqueststations.id, charactergroupsqueststations_charactergroups.created, title, url, stationpicture_id, latitude, longitude '. }
'FROM charactergroupsqueststations_charactergroups '.
'INNER JOIN charactergroupsqueststations ON charactergroupsqueststations.id = charactergroupsqueststations_charactergroups.charactergroupsqueststation_id '.
'WHERE '. /**
'charactergroupsqueststations_charactergroups.charactergroup_id = ? AND '. * Get all Stations for a Character groups Quest that have been solved
'charactergroupsqueststations_charactergroups.status = ? AND '. * by a Character group.
'charactergroupsquest_id = ? '. *
'ORDER BY charactergroupsqueststations_charactergroups.created ASC', * @param int $questId ID of Character groups Quest
'iii', * @param int $groupId ID of Character group
$groupId, * @return array List of Station
self::STATUS_ENTERED, */
$questId public function getSolvedStationsForQuestAndGroup($questId, $groupId)
); {
return $this->getStationsForQuestAndGroup($questId, $groupId, self::STATUS_SOLVED);
} }
@ -570,6 +572,33 @@
); );
} }
/**
* Get all Stations for a Character groups Quest with a minimum status.
*
* @param int $questId ID of Character groups Quest
* @param int $groupId ID of Character group
* @param int $statusMin Minimum status
* @return array List of Station
*/
private function getStationsForQuestAndGroup($questId, $groupId, $statusMin)
{
return $this->db->query(
'SELECT charactergroupsqueststations.id, charactergroupsqueststations_charactergroups.created, title, url, stationpicture_id, latitude, longitude '.
'FROM charactergroupsqueststations_charactergroups '.
'INNER JOIN charactergroupsqueststations ON charactergroupsqueststations.id = charactergroupsqueststations_charactergroups.charactergroupsqueststation_id '.
'WHERE '.
'charactergroupsqueststations_charactergroups.charactergroup_id = ? AND '.
'charactergroupsqueststations_charactergroups.status >= ? AND '.
'charactergroupsquest_id = ? '.
'ORDER BY charactergroupsqueststations_charactergroups.created ASC',
'iii',
$groupId,
$statusMin,
$questId
);
}
} }
?> ?>

View file

@ -78,6 +78,7 @@
<li> <li>
<span class="group"><a href="<?=$linker->link(array('charactergroups','group',$seminary['url'],$groupsgroup['url'],$group['url']))?>"><?=$group['name']?></a></span> <span class="group"><a href="<?=$linker->link(array('charactergroups','group',$seminary['url'],$groupsgroup['url'],$group['url']))?>"><?=$group['name']?></a></span>
<span class="xp"> <span class="xp">
<?=sprintf(_('%dStations'), count($group['stations']))?>,
<select name="xps[<?=$group['url']?>]"> <select name="xps[<?=$group['url']?>]">
<option value="null" <?php if(is_null($group['quest_group'])) : ?>selected="selected"<?php endif ?>><?=_('Not attended')?></option> <option value="null" <?php if(is_null($group['quest_group'])) : ?>selected="selected"<?php endif ?>><?=_('Not attended')?></option>
<?php for($i=0; $i<=$quest['xps']; $i++) : ?> <?php for($i=0; $i<=$quest['xps']; $i++) : ?>

View file

@ -139,7 +139,10 @@
<li> <li>
<span class="date"><?=$dateFormatter->format(new \DateTime($group['created']))?></span> <span class="date"><?=$dateFormatter->format(new \DateTime($group['created']))?></span>
<span class="group"><a href="<?=$linker->link(array('charactergroups','group',$seminary['url'],$groupsgroup['url'],$group['url']))?>"><?=$group['name']?></a></span> <span class="group"><a href="<?=$linker->link(array('charactergroups','group',$seminary['url'],$groupsgroup['url'],$group['url']))?>"><?=$group['name']?></a></span>
<span class="xp"><?=sprintf(_('%dXPs'), $group['xps'])?></span> <span class="xp">
<?=sprintf(_('%dStations'), count($group['stations']))?>,
<?=sprintf(_('%dXPs'), $group['xps'])?>
</span>
</li> </li>
<?php endforeach ?> <?php endforeach ?>
</ol> </ol>