From 23841c6aff0e1599f50f4e5c08387bfbbec31d2b Mon Sep 17 00:00:00 2001 From: coderkun Date: Fri, 4 Jul 2014 13:54:57 +0200 Subject: [PATCH] implement CRUD for Quest texts (issue #36) --- agents/intermediate/QuestsAgent.inc | 9 + configs/AppConfig.inc | 20 +- controllers/QuestsController.inc | 223 ++++++++++++++++++++ locale/de_DE/LC_MESSAGES/The Legend of Z.mo | Bin 19958 -> 20170 bytes locale/de_DE/LC_MESSAGES/The Legend of Z.po | 72 ++++--- models/MediaModel.inc | 3 + models/QuesttextsModel.inc | 115 +++++++--- views/html/quests/edittexts.tpl | 64 ++++++ views/html/quests/quest.tpl | 1 + 9 files changed, 441 insertions(+), 66 deletions(-) create mode 100644 views/html/quests/edittexts.tpl diff --git a/agents/intermediate/QuestsAgent.inc b/agents/intermediate/QuestsAgent.inc index 4afacc3c..4279181b 100644 --- a/agents/intermediate/QuestsAgent.inc +++ b/agents/intermediate/QuestsAgent.inc @@ -68,6 +68,15 @@ } + /** + * Action: edittexts. + */ + public function edittexts(\nre\core\Request $request, \nre\core\Response $response) + { + $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true); + } + + /** * Action: delete. */ diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 6d4e7aa6..056860be 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -240,11 +240,11 @@ array('^questgroups/([^/]+)/create/?$', 'questgroups/create/$1', true), array('^questgroups/([^/]+)/([^/]+)/(edit|edittexts|delete|moveup|movedown)/?$', 'questgroups/$3/$1/$2', 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/$3/$1/$2', true), - array('^quests/([^/]+)/([^/]+)/([^/]+)/(submissions|edit|delete)/?$', 'quests/$4/$1/$2/$3', true), - array('^quests/([^/]+)/([^/]+)/([^/]+)/(submission)/([^/]+)/?$', 'quests/$4/$1/$2/$3/$5', true), + array('^quests/([^/]+)/?$', 'quests/index/$1', true), + array('^quests/([^/]+)/all/?$', 'quests/index/$1/all', true), + array('^quests/([^/]+)/([^/]+)/(create|createmedia)/?$', 'quests/$3/$1/$2', true), + array('^quests/([^/]+)/([^/]+)/([^/]+)/(submissions|edit|edittexts|delete)/?$', 'quests/$4/$1/$2/$3', true), + array('^quests/([^/]+)/([^/]+)/([^/]+)/(submission)/([^/]+)/?$', 'quests/$4/$1/$2/$3/$5', true), array('^quests/(?!(index|create|createmedia))/?', 'quests/quest/$1', true), array('^characters/([^/]+)/(register|manage)/?$', 'characters/$2/$1', true), array('^characters/([^/]+)/?$', 'characters/index/$1', true), @@ -287,11 +287,11 @@ array('^questgroups/create/(.*)$', 'questgroups/$1/create', true), array('^questgroups/questgroup/(.*)$', 'questgroups/$1', true), array('^questgroups/(edit|edittexts|delete|moveup|movedown)/(.*)$', 'questgroups/$2/$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), - array('^quests/(submission|edit|delete)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$', 'quests/$2/$3/$4/$1/$5', 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), + array('^quests/(submission|edit|edittexts|delete)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$', 'quests/$2/$3/$4/$1/$5', true), array('^characters/(index|character)/(.*)$', 'characters/$2', true), array('^characters/(register|manage)/([^/]+)$', 'characters/$2/$1', true), array('^characters/(edit|delete)/([^/]+)/([^/]+)$', 'characters/$2/$3/$1', true), diff --git a/controllers/QuestsController.inc b/controllers/QuestsController.inc index 3c3f05c9..fc1ad610 100644 --- a/controllers/QuestsController.inc +++ b/controllers/QuestsController.inc @@ -43,6 +43,7 @@ 'submission' => array('admin', 'moderator', 'user'), 'create' => array('admin', 'moderator', 'user'), 'edit' => array('admin', 'moderator', 'user'), + 'edittexts' => array('admin', 'moderator', 'user'), 'delete' => array('admin', 'moderator', 'user') ); /** @@ -57,6 +58,7 @@ 'submission' => array('admin', 'moderator'), 'create' => array('admin', 'moderator'), 'edit' => array('admin', 'moderator'), + 'edittexts' => array('admin', 'moderator'), 'delete' => array('admin') ); @@ -769,6 +771,227 @@ } + /** + * Action: edittexts. + * + * Edit the texts of a Quest of a Seminary. + * + * @throws IdNotFoundException + * @param string $seminaryUrl URL-Title of Seminary + * @param string $questgroupUrl URL-Title of Questgroup + * @param string $questUrl URL-Title of Quest + */ + public function edittexts($seminaryUrl, $questgroupUrl, $questUrl) + { + // Get Seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Questgroup + $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl); + $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']); + $questgroup['picture'] = (!is_null($questgroup['questgroupspicture_id'])) ? $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']) : null; + + // Get Quest + $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl); + + // Get Questtexts + $questtextTypes = $this->Questtexts->getQuesttexttypes(); + foreach($questtextTypes as &$questtextType) + { + $questtextType['texts'] = $this->Questtexts->getQuesttextsOfQuest($quest['id'], $questtextType['url']); + foreach($questtextType['texts'] as &$questtext) + { + if(!is_null($questtext['questsmedia_id'])) { + $questtext['media'] = $this->Media->getSeminaryMediaById($questtext['questsmedia_id']); + } + } + } + + // Get allowed mimetypes + $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics']; + + // Check request method + $validations = array(); + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit'))) + { + $media = $_FILES['media']; + $texts = $this->request->getPostParam('questtexts'); + $deleteTexts = $this->request->getPostParam('deletes'); + if(!is_array($deleteTexts)) { + $deleteTexts = array(); + } + + foreach($questtextTypes as &$type) + { + // Edit or delete texts + if(!array_key_exists($type['url'], $texts)) { + continue; + } + foreach($type['texts'] as &$text) + { + if(array_key_exists($type['url'], $deleteTexts) && array_key_exists($text['id'], $deleteTexts[$type['url']])) + { + // Delete text + $this->Questtexts->deleteQuesttext($text); + //unset($texts[$type['url']][$text['id']]); + } + elseif(array_key_exists($type['url'], $texts) && array_key_exists($text['id'], $texts[$type['url']])) + { + // Edit text + $this->Questtexts->editQuesttext($text['id'], $texts[$type['url']][$text['id']]); + + // Validate medium + $medium = null; + $validation = true; + if(!empty($media) && array_key_exists($type['url'], $media['error']) && array_key_exists($text['id'], $media['error'][$type['url']]) && $media['error'][$type['url']][$text['id']] != UPLOAD_ERR_NO_FILE) + { + $medium = array( + 'name' => $media['name'][$type['url']][$text['id']], + 'tmp_name' => $media['tmp_name'][$type['url']][$text['id']], + 'type' => $media['type'][$type['url']][$text['id']], + 'size' => $media['size'][$type['url']][$text['id']], + 'error' => $media['error'][$type['url']][$text['id']] + ); + + // Check error + if($medium['error'] !== UPLOAD_ERR_OK) { + $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $medium); + } + + // Check mimetype + $mediaMimetype = null; + $medium['mimetype'] = \hhu\z\Utils::getMimetype($medium['tmp_name'], $medium['type']); + foreach($mimetypes as &$mimetype) { + if($mimetype['mimetype'] == $medium['mimetype']) { + $mediaMimetype = $mimetype; + break; + } + } + if(is_null($mediaMimetype)) { + $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $medium['mimetype']); + } + elseif($medium['size'] > $mediaMimetype['size']) { + $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']); + } + } + $validations[$type['url']][$text['id']] = $validation; + + // Upload medium + if(!is_null($medium) && $validation === true) + { + $questsmediaId = $this->Media->createQuestMedia( + $this->Auth->getUserId(), + $seminary['id'], + sprintf('questtext-%d-%d', $quest['id'], $text['id']), + $medium['name'], + $medium['type'], + $medium['tmp_name'] + ); + if($questsmediaId > 0) { + $this->Questtexts->setQuestmedia($text['id'], $questsmediaId); + } + } + + // Remove text from list + //unset($texts[$type['url']][$text['id']]); + } + } + + // Add new text + if(array_key_exists($type['url'], $texts) && array_key_exists('new', $texts[$type['url']])) + { + $text = $texts[$type['url']]['new']; + if(!empty($text)) + { + // Add text + $questtextId = $this->Questtexts->addQuesttextToQuest( + $this->Auth->getUserId(), + $quest['id'], + $type['url'], + $text + ); + + // Validate medium + $medium = null; + $validation = true; + if(!empty($media) && array_key_exists($type['url'], $media['error']) && array_key_exists('new', $media['error'][$type['url']]) && $media['error'][$type['url']]['new'] != UPLOAD_ERR_NO_FILE) + { + $medium = array( + 'name' => $media['name'][$type['url']]['new'], + 'tmp_name' => $media['tmp_name'][$type['url']]['new'], + 'type' => $media['type'][$type['url']]['new'], + 'size' => $media['size'][$type['url']]['new'], + 'error' => $media['error'][$type['url']]['new'] + ); + + // Check error + if($medium['error'] !== UPLOAD_ERR_OK) { + $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $medium); + } + + // Check mimetype + $mediaMimetype = null; + $medium['mimetype'] = \hhu\z\Utils::getMimetype($medium['tmp_name'], $medium['type']); + foreach($mimetypes as &$mimetype) { + if($mimetype['mimetype'] == $medium['mimetype']) { + $mediaMimetype = $mimetype; + break; + } + } + if(is_null($mediaMimetype)) { + $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $medium['mimetype']); + } + elseif($medium['size'] > $mediaMimetype['size']) { + $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']); + } + } + $validations[$type['url']]['new'] = $validation; + + // Upload medium + if(!is_null($medium) && $validation === true) + { + $questsmediaId = $this->Media->createQuestMedia( + $this->Auth->getUserId(), + $seminary['id'], + sprintf('questtext-%d-%d', $quest['id'], $questtextId), + $medium['name'], + $medium['type'], + $medium['tmp_name'] + ); + if($questsmediaId > 0) { + $this->Questtexts->setQuestmedia($questtextId, $questsmediaId); + } + } + } + } + + // Reload texts + $type['texts'] = $this->Questtexts->getQuesttextsOfQuest($quest['id'], $type['url']); + foreach($type['texts'] as &$questtext) + { + if(!is_null($questtext['questsmedia_id'])) { + $questtext['media'] = $this->Media->getSeminaryMediaById($questtext['questsmedia_id']); + } + } + } + } + + + // Set titile + $this->addTitleLocalized('Edit Quest texts'); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('questgroup', $questgroup); + $this->set('quest', $quest); + $this->set('questtexttypes', $questtextTypes); + $this->set('mimetypes', $mimetypes); + $this->set('validations', $validations); + } + + + /** * Action: delete. * 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 93d0ec1a91d1313f675a3c6b6dee49a25e10e046..0cb7d3bdf9799bebcbad59989e9ca246fac12652 100644 GIT binary patch delta 6538 zcmex1oAK0K#`=3gEK?a67#P$U85m?37#Ko085nvQ85nwmK%xu`2P7C6I2afh4oWaE za56A3oPzSNNH8$SF)%RPm0)1tW?*3WBf-ER&cMLHA<4j?&A`B*Aj!bM!@$7cBgw$P z$H2f4DGAY^A<4i1GP+0-Y+pS?t0csNMUo5*tPBhctDy=uN-{9;GB7Y4kz`Gf)oRTECT~Wz7zw476SuA zuM`7=7y|>t4k-V;6vTnQq(J7?Gcc%0Lo`@RGcY8ATq@1Lz{SA8uv?mefsKKI;g~c7 z13Lo)!&xYORT|>6yV48{MhpxLub}E=Wgrevkzrs^Vqjn}mVr1lOa`JpU50@{kb!}r zM23Munt_3#O@@I%sGfm=VUY~P0b6Al7=#%Z7%s~&FeoxGFg%xGV31&7VBnO67^EZ% z;Ty{`Fo=SJRu-Z@NtS_upMim)OcvxL28K3S1_nt628P*C@vTt(M`a=QT$6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KKK?EZMgFh&rGcYi0VSqGH8W|WE3K$p|xjT z7$XD2H3mrI;2{H~VgdDjLBk}VN(ih5L@+Qg$TBi8%mkGaj0_CV85kJmLB*LE85oQ~ zL-A1l4JiE;N`nTSK}^svK8SwJz`#)djsa4pS1>>t5TN!TXso6Mqyp5pV}R5Rhd{$J zpiyh6_$~$ph7}A9pf)O01VXVfGB5};GB89iFfepNgct-E85jyd<30=w44w>-$_ONt z4f3ZK0|Ubh5RZX@;UARlXJBA>1RCGnyjMbvZSog6(arMmjI5JA)wnm?tJLza8k$;} h7)(BBpbTaiZhmPnk7M#&OQFrDE&s4>zUT0U7XUnEc%J|O 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 76bf60f2..f11394df 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-07-01 15:40+0100\n" -"PO-Revision-Date: 2014-07-01 15:41+0100\n" +"POT-Creation-Date: 2014-07-01 23:17+0100\n" +"PO-Revision-Date: 2014-07-01 23:17+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -63,8 +63,8 @@ msgstr "Neuer Lösungsvorschlag" msgid "Character submission approved" msgstr "Lösungsvorschlag bewertet" -#: controllers/QuestsController.inc:1004 -#: questtypes/submit/html/submission.tpl:30 views/html/quests/quest.tpl:53 +#: controllers/QuestsController.inc:1107 +#: questtypes/submit/html/submission.tpl:30 views/html/quests/quest.tpl:54 #: views/html/quests/submissions.tpl:30 msgid "solved" msgstr "Richtig!" @@ -76,7 +76,7 @@ msgstr "Richtig!" msgid "lost" msgstr "verloren" -#: questtypes/bossfight/html/quest.tpl:41 views/html/quests/quest.tpl:128 +#: questtypes/bossfight/html/quest.tpl:41 views/html/quests/quest.tpl:129 msgid "Choose" msgstr "Wählen" @@ -191,7 +191,7 @@ msgstr "Bewertet von %s am %s um %s Uhr" msgid "Comment" msgstr "Kommentar" -#: questtypes/submit/html/submission.tpl:31 views/html/quests/quest.tpl:58 +#: questtypes/submit/html/submission.tpl:31 views/html/quests/quest.tpl:59 #: views/html/quests/submissions.tpl:20 msgid "unsolved" msgstr "Leider falsch!" @@ -482,7 +482,7 @@ msgstr "Motto" #: views/html/charactertypes/manage.tpl:91 views/html/library/create.tpl:46 #: views/html/library/edit.tpl:124 views/html/questgroups/create.tpl:76 #: views/html/questgroupshierarchy/create.tpl:63 -#: views/html/quests/create.tpl:110 views/html/seminaries/create.tpl:75 +#: views/html/quests/create.tpl:108 views/html/seminaries/create.tpl:75 #: views/html/users/create.tpl:96 msgid "create" msgstr "erstellen" @@ -513,9 +513,10 @@ msgstr "Soll die %s-Gruppen „%s“ wirklich gelöscht werden?" #: views/html/characters/delete.tpl:17 views/html/charactertypes/manage.tpl:48 #: views/html/library/delete.tpl:14 views/html/library/edit.tpl:83 #: views/html/questgroups/delete.tpl:17 +#: views/html/questgroups/edittexts.tpl:16 #: views/html/questgroupshierarchy/delete.tpl:14 -#: views/html/quests/delete.tpl:11 views/html/seminaries/delete.tpl:13 -#: views/html/users/delete.tpl:11 +#: views/html/quests/delete.tpl:11 views/html/quests/edittexts.tpl:22 +#: views/html/seminaries/delete.tpl:13 views/html/users/delete.tpl:11 msgid "delete" msgstr "löschen" @@ -550,8 +551,9 @@ msgstr "%s-Gruppe bearbeiten" #: views/html/charactergroups/editgroupsgroup.tpl:50 #: views/html/charactergroupsquests/edit.tpl:94 #: views/html/characters/edit.tpl:108 views/html/questgroups/edit.tpl:64 -#: views/html/questgroupshierarchy/edit.tpl:57 views/html/quests/edit.tpl:113 -#: views/html/seminaries/edit.tpl:77 +#: views/html/questgroups/edittexts.tpl:24 +#: views/html/questgroupshierarchy/edit.tpl:57 views/html/quests/edit.tpl:111 +#: views/html/quests/edittexts.tpl:32 views/html/seminaries/edit.tpl:77 msgid "edit" msgstr "bearbeiten" @@ -632,7 +634,6 @@ msgid "Add Characters" msgstr "Füge Charaktere hinzu" #: views/html/charactergroups/managegroup.tpl:59 -#: views/html/questgroups/questgroup.tpl:21 #: views/html/questgroups/questgroup.tpl:108 views/html/quests/index.tpl:9 msgid "Quests" msgstr "Quests" @@ -1157,7 +1158,7 @@ msgid "Moodpic" msgstr "Stimmungsbild" #: views/html/questgroups/delete.tpl:14 -#: views/html/questgroups/questgroup.tpl:16 +#: views/html/questgroups/questgroup.tpl:18 msgid "Delete Questgroup" msgstr "Questgruppe löschen" @@ -1170,7 +1171,16 @@ msgstr "Soll das die Questgruppe „%s“ wirklich gelöscht werden?" msgid "Edit Questgroup" msgstr "Questgruppe bearbeiten" -#: views/html/questgroups/questgroup.tpl:17 +#: views/html/questgroups/edittexts.tpl:8 +#: views/html/questgroups/questgroup.tpl:16 +msgid "Edit Questgroup texts" +msgstr "Questgruppetexte bearbeiten" + +#: views/html/questgroups/edittexts.tpl:20 views/html/quests/edittexts.tpl:27 +msgid "New Questgroup text" +msgstr "Neuer Questgruppentext" + +#: views/html/questgroups/questgroup.tpl:22 msgid "Create new Quest" msgstr "Neue Quest erstellen" @@ -1302,20 +1312,20 @@ msgstr "Das Bild ist ungültig" msgid "Picture" msgstr "Bild" -#: views/html/quests/create.tpl:103 views/html/quests/edit.tpl:106 +#: views/html/quests/create.tpl:102 views/html/quests/edit.tpl:105 msgid "Entry text" msgstr "Einstiegstext" -#: views/html/quests/create.tpl:105 views/html/quests/edit.tpl:108 -#: views/html/quests/quest.tpl:49 +#: views/html/quests/create.tpl:103 views/html/quests/edit.tpl:106 +#: views/html/quests/quest.tpl:50 msgid "Task" msgstr "Aufgabe" -#: views/html/quests/create.tpl:108 views/html/quests/edit.tpl:111 +#: views/html/quests/create.tpl:106 views/html/quests/edit.tpl:109 msgid "Wrong text" msgstr "Text für falsche Antwort" -#: views/html/quests/delete.tpl:8 views/html/quests/quest.tpl:13 +#: views/html/quests/delete.tpl:8 views/html/quests/quest.tpl:14 msgid "Delete Quest" msgstr "Quest löschen" @@ -1328,6 +1338,10 @@ msgstr "Soll die Quest „%s“ wirklich gelöscht werden?" msgid "Edit Quest" msgstr "Quest bearbeiten" +#: views/html/quests/edittexts.tpl:8 views/html/quests/quest.tpl:12 +msgid "Edit Quest texts" +msgstr "Questtexte bearbeiten" + #: views/html/quests/index.tpl:16 views/html/quests/index.tpl:23 msgid "all" msgstr "alle" @@ -1340,44 +1354,44 @@ msgstr "Questtyp" msgid "open submissions" msgstr "offene Lösungsvorschläge" -#: views/html/quests/quest.tpl:19 +#: views/html/quests/quest.tpl:20 msgid "Prolog" msgstr "Prolog" -#: views/html/quests/quest.tpl:54 +#: views/html/quests/quest.tpl:55 msgid "Quest completed." msgstr "Quest abgeschlossen." -#: views/html/quests/quest.tpl:54 +#: views/html/quests/quest.tpl:55 #, php-format msgid "You have earned %d XPs." msgstr "Du hast %d XP erhalten." -#: views/html/quests/quest.tpl:70 +#: views/html/quests/quest.tpl:71 msgid "Task already successfully solved" msgstr "Du hast die Aufgabe bereits erfolgreich gelöst" -#: views/html/quests/quest.tpl:72 +#: views/html/quests/quest.tpl:73 msgid "Show answer" msgstr "Lösung anzeigen" -#: views/html/quests/quest.tpl:82 +#: views/html/quests/quest.tpl:83 msgid "Epilog" msgstr "Epilog" -#: views/html/quests/quest.tpl:108 +#: views/html/quests/quest.tpl:109 msgid "Continuation" msgstr "Setze deine Reise fort" -#: views/html/quests/quest.tpl:115 views/html/quests/quest.tpl:131 +#: views/html/quests/quest.tpl:116 views/html/quests/quest.tpl:132 msgid "Quest" msgstr "Quest" -#: views/html/quests/quest.tpl:133 +#: views/html/quests/quest.tpl:134 msgid "Go on" msgstr "Fortfahren" -#: views/html/quests/quest.tpl:142 views/html/seminaries/seminary.tpl:52 +#: views/html/quests/quest.tpl:143 views/html/seminaries/seminary.tpl:52 msgid "Let’s go" msgstr "Auf ins Abenteuer!" diff --git a/models/MediaModel.inc b/models/MediaModel.inc index ca709c19..b02f51a1 100644 --- a/models/MediaModel.inc +++ b/models/MediaModel.inc @@ -270,6 +270,9 @@ $this->db->rollback(); $mediaId = false; } + else { + $this->db->commit(); + } } catch(\nre\exceptions\DatamodelException $e) { $this->db->rollback(); diff --git a/models/QuesttextsModel.inc b/models/QuesttextsModel.inc index a1a144a0..b66eb284 100644 --- a/models/QuesttextsModel.inc +++ b/models/QuesttextsModel.inc @@ -64,7 +64,7 @@ if(is_null($questtexttypeUrl)) { return $this->db->query( - 'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexts.out_text, questtexts.abort_text, questtexts.questsmedia_id, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '. + 'SELECT questtexts.id, questtexts.quest_id, questtexts.text, questtexts.pos, questtexts.out_text, questtexts.abort_text, questtexts.questsmedia_id, 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 = ?', @@ -75,7 +75,7 @@ else { return $this->db->query( - 'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexts.out_text, questtexts.abort_text, questtexts.questsmedia_id, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '. + 'SELECT questtexts.id, questtexts.quest_id, questtexts.text, questtexts.pos, questtexts.out_text, questtexts.abort_text, questtexts.questsmedia_id, 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 = ?', @@ -220,44 +220,105 @@ /** - * Add a list of Questtexts to a Quest. + * Add a Questtexts to a Quest. * * @param int $userId ID of user * @param int $questId ID of Quest to add texts to * @param string $questtexttypeUrl URL-type of Questtexttype of texts - * @param array $texts List of texts to add. + * @param string $text Text to add. */ - public function addQuesttextsToQuest($userId, $questId, $questtexttypeUrl, $texts) + public function addQuesttextToQuest($userId, $questId, $questtexttypeUrl, $text) { $questtexttype = $this->getQuesttexttypeByUrl($questtexttypeUrl); if(is_null($questtexttype)) { return; } - foreach($texts as &$text) - { - $pos = $this->db->query( - 'SELECT COALESCE(MAX(pos),0)+1 AS pos '. - 'FROM questtexts '. - 'WHERE quest_id = ?', - 'i', - $questId - ); - $pos = $pos[0]['pos']; - - $this->db->query( - 'INSERT INTO questtexts '. - '(created_user_id, quest_id, questtexttype_id, pos, text) '. - 'VALUES '. - '(?, ?, ?, ?, ?)', - 'iiiis', - $userId, $questId, $questtexttype['id'], $pos, - $text - ); - } + + // Get position + $pos = $this->db->query( + 'SELECT COALESCE(MAX(pos),0)+1 AS pos '. + 'FROM questtexts '. + 'WHERE quest_id = ?', + 'i', + $questId + ); + $pos = $pos[0]['pos']; + + // Add Questtext + $this->db->query( + 'INSERT INTO questtexts '. + '(created_user_id, quest_id, questtexttype_id, pos, text) '. + 'VALUES '. + '(?, ?, ?, ?, ?)', + 'iiiis', + $userId, $questId, $questtexttype['id'], $pos, + $text + ); + + + // Return ID + return $this->db->getInsertId(); + } + + + /** + * Set the media for a Quest text. + * + * @param int $questtextId ID of Quest text to set media for + * @param int $questmediaId ID of Questsmedia to set + */ + public function setQuestmedia($questtextId, $questsmediaId) + { + $this->db->query( + 'UPDATE questtexts '. + 'SET questsmedia_id = ? '. + 'WHERE id = ?', + 'ii', + $questsmediaId, + $questtextId + ); + } + + + /** + * Edit a Quest text. + * + * @param int $questtextId ID of Quest text to edit + * @param string $text New text + */ + public function editQuesttext($questtextId, $text) + { + $this->db->query( + 'UPDATE questtexts '. + 'SET text = ? '. + 'WHERE id = ?', + 'si', + $text, + $questtextId + ); } - + /** + * Delete a Quest text. + * + * @param array $questtext Data of Quest text to delete + */ + public function deleteQuesttext($questtext) + { + // Delete Quest text + $this->db->query('DELETE FROM questtexts WHERE id = ?', 'i', $questtext['id']); + + // Adjust positions + $this->db->query( + 'UPDATE questtexts '. + 'SET pos = pos - 1 '. + 'WHERE quest_id = ? AND pos > ?', + 'ii', + $questtext['quest_id'], + $questtext['pos'] + ); + } } diff --git a/views/html/quests/edittexts.tpl b/views/html/quests/edittexts.tpl new file mode 100644 index 00000000..e5ec350e --- /dev/null +++ b/views/html/quests/edittexts.tpl @@ -0,0 +1,64 @@ + +
+ +
+ + + +

+
+ +
+ + +
    + &$validation) : ?> + + &$settings) : ?> +
  • +
      + $value) : ?> +
    • + +
    • + +
    +
  • + + + +
+ +
    + +
  • + +
    + +
    +
    + + +
  • + +
  • +
    + +
  • +
+
+ + +
diff --git a/views/html/quests/quest.tpl b/views/html/quests/quest.tpl index 6c59203b..87695b38 100644 --- a/views/html/quests/quest.tpl +++ b/views/html/quests/quest.tpl @@ -9,6 +9,7 @@ 0) : ?>