From f41f48b928ca9b29d2161d4b51a8a5c4a56978a3 Mon Sep 17 00:00:00 2001 From: coderkun Date: Fri, 16 May 2014 00:22:24 +0200 Subject: [PATCH] implement managing of Queststopics --- configs/AppConfig.inc | 4 +- controllers/LibraryController.inc | 66 +++++++++++++++++++- locale/de_DE/LC_MESSAGES/The Legend of Z.mo | Bin 14853 -> 14898 bytes locale/de_DE/LC_MESSAGES/The Legend of Z.po | 15 +++-- models/QuesttopicsModel.inc | 60 ++++++++++++++++++ views/html/library/managetopic.tpl | 27 ++++++++ views/html/library/topic.tpl | 5 ++ 7 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 views/html/library/managetopic.tpl 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 f634d175f4590331375b9c112c8cbb21dad8202e..cfd2b333030621307e9520e6415dabca3f1b5e8f 100644 GIT binary patch delta 4884 zcmZwKca#;?0mt!+OD{`V`bJn_>4aUH)Cd}i56rUbkBy+A|r(I*b*yX`&jRRm8kc@Iye|x;{>dXMQ9T%(ECfU z48DOia648BArX#HsLzR0SQEd+YFM30Q*4aQ@FujuJiHcXVk>+BYvbNnKZ$mvLakJL zovM5yk~`25 zjzUK`0iEhe=#oAhEkrx89vk8gOw^@tih@18jNVX_ldfSqbOx?RuN%Z4Har1KV;&|) zh~8I#-nS;Y8GYbxw1dZ^r_grJ)n)$O9OpUVnp{Cgm`1B!&=75~DLS(DXhU7mk@t@0 z2O|H4A^hPIk^_+tG&iqnq*=dc&9Klz)Y;d1-!h z2AZL3-x{;9C;GsPLhy(l=se&_=RU~)5|n{om=l~d6h z=AkoGfHwRbIs?UMN4CcL;pivGs)oyG`x$I~ug^wiFcG>?u*W|_8|;IQcnCU`qtFgK zfOcpGI`vPY9WRJ3MqksV=mTCs2eJcg_W=5w6WA5cV2gp(A)U z){C(z^@C^!E}$d*25lgXr#Z!yF%9b=lNK`3nd%npi!G_&hCc6csVhP|unN6#4chZf=nT9YeIK`%VgTs4b2!V3H$ z?m_Rrh&h<3*&@gv}2W6U^|+LcB~ybgZ1)$>;H_uUqMGywN>i(Ytfm@K^yFWwlg@^$Dtj1 z41Mr3@%NX|b~a*J-~XM-LI`i8Q}`Zc;W>0~RB4@htr|pcKxb+!GK*n4I>MFc0Jfk@ z@D5hQ&(Xd0722UI=%%mUhIV*<=uM##jzC8+9=&in+TbEAgR9VXopruOV9x%HdAoz4x$&HMSJ)K+Vjik z`<~VzgihEUtxv|E;LFGu!X@m6%{!*1_#U)_Q_+siK?hn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nTdg4s~P{bvPDQQ`KY6{1 zOZ?PD-^L;2@pvw8kw?huq&Ink_}+T_m<%No3r|$6m3Wd;2l5V?LY^Wy#G`;zCzr^p zWB}Pn`Vf!zlNA4BYjiCC68FUN?r3)$OWd{|kCHQFnREOB1;2vwiN|U3Te5+4BOZIn z919%vlNA5NY^J=3_Z(-ymoml3hURa9m{z|ed?7jS2VKe Hfzdb->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:

+
+
    + +
  • +

    + + checked="checked" /> +
    + +
  • + +
+ +
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: /