diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 8291a1f1..01237cc3 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -132,7 +132,8 @@ public static $misc = array( 'ranking_range' => 2, 'achievements_range' => 3, - 'title_delimiter' => ' – ' + 'title_delimiter' => ' – ', + 'questlist_limit' => 10 ); @@ -212,6 +213,7 @@ array('^questgroups/([^/]+)/(create)/?$', 'questgroups/$2/$1', true), array('^questgroups/([^/]+)/([^/]+)/?$', 'questgroups/questgroup/$1/$2', true), array('^quests/([^/]+)/?$', 'quests/index/$1', true), + array('^quests/([^/]+)/all/?$', 'quests/index/$1/all', true), array('^quests/([^/]+)/(create|createmedia)/?$', 'quests/$2/$1' , true), array('^quests/([^/]+)/([^/]+)/([^/]+)/(submissions)/?$', 'quests/$4/$1/$2/$3', true), array('^quests/([^/]+)/([^/]+)/([^/]+)/(submission)/([^/]+)/?$', 'quests/$4/$1/$2/$3/$5', true), @@ -250,7 +252,7 @@ array('^seminaries/seminary/(.*)$', 'seminaries/$1', false), array('^questgroups/create/(.*)$', 'questgroups/$2/$1', true), array('^questgroups/questgroup/(.*)$', 'questgroups/$1', true), - array('^quests/index/([^/]+)$', 'quests/$1', true), + array('^quests/index/(.+)$', 'quests/$1', true), array('^quests/quest/(.*)$', 'quests/$1', true), array('^quests/(create|createmedia)/(.*)$', 'quests/$2/$1' , true), array('^quests/(submissions)/(.*)$', 'quests/$2/$1', true), diff --git a/controllers/QuestsController.inc b/controllers/QuestsController.inc index c506219b..291b6cba 100644 --- a/controllers/QuestsController.inc +++ b/controllers/QuestsController.inc @@ -74,53 +74,49 @@ * List all Quests for a Seminary. * * @param string $seminaryUrl URL-Title of Seminary + * @param string $all Show all Quests */ - public function index($seminaryUrl) + public function index($seminaryUrl, $all=null) { // Get seminary $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); - // Prepare filters - $filters = array( - 'questgroups' => array(), - 'questtypes' => array() - ); - - // Get selected filters - $selectedFilters = array( - 'questgroup' => "0", - 'questtype' => "" - ); - if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('filters'))) { - $selectedFilters = $this->request->getPostParam('filters'); + // Set filters + $selectedQuestgroup = null; + $selectedQuesttype = null; + if($this->request->getRequestMethod() == 'GET') + { + $selectedQuestgroup = !empty($this->request->getGetParam('questgroup')) ? $this->request->getGetParam('questgroup') : null; + $selectedQuesttype = !empty($this->request->getGetParam('questtype')) ? $this->request->getGetParam('questtype') : null; } // Get Quests - $quests = array(); - foreach($this->Quests->getQuestsForSeminary($seminary['id']) as $quest) + $limit = (is_null($all) && is_null($selectedQuestgroup) && is_null($selectedQuesttype)) ? \nre\configs\AppConfig::$misc['questlist_limit'] : null; + $quests = $this->Quests->getQuestsForSeminary($seminary['id'], $selectedQuestgroup, $selectedQuesttype, $limit); + foreach($quests as &$quest) { // Get Questgroup $quest['questgroup'] = $this->Questgroups->getQuestgroupById($quest['questgroup_id']); - if($selectedFilters['questgroup'] != "0" && $selectedFilters['questgroup'] != $quest['questgroup']['id']) { - continue; - } // Get Questtype $quest['questtype'] = $this->Questtypes->getQuesttypeById($quest['questtype_id']); - if($selectedFilters['questtype'] != "" && $selectedFilters['questtype'] != $quest['questtype']['classname']) { - continue; - } - - // Add filter values - $filters['questgroups'][$quest['questgroup']['id']] = $quest['questgroup']; - $filters['questtypes'][$quest['questtype']['classname']] = $quest['questtype']; // Add open submissions count $quest['opensubmissionscount'] = count($this->Characters->getCharactersSubmittedQuest($quest['id'])); - - $quests[] = $quest; } + // Sort Quests + usort($quests, function($a, $b) { + if($a['opensubmissionscount'] == $b['opensubmissionscount']) { + return 0; + } + return ($a['opensubmissionscount'] < $b['opensubmissionscount']) ? 1 : -1; + }); + + // Get filter values + $questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']); + $questtypes = $this->Questtypes->getQuesttypes(); + // Set titile $this->addTitleLocalized('Quests'); @@ -128,9 +124,12 @@ // Pass data to view $this->set('seminary', $seminary); + $this->set('questgroups', $questgroups); + $this->set('questtypes', $questtypes); + $this->set('selectedQuestgroup', $selectedQuestgroup); + $this->set('selectedQuesttype', $selectedQuesttype); $this->set('quests', $quests); - $this->set('filters', $filters); - $this->set('selectedFilters', $selectedFilters); + $this->set('limit', $limit); } 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 82b2b8be..f634d175 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 709e2acd..45a50f3d 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 18:15+0100\n" -"PO-Revision-Date: 2014-05-15 18:15+0100\n" +"POT-Creation-Date: 2014-05-15 23:32+0100\n" +"PO-Revision-Date: 2014-05-15 23:33+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -427,7 +427,7 @@ msgstr "%s-Gruppe verwalten" #: views/html/characters/character.tpl:77 #: views/html/characters/character.tpl:83 #: views/html/characters/character.tpl:89 -#: views/html/characters/character.tpl:103 views/html/quests/index.tpl:37 +#: views/html/characters/character.tpl:103 views/html/quests/index.tpl:73 #: views/html/seminaries/index.tpl:29 views/html/seminarybar/index.tpl:7 #: views/html/seminarybar/index.tpl:43 #, php-format @@ -908,17 +908,57 @@ msgstr "Text für falsche Antwort" msgid "Task" msgstr "Aufgabe" +#: views/html/quests/index.tpl:16 views/html/quests/index.tpl:23 +msgid "all" +msgstr "alle" + #: views/html/quests/index.tpl:21 msgid "Questtype" msgstr "Questtyp" -#: views/html/quests/index.tpl:29 +#: views/html/quests/index.tpl:27 views/html/quests/index.tpl:57 +msgid "Questtype Empty" +msgstr "Leere Aufgabe" + +#: views/html/quests/index.tpl:29 views/html/quests/index.tpl:59 +msgid "Questtype bossfight" +msgstr "Boss-Fight" + +#: views/html/quests/index.tpl:31 views/html/quests/index.tpl:61 +msgid "Questtype choiceinput" +msgstr "Auswahleingabe" + +#: views/html/quests/index.tpl:33 views/html/quests/index.tpl:63 +msgid "Questtype crossword" +msgstr "Kreuzworträtsel" + +#: views/html/quests/index.tpl:35 views/html/quests/index.tpl:65 +msgid "Questtype dragndrop" +msgstr "Drag&Drop" + +#: views/html/quests/index.tpl:37 views/html/quests/index.tpl:67 +msgid "Questtype multiplechoice" +msgstr "Multiple Choice" + +#: views/html/quests/index.tpl:39 views/html/quests/index.tpl:69 +msgid "Questtype submit" +msgstr "Abgabeaufgabe" + +#: views/html/quests/index.tpl:41 views/html/quests/index.tpl:71 +msgid "Questtype textinput" +msgstr "Texteingabe" + +#: views/html/quests/index.tpl:48 msgid "Apply filters" msgstr "Filter anwenden" -#: views/html/quests/index.tpl:30 -msgid "Reset filters" -msgstr "Filter zurücksetzen" +#: views/html/quests/index.tpl:54 +msgid "open submissions" +msgstr "offene Lösungsvorschläge" + +#: views/html/quests/index.tpl:79 +msgid "Show all" +msgstr "Alle anzeigen" #: views/html/quests/quest.tpl:11 msgid "Prolog" @@ -1193,6 +1233,9 @@ msgstr "Registrieren" msgid "Roles" msgstr "Rollen" +#~ msgid "Reset filters" +#~ msgstr "Filter zurücksetzen" + #~ msgid "Create" #~ msgstr "Erstellen" diff --git a/models/QuestsModel.inc b/models/QuestsModel.inc index d87deff9..92749c03 100644 --- a/models/QuestsModel.inc +++ b/models/QuestsModel.inc @@ -354,13 +354,16 @@ * @param int $seminaryId ID of Seminary * @return array Quests for this Seminary */ - public function getQuestsForSeminary($seminaryId) + public function getQuestsForSeminary($seminaryId, $questgroupId=null, $questtypeId=null, $limit=null) { return $this->db->query( 'SELECT DISTINCT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.wrong_text, quests.questsmedia_id '. 'FROM questgroups '. 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '. - 'WHERE questgroups.seminary_id = ?', + 'WHERE questgroups.seminary_id = ?'. + (!empty($questgroupId) ? ' AND questgroups.id = '.intval($questgroupId) : null). + (!empty($questtypeId) ? ' AND quests.questtype_id = '.intval($questtypeId) : null). + (!empty($limit) ? ' LIMIT '.intval($limit) : null), 'i', $seminaryId ); diff --git a/views/html/quests/index.tpl b/views/html/quests/index.tpl index 03724b57..576183ce 100644 --- a/views/html/quests/index.tpl +++ b/views/html/quests/index.tpl @@ -8,34 +8,73 @@
=$quest['title']?>=$quest['opensubmissionscount']?> open submissions
-=$quest['questtype']['title']?>, =sprintf(_('%d XPs'), $quest['xps'])?>
+=$quest['title']?>=$quest['opensubmissionscount']?> =_('open submissions')?>
++ , =sprintf(_('%d XPs'), $quest['xps'])?>