diff --git a/agents/intermediate/LibraryAgent.inc b/agents/intermediate/LibraryAgent.inc new file mode 100644 index 00000000..aedc890a --- /dev/null +++ b/agents/intermediate/LibraryAgent.inc @@ -0,0 +1,35 @@ + + * @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 list Quest topics. + * + * @author Oliver Hanraths + */ + class LibraryAgent extends \nre\agents\IntermediateAgent + { + + + + + /** + * Action: index. + */ + public function index(\nre\core\Request $request, \nre\core\Response $response) + { + } + + } + +?> diff --git a/controllers/CharactersController.inc b/controllers/CharactersController.inc index fbeb0ead..70a651dd 100644 --- a/controllers/CharactersController.inc +++ b/controllers/CharactersController.inc @@ -24,7 +24,7 @@ * * @var array */ - public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'seminarycharacterfields', 'avatars', 'media'); + public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'seminarycharacterfields', 'avatars', 'media', 'questtopics'); /** * Required components * @@ -123,6 +123,14 @@ // Get Achievements $achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']); + // Get Quest topics + $questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']); + foreach($questtopics as &$questtopic) + { + $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']); + $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']); + } + // Pass data to view $this->set('seminary', $seminary); @@ -131,6 +139,7 @@ $this->set('user', $user); $this->set('groups', $groups); $this->set('achievements', $achievements); + $this->set('questtopics', $questtopics); } diff --git a/controllers/LibraryController.inc b/controllers/LibraryController.inc new file mode 100644 index 00000000..1aa78b80 --- /dev/null +++ b/controllers/LibraryController.inc @@ -0,0 +1,129 @@ + + * @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 LibraryAgent to list Quest topics. + * + * @author Oliver Hanraths + */ + class LibraryController extends \hhu\z\controllers\SeminaryRoleController + { + /** + * Required models + * + * @var array + */ + public $models = array('questtopics', 'seminaries', 'quests', 'questgroups'); + /** + * 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') + ); + + + + + /** + * Action: index. + * + * List Questtopics of a Seminary. + * + * @throws IdNotFoundException + * @param string $seminaryUrl URL-Title of Seminary + */ + public function index($seminaryUrl) + { + // Get Seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character + $character = IntermediateController::$character; + + // Get Quest topics + $questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']); + foreach($questtopics as &$questtopic) + { + // Get Quest count + $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']); + + // Get Character progress + $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']); + } + + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('questtopics', $questtopics); + } + + + /** + * Action: topic. + * + * Show a Questtopic and its Quests with Questsubtopics. + * + * @throws IdNotFoundException + * @param string $eminaryUrl URL-Title of Seminary + * @param string $questtopicUrl URL-Title of Questtopic + */ + public function topic($seminaryUrl, $questtopicUrl) + { + // Get Seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character + $character = IntermediateController::$character; + + // Get Questtopic + $questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl); + $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']); + $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']); + + // Get Quests + $quests = array(); + foreach($this->Quests->getQuestsForQuesttopic($questtopic['id']) as $quest) + { + if($this->Quests->hasCharacterEnteredQuest($quest['id'], $character['id'])) + { + // Get Questgroup + $quest['questgroup'] = $this->Questgroups->getQuestgroupById($quest['questgroup_id']); + + // Get Subtopics + $quest['subtopics'] = $this->Questtopics->getQuestsubtopicsForQuest($quest['id']); + + $quests[] = $quest; + } + } + + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('questtopic', $questtopic); + $this->set('quests', $quests); + } + + } + +?> diff --git a/models/QuestsModel.inc b/models/QuestsModel.inc index 87cadc9b..815e8294 100644 --- a/models/QuestsModel.inc +++ b/models/QuestsModel.inc @@ -325,6 +325,25 @@ } + /** + * Get all Quests that are linked to a Questtopic. + * + * @param int $questtopicId ID of Questtopic + * @return array Quests for this Questtopic + */ + public function getQuestsForQuesttopic($questtopicId) + { + return $this->db->query( + 'SELECT DISTINCT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.right_text, quests.wrong_text, quests.questsmedia_id '. + 'FROM quests_questsubtopics '. + 'INNER JOIN quests ON quests.id = quests_questsubtopics.quest_id '. + 'WHERE quests_questsubtopics.questsubtopic_id = ?', + 'i', + $questtopicId + ); + } + + /** diff --git a/models/QuesttopicsModel.inc b/models/QuesttopicsModel.inc new file mode 100644 index 00000000..abd246f7 --- /dev/null +++ b/models/QuesttopicsModel.inc @@ -0,0 +1,154 @@ + + * @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 Questtopics-table. + * + * @author Oliver Hanraths + */ + class QuesttopicsModel extends \hhu\z\Model + { + + + + + /** + * Construct a new QuesttopicsModel. + */ + public function __construct() + { + parent::__construct(); + } + + + + + /** + * Get a Questtopic by its URL. + * + * @param int $seminaryId ID of Seminary + * @param string $questtopicUrl URL-Title of Questtopic + * @return array Questtopic data + */ + public function getQuesttopicByUrl($seminaryId, $questtopicUrl) + { + $data = $this->db->query( + 'SELECT id, title, url '. + 'FROM questtopics '. + 'WHERE seminary_id = ? AND url = ?', + 'is', + $seminaryId, $questtopicUrl + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($questtopicUrl); + } + + + return $data[0]; + } + + + /** + * Get all Questtopics for a Seminary. + * + * @param int $seminaryId ID of Seminary + * @return array List of Questtopics + */ + public function getQuesttopicsForSeminary($seminaryId) + { + return $this->db->query( + 'SELECT id, title, url '. + 'FROM questtopics '. + 'WHERE seminary_id = ?', + 'i', + $seminaryId + ); + } + + + /** + * Get count of Quests that are linked to a Questtopic. + * + * @param int $questtopicId ID of Questtopic + * @return int Count of Quests + */ + public function getQuestCountForQuesttopic($questtopicId) + { + $data = $this->db->query( + 'SELECT count(DISTINCT quests_questsubtopics.quest_id) AS c ' . + 'FROM questsubtopics '. + 'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '. + 'WHERE questsubtopics.questtopic_id = ?', + 'i', + $questtopicId + ); + if(!empty($data)) { + return $data[0]['c']; + } + + + return 0; + } + + + /** + * Get count of Quests that are linked to a Questtopic and are + * unlocked by a Character. + * + * @param int $questtopicId ID of Questtopic + * @param int $characterId ID of Character + * @return int Count of Quests + */ + public function getCharacterQuestCountForQuesttopic($questtopicId, $characterId) + { + $data = $this->db->query( + 'SELECT count(DISTINCT quests_characters.quest_id) AS c '. + 'FROM questsubtopics '. + 'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '. + 'INNER JOIN quests_characters ON quests_characters.quest_id = quests_questsubtopics.quest_id AND quests_characters.character_id = ? AND quests_characters.status = 3 '. + 'WHERE questsubtopics.questtopic_id = ?', + 'ii', + $characterId, + $questtopicId + ); + if(!empty($data)) { + return $data[0]['c']; + } + + + return 0; + } + + + /** + * Get all Questsubtopics for a Quest. + * + * @param int $questId ID of Quest + * @return array List of Questsubtopics + */ + public function getQuestsubtopicsForQuest($questId) + { + return $this->db->query( + 'SELECT DISTINCT id, questtopic_id, title, url '. + 'FROM quests_questsubtopics '. + 'INNER JOIN questsubtopics ON questsubtopics.id = quests_questsubtopics.questsubtopic_id '. + 'WHERE quests_questsubtopics.quest_id = ?', + 'i', + $questId + ); + } + + } + +?> diff --git a/views/html/characters/character.tpl b/views/html/characters/character.tpl index a19f2355..dedab4c8 100644 --- a/views/html/characters/character.tpl +++ b/views/html/characters/character.tpl @@ -94,38 +94,16 @@
-

Thematischer Fortschritt

+

diff --git a/views/html/library/index.tpl b/views/html/library/index.tpl new file mode 100644 index 00000000..be5b441d --- /dev/null +++ b/views/html/library/index.tpl @@ -0,0 +1,21 @@ + +
+ +
+ +

+

+ +
    + +
  • +

    +
    +
    + +
    +

    /

    +
    +
  • + +
diff --git a/views/html/library/topic.tpl b/views/html/library/topic.tpl new file mode 100644 index 00000000..be396d4f --- /dev/null +++ b/views/html/library/topic.tpl @@ -0,0 +1,28 @@ + +
+ +
+ +

+

+

+ +
+
+ +
+

/

+
+ +
    + +
  • + +
      + +
    • + +
    +
  • + +