diff --git a/controllers/CharactergroupsquestsController.inc b/controllers/CharactergroupsquestsController.inc index 21c1778e..24fdeafc 100644 --- a/controllers/CharactergroupsquestsController.inc +++ b/controllers/CharactergroupsquestsController.inc @@ -25,7 +25,7 @@ * * @var array */ - public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'media', 'questgroups', 'uploads'); + public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'media', 'questgroups', 'uploads'); /** * Required components * @@ -78,6 +78,30 @@ $questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']); $questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']); + // Get Character group + $charactergroup = null; + $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']); + $charactergroups = $this->Charactergroups->getGroupsForCharacter($character['id']); + if(!empty($charactergroups)) { + // TODO Multiple Character groups + $charactergroup = $charactergroups[0]; + } + + // Get Stations + $stations = null; + if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) { + $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); + } + elseif(!is_null($charactergroup)) { + $stations = $this->Charactergroupsqueststations->getStationsForQuestAndGroup($quest['id'], $charactergroup['id']); + foreach($stations as &$station) { + $station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( + $station['id'], + $charactergroup['id'] + ); + } + } + // Get Character groups-groups $groups = $this->Charactergroups->getGroupsForQuest($quest['id']); @@ -98,6 +122,7 @@ $this->set('groupsgroup', $groupsgroup); $this->set('quest', $quest); $this->set('questgroup', $questgroup); + $this->set('stations', $stations); $this->set('groups', $groups); $this->set('uploads', $uploads); } diff --git a/models/CharactergroupsModel.inc b/models/CharactergroupsModel.inc index 1b36324a..5c237c74 100644 --- a/models/CharactergroupsModel.inc +++ b/models/CharactergroupsModel.inc @@ -95,7 +95,7 @@ public function getGroupsgroupById($groupsgroupId) { $data = $this->db->query( - 'SELECT id, name, url, preferred '. + 'SELECT id, seminary_id, name, url, preferred '. 'FROM charactergroupsgroups '. 'WHERE id = ?', 'i', @@ -400,6 +400,28 @@ } + /** + * Get Character groups that have entered a Character groups Quest + * station. + * + * @param int $stationId ID of station + * @return array List of groups + */ + public function getGroupsForQueststation($stationId) + { + return $this->db->query( + 'SELECT charactergroups.id, charactergroups.name, charactergroups.url, charactergroupsqueststations_charactergroups.created '. + 'FROM charactergroupsqueststations_charactergroups '. + 'INNER JOIN charactergroups ON charactergroups.id = charactergroupsqueststations_charactergroups.charactergroup_id '. + 'WHERE charactergroupsqueststations_charactergroups.charactergroupsqueststation_id = ? AND status = ? '. + 'ORDER BY charactergroupsqueststations_charactergroups.created ASC', + 'ii', + $stationId, + CharactergroupsqueststationsModel::STATUS_ENTERED + ); + } + + /** * Check if a Character group name already exists. * diff --git a/models/CharactergroupsquestsModel.inc b/models/CharactergroupsquestsModel.inc index 61de9715..7b21674f 100644 --- a/models/CharactergroupsquestsModel.inc +++ b/models/CharactergroupsquestsModel.inc @@ -97,7 +97,7 @@ public function getQuestById($questId) { $data = $this->db->query( - 'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '. + 'SELECT id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '. 'FROM charactergroupsquests '. 'WHERE id = ?', 'i', diff --git a/views/html/charactergroupsquests/quest.tpl b/views/html/charactergroupsquests/quest.tpl index cad646bc..a5c112b8 100644 --- a/views/html/charactergroupsquests/quest.tpl +++ b/views/html/charactergroupsquests/quest.tpl @@ -39,23 +39,63 @@ =_('Description')?> - =$t->t($quest['description'])?> + + =$t->t($quest['description'])?> + =_('Rules')?> - =$t->t($quest['rules'])?> + + =$t->t($quest['rules'])?> + =_('Won Quest')?> - =$t->t($quest['won_text'])?> + + =$t->t($quest['won_text'])?> + =_('Lost Quest')?> - =$t->t($quest['lost_text'])?> + + =$t->t($quest['lost_text'])?> + + + + + + + =_('Stations')?> + + + 0) : ?> + + + =_('Create new station')?> + + + + + + + + + =$dateFormatter->format(new \DateTime($station['created']))?> + =$timeFormatter->format(new \DateTime($station['created']))?> + + + + =$station['title']?> + + + + + + @@ -71,3 +111,111 @@ + +
=$t->t($quest['description'])?>
=$t->t($quest['rules'])?>
=$t->t($quest['won_text'])?>
=$t->t($quest['lost_text'])?>