add selector which Character group to show for Stations (implements #133)

This commit is contained in:
oliver 2016-02-12 09:57:11 +01:00
commit 14ea890c8b
4 changed files with 77 additions and 27 deletions

View file

@ -78,13 +78,31 @@
$questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']); $questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']);
$questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']); $questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']);
// Get Character group // Get Character group(s)
$charactergroup = null; $stationgroups = null;
$stationgroup = null;
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) {
$stationgroups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']);
}
else
{
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']); $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
$charactergroups = $this->Charactergroups->getGroupsForCharacter($character['id']); $stationgroups = $this->Charactergroups->getGroupsForCharacter($character['id']);
if(!empty($charactergroups)) { if(!empty($stationgroups)) {
// TODO Multiple Character groups $stationgroup = $stationgroups[0];
$charactergroup = $charactergroups[0]; }
}
// Select group by parameter
$selectedStationGroupId = $this->request->getGetParam('stationgroup');
if(!is_null($selectedStationGroupId))
{
$selectedStationGroupId = intval($selectedStationGroupId);
foreach($stationgroups as &$group) {
if($group['id'] == $selectedStationGroupId) {
$stationgroup = $group;
break;
}
}
} }
// Get Stations // Get Stations
@ -99,21 +117,21 @@
} }
// Entered state // Entered state
if(!is_null($charactergroup)) { if(!is_null($stationgroup)) {
$station['entered'] = $this->Charactergroupsqueststations->hasCharactergroupEnteredStation( $station['entered'] = $this->Charactergroupsqueststations->hasCharactergroupEnteredStation(
$station['id'], $station['id'],
$charactergroup['id'] $stationgroup['id']
); );
if($station['entered']) { if($station['entered']) {
$stationsDiscovered = true; $stationsDiscovered = true;
$station['tried'] = $this->Charactergroupsqueststations->hasCharactergroupTriedStation( $station['tried'] = $this->Charactergroupsqueststations->hasCharactergroupTriedStation(
$station['id'], $station['id'],
$charactergroup['id'] $stationgroup['id']
); );
if($station['tried']) { if($station['tried']) {
$station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( $station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation(
$station['id'], $station['id'],
$charactergroup['id'] $stationgroup['id']
); );
} }
} }
@ -150,6 +168,8 @@
$this->set('questgroup', $questgroup); $this->set('questgroup', $questgroup);
$this->set('stations', $stations); $this->set('stations', $stations);
$this->set('stationsDiscovered', $stationsDiscovered); $this->set('stationsDiscovered', $stationsDiscovered);
$this->set('stationgroups', $stationgroups);
$this->set('stationgroup', $stationgroup);
$this->set('groups', $groups); $this->set('groups', $groups);
$this->set('uploads', $uploads); $this->set('uploads', $uploads);
} }

View file

@ -84,20 +84,39 @@
$quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
// Get Character group // Get Character group
$charactergroups = null;
$charactergroup = null; $charactergroup = null;
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) {
$charactergroups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']);
}
else {
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']); $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
$charactergroups = $this->Charactergroups->getGroupsForCharacter($character['id']); $charactergroups = $this->Charactergroups->getGroupsForCharacter($character['id']);
if(!empty($charactergroups)) { if(!empty($charactergroups)) {
// TODO Multiple Character groups $charactergroup = $stationgroups[0];
$charactergroup = $charactergroups[0]; }
}
// Select group by parameter
$selectedStationGroupId = $this->request->getGetParam('stationgroup');
if(!is_null($selectedStationGroupId))
{
$selectedStationGroupId = intval($selectedStationGroupId);
foreach($charactergroups as &$group) {
if($group['id'] == $selectedStationGroupId) {
$charactergroup = $group;
break;
}
}
} }
// Get Stations // Get Stations
$stations = null; $stations = array();
if(is_null($charactergroup)) {
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) { if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) {
$stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']);
} }
elseif(!is_null($charactergroup)) { }
else {
$stations = $this->Charactergroupsqueststations->getEnteredStationsForQuestAndGroup($quest['id'], $charactergroup['id']); $stations = $this->Charactergroupsqueststations->getEnteredStationsForQuestAndGroup($quest['id'], $charactergroup['id']);
} }

View file

@ -589,7 +589,7 @@
'INNER JOIN charactergroupsqueststations ON charactergroupsqueststations.id = charactergroupsqueststations_charactergroups.charactergroupsqueststation_id '. 'INNER JOIN charactergroupsqueststations ON charactergroupsqueststations.id = charactergroupsqueststations_charactergroups.charactergroupsqueststation_id '.
'WHERE '. 'WHERE '.
'charactergroupsqueststations_charactergroups.charactergroup_id = ? AND '. 'charactergroupsqueststations_charactergroups.charactergroup_id = ? AND '.
'charactergroupsqueststations_charactergroups.status >= ? AND '. 'charactergroupsqueststations_charactergroups.status = ? AND '.
'charactergroupsquest_id = ? '. 'charactergroupsquest_id = ? '.
'ORDER BY charactergroupsqueststations_charactergroups.created ASC', 'ORDER BY charactergroupsqueststations_charactergroups.created ASC',
'iii', 'iii',

View file

@ -80,6 +80,19 @@
</ul> </ul>
</nav> </nav>
<?php endif ?> <?php endif ?>
<?php if(count($stationgroups) > 1) : ?>
<form method="get" action="<?=$linker->link(null, 5, true, null, true, 'stations')?>">
<label for="stationgroup"><?=sprintf(_('%s-Group to show'), $groupsgroup['name'])?>:</label>
<select id="stationgroup" name="stationgroup" onchange="this.form.submit();">
<?php if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?>
<option><?=sprintf(_('Select %s-Group'), $groupsgroup['name'])?></option>
<?php endif ?>
<?php foreach($stationgroups as &$group) : ?>
<option value="<?=$group['id']?>" <?php if($group['id'] == $stationgroup['id']) : ?>selected="selected"<?php endif ?>><?=$group['name']?></option>
<?php endforeach ?>
</select>
</form>
<?php endif ?>
<ol class="grpqlist"> <ol class="grpqlist">
<?php foreach($stations as &$station) : ?> <?php foreach($stations as &$station) : ?>
<li> <li>
@ -154,7 +167,11 @@
<script> <script>
var markersSource = new ol.source.Vector({ var markersSource = new ol.source.Vector({
<?php if(!is_null($stationgroup)) : ?>
url: '<?=$linker->link(array('charactergroupsqueststations','index',$seminary['url'],$groupsgroup['url'],$quest['url']), 0, true, array('stationgroup'=>$stationgroup['id']))?>',
<?php else : ?>
url: '<?=$linker->link(array('charactergroupsqueststations','index',$seminary['url'],$groupsgroup['url'],$quest['url']))?>', url: '<?=$linker->link(array('charactergroupsqueststations','index',$seminary['url'],$groupsgroup['url'],$quest['url']))?>',
<?php endif ?>
format: new ol.format.GeoJSON() format: new ol.format.GeoJSON()
}); });
markersSource.on('change', function(e) { markersSource.on('change', function(e) {
@ -165,12 +182,6 @@
} }
); );
}); });
/*
var pathSource = new ol.source.Vector({
url: '<?=$linker->link(array('charactergroupsqueststations','index',$seminary['url'],$groupsgroup['url'],$quest['url']))?>',
format: new ol.format.GeoJSON()
});
*/
var styleFunction = function(feature, resolution) { var styleFunction = function(feature, resolution) {
var styles = []; var styles = [];
var geometry = feature.getGeometry(); var geometry = feature.getGeometry();