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 zcmZoI*;G=0Pl#nI0|NuY69xtb83qOh8+HZ;V@3vs7(S3F1A~Sz0|N&G1B0e80|O@m z1A`HiZzIgWz|FwG;3~|(AkM(R5Gc&Rpv}O*kSWZ-z{9}6Fjbg=0c6A?sQQh<3=FIc z3=F%385o2Z7#I!+GcfQnFw`?#7G_|OVqjo+D9peh!oa}rN0@;@fPsNQP=tX&m4Sgl zNrZtxje&u|Lj+=Az6b+@ECT~Wod^Si76Svr91#WvF$M;P<52!R5r{)LMIq*yiZU>8 zF)%QAi83&-F)%QMiZU>;GcYj3h=Lqi&%lr(%D`a6z`#%_3bA+zSb~9Jt0)75AOi!# zAyJ5nuZTh{elE(uAk4tPz$(VTpvb_$ASnjnTZ=I;@G~$l_=`a-ju&HKkYr$BD1nOi zi9yVtCk8QRJxIKsfq~(y7$hj~Lg|-ckRbgk1`Z+yUU7)erNtQ-q!}0(w8SCeZsL$A z2@!|*Fisre!%T5VP#1_pqO=T3PZozbV1qaVgFFKR!$ENdhI$E5(2GM{`U|R1L;@5v z3=D=6kPxtwU|;~L3y^>qoGHP;z{0@5kS_tzS0Vwis1K@dHI&{V0kQC?1jK>Yp!7qi zId3Ew>cNTYlLRDAeoH`n$Seu5NL~`+5LHQt&x|A?23bl%eC`4j_mhM;BvcX-1^JQ? zhu1^(PlVF*pysZI>f0z;53zU$)Zhb9gHKCB66IB>h7XdEApa%_iE|byNC>D&LE>Ip zih)6afq}tZ3gX}dC_h&UqP|ZGl1Mi|<&R52%)e3(6?iWN$!33`d{$`&22lnE1|eyP zxP~+&C=I0<7*rS-7@VXbxg#B_u2&k8W)@3BJhWSy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3hHM5%2!MK) zz6=ZuwG0fCi}@rO`zQDEiSynD2}5z+3s|g3<(Sj46#r? zh}zA-z!1#9z_5jZfx(Y~fnf&&B;SJM8bIA|1_p+T$rlCW>ytq(HUi;q@Fg#*lU|7Pyzz_jyR536x1b`$N7#L1LX;5P;56Yec>SIIMd!RI^ z!C$}tNwy%Na8Uc1fq`KvCK zfta9SiFFJN3=P<2*FsxxJt504b15KpX}JhDs=%!oa`~3hHn%FfcSTKnm+7 z1_p*B3=9kp7#J9qGC*1bmq4`%sQ<+PDc~&w86drY`3wvUi=l>XWPo(aKm#um85kIB z7$Ai)NO}W^U|?XFx>;4Ym~Hb?$r>(pQw1YqD`TU{8Y+rVw(;fw6&|k5IeN#q0i(~> AJOBUy 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:

+
+
    + +
  • +

    + + 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: /