issue fix: dynamic images for quest groups
This commit is contained in:
commit
207b735df5
187 changed files with 15803 additions and 0 deletions
37
controllers/BinaryController.inc
Normal file
37
controllers/BinaryController.inc
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?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 BinaryAgent to show binary data.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class BinaryController extends \hhu\z\controllers\ToplevelController
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Create binary data.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
143
controllers/CharactergroupsController.inc
Normal file
143
controllers/CharactergroupsController.inc
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?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 CharactergroupsAgent to display Character groups.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Show Character groups-groups for a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
*/
|
||||
public function index($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-groups
|
||||
$groupsgroups = $this->Charactergroups->getGroupsroupsForSeminary($seminary['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroups', $groupsgroups);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: groupsgroups.
|
||||
*
|
||||
* Show Character groups for a Character groups-group of a
|
||||
* Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
*/
|
||||
public function groupsgroup($seminaryUrl, $groupsgroupUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Character groups
|
||||
$groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']);
|
||||
|
||||
// Get Character groups-group Quests
|
||||
$quests = $this->Charactergroupsquests->getQuestsForCharactergroupsgroup($groupsgroup['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('groups', $groups);
|
||||
$this->set('quests', $quests);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: group.
|
||||
*
|
||||
* Show a Character group for a Character groups-group of a
|
||||
* Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
* @param string $groupUrl URL-Title of a Character group
|
||||
*/
|
||||
public function group($seminaryUrl, $groupsgroupUrl, $groupUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Character group
|
||||
$group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
|
||||
|
||||
// Get Characters
|
||||
$characters = $this->Characters->getCharactersForGroup($group['id']);
|
||||
|
||||
// Get Character groups Quests
|
||||
$quests = $this->Charactergroupsquests->getQuestsForGroup($group['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('group', $group);
|
||||
$this->set('characters', $characters);
|
||||
$this->set('quests', $quests);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
91
controllers/CharactergroupsquestsController.inc
Normal file
91
controllers/CharactergroupsquestsController.inc
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?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 CharactergroupsquestsAgent to display Character
|
||||
* groups Quests.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsquestsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'media');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show a Character groups Quest for a Character groups-group
|
||||
* of a Seminary.
|
||||
*
|
||||
* @throws 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 quest($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 groups-groups
|
||||
$groups = $this->Charactergroupsquests->getGroupsForQuest($quest['id']);
|
||||
|
||||
// Media
|
||||
$questmedia = null;
|
||||
if(!is_null($quest['questsmedia_id'])) {
|
||||
$questmedia = $this->Media->getMediaById($quest['questsmedia_id']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('quest', $quest);
|
||||
$this->set('groups', $groups);
|
||||
$this->set('media', $questmedia);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
101
controllers/CharactersController.inc
Normal file
101
controllers/CharactersController.inc
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?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 Agent to list registered users and their data.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactersController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator'),
|
||||
'character' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'seminarycharacterfields');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* List registered Characters for a Seminary
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
*/
|
||||
public function index($seminaryUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get registered Characters
|
||||
$characters = $this->Characters->getCharactersForSeminary($seminary['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('characters', $characters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: character.
|
||||
*
|
||||
* Show a Charater and its details.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $characterUrl URL-name of a Charater
|
||||
*/
|
||||
public function character($seminaryUrl, $characterUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
|
||||
|
||||
// Get Seminarycharacterfields
|
||||
$characterfields = $this->Seminarycharacterfields->getFieldsForCharacter($character['id']);
|
||||
|
||||
// Get User
|
||||
$user = $this->Users->getUserById($character['user_id']);
|
||||
|
||||
// Get Character groups
|
||||
$groups = $this->Charactergroups->getGroupsForCharacter($character['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('characterfields', $characterfields);
|
||||
$this->set('user', $user);
|
||||
$this->set('groups', $groups);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
48
controllers/ErrorController.inc
Normal file
48
controllers/ErrorController.inc
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?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 Agent to show an error page.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ErrorController extends \hhu\z\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Set HTTP-header and print an error message.
|
||||
*
|
||||
* @param int $httpStatusCode HTTP-statuscode of the error that occurred
|
||||
*/
|
||||
public function index($httpStatusCode)
|
||||
{
|
||||
// Set HTTP-header
|
||||
if(!array_key_exists($httpStatusCode, \nre\core\WebUtils::$httpStrings)) {
|
||||
$httpStatusCode = 200;
|
||||
}
|
||||
$this->response->addHeader(\nre\core\WebUtils::getHttpHeader($httpStatusCode));
|
||||
|
||||
// Display statuscode and message
|
||||
$this->set('code', $httpStatusCode);
|
||||
$this->set('string', \nre\core\WebUtils::$httpStrings[$httpStatusCode]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
37
controllers/FaultController.inc
Normal file
37
controllers/FaultController.inc
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?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 Agent to display a toplevel error page.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class FaultController extends \nre\core\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Show the error message.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
59
controllers/HtmlController.inc
Normal file
59
controllers/HtmlController.inc
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?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 HtmlAgent to display a HTML-page.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class HtmlController extends \hhu\z\controllers\ToplevelController
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
parent::preFilter($request, $response);
|
||||
|
||||
// Set content-type
|
||||
$this->response->addHeader("Content-type: text/html; charset=utf-8");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Create the HTML-structure.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// Set the name of the current IntermediateAgent as page title
|
||||
$this->set('title', $this->request->getParam(1, 'intermediate'));
|
||||
|
||||
// Set userdata
|
||||
$this->set('loggedUser', static::$user);
|
||||
$this->set('loggedSeminary', static::$seminary);
|
||||
$this->set('loggedCharacter', static::$character);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
35
controllers/IntroductionController.inc
Normal file
35
controllers/IntroductionController.inc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?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 Agent to show an introduction page.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class IntroductionController extends \hhu\z\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
143
controllers/MediaController.inc
Normal file
143
controllers/MediaController.inc
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?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 MediaAgent to process and show Media.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MediaController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
parent::preFilter($request, $response);
|
||||
|
||||
// Set headers for caching control
|
||||
$response->addHeader("Pragma: public");
|
||||
$response->addHeader("Cache-control: public, max-age=".(60*60*24));
|
||||
$response->addHeader("Expires: ".gmdate('r', time()+(60*60*24)));
|
||||
$response->addHeader("Date: ".gmdate(\DateTime::RFC822));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Display a medium without processing.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of the Seminary
|
||||
* @param string $mediaUrl URL-name of the medium
|
||||
*/
|
||||
public function index($seminaryUrl, $mediaUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Media
|
||||
$media = $this->Media->getMediaByUrl($seminary['id'], $mediaUrl);
|
||||
|
||||
// Set content-type
|
||||
$this->response->addHeader("Content-type: ".$media['mimetype']."");
|
||||
|
||||
// Set filename
|
||||
$media['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['media'].DS.$media['id'];
|
||||
if(!file_exists($media['filename'])) {
|
||||
throw new \nre\exceptions\IdNotFoundException($mediaUrl);
|
||||
}
|
||||
|
||||
// Cache
|
||||
if($this->setCacheHeaders($media['filename'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('media', $media);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determine file information and set the HTTP-header for
|
||||
* caching accordingly.
|
||||
*
|
||||
* @param string $fileName Filename
|
||||
* @return boolean HTTP-status 304 was set (in cache)
|
||||
*/
|
||||
private function setCacheHeaders($fileName)
|
||||
{
|
||||
// Determine last change of file
|
||||
$fileLastModified = gmdate('r', filemtime($fileName));
|
||||
|
||||
// Generate E-Tag
|
||||
$fileEtag = hash('sha256', $fileLastModified.$fileName);
|
||||
|
||||
|
||||
// Set header
|
||||
$this->response->addHeader("Last-Modified: ".$fileLastModified);
|
||||
$this->response->addHeader("Etag: ".$fileEtag);
|
||||
// HTTP-status
|
||||
$headerModifiedSince = $this->request->getServerParam('HTTP_IF_MODIFIED_SINCE');
|
||||
$headerNoneMatch = $this->request->getServerParam('HTTP_IF_NONE_MATCH');
|
||||
if(
|
||||
!is_null($headerModifiedSince) && $fileLastModified < strtotime($headerModifiedSince) &&
|
||||
!is_null($headerNoneMatch) && $headerNoneMatch == $fileEtag
|
||||
) {
|
||||
$this->response->setExit(true);
|
||||
$this->response->addHeader(\nre\core\WebUtils::getHttpHeader(304));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
50
controllers/MenuController.inc
Normal file
50
controllers/MenuController.inc
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?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 Agent to display a menu.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MenuController extends \hhu\z\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
parent::preFilter($request, $response);
|
||||
|
||||
// Set userdata
|
||||
$this->set('loggedUser', HtmlController::$user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
135
controllers/QuestgroupsController.inc
Normal file
135
controllers/QuestgroupsController.inc
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<?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 QuestgroupsAgent to display Questgroups.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'questgroupshierarchy', 'questgroups', 'quests');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'questgroup' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'questgroup' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: questgroup.
|
||||
*
|
||||
* Display a Questgroup and its data.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $questgroupUrl URL-Title of a Questgroup
|
||||
*/
|
||||
public function questgroup($seminaryUrl, $questgroupUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Questgroup
|
||||
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
|
||||
|
||||
// Get Questgrouphierarchy
|
||||
$questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyById($questgroup['questgroupshierarchy_id']);
|
||||
|
||||
// Get Character
|
||||
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||
|
||||
// Check permission
|
||||
$previousQuestgroup = $this->Questgroups->getPreviousQuestgroup($questgroup['id']);
|
||||
if(!is_null($previousQuestgroup)) {
|
||||
if(!$this->Questgroups->hasCharacterSolvedQuestgroup($previousQuestgroup['id'], $character['id'])) {
|
||||
throw new \nre\exceptions\AccessDeniedException();
|
||||
}
|
||||
}
|
||||
|
||||
// Get child Questgroupshierarchy
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupshierarchy['id']);
|
||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
||||
|
||||
// Get additional data
|
||||
for($i=0; $i<count($hierarchy['questgroups']); $i++)
|
||||
{
|
||||
// Get Character XPs
|
||||
$hierarchy['questgroups'][$i]['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($hierarchy['questgroups'][$i]['id'], $character['id']);
|
||||
|
||||
// Check permission of Questgroups
|
||||
if($i >= 1) {
|
||||
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get texts
|
||||
$questgroupTexts = $this->Questgroups->getQuestgroupTexts($questgroup['id']);
|
||||
|
||||
// Get Character XPs
|
||||
$questgroup['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($questgroup['id'], $character['id']);
|
||||
|
||||
|
||||
// Get Quests
|
||||
$quests = null;
|
||||
if(count($childQuestgroupshierarchy) == 0)
|
||||
{
|
||||
$quests = $this->Quests->getMainquestsForQuestgroup($questgroup['id']);
|
||||
for($i=0; $i<count($quests); $i++)
|
||||
{
|
||||
// Check permission
|
||||
if($i > 0) {
|
||||
$quests[$i]['access'] = $this->Quests->hasCharacterSolvedQuest($quests[$i-1]['id'], $character['id']);
|
||||
}
|
||||
|
||||
// Attach sidequests
|
||||
$quests[$i]['sidequests'] = $this->Quests->getSidequestsForQuest($quests[$i]['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questgroup', $questgroup);
|
||||
$this->set('questgroupshierarchy', $questgroupshierarchy);
|
||||
$this->set('childquestgroupshierarchy', $childQuestgroupshierarchy);
|
||||
$this->set('texts', $questgroupTexts);
|
||||
$this->set('quests', $quests);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
76
controllers/QuestgroupshierarchypathController.inc
Normal file
76
controllers/QuestgroupshierarchypathController.inc
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?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 QuestgroupshierarchypathAgent to display the
|
||||
* Questgroups hierarchy path.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupshierarchypathController extends \hhu\z\Controller
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'questgroups', 'questgroupshierarchy');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Calculate and show the hierarchy path of a Questgroup.
|
||||
*
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $questgroupUrl URL-Title of a Questgroup
|
||||
* @param boolean $showGroup Show the current group itself
|
||||
*/
|
||||
public function index($seminaryUrl, $questgroupUrl, $showGroup=false)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Questgroup
|
||||
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
|
||||
|
||||
// Get parent Questgrouphierarchy
|
||||
$parentQuestgroupshierarchy = array();
|
||||
$currentQuestgroup = $questgroup;
|
||||
if($showGroup) {
|
||||
$currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyById($currentQuestgroup['questgroupshierarchy_id']);
|
||||
array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
|
||||
}
|
||||
while(!is_null($currentQuestgroup['parent_questgroup_id']))
|
||||
{
|
||||
// Get Questgroup
|
||||
$currentQuestgroup = $this->Questgroups->GetQuestgroupById($currentQuestgroup['parent_questgroup_id']);
|
||||
|
||||
// Get Questgroupshierarchy
|
||||
$currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyById($currentQuestgroup['questgroupshierarchy_id']);
|
||||
|
||||
array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('parentquestgroupshierarchy', $parentQuestgroupshierarchy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
65
controllers/QuestgroupspictureController.inc
Normal file
65
controllers/QuestgroupspictureController.inc
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?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 QuestgroupspictureAgent to display the picture of a
|
||||
* Questgroups.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupspictureController extends \hhu\z\Controller
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'questgroups', 'media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Show the picture of a Questgroup.
|
||||
*
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $questgroupUrl URL-Title of a Questgroup
|
||||
*/
|
||||
public function index($seminaryUrl, $questgroupUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Questgroup
|
||||
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
|
||||
|
||||
// Get Picture
|
||||
$picture = null;
|
||||
try {
|
||||
$picture = $this->Media->getMediaById($questgroup['questgroupspicture_id']);
|
||||
}
|
||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('picture', $picture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
549
controllers/QuestsController.inc
Normal file
549
controllers/QuestsController.inc
Normal file
|
|
@ -0,0 +1,549 @@
|
|||
<?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 QuestsAgent to display Quests.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'questgroups', 'quests', 'questtexts', 'media', 'questtypes', 'questgroupshierarchy');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user'),
|
||||
'submissions' => array('admin', 'moderator'),
|
||||
'submission' => array('admin', 'moderator')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user'),
|
||||
'submissions' => array('admin', 'moderator'),
|
||||
'submission' => array('admin', 'moderator')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show a quest and its task.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of Seminary
|
||||
* @param string $questgroupUrl URL-Title of Questgroup
|
||||
* @param string $questUrl URL-Title of Quest
|
||||
* @param string $questtexttypeUrl URL-Title of Questtexttype
|
||||
* @param int $questtextPos Position of Questtext
|
||||
*/
|
||||
public function quest($seminaryUrl, $questgroupUrl, $questUrl, $questtexttypeUrl=null, $questtextPos=1)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Questgroup
|
||||
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
|
||||
|
||||
// Get Quest
|
||||
$quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
|
||||
|
||||
// Get Character
|
||||
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||
|
||||
// Check permissions
|
||||
$previousQuests = $this->Quests->getPreviousQuests($quest['id']);
|
||||
if(count($previousQuests) == 0)
|
||||
{
|
||||
// Previous Questgroup
|
||||
$previousQuestgroup = $this->Questgroups->getPreviousQuestgroup($questgroup['id']);
|
||||
if(!is_null($previousQuestgroup) && !$this->Questgroups->hasCharacterSolvedQuestgroup($previousQuestgroup['id'], $character['id'])) {
|
||||
throw new \nre\exceptions\AccessDeniedException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Previous Quests
|
||||
if(count($previousQuests) > 0)
|
||||
{
|
||||
$solved = false;
|
||||
foreach($previousQuests as &$previousQuest)
|
||||
{
|
||||
if($this->Quests->hasCharacterSolvedQuest($previousQuest['id'], $character['id'])) {
|
||||
$solved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$solved) {
|
||||
throw new \nre\exceptions\AccessDeniedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get (related) Questtext (for Sidequests)
|
||||
$relatedQuesttext = null;
|
||||
if(!$quest['is_mainquest'])
|
||||
{
|
||||
$relatedQuesttext = $this->Questtexts->getQuesttextForSidequest($quest['id']);
|
||||
if(!empty($relatedQuesttext)) {
|
||||
$relatedQuesttext['quest'] = $this->Quests->getQuestById($relatedQuesttext['quest_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// Get Questtext
|
||||
$questtext = null;
|
||||
if(is_null($questtexttypeUrl)) {
|
||||
$questtexttypeUrl = 'Prolog';
|
||||
}
|
||||
$questtexttypes = $this->Questtexts->getQuesttexttypes();
|
||||
$questtexttypes = array_map(function($t) { return $t['url']; }, $questtexttypes);
|
||||
$questtextCount = $this->Questtexts->getQuesttextsCountForQuest($quest['id'], $questtexttypeUrl);
|
||||
if($questtextCount > 0 && in_array($questtexttypeUrl, $questtexttypes))
|
||||
{
|
||||
$questtextPos = max(intval($questtextPos), 1);
|
||||
$questtext = $this->Questtexts->getQuesttextByUrl($quest['id'], $questtexttypeUrl, $questtextPos);
|
||||
$questtext['count'] = $questtextCount;
|
||||
$questtext['sidequests'] = $this->Quests->getSidequestsForQuesttext($questtext['id']);
|
||||
}
|
||||
|
||||
// Quest status
|
||||
$questStatus = $this->request->getGetParam('status');
|
||||
$questStatusText = null;
|
||||
if(!is_null($questStatus))
|
||||
{
|
||||
switch($questStatus)
|
||||
{
|
||||
case 'solved':
|
||||
$questStatusText = $quest['right_text'];
|
||||
break;
|
||||
case 'unsolved':
|
||||
$questStatusText = $quest['wrong_text'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Media
|
||||
$questmedia = null;
|
||||
if(!is_null($questtext) && array_key_exists('questmedia_id', $questtext) && !empty($questtext['questsmedia_id'])) {
|
||||
$questmedia = $this->Media->getMediaById($questtext['questsmedia_id']);
|
||||
}
|
||||
elseif(!is_null($quest['questsmedia_id'])) {
|
||||
$questmedia = $this->Media->getMediaById($quest['questsmedia_id']);
|
||||
}
|
||||
|
||||
// Task
|
||||
$task = null;
|
||||
if($questtexttypeUrl == 'Prolog')
|
||||
{
|
||||
// Questtype
|
||||
$questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
|
||||
|
||||
// Render task
|
||||
$task = $this->renderTask($questtype['classname'], $seminary, $questgroup, $quest, $character);
|
||||
}
|
||||
|
||||
// Next Quest/Questgroup
|
||||
$nextQuests = null;
|
||||
$nextQuestgroup = null;
|
||||
if($questtexttypeUrl == 'Epilog')
|
||||
{
|
||||
if($quest['is_mainquest'])
|
||||
{
|
||||
// Next Quest
|
||||
$nextQuests = $this->Quests->getNextQuests($quest['id']);
|
||||
|
||||
// Next Questgroup
|
||||
if(empty($nextQuests))
|
||||
{
|
||||
$nextQuestgroup = $this->Questgroups->getNextQuestgroup($questgroup['id']);
|
||||
$nextQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyById($nextQuestgroup['questgroupshierarchy_id']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Related (Main-) Quest
|
||||
$nextQuest = $relatedQuesttext['quest'];
|
||||
$nextQuest['questgroup_url'] = $questgroup['url'];
|
||||
$nextQuests = array($nextQuest);
|
||||
}
|
||||
}
|
||||
|
||||
// Has Character solved quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questgroup', $questgroup);
|
||||
$this->set('questtext', $questtext);
|
||||
$this->set('quest', $quest);
|
||||
$this->set('queststatus', $questStatus);
|
||||
$this->set('queststatustext', $questStatusText);
|
||||
$this->set('relatedquesttext', $relatedQuesttext);
|
||||
$this->set('nextquests', $nextQuests);
|
||||
$this->set('nextquestgroup', $nextQuestgroup);
|
||||
$this->set('task', $task);
|
||||
$this->set('media', $questmedia);
|
||||
$this->set('solved', $solved);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List Character submissions for a Quest.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of Seminary
|
||||
* @param string $questgroupUrl URL-Title of Questgroup
|
||||
* @param string $questUrl URL-Title of Quest
|
||||
*/
|
||||
public function submissions($seminaryUrl, $questgroupUrl, $questUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Questgroup
|
||||
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
|
||||
|
||||
// Get Quest
|
||||
$quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
|
||||
|
||||
// Get (related) Questtext (for Sidequests)
|
||||
$relatedQuesttext = null;
|
||||
if(!$quest['is_mainquest'])
|
||||
{
|
||||
$relatedQuesttext = $this->Questtexts->getQuesttextForSidequest($quest['id']);
|
||||
if(!empty($relatedQuesttext)) {
|
||||
$relatedQuesttext['quest'] = $this->Quests->getQuestById($relatedQuesttext['quest_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// Media
|
||||
$questmedia = null;
|
||||
if(!is_null($quest['questsmedia_id'])) {
|
||||
$questmedia = $this->Media->getMediaById($quest['questsmedia_id']);
|
||||
}
|
||||
|
||||
// Get unsolved Character submissions
|
||||
$unsolvedSubmissions = $this->Quests->getCharactersUnsolvedQuest($quest['id']);
|
||||
foreach($unsolvedSubmissions as &$submission) {
|
||||
$submission['character'] = $this->Characters->getCharacterById($submission['character_id']);
|
||||
}
|
||||
|
||||
// Get solved Character submissions
|
||||
$solvedSubmissions = $this->Quests->getCharactersSolvedQuest($quest['id']);
|
||||
foreach($solvedSubmissions as &$submission) {
|
||||
$submission['character'] = $this->Characters->getCharacterById($submission['character_id']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questgroup', $questgroup);
|
||||
$this->set('quest', $quest);
|
||||
$this->set('relatedquesttext', $relatedQuesttext);
|
||||
$this->set('media', $questmedia);
|
||||
$this->set('unsolvedsubmissions', $unsolvedSubmissions);
|
||||
$this->set('solvedsubmissions', $solvedSubmissions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show and handle the submission of a Character for a Quest.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of Seminary
|
||||
* @param string $questgroupUrl URL-Title of Questgroup
|
||||
* @param string $questUrl URL-Title of Quest
|
||||
* @param string $characterUrl URL-Title of Character
|
||||
*/
|
||||
public function submission($seminaryUrl, $questgroupUrl, $questUrl, $characterUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Questgroup
|
||||
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
|
||||
|
||||
// Get Quest
|
||||
$quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
|
||||
|
||||
// Character
|
||||
$character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
|
||||
|
||||
// Media
|
||||
$questmedia = null;
|
||||
if(!is_null($quest['questsmedia_id'])) {
|
||||
$questmedia = $this->Media->getMediaById($quest['questsmedia_id']);
|
||||
}
|
||||
|
||||
// Questtype
|
||||
$questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
|
||||
|
||||
// Render Questtype output
|
||||
$output = $this->renderTaskSubmission($questtype['classname'], $seminary, $questgroup, $quest, $character);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questgroup', $questgroup);
|
||||
$this->set('quest', $quest);
|
||||
$this->set('character', $character);
|
||||
$this->set('media', $questmedia);
|
||||
$this->set('output', $output);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Render and handle the task of a Quest.
|
||||
*
|
||||
* @param string $questtypeClassname Name of the class for the Questtype of a Quest
|
||||
* @param array $seminary Seminary data
|
||||
* @param array $questgroup Questgroup data
|
||||
* @param array $quest Quest data
|
||||
* @param array $character Character data
|
||||
* @return string Rendered output
|
||||
*/
|
||||
private function renderTask($questtypeClassname, $seminary, $questgroup, $quest, $character)
|
||||
{
|
||||
$task = null;
|
||||
try {
|
||||
// Generate request and response
|
||||
$request = clone $this->request;
|
||||
$response = $this->createQuesttypeResponse('quest', $quest['id'], $character['id']);
|
||||
|
||||
// Load Questtype Agent
|
||||
$questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
|
||||
|
||||
// Solve Quest
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')) && !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']))
|
||||
{
|
||||
// Get user answers
|
||||
$answers = $this->request->getPostParam('answers');
|
||||
|
||||
// Save answers in database
|
||||
$questtypeAgent->saveAnswersOfCharacter($quest['id'], $character['id'], $answers);
|
||||
|
||||
// Match answers with correct ones
|
||||
$status = $questtypeAgent->matchAnswersofCharacter($quest['id'], $character['id'], $answers);
|
||||
if($status === true)
|
||||
{
|
||||
// Mark Quest as solved
|
||||
$this->Quests->setQuestSolved($quest['id'], $character['id']);
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link('Epilog', 5, true, array('status'=>'solved')));
|
||||
}
|
||||
elseif($status === false)
|
||||
{
|
||||
// Mark Quest as unsolved
|
||||
$this->Quests->setQuestUnsolved($quest['id'], $character['id']);
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link('Prolog', 5, true, array('status'=>'unsolved')));
|
||||
}
|
||||
}
|
||||
|
||||
// Render Task
|
||||
$task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
// Return rendered output
|
||||
return $task;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render and handle a Character submission for a Quest.
|
||||
*
|
||||
* @param string $questtypeClassname Name of the class for the Questtype of a Quest
|
||||
* @param array $seminary Seminary data
|
||||
* @param array $questgroup Questgroup data
|
||||
* @param array $quest Quest data
|
||||
* @param array $character Character data
|
||||
* @return string Rendered output
|
||||
*/
|
||||
private function renderTaskSubmission($questtypeClassname, $seminary, $questgroup, $quest, $character)
|
||||
{
|
||||
$task = null;
|
||||
try {
|
||||
// Generate request and response
|
||||
$request = clone $this->request;
|
||||
$response = $this->createQuesttypeResponse('submission', $quest['id'], $character['id']);
|
||||
|
||||
// Load Questtype Agent
|
||||
$questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
|
||||
|
||||
// Solve Quest
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')))
|
||||
{
|
||||
// Set status
|
||||
if($this->request->getPostParam('submit') == _('solved'))
|
||||
{
|
||||
// Mark Quest as solved
|
||||
$this->Quests->setQuestSolved($quest['id'], $character['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mark Quest as unsolved
|
||||
$this->Quests->setQuestUnsolved($quest['id'], $character['id']);
|
||||
}
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('submissions', $seminary['url'], $questgroup['url'], $quest['url']), 1));
|
||||
}
|
||||
|
||||
// Render task submissions
|
||||
$task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
|
||||
$task = $e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
// Return rendered output
|
||||
return $task;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a response for the Questtype rendering.
|
||||
*
|
||||
* @param string $action Action to run
|
||||
* @param mixed $param Additional parameters to add to the response
|
||||
* @return Response Generated response
|
||||
*/
|
||||
private function createQuesttypeResponse($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 QuesttypeAgent for a Questtype.
|
||||
*
|
||||
* @param string $questtypeClassname Name of the class for the Questtype of a Quest
|
||||
* @param Request $request Request
|
||||
* @param Response $response Response
|
||||
* @return QuesttypeAgent
|
||||
*/
|
||||
private function loadQuesttypeAgent($questtypeClassname, $request, $response)
|
||||
{
|
||||
// Load Agent
|
||||
\hhu\z\QuesttypeAgent::load($questtypeClassname);
|
||||
|
||||
|
||||
// Construct and return Agent
|
||||
return \hhu\z\QuesttypeAgent::factory($questtypeClassname, $request, $response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run and render the Agent for a QuesttypeAgent and return ist output.
|
||||
*
|
||||
* @param Agent $questtypeAgent QuesttypeAgent to run and render
|
||||
* @param Request $request Request
|
||||
* @param Response $response Response
|
||||
* @return string Rendered output
|
||||
*/
|
||||
private function runQuesttypeAgent($questtypeAgent, $request, $response)
|
||||
{
|
||||
// Run Agent
|
||||
$questtypeAgent->run($request, $response);
|
||||
|
||||
|
||||
// Render and return output
|
||||
return $questtypeAgent->render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
229
controllers/SeminariesController.inc
Normal file
229
controllers/SeminariesController.inc
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
<?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 Agent to list registered seminaries.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SeminariesController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'users', 'questgroupshierarchy', 'questgroups');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator', 'user'),
|
||||
'seminary' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin', 'moderator'),
|
||||
'edit' => array('admin', 'moderator', 'user'),
|
||||
'delete' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'edit' => array('admin', 'moderator'),
|
||||
'delete' => array('admin', 'moderator')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* List registered seminaries.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// Get seminaries
|
||||
$seminaries = $this->Seminaries->getSeminaries();
|
||||
|
||||
// Get additional data
|
||||
foreach($seminaries as &$seminary)
|
||||
{
|
||||
// Created user
|
||||
$seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminaries', $seminaries);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: seminary.
|
||||
*
|
||||
* Show a seminary and its details.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a seminary
|
||||
*/
|
||||
public function seminary($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Created user
|
||||
$seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
|
||||
|
||||
// Get Character
|
||||
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||
|
||||
// Questgrouphierarchy and Questgroups
|
||||
$questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyForSeminary($seminary['id']);
|
||||
foreach($questgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
||||
|
||||
// Get additional data
|
||||
for($i=0; $i<count($hierarchy['questgroups']); $i++)
|
||||
{
|
||||
// Get first Questgroup text
|
||||
$text = $this->Questgroups->getFirstQuestgroupText($hierarchy['questgroups'][$i]['id']);
|
||||
if(!empty($text))
|
||||
{
|
||||
$text = \hhu\z\Utils::shortenString($text['text'], 100, 120).' …';
|
||||
$hierarchy['questgroups'][$i]['text'] = $text;
|
||||
}
|
||||
|
||||
// Get Character XPs
|
||||
$hierarchy['questgroups'][$i]['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($hierarchy['questgroups'][$i]['id'], $character['id']);
|
||||
|
||||
// Check permission of Questgroups
|
||||
if($i >= 1) {
|
||||
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questgroupshierarchy', $questgroupshierarchy);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: create.
|
||||
*
|
||||
* Create a new seminary.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
|
||||
{
|
||||
// Create new seminary
|
||||
var_dump($this->Auth->getUserId());
|
||||
$seminaryId = $this->Seminaries->createSeminary(
|
||||
$this->request->getPostParam('title'),
|
||||
$this->Auth->getUserId()
|
||||
);
|
||||
|
||||
// Redirect to seminary
|
||||
$user = $this->Seminaries->getSeminaryById($seminaryId);
|
||||
$this->redirect($this->linker->link(array($seminary['url']), 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edit.
|
||||
*
|
||||
* Edit a seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a seminary
|
||||
*/
|
||||
public function edit($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Check request method
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
// Save changes
|
||||
if(!is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Edit seminary
|
||||
$this->Seminaries->editSeminary(
|
||||
$seminary['id'],
|
||||
$this->request->getPostParam('title')
|
||||
);
|
||||
$seminary = $this->Seminaries->getSeminaryById($seminary['id']);
|
||||
}
|
||||
|
||||
|
||||
// Redirect to entry
|
||||
$this->redirect($this->linker->link(array($seminary['url']), 1));
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: delete.
|
||||
*
|
||||
* Delete a seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a seminary
|
||||
*/
|
||||
public function delete($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Check request method
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
// Check confirmation
|
||||
if(!is_null($this->request->getPostParam('delete')))
|
||||
{
|
||||
// Delete seminary
|
||||
$this->Seminaries->deleteSeminary($seminary['id']);
|
||||
|
||||
// Redirect to overview
|
||||
$this->redirect($this->linker->link(null, 1));
|
||||
}
|
||||
|
||||
// Redirect to entry
|
||||
$this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
|
||||
}
|
||||
|
||||
|
||||
// Show confirmation
|
||||
$this->set('seminary', $seminary);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
47
controllers/UserrolesController.inc
Normal file
47
controllers/UserrolesController.inc
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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 Agent to display and manage userroles.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UserrolesController extends \hhu\z\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: user.
|
||||
*
|
||||
* Show a user and its details.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $userUrl URL-Username of an user
|
||||
*/
|
||||
public function user($userUrl)
|
||||
{
|
||||
// Get userroles
|
||||
$roles = $this->Userroles->getUserrolesForUserByUrl($userUrl);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('roles', $roles);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
231
controllers/UsersController.inc
Normal file
231
controllers/UsersController.inc
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
<?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 Agent to list registered users and their data.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UsersController extends \hhu\z\Controller
|
||||
{
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator'),
|
||||
'user' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin', 'moderator'),
|
||||
'edit' => array('admin', 'moderator'),
|
||||
'delete' => array('admin')
|
||||
);
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('users', 'characters');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// Get registered users
|
||||
$users = $this->Users->getUsers();
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('users', $users);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: user.
|
||||
*
|
||||
* Show a user and its details.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $userUrl URL-Username of an user
|
||||
*/
|
||||
public function user($userUrl)
|
||||
{
|
||||
// Get user
|
||||
$user = $this->Users->getUserByUrl($userUrl);
|
||||
|
||||
// Get Characters
|
||||
$characters = $this->Characters->getCharactersForUser($user['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('user', $user);
|
||||
$this->set('characters', $characters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: login.
|
||||
*
|
||||
* Log in a user.
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$username = '';
|
||||
|
||||
// Log the user in
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('login')))
|
||||
{
|
||||
$username = $this->request->getPostParam('username');
|
||||
$userId = $this->Users->login(
|
||||
$username,
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
|
||||
if(!is_null($userId))
|
||||
{
|
||||
$this->Auth->setUserId($userId);
|
||||
$user = $this->Users->getUserById($userId);
|
||||
|
||||
$this->redirect($this->linker->link(array($user['url']), 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('username', $username);
|
||||
$this->set('failed', ($this->request->getRequestMethod() == 'POST'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: logout.
|
||||
*
|
||||
* Log out a user.
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
// Unset the currently logged in user
|
||||
$this->Auth->setUserId(null);
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: create.
|
||||
*
|
||||
* Create a new user.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
|
||||
{
|
||||
// Create new user
|
||||
$userId = $this->Users->createUser(
|
||||
$this->request->getPostParam('username'),
|
||||
$this->request->getPostParam('email'),
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
|
||||
// Redirect to user
|
||||
$user = $this->Users->getUserById($userId);
|
||||
$this->redirect($this->linker->link(array($user['url']), 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edit.
|
||||
*
|
||||
* Edit a user.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $userUrl URL-Username of an user
|
||||
*/
|
||||
public function edit($userUrl)
|
||||
{
|
||||
// User
|
||||
$user = $this->Users->getUserByUrl($userUrl);
|
||||
|
||||
// Check request method
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
// Save changes
|
||||
if(!is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Edit user
|
||||
$this->Users->editUser(
|
||||
$user['id'],
|
||||
$this->request->getPostParam('username'),
|
||||
$this->request->getPostParam('email'),
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
$user = $this->Users->getUserById($user['id']);
|
||||
}
|
||||
|
||||
|
||||
// Redirect to entry
|
||||
$this->redirect($this->linker->link(array($user['url']), 1));
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('user', $user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: delete.
|
||||
*
|
||||
* Delete a user.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $userUrl URL-Username of an user
|
||||
*/
|
||||
public function delete($userUrl)
|
||||
{
|
||||
// User
|
||||
$user = $this->Users->getUserByUrl($userUrl);
|
||||
|
||||
// Check request method
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
// Check confirmation
|
||||
if(!is_null($this->request->getPostParam('delete')))
|
||||
{
|
||||
// Delete user
|
||||
$this->Users->deleteUser($user['id']);
|
||||
|
||||
// Redirect to overview
|
||||
$this->redirect($this->linker->link(null, 1));
|
||||
}
|
||||
|
||||
// Redirect to entry
|
||||
$this->redirect($this->linker->link(array('user', $user['url']), 1));
|
||||
}
|
||||
|
||||
|
||||
// Show confirmation
|
||||
$this->set('user', $user);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
41
controllers/components/AchievementComponent.inc
Normal file
41
controllers/components/AchievementComponent.inc
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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\components;
|
||||
|
||||
|
||||
/**
|
||||
* Component to handle achievements.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AchievementComponent extends \nre\core\Component
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('achievements');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Achievements-component.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
79
controllers/components/AuthComponent.inc
Normal file
79
controllers/components/AuthComponent.inc
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?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\components;
|
||||
|
||||
|
||||
/**
|
||||
* Component to handle authentication and authorization.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AuthComponent extends \nre\core\Component
|
||||
{
|
||||
/**
|
||||
* Key to save a user-ID as
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const KEY_USER_ID = 'user_id';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Auth-component.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Start session
|
||||
if(session_id() === '') {
|
||||
session_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the ID of the user that is currently logged in.
|
||||
*
|
||||
* @param int $userId ID of the currently logged in user
|
||||
*/
|
||||
public function setUserId($userId)
|
||||
{
|
||||
if(is_null($userId)) {
|
||||
unset($_SESSION[self::KEY_USER_ID]);
|
||||
}
|
||||
else {
|
||||
$_SESSION[self::KEY_USER_ID] = $userId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the ID of the user that is currently logged in.
|
||||
*
|
||||
* @return int ID of the currently logged in user
|
||||
*/
|
||||
public function getUserId()
|
||||
{
|
||||
if(array_key_exists(self::KEY_USER_ID, $_SESSION)) {
|
||||
return $_SESSION[self::KEY_USER_ID];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue