implement basic Questgroups and Quests structure
This commit is contained in:
parent
ff85002070
commit
efd4f990fa
19 changed files with 774 additions and 8 deletions
143
models/QuestgroupsModel.inc
Normal file
143
models/QuestgroupsModel.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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Questgroups-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuestgroupsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questgroups for a Questgroup hierarchy.
|
||||
*
|
||||
* @param int $hierarchyId ID of the Questgroup hierarchy to get Questgroups for
|
||||
* @param int $parentQuestgroupId ID of the parent Questgroup hierarchy
|
||||
* @return array Questgroups for the given hierarchy
|
||||
*/
|
||||
public function getQuestgroupsForHierarchy($hierarchyId, $parentQuestgroupId=null)
|
||||
{
|
||||
if(is_null($parentQuestgroupId))
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id IS NULL '.
|
||||
'ORDER BY questgroups.pos ASC',
|
||||
'i',
|
||||
$hierarchyId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id = ? '.
|
||||
'ORDER BY questgroups.pos ASC',
|
||||
'ii',
|
||||
$hierarchyId, $parentQuestgroupId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array Questgroup data
|
||||
*/
|
||||
public function getQuestgroupById($questgroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, parent_questgroup_id, pos, title, url '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the corresponding seminary
|
||||
* @param string $questgroupURL URL-title of a Questgroup
|
||||
* @return array Questgroup data
|
||||
*/
|
||||
public function getQuestgroupByUrl($seminaryId, $questgroupUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questgroups.id, questgroups.questgroupshierarchy_id, questgroups.parent_questgroup_id, questgroups.pos, questgroups.title, questgroups.url '.
|
||||
'FROM questgroups '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'WHERE questgroupshierarchy.seminary_id = ? AND questgroups.url = ?',
|
||||
'is',
|
||||
$seminaryId, $questgroupUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get texts of a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array Texts of this Questgroup
|
||||
*/
|
||||
public function getQuestgroupTexts($questgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, pos, text '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
103
models/QuestgroupshierarchyModel.inc
Normal file
103
models/QuestgroupshierarchyModel.inc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?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 Questgroupshierarchy-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupshierarchyModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuestgroupshierarchyModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup hierarchy by its ID.
|
||||
*
|
||||
* throws IdNotFoundException
|
||||
* @param int $questgroupshierarchyId ID of a Questgroup hierarchy
|
||||
* @return array Questgroup hierarchy
|
||||
*/
|
||||
public function getHierarchyById($questgroupshierarchyId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE questgroupshierarchy.id = ?',
|
||||
'i',
|
||||
$questgroupshierarchyId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the toplevel hierarchy entries of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of the seminary to get hierarchy for
|
||||
* @return array Toplevel hierarchy
|
||||
*/
|
||||
public function getHierarchyForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE '.
|
||||
'questgroupshierarchy.seminary_id = ? AND '.
|
||||
'questgroupshierarchy.parent_questgroupshierarchy_id IS NULL '.
|
||||
'ORDER BY questgroupshierarchy.pos ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the child hierarchy entries of a Questgroup hierarchy.
|
||||
*
|
||||
* @param int $questgroupshierarchyId ID of a Questgroup hierarchy
|
||||
* @return array Child Questgroup hierarchy entries
|
||||
*/
|
||||
public function getChildQuestgroupshierarchy($questgroupshierarchyId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE questgroupshierarchy.parent_questgroupshierarchy_id = ? '.
|
||||
'ORDER BY questgroupshierarchy.pos ASC',
|
||||
'i',
|
||||
$questgroupshierarchyId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
85
models/QuestsModel.inc
Normal file
85
models/QuestsModel.inc
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?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 Quests-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuestsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all Quests for the given Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array Quests of the given Questgroup
|
||||
*/
|
||||
public function getQuestsForQuestgroup($questgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questtype_id, title, url, xps, text '.
|
||||
'FROM quests '.
|
||||
'WHERE questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Quest and its data by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the corresponding Seminary
|
||||
* @param int $questgroupId ID of the corresponding Questgroup
|
||||
* @param string $questURL URL-title of a Quest
|
||||
* @return array Quest data
|
||||
*/
|
||||
public function getQuestByUrl($seminaryId, $questgroupId, $questUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT quests.id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.text '.
|
||||
'FROM quests '.
|
||||
'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'WHERE questgroupshierarchy.seminary_id = ? AND questgroups.id = ? AND quests.url = ?',
|
||||
'iis',
|
||||
$seminaryId, $questgroupId, $questUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
{
|
||||
// Get seminaries
|
||||
return $this->db->query(
|
||||
'SELECT id, created, created_user_id, title, url '.
|
||||
'SELECT id, created, created_user_id, title, url, description '.
|
||||
'FROM seminaries '.
|
||||
'ORDER BY created DESC'
|
||||
);
|
||||
|
|
@ -60,7 +60,7 @@
|
|||
public function getSeminaryById($seminaryId)
|
||||
{
|
||||
$seminary = $this->db->query(
|
||||
'SELECT id, created, created_user_id, title, url '.
|
||||
'SELECT id, created, created_user_id, title, url, description '.
|
||||
'FROM seminaries '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
public function getSeminaryByUrl($seminaryUrl)
|
||||
{
|
||||
$seminary = $this->db->query(
|
||||
'SELECT id, created, created_user_id, title, url '.
|
||||
'SELECT id, created, created_user_id, title, url, description '.
|
||||
'FROM seminaries '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue