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 93d0ec1a..0cb7d3bd 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 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 @@ + +
+ +
+ + + +

+
+ +
+ + + + + +
+ + +
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) : ?>