From 46364ac6f21bef85ea2e07e6c08f5c7abb12835a Mon Sep 17 00:00:00 2001 From: coderkun Date: Wed, 12 Feb 2014 23:39:15 +0100 Subject: [PATCH] implement Questtexts and Sidequests --- agents/intermediate/QuestsAgent.inc | 9 ++ controllers/QuestgroupsController.inc | 8 +- controllers/QuestsController.inc | 85 +++++++++++++-- locale/de_DE/LC_MESSAGES/The Legend of Z.mo | Bin 1888 -> 2106 bytes locale/de_DE/LC_MESSAGES/The Legend of Z.po | 22 +++- models/QuestsModel.inc | 73 +++++++++++++ models/QuesttextsModel.inc | 113 +++++++++++++++++++- views/html/questgroups/questgroup.tpl | 15 ++- views/html/quests/quest.tpl | 22 +++- views/html/quests/sidequest.tpl | 23 ++++ 10 files changed, 355 insertions(+), 15 deletions(-) create mode 100644 views/html/quests/sidequest.tpl diff --git a/agents/intermediate/QuestsAgent.inc b/agents/intermediate/QuestsAgent.inc index e58e5092..faed65a5 100644 --- a/agents/intermediate/QuestsAgent.inc +++ b/agents/intermediate/QuestsAgent.inc @@ -31,6 +31,15 @@ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true); } + + /** + * Action: quest. + */ + public function sidequest(\nre\core\Request $request, \nre\core\Response $response) + { + $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true); + } + } ?> diff --git a/controllers/QuestgroupsController.inc b/controllers/QuestgroupsController.inc index 2ab68d9e..a0639592 100644 --- a/controllers/QuestgroupsController.inc +++ b/controllers/QuestgroupsController.inc @@ -76,8 +76,14 @@ // Get Quests $quests = null; - if(count($childQuestgroupshierarchy) == 0) { + if(count($childQuestgroupshierarchy) == 0) + { $quests = $this->Quests->getQuestsForQuestgroup($questgroup['id']); + + // Attach sidequests + foreach($quests as &$quest) { + $quest['sidequests'] = $this->Quests->getSidequestsForQuest($quest['id']); + } } diff --git a/controllers/QuestsController.inc b/controllers/QuestsController.inc index cccd1581..ed6a1f3c 100644 --- a/controllers/QuestsController.inc +++ b/controllers/QuestsController.inc @@ -51,9 +51,11 @@ * Show a quest and its task. * * @throws IdNotFoundException - * @param string $seminaryUrl URL-Title of a Seminary - * @param string $questgroupUrl URL-Title of a Questgroup - * @param string $questUrl URL-Title of a Quest + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $questgroupUrl URL-Title of a Questgroup + * @param string $questUrl URL-Title of a Quest + * @param string $questtexttypeUrl URL-Title of a Questtexttype + * @param int $questtextPos Position of Questtext */ public function quest($seminaryUrl, $questgroupUrl, $questUrl, $questtexttypeUrl=null, $questtextPos=1) { @@ -73,10 +75,16 @@ if(is_null($questtexttypeUrl)) { $questtexttypeUrl = 'Prolog'; } - if(in_array($questtexttypeUrl, $questtexttypes)) + $questtextCount = $this->Questtexts->getQuesttextsCountForQuest($quest['id'], $questtexttypeUrl); + if($questtextCount > 0) { - $questtextPos = max(intval($questtextPos), 1); - $questtext = $this->Questtexts->getQuesttextByUrl($quest['id'], $questtexttypeUrl, $questtextPos); + if(in_array($questtexttypeUrl, $questtexttypes)) + { + $questtextPos = max(intval($questtextPos), 1); + $questtext = $this->Questtexts->getQuesttextByUrl($quest['id'], $questtexttypeUrl, $questtextPos); + $questtext['count'] = $questtextCount; + $questtext['sidequests'] = $this->Quests->getSidequestsForQuesttext($questtext['id']); + } } // Show task only for Prologes @@ -94,6 +102,71 @@ $this->set('showtask', $showTask); } + /** + * Action: sidequest. + * + * Show a sidequest and its task. + * + * @throws IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $questgroupUrl URL-Title of a Questgroup + * @param string $questUrl URL-Title of a Quest + * @param string $sidequestUrl URL-Title of a Sidequest + * @param string $questtexttypeUrl URL-Title of a Questtexttype + * @param int $questtextPos Position of Questtext + */ + public function sidequest($seminaryUrl, $questgroupUrl, $questUrl, $sidequestUrl, $sidequesttexttypeUrl=null, $sidequesttextPos=1) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Questgroup + $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl); + + // Get Quest + $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl); + + // Get Sidequest + $sidequest = $this->Quests->getSidequestByUrl($seminary['id'], $questgroup['id'], $quest['id'], $sidequestUrl); + + // Get Questtext + $questtext = $this->Questtexts->getQuesttextForSidequest($sidequest['id']); + + // Get Sidequesttext + $sidequesttext = null; + $questtexttypes = $this->Questtexts->getQuesttexttypes(); + $questtexttypes = array_map(function($t) { return $t['url']; }, $questtexttypes); + if(is_null($sidequesttexttypeUrl)) { + $sidequesttexttypeUrl = 'Prolog'; + } + $sidequesttextCount = $this->Questtexts->getQuesttextsCountForSidequest($sidequest['id'], $sidequesttexttypeUrl); + if($sidequesttextCount > 0) + { + if(in_array($sidequesttexttypeUrl, $questtexttypes)) + { + $sidequesttextPos = max(intval($sidequesttextPos), 1); + $sidequesttext = $this->Questtexts->getSidequesttextByUrl($sidequest['id'], $sidequesttexttypeUrl, $sidequesttextPos); + $sidequesttext['count'] = $sidequesttextCount; + } + } + + // Show task only for Prologes + $showTask = false; + if($sidequesttext['type'] == 'Prolog') { + $showTask = true; + } + + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('questgroup', $questgroup); + $this->set('sidequesttext', $sidequesttext); + $this->set('quest', $quest); + $this->set('questtext', $questtext); + $this->set('sidequest', $sidequest); + $this->set('showtask', $showTask); + } + } ?> 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 ab0f294c9cf370b826dbce9096447d57728a950e..8680ecbba6a35368600de60d9e20a7e18e7ec4ce 100644 GIT binary patch delta 959 zcmZ9~KWGzS7{~F)Bu(PK+E$}6)%FS%9R!mqh@I-cF6t1exO#@OIgOX%UBxPr!9ggv zcsTe66r4I&5Cu1J6$b|wQ4rL{sSZy1{pBthe7X1iyzkw6@AJOT-Iu}FL!Hkfxd%p> zpzfkht}{D;`!h6@AGiU3;#OS4Em+JZmT@EFeYhD9;d(rV19%#T@GNe^MtXk%^JX2p zo<6vZMJ6n##>oVGf?DV~Y9lMC4ZgrCe#0D=XtrYoHNS>h?{GSvK?2$=R`5)B+%ap? z(aGBBggdAmFC&*drg=(Mo}o4{!z$bG6qfM<>f}o}jCWBPdWc$g1-a}Ejn;jO%GgI7 zAijO2!)4!T6yO&Q;vduriiPC)aB3NK!f~wO9-PMW$Yu9ww6RC1d8??@ze26|4)uxN zV`r4kr}V~eEHVCznpmRIiN;VbRFOp32vq@;M!o-kQBVcc|D;UlvuItNTECV4wX|IB zs`M$|E$w3*4(oC$xqeG`yBI+Ck*{fgjBG=O-(K z@rUeMHsu=xJ!5+}Xy^X_|n_ndp)tHd9orTe6}YeX+2&G72X2JsaY+X1si z+`(4d!x$bp&#{U5HMZa#HsA|}u!?c~#Aa*?{#;LCy;;fnIMIzPMzG+VKrK*26)=s% zIEOjhboWnC&z-sX1+uVRId4#f-@5r5s-P-**g2?sc6;UQE^4l^e{A`_r9@xMaDU*>tyIPm3S@I#Zb_ZTByoyhIXM)QWd69 z<>ar0x}y##i4y-t4<|{6z9)4=#i)b-qk{?cBx|i!I~Do}&3_7<`Uk-kzu=|)C2uv7 g8_VPi<0GT~vzPgslw+Ylz)ywO{BpS8{|HZg12BX-2LJ#7 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 b9117fec..e5954918 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-02-09 12:48+0100\n" -"PO-Revision-Date: 2014-02-09 12:48+0100\n" +"POT-Creation-Date: 2014-02-12 23:09+0100\n" +"PO-Revision-Date: 2014-02-12 23:10+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -30,6 +30,7 @@ msgstr "Benutzer" #: ../../../views/html/seminaries/create.tpl:1 #: ../../../views/html/questgroups/questgroup.tpl:1 #: ../../../views/html/quests/quest.tpl:1 +#: ../../../views/html/quests/sidequest.tpl:1 msgid "Seminaries" msgstr "Kurse" @@ -156,10 +157,27 @@ msgstr "Soll der Kurs „%s“ wirklich gelöscht werden?" msgid "New seminary" msgstr "Neuer Kurs" +#: ../../../views/html/questgroups/questgroup.tpl:23 +msgid "Quests" +msgstr "Quests" + +#: ../../../views/html/questgroups/questgroup.tpl:29 +msgid "containing optional Quests" +msgstr "Enthaltene optionale Quests" + #: ../../../views/html/introduction/index.tpl:1 msgid "Introduction" msgstr "Einführung" +#: ../../../views/html/quests/quest.tpl:33 +#: ../../../views/html/quests/sidequest.tpl:20 +msgid "Task" +msgstr "Aufgabe" + +#: ../../../views/html/quests/sidequest.tpl:8 +msgid "This Quest is optional" +msgstr "Diese Quest ist optional" + #~ msgid "created by %s on %s at %s" #~ msgstr "erstellt von %s am %s um %s Uhr" diff --git a/models/QuestsModel.inc b/models/QuestsModel.inc index 2f991143..dd30a5dd 100644 --- a/models/QuestsModel.inc +++ b/models/QuestsModel.inc @@ -80,6 +80,79 @@ return $data[0]; } + + /** + * Get a Sidequest 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 int $questId ID of the Quest + * @param string $sidequestUrl URL-title of a Sidequest + * @return array Sidequest data + */ + public function getSidequestByUrl($seminaryId, $questgroupId, $questId, $sidequestUrl) + { + $data = $this->db->query( + 'SELECT sidequests.id, sidequests.questtype_id, sidequests.title, sidequests.url, sidequests.xps, sidequests.task '. + 'FROM sidequests '. + 'LEFT JOIN questtexts ON questtexts.id = sidequests.questtext_id '. + 'LEFT JOIN quests ON quests.id = questtexts.quest_id '. + 'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '. + 'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '. + 'LEFT JOIN seminaries ON seminaries.id = questgroupshierarchy.seminary_id '. + 'WHERE sidequests.url = ? AND quests.id = ? AND questgroups.id = ? AND seminaries.id = ?', + 'siii', + $sidequestUrl, + $questId, + $questgroupId, + $seminaryId + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException(); + } + + + return $data[0]; + } + + + /** + * Get all sidequests for a Quest. + * + * @param int $questId ID of the quest + * @return array Sidequests for the quest + */ + public function getSidequestsForQuest($questId) + { + return $this->db->query( + 'SELECT sidequests.id, sidequests.questtext_id, sidequests.title, sidequests.url, sidequests.entry_text '. + 'FROM sidequests '. + 'LEFT JOIN questtexts ON questtexts.id = sidequests.questtext_id '. + 'WHERE questtexts.quest_id = ?', + 'i', + $questId + ); + } + + + /** + * Get all sidequests for a Questtext. + * + * @param int $questtextId ID of the questtext + * @return array Sidequests for the questtext + */ + public function getSidequestsForQuesttext($questtextId) + { + return $this->db->query( + 'SELECT id, questtext_id, title, url, entry_text '. + 'FROM sidequests '. + 'WHERE questtext_id = ?', + 'i', + $questtextId + ); + } + } ?> diff --git a/models/QuesttextsModel.inc b/models/QuesttextsModel.inc index 7387b3a2..aa1a054c 100644 --- a/models/QuesttextsModel.inc +++ b/models/QuesttextsModel.inc @@ -46,10 +46,10 @@ public function getQuesttextByUrl($questId, $questtexttypeUrl, $pos) { $data = $this->db->query( - 'SELECT questtexts.id, questtexts.text, questtexts.out_text, questtexttypes.type '. + 'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexts.out_text, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '. 'FROM questtexts '. 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '. - 'WHERE questtexts.quest_id = ? AnD questtexttypes.url = ? AND questtexts.pos = ?', + 'WHERE questtexts.quest_id = ? AND questtexttypes.url = ? AND questtexts.pos = ?', 'isi', $questId, $questtexttypeUrl, $pos ); @@ -62,6 +62,115 @@ } + /** + * Get a Questtext for a Sidequest by its URL. + * + * @throws IdNotFoundException + * @param int $sidequestId ID of the Sidequest to get text for + * @param string $questtexttypeUrl URL of the Questtexttype + * @param int $pos Position of Questtexttype + * @return array Questtexttype data + */ + public function getSidequesttextByUrl($sidequestId, $questtexttypeUrl, $pos) + { + $data = $this->db->query( + 'SELECT sidequesttexts.id, sidequesttexts.text, sidequesttexts.pos, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '. + 'FROM sidequesttexts '. + 'LEFT JOIN questtexttypes ON questtexttypes.id = sidequesttexts.questtexttype_id '. + 'WHERE sidequesttexts.sidequest_id = ? AND questtexttypes.url = ? AND sidequesttexts.pos = ?', + 'isi', + $sidequestId, $questtexttypeUrl, $pos + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($questtexttypeUrl); + } + + + return $data = $data[0]; + } + + + /** + * Get count of Questtexts for a Quest. + * + * @param int $questId ID of the Quest + * @param string $questtexttypeUrl URL of the Questtexttype + * @return int Conut of Questtexts for Quest + */ + public function getQuesttextsCountForQuest($questId, $questtexttypUrl) + { + $count = 0; + $data = $this->db->query( + 'SELECT COUNT(questtexts.id) AS c '. + 'FROM questtexts '. + 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '. + 'WHERE questtexts.quest_id = ? AND questtexttypes.url = ?', + 'is', + $questId, $questtexttypUrl + ); + if(!empty($data)) { + $count = $data[0]['c']; + } + + + return $count; + } + + + /** + * Get count of Questtexts for a Sidequest. + * + * @param int $sidequestId ID of the Sidequest + * @param string $questtexttypeUrl URL of the Questtexttype + * @return int Conut of Questtexts for Sideuest + */ + public function getQuesttextsCountForSidequest($questId, $questtexttypUrl) + { + $count = 0; + $data = $this->db->query( + 'SELECT COUNT(sidequesttexts.id) AS c '. + 'FROM sidequesttexts '. + 'LEFT JOIN questtexttypes ON questtexttypes.id = sidequesttexts.questtexttype_id '. + 'WHERE sidequesttexts.sidequest_id = ? AND questtexttypes.url = ?', + 'is', + $questId, $questtexttypUrl + ); + if(!empty($data)) { + $count = $data[0]['c']; + } + + + return $count; + } + + + /** + * Get corresponding Questtext for a Sidequest. + * + * @throws IdNotFoundException + * @param int $sidequestId ID of the Sidequest to get the Questtext for + * @param array Questtext data + */ + public function getQuesttextForSidequest($sidequestId) + { + $data = $this->db->query( + 'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '. + 'FROM sidequests '. + 'LEFT JOIN questtexts ON questtexts.id = sidequests.questtext_id '. + 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '. + 'WHERE sidequests.id = ?', + 'i', + $sidequestId + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException(); + } + + + return $data[0]; + } + + /** * Get all registered Questtexttypes. * diff --git a/views/html/questgroups/questgroup.tpl b/views/html/questgroups/questgroup.tpl index 3cca41f4..231f663e 100644 --- a/views/html/questgroups/questgroup.tpl +++ b/views/html/questgroups/questgroup.tpl @@ -20,10 +20,21 @@ -

Quests

+

    -
  • +
  • + +
    + : + 0) : ?> +
      + +
    • + +
    + +
diff --git a/views/html/quests/quest.tpl b/views/html/quests/quest.tpl index 836ce775..598342da 100644 --- a/views/html/quests/quest.tpl +++ b/views/html/quests/quest.tpl @@ -5,14 +5,32 @@

+

- - + + +
    + +
  • + + +
  • + +
+ + + + + + 1) : ?>< + / + >
+

diff --git a/views/html/quests/sidequest.tpl b/views/html/quests/sidequest.tpl new file mode 100644 index 00000000..7b1dc3db --- /dev/null +++ b/views/html/quests/sidequest.tpl @@ -0,0 +1,23 @@ +

+

+ + + +

+

+

.

+
+

+

+ + 1) : ?>< + / + > +
+ + +
+

+

+
+