From 05bee46c0d4653f48a527c0816e863d9f56438b9 Mon Sep 17 00:00:00 2001 From: oliver Date: Fri, 25 Dec 2015 16:39:26 +0100 Subject: [PATCH] add CharactergroupsqueststationsAgent --- .../CharactergroupsqueststationsAgent.inc | 51 +++ ...CharactergroupsqueststationsController.inc | 383 ++++++++++++++++++ db/create.sql | 54 +++ models/CharactergroupsqueststationsModel.inc | 284 +++++++++++++ models/StationtypesModel.inc | 77 ++++ .../charactergroupsqueststations/index.tpl | 43 ++ .../charactergroupsqueststations/station.tpl | 127 ++++++ 7 files changed, 1019 insertions(+) create mode 100644 agents/intermediate/CharactergroupsqueststationsAgent.inc create mode 100644 controllers/CharactergroupsqueststationsController.inc create mode 100644 models/CharactergroupsqueststationsModel.inc create mode 100644 models/StationtypesModel.inc create mode 100644 views/ajax/charactergroupsqueststations/index.tpl create mode 100644 views/html/charactergroupsqueststations/station.tpl diff --git a/agents/intermediate/CharactergroupsqueststationsAgent.inc b/agents/intermediate/CharactergroupsqueststationsAgent.inc new file mode 100644 index 00000000..dfbe47ba --- /dev/null +++ b/agents/intermediate/CharactergroupsqueststationsAgent.inc @@ -0,0 +1,51 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\agents\intermediate; + + + /** + * Agent to display Character groups Quest stations. + * + * @author Oliver Hanraths + */ + class CharactergroupsqueststationsAgent extends \nre\agents\IntermediateAgent + { + + + + + /** + * Action: index. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function index(\nre\core\Request $request, \nre\core\Response $response) + { + } + + + /** + * Action: quest. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function station(\nre\core\Request $request, \nre\core\Response $response) + { + // Add Moodpic + $this->addSubAgent('Moodpic', 'seminary', $request->getParam(3), 'charactergroups'); + } + + } + +?> diff --git a/controllers/CharactergroupsqueststationsController.inc b/controllers/CharactergroupsqueststationsController.inc new file mode 100644 index 00000000..4f436458 --- /dev/null +++ b/controllers/CharactergroupsqueststationsController.inc @@ -0,0 +1,383 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\controllers; + + + /** + * Controller of the CharactergroupsqueststationAgent to display Character + * groups Quest stations. + * + * @author Oliver Hanraths + */ + class CharactergroupsqueststationsController extends \hhu\z\controllers\SeminaryController + { + /** + * Required models + * + * @var array + */ + public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'stationtypes', 'media'); + /** + * User permissions + * + * @var array + */ + public $permissions = array( + 'index' => array('admin', 'moderator', 'user'), + 'station' => array('admin', 'moderator', 'user') + ); + /** + * User seminary permissions + * + * @var array + */ + public $seminaryPermissions = array( + 'index' => array('admin', 'moderator', 'user'), + 'station' => array('admin', 'moderator', 'user') + ); + + + + + /** + * Action: index. + * + * Show all stations of a Character groups Quest. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + */ + public function index($seminaryUrl, $groupsgroupUrl, $questUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // 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']); + } + + + // Pass data to view + $this->set('stations', $stations); + $this->set('hasgroup', !is_null($charactergroup)); + } + + + /** + * Action: station. + * + * Show a station of a Character groups Quest. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + * @param string $stationUrl URL of station + */ + public function station($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Station + $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + if(!is_null($station['stationpicture_id'])) { + $station['picture'] = $this->Media->getSeminaryMediaById($station['stationpicture_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]; + } + + // TODO Check permissions + + // Set status “entered” + if(!is_null($charactergroup)) { + $this->Charactergroupsqueststations->setStationEntered($station['id'], $charactergroup['id']); + } + + // Get Character groups-groups + $groups = null; + if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) + { + $groups = $this->Charactergroups->getGroupsForQueststation($station['id']); + foreach($groups as &$group) { + $group['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( + $station['id'], + $group['id'] + ); + } + } + + // Task + $task = null; + $stationtype = $this->Stationtypes->getStationtypeById($station['stationtype_id']); + if(!is_null($stationtype['classname'])) { + $task = $this->renderTask($stationtype['classname'], $seminary, $groupsgroup, $quest, $station, $charactergroup); + } + else + { + // Mark Station as solved + if(!is_null($charactergroup)) { + $this->Charactergroupsqueststations->setStationSolved($station['id'], $charactergroup['id']); + } + } + + // Status + $solved = false; + $tried = false; + if(!is_null($charactergroup)) { + $solved = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation($station['id'], $charactergroup['id']); + if(!$solved) { + $tried = $this->Charactergroupsqueststations->hasCharactergroupTriedStation($station['id'], $charactergroup['id']); + } + } + + + // Set title + $this->addTitle($station['title']); + $this->addTitle($quest['title']); + $this->addTitle($groupsgroup['name']); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('groupsgroup', $groupsgroup); + $this->set('quest', $quest); + $this->set('station', $station); + $this->set('task', $task); + $this->set('groups', $groups); + $this->set('solved', $solved); + $this->set('tried', $tried); + } + + + + + /** + * Render and handle the task of a Station. + * + * @param string $stationtypeClassname Name of the class for the Stationtype of a Station + * @param array $seminary Seminary data + * @param array $questgroup Questgroup data + * @param array $quest Quest data + * @param array $station Station data + * @param array $charactergroup Charactergroup data + * @return string Rendered output + */ + private function renderTask($stationtypeClassname, $seminary, $groupsgroup, $quest, $station, $charactergroup) + { + $task = null; + try { + // Generate request and response + $request = clone $this->request; + $response = $this->createStationtypeResponse('quest', $seminary, $groupsgroup, $quest, $station, $charactergroup); + + // Load Stationtype Agent + $stationtypeAgent = $this->loadStationtypeAgent($stationtypeClassname, $request, $response); + + // Solve Quest + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit'))) + { + // Get user answers + $answer = $this->request->getPostParam('answer'); + + // Save answers in database + try { + // save answer + if(!is_null($charactergroup)) { + if(!$this->Charactergroupsqueststations->hasCharactergroupSolvedStation($station['id'], $charactergroup['id'])) { + $stationtypeAgent->saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer); + } + } + + // Match answer with correct one + $status = $stationtypeAgent->matchAnswer( + $seminary, + $groupsgroup, + $quest, + $station, + $charactergroup, + $answer + ); + if($status === true) + { + if(!is_null($charactergroup)) + { + // Mark Station as solved + $this->Charactergroupsqueststations->setStationSolved($station['id'], $charactergroup['id']); + } + + // Redirect + $this->redirect($this->linker->link(array(), 6, true, null, false, 'task')); + } + elseif($status === false) + { + if(!is_null($charactergroup)) { + // Mark Station as unsolved + $this->Charactergroupsqueststations->setStationUnsolved( + $station['id'], + $charactergroup['id'] + ); + } + + // Redirect + $this->redirect($this->linker->link(array(), 6, true, null, false, 'task')); + } + else { + // Redirect + $this->redirect($this->linker->link(array(), 6, true, null, false, 'task')); + } + } + catch(\hhu\z\exceptions\SubmissionNotValidException $e) { + $response->addParam($e); + } + } + + // Render Task + $task = $this->runStationtypeAgent($stationtypeAgent, $request, $response); + } + catch(\nre\exceptions\ViewNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\nre\exceptions\ActionNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeModelNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeModelNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeControllerNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeControllerNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeAgentNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\stationtypeAgentNotFoundException $e) { + $task = $e->getMessage(); + } + + + // Return rendered output + return $task; + } + + + /** + * Create a response for the Stationtype rendering. + * + * @param string $action Action to run + * @param mixed $param Additional parameters to add to the response + * @return \nre\core\Response Generated response + */ + private function createStationtypeResponse($action, $param1) + { + // Clone current response + $response = clone $this->response; + // Clear parameters + $response->clearParams(1); + + // Add Action + $response->addParams( + null, + $action + ); + + // Add additional parameters + foreach(array_slice(func_get_args(), 1) as $param) { + $response->addParam($param); + } + + + // Return response + return $response; + } + + + /** + * Load and construct the StationtypeAgent for a Stationtype. + * + * @param string $stationtypeClassname Name of the class for the Stationtype of a Station + * @param \nre\core\Request $request Request + * @param \nre\core\Response $response Response + * @return \hhu\z\agents\StationtypeAgent Stationtype Agent + */ + private function loadStationtypeAgent($stationtypeClassname, $request, $response) + { + // Load Agent + \hhu\z\agents\StationtypeAgent::load($stationtypeClassname); + + + // Construct and return Agent + return \hhu\z\agents\StationtypeAgent::factory($stationtypeClassname, $request, $response); + } + + + /** + * Run and render the Agent for a StationtypeAgent and return ist output. + * + * @param \nre\core\Agent $stationtypeAgent StationtypeAgent to run and render + * @param \nre\core\Request $request Request + * @param \nre\core\Response $response Response + * @return string Rendered output + */ + private function runStationtypeAgent($stationtypeAgent, $request, $response) + { + // Run Agent + $stationtypeAgent->run($request, $response); + + + // Render and return output + return $stationtypeAgent->render(); + } + + } + +?> diff --git a/db/create.sql b/db/create.sql index c3fbee7d..3ab98d6a 100644 --- a/db/create.sql +++ b/db/create.sql @@ -568,6 +568,60 @@ CREATE TABLE `charactergroupsquests_seminaryuploads` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `charactergroupsqueststations` +-- + +DROP TABLE IF EXISTS `charactergroupsqueststations`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `charactergroupsqueststations` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `charactergroupsquest_id` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `stationtype_id` int(11) NOT NULL, + `title` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `url` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `pos` int(10) unsigned NOT NULL, + `stationpicture_id` int(11) DEFAULT NULL, + `task` text COLLATE utf8mb4_unicode_ci NOT NULL, + `latitude` decimal(10,6) DEFAULT NULL, + `longitude` decimal(10,6) DEFAULT NULL, + `righttext` text COLLATE utf8mb4_unicode_ci NOT NULL, + `wrongtext` text COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `charactergroupsquest_id_2` (`charactergroupsquest_id`,`url`), + UNIQUE KEY `charactergroupsquest_id_3` (`charactergroupsquest_id`,`pos`), + KEY `charactergroupsquest_id` (`charactergroupsquest_id`), + KEY `charactergroupsqueststationtype_id` (`stationtype_id`), + KEY `stationpicture_id` (`stationpicture_id`) USING BTREE, + CONSTRAINT `charactergroupsqueststations_ibfk_1` FOREIGN KEY (`charactergroupsquest_id`) REFERENCES `charactergroupsquests` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `charactergroupsqueststations_ibfk_2` FOREIGN KEY (`stationpicture_id`) REFERENCES `seminarymedia` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, + CONSTRAINT `charactergroupsqueststations_ibfk_3` FOREIGN KEY (`stationtype_id`) REFERENCES `stationtypes` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `charactergroupsqueststations_charactergroups` +-- + +DROP TABLE IF EXISTS `charactergroupsqueststations_charactergroups`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `charactergroupsqueststations_charactergroups` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `charactergroupsqueststation_id` int(11) NOT NULL, + `charactergroup_id` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `status` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `charactergroupsqueststation_id` (`charactergroupsqueststation_id`), + KEY `charactergroup_id` (`charactergroup_id`), + CONSTRAINT `charactergroupsqueststations_charactergroups_ibfk_1` FOREIGN KEY (`charactergroupsqueststation_id`) REFERENCES `charactergroupsqueststations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `charactergroupsqueststations_charactergroups_ibfk_2` FOREIGN KEY (`charactergroup_id`) REFERENCES `charactergroups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `characterroles` -- diff --git a/models/CharactergroupsqueststationsModel.inc b/models/CharactergroupsqueststationsModel.inc new file mode 100644 index 00000000..63100e1a --- /dev/null +++ b/models/CharactergroupsqueststationsModel.inc @@ -0,0 +1,284 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\models; + + + /** + * Model of the CharactergroupsqueststationsAgent to interact with + * Charactergroupsqueststations-table. + * + * @author Oliver Hanraths + */ + class CharactergroupsqueststationsModel extends \hhu\z\Model + { + /** + * Status: Entered + * + * @var int; + */ + const STATUS_ENTERED = 0; + /** + * Status: Unsolved + * + * @var int; + */ + const STATUS_UNSOLVED = 2; + /** + * Status: Solved + * + * @var int; + */ + const STATUS_SOLVED = 3; + + + + + /** + * Construct a new CharactergroupsqueststationsModel. + */ + public function __construct() + { + parent::__construct(); + } + + + + + /** + * Get a Station by its ID. + * + * @throws \nre\exceptions\IdNotFoundException + * @param int $stationId ID of Station to get + * @return array Station data + */ + public function getStationById($stationId) + { + $data = $this->db->query( + 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, task, latitude, longitude, righttext, wrongtext '. + 'FROM charactergroupsqueststations '. + 'WHERE id = ?', + 'i', + $stationId + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($stationId); + } + + + return $data[0]; + } + + + /** + * Get a Station by its ID. + * + * @throws \nre\exceptions\IdNotFoundException + * @param int $stationId ID of Station to get + * @return array Station data + */ + public function getStationByUrl($groupsquestId, $stationUrl) + { + $data = $this->db->query( + 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, task, latitude, longitude, righttext, wrongtext '. + 'FROM charactergroupsqueststations '. + 'WHERE charactergroupsquest_id = ? AND url = ?', + 'is', + $groupsquestId, + $stationUrl + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($stationUrl); + } + + + return $data[0]; + } + + /** + * Get all Stations for a Character groups Quest. + * + * @param int $questId ID of the Character groups Quest + * @return array List of Stations + */ + public function getStationsForQuest($questId) + { + return $this->db->query( + 'SELECT id, title, url, stationpicture_id, latitude, longitude '. + 'FROM charactergroupsqueststations '. + 'WHERE charactergroupsquest_id = ? '. + 'ORDER BY pos ASC', + 'i', + $questId + ); + } + + + /** + * Get all Stations for a Character groups Quest and 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) + { + 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 + ); + } + + + /** + * Mark a Station as entered for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + */ + public function setStationEntered($stationId, $groupId) + { + $this->setStatus($stationId, $groupId, self::STATUS_ENTERED); + } + + + /** + * Mark a Station as solved for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + */ + public function setStationSolved($stationId, $groupId) + { + $this->setStatus($stationId, $groupId, self::STATUS_SOLVED); + } + + + /** + * Mark a Station as unsolved for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + */ + public function setStationUnsolved($stationId, $groupId) + { + $this->setStatus($stationId, $groupId, self::STATUS_UNSOLVED); + } + + + /** + * Check if a Character group has tried to solve a Station. + * + * @param int $stationId ID of Station to check + * @param int $groupId ID of Character group to check + * @return bool Whether the group has tried the station or not + */ + public function hasCharactergroupTriedStation($stationId, $groupId) + { + $data = $this->db->query( + 'SELECT created '. + 'FROM charactergroupsqueststations_charactergroups '. + 'WHERE charactergroupsqueststation_id = ? AND charactergroup_id = ? AND (status = ? OR status = ?)', + 'iiii', + $stationId, + $groupId, + self::STATUS_UNSOLVED, + self::STATUS_SOLVED + ); + if(!empty($data)) { + return $data[0]['created']; + } + + + return false; + } + + + /** + * Check if a Character group has solved a Station. + * + * @param int $questId ID of Quest to check + * @param int $groupId ID of Character to check + * @result boolean Whether Character has solved the Quest or not + */ + public function hasCharactergroupSolvedStation($stationId, $groupId) + { + $data = $this->db->query( + 'SELECT created '. + 'FROM charactergroupsqueststations_charactergroups '. + 'WHERE charactergroupsqueststation_id = ? AND charactergroup_id = ? AND status = ?', + 'iii', + $stationId, + $groupId, + self::STATUS_SOLVED + ); + if(!empty($data)) { + return $data[0]['created']; + } + + + return false; + } + + + + + + /** + * Mark a Station for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + * @param int $status Status to set + */ + private function setStatus($stationId, $groupId, $status) + { + // Check if status is already set + $count = $this->db->query( + 'SELECT count(*) AS c '. + 'FROM charactergroupsqueststations_charactergroups '. + 'WHERE charactergroupsqueststation_id = ? AND charactergroup_id = ? AND status = ?', + 'iii', + $stationId, + $groupId, + $status + ); + if(!empty($count) && intval($count[0]['c']) > 0) { + // Do not set status twice + return; + } + + // Set status + $this->db->query( + 'INSERT INTO charactergroupsqueststations_charactergroups '. + '(charactergroupsqueststation_id, charactergroup_id, status) '. + 'VALUES '. + '(?, ?, ?) ', + 'iii', + $stationId, + $groupId, + $status + ); + } + + } + +?> diff --git a/models/StationtypesModel.inc b/models/StationtypesModel.inc new file mode 100644 index 00000000..e46422a2 --- /dev/null +++ b/models/StationtypesModel.inc @@ -0,0 +1,77 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\models; + + + /** + * Model to interact with stationtypes-table. + * + * @author Oliver Hanraths + */ + class StationtypesModel extends \hhu\z\Model + { + + + + + /** + * Construct a new Model. + */ + public function __construct() + { + parent::__construct(); + } + + + + + /** + * Get all registered Stationtypes. + * + * @return array List of registered Stationtypes + */ + public function getStationtypes() + { + return $this->db->query( + 'SELECT id, title, url, classname '. + 'FROM stationtypes '. + 'ORDER BY title ASC' + ); + } + + + /** + * Get a Stationtype by its ID. + * + * @param int $stationtypeId ID of Stationtype + * @return array Stationtype data + */ + public function getStationtypeById($stationtypeId) + { + $data = $this->db->query( + 'SELECT title, classname '. + 'FROM stationtypes '. + 'WHERE id = ?', + 'i', + $stationtypeId + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($stationtypeId); + } + + + return $data = $data[0]; + } + + } + +?> diff --git a/views/ajax/charactergroupsqueststations/index.tpl b/views/ajax/charactergroupsqueststations/index.tpl new file mode 100644 index 00000000..5b043181 --- /dev/null +++ b/views/ajax/charactergroupsqueststations/index.tpl @@ -0,0 +1,43 @@ + 'Feature', + 'id' => $station['id'], + 'properties' => array( + 'name' => $station['title'], + ), + 'geometry' => array( + 'type' => 'Point', + 'coordinates' => $coordinate + ) + ); + } + + // Add lines between points + if($hasgroup) { + $features[] = array( + 'type' => 'Feature', + 'name' => 'Line', + 'geometry' => array( + 'type' => 'LineString', + 'coordinates' => $coordinates + ) + ); + } + +?> + 'FeatureCollection', + 'features' => $features +))?> diff --git a/views/html/charactergroupsqueststations/station.tpl b/views/html/charactergroupsqueststations/station.tpl new file mode 100644 index 00000000..9d0f1262 --- /dev/null +++ b/views/html/charactergroupsqueststations/station.tpl @@ -0,0 +1,127 @@ + + + + 0) : ?> + + + + +

+ +
    + +
  • + 0)?'N':'S', $station['longitude'], ($station['longitude']>0)?'E':'W')?> +
  • + + 0) : ?> +
  • + + + +
  • + +
+ + +
+
+ +
+ + + +
+

+
    + +
  1. + + format(new \DateTime($group['created']))?> + format(new \DateTime($group['created']))?> + + + + + + format(new \DateTime($group['solved']))))?> + + +
  2. + +
+
+ + + +
+

+ + +
+ t($station['righttext'])?> +
+ +
+ t($station['wrongtext'])?> +
+ +
+ t($station['task'])?> + +
+ +
+