* @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 */ 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]; } } ?>