provide methods to mark Quests as solved and unsolved for QuesttypeControllers
This commit is contained in:
parent
41f64d48be
commit
7f5572f0e1
2 changed files with 134 additions and 1 deletions
|
|
@ -17,8 +17,14 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
abstract class QuesttypeController extends \nre\core\Controller
|
abstract class QuesttypeController extends \hhu\z\Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Required models
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $models = array('seminaries', 'questgroups', 'quests', 'characters');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -230,6 +236,71 @@
|
||||||
$this->view = QuesttypeView::loadAndFactory($layoutName, $controllerName, $action);
|
$this->view = QuesttypeView::loadAndFactory($layoutName, $controllerName, $action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the current Quest as solved and redirect to solved page.
|
||||||
|
*/
|
||||||
|
protected function setQuestSolved()
|
||||||
|
{
|
||||||
|
// Get seminary
|
||||||
|
$seminary = $this->Seminaries->getSeminaryByUrl($this->request->getParam(3));
|
||||||
|
|
||||||
|
// Get Questgroup
|
||||||
|
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $this->request->getParam(4));
|
||||||
|
|
||||||
|
// Get Quest
|
||||||
|
$quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $this->request->getParam(5));
|
||||||
|
|
||||||
|
// Sidequest
|
||||||
|
$sidequest = null;
|
||||||
|
if($this->request->getParam(2) == 'sidequest') {
|
||||||
|
$sidequest = $this->Quests->getSidequestByUrl($seminary['id'], $questgroup['id'], $quest['id'], $this->request->getParam(6));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Character
|
||||||
|
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||||
|
|
||||||
|
// Set solved
|
||||||
|
$this->Quests->setQuestSolved($quest['id'], $character['id']);
|
||||||
|
|
||||||
|
|
||||||
|
// Redirect
|
||||||
|
$this->redirect($this->linker->link('solved', $sidequest != null ? 6 : 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the current Quest as unsolved and redirect to unsolved
|
||||||
|
* page.
|
||||||
|
*/
|
||||||
|
protected function setQuestUnsolved()
|
||||||
|
{
|
||||||
|
// Get seminary
|
||||||
|
$seminary = $this->Seminaries->getSeminaryByUrl($this->request->getParam(3));
|
||||||
|
|
||||||
|
// Get Questgroup
|
||||||
|
$questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $this->request->getParam(4));
|
||||||
|
|
||||||
|
// Get Quest
|
||||||
|
$quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $this->request->getParam(5));
|
||||||
|
|
||||||
|
// Sidequest
|
||||||
|
$sidequest = null;
|
||||||
|
if($this->request->getParam(2) == 'sidequest') {
|
||||||
|
$sidequest = $this->Quests->getSidequestByUrl($seminary['id'], $questgroup['id'], $quest['id'], $this->request->getParam(6));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Character
|
||||||
|
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||||
|
|
||||||
|
// Set solved
|
||||||
|
$this->Quests->setQuestSolved($quest['id'], $character['id']);
|
||||||
|
|
||||||
|
|
||||||
|
// Redirect
|
||||||
|
$this->redirect($this->linker->link('unsolved', $sidequest != null ? 6 : 5));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
62
models/QuesttypesModel.inc
Normal file
62
models/QuesttypesModel.inc
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?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 Questtypes-table.
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
*/
|
||||||
|
class QuesttypesModel extends \hhu\z\Model
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new QuesttypesModel.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Questtype by its ID
|
||||||
|
*
|
||||||
|
* @param int $questtypeId ID of Questtype
|
||||||
|
* @return array Questtype data
|
||||||
|
*/
|
||||||
|
public function getQuesttypeById($questtypeId)
|
||||||
|
{
|
||||||
|
$data = $this->db->query(
|
||||||
|
'SELECT title, classname '.
|
||||||
|
'FROM questtypes '.
|
||||||
|
'WHERE id = ?',
|
||||||
|
'i',
|
||||||
|
$questtypeId
|
||||||
|
);
|
||||||
|
if(empty($data)) {
|
||||||
|
throw new \nre\exceptions\IdNotFoundException($questtypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $data = $data[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue