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

This commit is contained in:
oliver 2016-02-02 10:02:17 +01:00
parent e3b1fa85b5
commit 03cc6a475b
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']);
foreach($groups as &$group)
{
// Get count of solved Stations
$group['stations'] = $this->Charactergroupsqueststations->getSolvedStationsForQuestAndGroup(
$quest['id'],
$group['id']
);
}
// Get uploads
$uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
@ -172,6 +180,14 @@
// Get Character groups
$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
$mimetypes = \nre\configs\AppConfig::$mimetypes['charactergroupsquests'];

View file

@ -98,7 +98,7 @@
$stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']);
}
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 $groupId ID of Character group
* @return array List of Station
*/
public function getStationsForQuestAndGroup($questId, $groupId)
private function getEnteredStationsForQuestAndGroup($questId, $groupId)
{
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,
self::STATUS_ENTERED,
$questId
);
return $this->getStationsForQuestAndGroup($questId, $groupId, self::STATUS_ENTERED);
}
/**
* Get all Stations for a Character groups Quest that have been solved
* by a Character group.
*
* @param int $questId ID of Character groups Quest
* @param int $groupId ID of Character group
* @return array List of Station
*/
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>
<span class="group"><a href="<?=$linker->link(array('charactergroups','group',$seminary['url'],$groupsgroup['url'],$group['url']))?>"><?=$group['name']?></a></span>
<span class="xp">
<?=sprintf(_('%dStations'), count($group['stations']))?>,
<select name="xps[<?=$group['url']?>]">
<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++) : ?>

View file

@ -139,7 +139,10 @@
<li>
<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="xp"><?=sprintf(_('%dXPs'), $group['xps'])?></span>
<span class="xp">
<?=sprintf(_('%dStations'), count($group['stations']))?>,
<?=sprintf(_('%dXPs'), $group['xps'])?>
</span>
</li>
<?php endforeach ?>
</ol>