add CharactergroupsqueststationsAgent
This commit is contained in:
parent
f31032cbb2
commit
f779b22574
7 changed files with 1019 additions and 0 deletions
51
agents/intermediate/CharactergroupsqueststationsAgent.inc
Normal file
51
agents/intermediate/CharactergroupsqueststationsAgent.inc
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
383
controllers/CharactergroupsqueststationsController.inc
Normal file
383
controllers/CharactergroupsqueststationsController.inc
Normal file
|
@ -0,0 +1,383 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -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`
|
||||
--
|
||||
|
|
284
models/CharactergroupsqueststationsModel.inc
Normal file
284
models/CharactergroupsqueststationsModel.inc
Normal file
|
@ -0,0 +1,284 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
77
models/StationtypesModel.inc
Normal file
77
models/StationtypesModel.inc
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
43
views/ajax/charactergroupsqueststations/index.tpl
Normal file
43
views/ajax/charactergroupsqueststations/index.tpl
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
$features = array();
|
||||
$coordinates = array();
|
||||
|
||||
// Add points
|
||||
foreach($stations as &$station)
|
||||
{
|
||||
$coordinate = array(
|
||||
floatval($station['longitude']),
|
||||
floatval($station['latitude'])
|
||||
);
|
||||
$coordinates[] = $coordinate;
|
||||
$features[] = array(
|
||||
'type' => '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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
<?=json_encode(array(
|
||||
'type' => 'FeatureCollection',
|
||||
'features' => $features
|
||||
))?>
|
127
views/html/charactergroupsqueststations/station.tpl
Normal file
127
views/html/charactergroupsqueststations/station.tpl
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?=$moodpic?>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('charactergroups','index',$seminary['url']))?>"><?=_('Character Groups')?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('charactergroups','groupsgroup',$seminary['url'],$groupsgroup['url']))?>"><?=$groupsgroup['name']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('charactergroupsquests','quest',$seminary['url'],$groupsgroup['url'],$quest['url']))?>"><?=$quest['title']?></a></li>
|
||||
</ul>
|
||||
|
||||
<?php if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?>
|
||||
<nav class="admin">
|
||||
<li><a href="<?=$linker->link(array('edit',$seminary['url'],$groupsgroup['url'],$quest['url'],$station['url']),1)?>"><?=_('Edit')?></a></li>
|
||||
<li><a href="<?=$linker->link(array('delete',$seminary['url'],$groupsgroup['url'],$quest['url'],$station['url']),1)?>"><?=_('Delete')?></a></li>
|
||||
<li><a href="<?=$linker->link(array('manage',$seminary['url'],$groupsgroup['url'],$quest['url'],$station['url']),1)?>"><?=_('Manage')?></a></li>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if(array_key_exists('picture', $station)) : ?>
|
||||
<h1><?=$station['title']?></h1>
|
||||
<?php endif ?>
|
||||
<ul class="gdata cf">
|
||||
<?php if(!empty($station['longitude']) && !empty($station['latitude'])) : ?>
|
||||
<li>
|
||||
<span class="fwb"><?=sprintf(_('%1.6F°%s %1.6F°%s'), $station['latitude'], ($station['latitude']>0)?'N':'S', $station['longitude'], ($station['longitude']>0)?'E':'W')?></span>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?>
|
||||
<li>
|
||||
<a href="<?=$linker->link(array('qrcodes','charactergroupsqueststation',$seminary['url'],$groupsgroup['url'],$quest['url'],$station['url'],'50'))?>">
|
||||
<i class="fa fa-qrcode"></i>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
|
||||
<?php if(!empty($station['longitude']) && !empty($station['latitude'])) : ?>
|
||||
<section>
|
||||
<div id="map" class="map"></div>
|
||||
<script type="text/javascript">
|
||||
var center = ol.proj.transform([<?=$station['longitude']?>, <?=$station['latitude']?>], 'EPSG:4326', 'EPSG:3857');
|
||||
|
||||
var markersSource = new ol.source.Vector();
|
||||
markersSource.addFeature(
|
||||
new ol.Feature({
|
||||
geometry: new ol.geom.Point(
|
||||
ol.proj.transform([<?=$station['longitude']?>, <?=$station['latitude']?>], 'EPSG:4326', 'EPSG:3857')
|
||||
),
|
||||
name: '<?=$station['title']?>'
|
||||
})
|
||||
);
|
||||
var markersStyle = new ol.style.Style({
|
||||
text: new ol.style.Text({
|
||||
//text: '\uf041',
|
||||
text: '\uf276',
|
||||
font: 'normal 28px FontAwesome',
|
||||
textBaseline: 'Bottom',
|
||||
fill: new ol.style.Fill({
|
||||
color: '#0F373C'
|
||||
})
|
||||
})
|
||||
});
|
||||
var markersLayer = new ol.layer.Vector({
|
||||
source: markersSource,
|
||||
style: markersStyle
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
}),
|
||||
markersLayer
|
||||
],
|
||||
controls: ol.control.defaults(),
|
||||
target: 'map',
|
||||
view: new ol.View({
|
||||
center: center,
|
||||
zoom: 18,
|
||||
maxZoom: 19
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</section>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if(!empty($groups)) : ?>
|
||||
<section>
|
||||
<h1><?=_('Character Groups')?></h1>
|
||||
<ol class="grpqlist">
|
||||
<?php foreach($groups as &$group) : ?>
|
||||
<li>
|
||||
<span class="date">
|
||||
<?=$dateFormatter->format(new \DateTime($group['created']))?>
|
||||
<?=$timeFormatter->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>
|
||||
<?php if($group['solved'] !== false) : ?>
|
||||
<span class="xp">
|
||||
<i class="fa fa-check-square-o fa-fw"></i>
|
||||
<?=_(sprintf('solved at %s', $timeFormatter->format(new \DateTime($group['solved']))))?>
|
||||
</span>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
</section>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if(!is_null($task)) : ?>
|
||||
<section class="task">
|
||||
<h1 id="task"><?=_('Task')?></h1>
|
||||
|
||||
<?php if($solved): ?>
|
||||
<div class="text">
|
||||
<?=$t->t($station['righttext'])?>
|
||||
</div>
|
||||
<?php elseif($tried) : ?>
|
||||
<div class="text">
|
||||
<?=$t->t($station['wrongtext'])?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="text">
|
||||
<?=$t->t($station['task'])?>
|
||||
<?=$task?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</section>
|
||||
<?php endif ?>
|
Loading…
Add table
Reference in a new issue