diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 01237cc3..60021cf4 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -235,6 +235,7 @@ array('^achievements/([^/]+)/?$', 'achievements/index/$1', true), array('^library/([^/]+)/?$', 'library/index/$1', true), array('^library/([^/]+)/([^/]+)/?$', 'library/topic/$1/$2', true), + array('^library/([^/]+)/([^/]+)/manage/?$', 'library/managetopic/$1/$2', true), array('^media/(.*)$', 'media/$1?layout=binary', false), array('^uploads/(.*)$', 'uploads/$1?layout=binary', false) ); @@ -271,7 +272,8 @@ array('^charactergroupsquests/quest/(.*)$', 'charactergroupsquests/$1', true), array('^charactergroupsquests/(edit|delete|manage)/([^/]+)/([^/]+)/([^/]+)$', 'charactergroupsquests/$2/$3/$4/$1', true), array('^achievements/index/(.*)$', 'achievements/$1', true), - array('^library/(index|topic)/(.*)$', 'library/$2', true) + array('^library/(index|topic)/(.*)$', 'library/$2', true), + array('^library/managetopic/(.*)$', 'library/$1/manage', true) ); diff --git a/controllers/LibraryController.inc b/controllers/LibraryController.inc index a82387e6..c88cb21c 100644 --- a/controllers/LibraryController.inc +++ b/controllers/LibraryController.inc @@ -31,7 +31,9 @@ * @var array */ public $permissions = array( - 'index' => array('admin', 'moderator', 'user') + 'index' => array('admin', 'moderator', 'user'), + 'topic' => array('admin', 'moderator', 'user'), + 'managetopic' => array('admin', 'moderator', 'user') ); /** * User seminary permissions @@ -39,7 +41,9 @@ * @var array */ public $seminaryPermissions = array( - 'index' => array('admin', 'moderator', 'user') + 'index' => array('admin', 'moderator', 'user', 'guest'), + 'topic' => array('admin', 'moderator', 'user', 'guest'), + 'managetopic' => array('admin', 'moderator') ); @@ -139,6 +143,64 @@ $this->set('quests', $quests); } + + /** + * Action: managetopic. + * + * Manage 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 managetopic($seminaryUrl, $questtopicUrl) + { + // Get Seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Questtopic + $questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl); + + // Get Questsubtopics + $questsubtopics = $this->Questtopics->getSubtopicsForQuesttopic($questtopic['id']); + + // Set Questsubtopics for Quests + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('questsubtopics'))) + { + $quests = $this->Quests->getQuestsForQuesttopic($questtopic['id']); + $selectedSubtopics = $this->request->getPostParam('questsubtopics'); + foreach($quests as &$quest) + { + $subtopics = (array_key_exists($quest['id'], $selectedSubtopics)) ? $selectedSubtopics[$quest['id']] : array(); + $this->Questtopics->setQuestsubtopicsForQuest($quest['id'], array_keys($subtopics)); + } + } + + // Get Quests + $quests = $this->Quests->getQuestsForQuesttopic($questtopic['id']); + foreach($quests as &$quest) + { + // Get Questgroup + $quest['questgroup'] = $this->Questgroups->getQuestgroupById($quest['questgroup_id']); + + // Get Subtopics + $quest['subtopics'] = $this->Questtopics->getQuestsubtopicsForQuest($quest['id']); + $quest['subtopics'] = array_map(function($t) { return $t['id']; }, $quest['subtopics']); + } + + + // Set title + $this->addTitle($questtopic['title']); + $this->addTitleLocalized('Library'); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('questtopic', $questtopic); + $this->set('questsubtopics', $questsubtopics); + $this->set('quests', $quests); + } + } ?> diff --git a/locale/de_DE/LC_MESSAGES/The Legend of Z.mo b/locale/de_DE/LC_MESSAGES/The Legend of Z.mo index f634d175..cfd2b333 100644 Binary files a/locale/de_DE/LC_MESSAGES/The Legend of Z.mo and b/locale/de_DE/LC_MESSAGES/The Legend of Z.mo differ diff --git a/locale/de_DE/LC_MESSAGES/The Legend of Z.po b/locale/de_DE/LC_MESSAGES/The Legend of Z.po index 45a50f3d..6d408ad1 100644 --- a/locale/de_DE/LC_MESSAGES/The Legend of Z.po +++ b/locale/de_DE/LC_MESSAGES/The Legend of Z.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: The Legend of Z\n" -"POT-Creation-Date: 2014-05-15 23:32+0100\n" -"PO-Revision-Date: 2014-05-15 23:33+0100\n" +"POT-Creation-Date: 2014-05-16 00:20+0100\n" +"PO-Revision-Date: 2014-05-16 00:21+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -732,7 +732,8 @@ msgstr "Das Kursfeld „%s“ ist ungültig" msgid "Seminary fields" msgstr "Kursfelder" -#: views/html/characters/index.tpl:13 views/html/users/index.tpl:7 +#: views/html/characters/index.tpl:13 views/html/library/managetopic.tpl:26 +#: views/html/users/index.tpl:7 msgid "Manage" msgstr "Verwalten" @@ -842,8 +843,8 @@ msgstr "Du hast Level %d erreicht" msgid "Introduction" msgstr "Einführung" -#: views/html/library/index.tpl:9 views/html/library/topic.tpl:8 -#: views/html/seminarymenu/index.tpl:7 +#: views/html/library/index.tpl:9 views/html/library/managetopic.tpl:8 +#: views/html/library/topic.tpl:8 views/html/seminarymenu/index.tpl:7 msgid "Library" msgstr "Bibliothek" @@ -861,6 +862,10 @@ msgstr "" msgid "Total progress: %d %%" msgstr "Gesamtfortschritt: %d%%" +#: views/html/library/topic.tpl:13 +msgid "Manage topic" +msgstr "Thema verwalten" + #: views/html/menu/index.tpl:2 views/html/users/create.tpl:5 #: views/html/users/delete.tpl:5 views/html/users/edit.tpl:6 #: views/html/users/edit.tpl:8 views/html/users/index.tpl:4 diff --git a/models/QuesttopicsModel.inc b/models/QuesttopicsModel.inc index abd246f7..31328572 100644 --- a/models/QuesttopicsModel.inc +++ b/models/QuesttopicsModel.inc @@ -131,6 +131,25 @@ } + /** + * Get alle Questsubtopics for a Questtopic. + * + * @param int $questtopicId ID of Questtopic + * @return array List of Questsubtopics for this Questtopic + */ + public function getSubtopicsForQuesttopic($questtopicId) + { + return $this->db->query( + 'SELECT id, questtopic_id, title, url '. + 'FROM questsubtopics '. + 'WHERE questsubtopics.questtopic_id = ? '. + 'ORDER BY title ASC', + 'i', + $questtopicId + ); + } + + /** * Get all Questsubtopics for a Quest. * @@ -149,6 +168,47 @@ ); } + + /** + * Set Questsubtopics for a Quest. + * + * @param int $questId ID of Quest to set subtopics for + * @param array $questsubtopicIds List of IDs of subtopics to set + */ + public function setQuestsubtopicsForQuest($questId, $questsubtopicIds) + { + $this->db->setAutocommit(false); + try { + // Remove Questsubtopics + $this->db->query( + 'DELETE FROM quests_questsubtopics '. + 'WHERE quest_id = ?', + 'i', + $questId + ); + + // Add Questsubtopics + foreach($questsubtopicIds as &$questsubtopicId) + { + $this->db->query( + 'INSERT INTO quests_questsubtopics '. + '(quest_id, questsubtopic_id) '. + 'VALUES '. + '(?, ?)', + 'ii', + $questId, $questsubtopicId + ); + } + } + catch(\nre\exceptions\DatamodelException $e) { + $this->db->rollback(); + $this->db->setAutocommit(true); + throw $e; + } + + $this->db->setAutocommit(true); + } + } ?> diff --git a/views/html/library/managetopic.tpl b/views/html/library/managetopic.tpl new file mode 100644 index 00000000..6303e191 --- /dev/null +++ b/views/html/library/managetopic.tpl @@ -0,0 +1,27 @@ + +
+ +
+ + +

+ +

Quests zu diesem Thema:

+
+ + +
diff --git a/views/html/library/topic.tpl b/views/html/library/topic.tpl index 8d153215..472ae7b1 100644 --- a/views/html/library/topic.tpl +++ b/views/html/library/topic.tpl @@ -8,6 +8,11 @@
  • + 0) : ?> + +

    Themenfortschritt: /