diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 60021cf4..1a70a84e 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -234,8 +234,9 @@ array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/(edit|delete|manage)/?$', 'charactergroupsquests/$4/$1/$2/$3', true), array('^achievements/([^/]+)/?$', 'achievements/index/$1', true), array('^library/([^/]+)/?$', 'library/index/$1', true), + array('^library/([^/]+)/create/?$', 'library/create/$1', true), array('^library/([^/]+)/([^/]+)/?$', 'library/topic/$1/$2', true), - array('^library/([^/]+)/([^/]+)/manage/?$', 'library/managetopic/$1/$2', true), + array('^library/([^/]+)/([^/]+)/(edit|delete|manage)/?$', 'library/$3/$1/$2', true), array('^media/(.*)$', 'media/$1?layout=binary', false), array('^uploads/(.*)$', 'uploads/$1?layout=binary', false) ); @@ -272,8 +273,10 @@ 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/managetopic/(.*)$', 'library/$1/manage', true) + array('^library/index/([^/]+)/?$', 'library/$1', true), + array('^library/create/([^/]+)/?$', 'library/$1/create', true), + array('^library/topic/([^/]+)/([^/]+)/?$', 'library/$1/$2', true), + array('^library/(edit|delete|manage)/([^/]+)/([^/]+)/?$', 'library/$2/$3/$1', true) ); diff --git a/controllers/LibraryController.inc b/controllers/LibraryController.inc index bd782950..01976e1b 100644 --- a/controllers/LibraryController.inc +++ b/controllers/LibraryController.inc @@ -25,6 +25,12 @@ * @var array */ public $models = array('questtopics', 'seminaries', 'quests', 'questgroups'); + /** + * Required components + * + * @var array + */ + public $components = array('validation'); /** * User permissions * @@ -33,7 +39,10 @@ public $permissions = array( 'index' => array('admin', 'moderator', 'user'), 'topic' => array('admin', 'moderator', 'user'), - 'managetopic' => array('admin', 'moderator', 'user') + 'manage' => array('admin', 'moderator', 'user'), + 'create' => array('admin', 'moderator', 'user'), + 'edit' => array('admin', 'moderator', 'user'), + 'delete' => array('admin', 'moderator', 'user') ); /** * User seminary permissions @@ -43,7 +52,10 @@ public $seminaryPermissions = array( 'index' => array('admin', 'moderator', 'user', 'guest'), 'topic' => array('admin', 'moderator', 'user', 'guest'), - 'managetopic' => array('admin', 'moderator') + 'manage' => array('admin', 'moderator'), + 'create' => array('admin', 'moderator'), + 'edit' => array('admin', 'moderator'), + 'delete' => array('admin', 'moderator') ); @@ -142,7 +154,7 @@ /** - * Action: managetopic. + * Action: manage. * * Manage a Questtopic and its Quests with Questsubtopics. * @@ -150,7 +162,7 @@ * @param string $eminaryUrl URL-Title of Seminary * @param string $questtopicUrl URL-Title of Questtopic */ - public function managetopic($seminaryUrl, $questtopicUrl) + public function manage($seminaryUrl, $questtopicUrl) { // Get Seminary $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); @@ -214,6 +226,288 @@ $this->set('allQuests', $allQuests); } + + /** + * Action: create. + * + * Create a new Questtopic for a Seminary. + * + * @throws IdNotFoundException + * @param string $seminaryUrl URL-Title of Seminary + */ + public function create($seminaryUrl) + { + // Get Seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Values + $title = ''; + $fields = array('title'); + $validation = array(); + + // Create new Questtopic + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create'))) + { + // Get params and validate them + $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields); + $title = $this->request->getPostParam('title'); + if($this->Questtopics->questtopicTitleExists($title)) { + $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true); + } + + // Create + if($validation === true) + { + $questtopicId = $this->Questtopics->createQuesttopic( + $this->Auth->getUserId(), + $seminary['id'], + $title + ); + $questtopic = $this->Questtopics->getQuesttopicById($questtopicId); + + // Redirect to Questtopic + $this->redirect($this->linker->link(array('topic', $seminary['url'], $questtopic['url']), 1)); + } + } + + // Get validation settings + $validationSettings = array(); + foreach($fields as &$field) { + $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field]; + } + + + // Set title + $this->addTitleLocalized('New Questtopic'); + $this->addTitleLocalized('Library'); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('title', $title); + $this->set('validation', $validation); + $this->set('validationSettings', $validationSettings); + } + + + /** + * Action: edit. + * + * Edit a Questtopic of a Seminary and its Questsubtopics. + * + * @throws IdNotFoundException + * @param string $eminaryUrl URL-Title of Seminary + * @param string $questtopicUrl URL-Title of Questtopic + */ + public function edit($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']); + + // Values + $questtopicTitle = $questtopic['title']; + $subtopicsTitles = array(); + foreach($questsubtopics as &$questsubtopic) { + $subtopicsTitles[$questsubtopic['id']] = $questsubtopic['title']; + } + $deleteSubtopics = null; + $subtopicTitle = ''; + $validations = array( + 'edit' => true, + 'edit-subtopics' => true, + 'create-subtopic' => true + ); + + // Edit + $action = null; + if($this->request->getRequestMethod() == 'POST') + { + // Edit Questtopic + if(!is_null($this->request->getPostParam('edit'))) + { + $action = 'edit'; + + // Get params and validate them + $validations[$action] = $this->Validation->validateParams($this->request->getPostParams(), array('title')); + $questtopicTitle = $this->request->getPostParam('title'); + if($this->Questtopics->questsubtopicTitleExists($questtopicTitle, $questtopic['id'])) { + $validations[$action] = $this->Validation->addValidationResult($validations[$action], 'title', 'exist', true); + } + + // Edit + if($validations[$action] === true) + { + $this->Questtopics->editQuesttopic( + $questtopic['id'], + $questtopicTitle + ); + $questtopic = $this->Questtopics->getQuesttopicById($questtopic['id']); + + // Redirect + $this->redirect($this->linker->link(array('topic', $seminary['url'], $questtopic['url']), 1)); + } + } + + // Edit and delete Questsubtopics + elseif(!is_null($this->request->getPostParam('edit-subtopics'))) + { + $action = 'edit-subtopics'; + + // Get params and validate them + $subtopicsTitles = $this->request->getPostParam('subtopics'); + $deleteSubtopics = $this->request->getPostParam('delete-subtopics'); + foreach($questsubtopics as &$questsubtopic) + { + if(!is_null($deleteSubtopics) && array_key_exists($questsubtopic['id'], $deleteSubtopics)) { + continue; + } + + $title = $subtopicsTitles[$questsubtopic['id']]; + $subtopicValidation = $this->Validation->validate($title, \nre\configs\AppConfig::$validation['title']); + if($subtopicValidation !== true) + { + if(!is_array($validations['edit-subtopics'])) { + $validations['edit-subtopics'] = array(); + } + if(!array_key_exists($questsubtopic['id'], $validations['edit-subtopics']) || !is_array($validations['edit-subtopics'][$questsubtopic['id']])) { + $validations['edit-subtopics'][$questsubtopic['id']] = array(); + } + //$validations['edit-subtopics'][$questsubtopic['id']]['title'] = $subtopicValidation; + $validations['edit-subtopics'][$questsubtopic['id']] = $this->Validation->addValidationResults($validations['edit-subtopics'][$questsubtopic['id']], 'title', $subtopicValidation); + } + if($this->Questtopics->questsubtopicTitleExists($questtopic['id'], $title, $questsubtopic['id'])) + { + if(!is_array($validations['edit-subtopics'])) { + $validations['edit-subtopics'] = array(); + } + if(!array_key_exists($questsubtopic['id'], $validations['edit-subtopics']) || !is_array($validations['edit-subtopics'][$questsubtopic['id']])) { + $validations['edit-subtopics'][$questsubtopic['id']] = array(); + } + $validations['edit-subtopics'][$questsubtopic['id']] = $this->Validation->addValidationResult($validations['edit-subtopics'][$questsubtopic['id']], 'title', 'exist', true); + } + } + + // Edit and delete + if($validations['edit-subtopics'] === true) + { + foreach($questsubtopics as &$questsubtopic) + { + // Delete + if(!is_null($deleteSubtopics) && array_key_exists($questsubtopic['id'], $deleteSubtopics)) { + $this->Questtopics->deleteQuestsubtopic($questsubtopic['id']); + } + // Edit + elseif(!is_null($subtopicsTitles) && array_key_exists($questsubtopic['id'], $subtopicsTitles)) + { + $title = $subtopicsTitles[$questsubtopic['id']]; + $this->Questtopics->editQuestsubtopic($questsubtopic['id'], $title); + } + } + + // Redirect + $this->redirect($this->linker->link(array($seminary['url'], $questtopic['url']), 2)); + } + } + + // Create Questsubtopic + elseif(!is_null($this->request->getPostParam('create-subtopic'))) + { + $action = 'create-subtopic'; + + // Get params and validate them + $validations[$action] = $this->Validation->validateParams($this->request->getPostParams(), array('title')); + $subtopicTitle = $this->request->getPostParam('title'); + if($this->Questtopics->questsubtopicTitleExists($questtopic['id'], $subtopicTitle)) { + $validations[$action] = $this->Validation->addValidationResult($validations[$action], 'title', 'exist', true); + } + + // Create + if($validations[$action] === true) + { + $this->Questtopics->createQuestsubtopic( + $this->Auth->getUserId(), + $questtopic['id'], + $subtopicTitle + ); + $subtopicTitle = ''; + + // Redirect + $this->redirect($this->linker->link(null, 4)); + } + } + } + + // Get validation settings + $validationSettings = array( + 'title' => \nre\configs\AppConfig::$validation['title'] + ); + + + // Set title + $this->addTitleLocalized('Edit Questtopic'); + $this->addTitleLocalized('Library'); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('questtopicTitle', $questtopicTitle); + $this->set('subtopicsTitles', $subtopicsTitles); + $this->set('deleteSubtopics', $deleteSubtopics); + $this->set('subtopicTitle', $subtopicTitle); + $this->set('action', $action); + $this->set('validations', $validations); + $this->set('validationSettings', $validationSettings); + } + + + /** + * Action: delete. + * + * Delete a Questtopic of a Seminary. + * + * @throws IdNotFoundException + * @param string $eminaryUrl URL-Title of Seminary + * @param string $questtopicUrl URL-Title of Questtopic + */ + public function delete($seminaryUrl, $questtopicUrl) + { + // Get Seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Questtopic + $questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl); + + // Check request method + if($this->request->getRequestMethod() == 'POST') + { + // Check confirmation + if(!is_null($this->request->getPostParam('delete'))) + { + // Delete seminary + $this->Questtopics->deleteQuesttopic($questtopic['id']); + + // Redirect to overview + $this->redirect($this->linker->link(array('index', $seminary['url']), 1)); + } + } + + + // Set title + $this->addTitleLocalized('Delete Questtopic'); + $this->addTitleLocalized('Library'); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('questtopic', $questtopic); + } + } ?> 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 cfd2b333..e28e5deb 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 6d408ad1..7c3c9dac 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-16 00:20+0100\n" -"PO-Revision-Date: 2014-05-16 00:21+0100\n" +"POT-Creation-Date: 2014-05-17 13:42+0100\n" +"PO-Revision-Date: 2014-05-17 13:43+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -343,7 +343,8 @@ msgstr "Motto" #: views/html/charactergroups/creategroup.tpl:77 #: views/html/charactergroups/creategroupsgroup.tpl:50 #: views/html/charactergroupsquests/create.tpl:93 -#: views/html/characters/register.tpl:94 views/html/questgroups/create.tpl:17 +#: views/html/characters/register.tpl:94 views/html/library/create.tpl:46 +#: views/html/library/edit.tpl:124 views/html/questgroups/create.tpl:17 #: views/html/quests/create.tpl:43 views/html/seminaries/create.tpl:14 #: views/html/users/create.tpl:96 msgid "create" @@ -372,7 +373,8 @@ msgstr "Soll die %s-Gruppen „%s“ wirklich gelöscht werden?" #: views/html/charactergroups/deletegroup.tpl:15 #: views/html/charactergroups/deletegroupsgroup.tpl:14 #: views/html/charactergroupsquests/delete.tpl:15 -#: views/html/characters/delete.tpl:17 views/html/seminaries/delete.tpl:13 +#: views/html/characters/delete.tpl:17 views/html/library/delete.tpl:14 +#: views/html/library/edit.tpl:83 views/html/seminaries/delete.tpl:13 #: views/html/users/delete.tpl:11 msgid "delete" msgstr "löschen" @@ -380,8 +382,8 @@ msgstr "löschen" #: views/html/charactergroups/deletegroup.tpl:16 #: views/html/charactergroups/deletegroupsgroup.tpl:15 #: views/html/charactergroupsquests/delete.tpl:16 -#: views/html/characters/delete.tpl:18 views/html/seminaries/delete.tpl:14 -#: views/html/users/delete.tpl:12 +#: views/html/characters/delete.tpl:18 views/html/library/delete.tpl:15 +#: views/html/seminaries/delete.tpl:14 views/html/users/delete.tpl:12 msgid "cancel" msgstr "abbrechen" @@ -510,28 +512,38 @@ msgstr "Neue %s-Quest" #: views/html/charactergroupsquests/create.tpl:34 #: views/html/charactergroupsquests/edit.tpl:34 +#: views/html/library/create.tpl:22 views/html/library/edit.tpl:22 +#: views/html/library/edit.tpl:62 views/html/library/edit.tpl:100 #, php-format msgid "Title is too short (min. %d chars)" msgstr "Der Titel ist zu kurz (min. %d Zeichen)" #: views/html/charactergroupsquests/create.tpl:36 #: views/html/charactergroupsquests/edit.tpl:36 +#: views/html/library/create.tpl:24 views/html/library/edit.tpl:24 +#: views/html/library/edit.tpl:64 views/html/library/edit.tpl:102 #, php-format msgid "Title is too long (max. %d chars)" msgstr "Der Titel ist zu lang (max. %d Zeichen)" #: views/html/charactergroupsquests/create.tpl:38 #: views/html/charactergroupsquests/edit.tpl:38 +#: views/html/library/create.tpl:26 views/html/library/edit.tpl:26 +#: views/html/library/edit.tpl:66 views/html/library/edit.tpl:104 msgid "Title contains illegal characters" msgstr "Der Titel enthält ungültige Zeichen" #: views/html/charactergroupsquests/create.tpl:40 #: views/html/charactergroupsquests/edit.tpl:40 +#: views/html/library/create.tpl:28 views/html/library/edit.tpl:28 +#: views/html/library/edit.tpl:68 views/html/library/edit.tpl:106 msgid "Title already exists" msgstr "Der Titel existiert bereits" #: views/html/charactergroupsquests/create.tpl:42 #: views/html/charactergroupsquests/edit.tpl:42 +#: views/html/library/create.tpl:30 views/html/library/edit.tpl:30 +#: views/html/library/edit.tpl:70 views/html/library/edit.tpl:108 msgid "Title invalid" msgstr "Der Titel ist ungültig" @@ -555,6 +567,9 @@ msgstr "Die XP-Angabe ist ungültig" #: views/html/charactergroupsquests/create.tpl:75 #: views/html/charactergroupsquests/edit.tpl:75 #: views/html/charactergroupsquests/edit.tpl:76 +#: views/html/library/create.tpl:43 views/html/library/create.tpl:44 +#: views/html/library/edit.tpl:43 views/html/library/edit.tpl:44 +#: views/html/library/edit.tpl:121 views/html/library/edit.tpl:122 #: views/html/questgroups/create.tpl:14 views/html/questgroups/create.tpl:15 #: views/html/seminaries/create.tpl:11 views/html/seminaries/create.tpl:12 #: views/html/seminaries/edit.tpl:13 views/html/seminaries/edit.tpl:14 @@ -624,6 +639,7 @@ msgid "File invalid" msgstr "Die Datei ist ungültig" #: views/html/charactergroupsquests/manage.tpl:66 +#: views/html/library/edit.tpl:46 views/html/library/edit.tpl:86 #: views/html/seminaries/edit.tpl:16 views/html/users/edit.tpl:103 msgid "save" msgstr "speichern" @@ -732,7 +748,7 @@ msgstr "Das Kursfeld „%s“ ist ungültig" msgid "Seminary fields" msgstr "Kursfelder" -#: views/html/characters/index.tpl:13 views/html/library/managetopic.tpl:26 +#: views/html/characters/index.tpl:13 views/html/library/manage.tpl:39 #: views/html/users/index.tpl:7 msgid "Manage" msgstr "Verwalten" @@ -843,12 +859,43 @@ msgstr "Du hast Level %d erreicht" msgid "Introduction" msgstr "Einführung" -#: views/html/library/index.tpl:9 views/html/library/managetopic.tpl:8 -#: views/html/library/topic.tpl:8 views/html/seminarymenu/index.tpl:7 +#: views/html/library/create.tpl:8 views/html/library/delete.tpl:8 +#: views/html/library/edit.tpl:8 views/html/library/index.tpl:9 +#: views/html/library/manage.tpl:8 views/html/library/topic.tpl:8 +#: views/html/seminarymenu/index.tpl:7 msgid "Library" msgstr "Bibliothek" -#: views/html/library/index.tpl:10 +#: views/html/library/create.tpl:10 +msgid "New Questtopic" +msgstr "Neues Thema" + +#: views/html/library/delete.tpl:11 views/html/library/topic.tpl:14 +msgid "Delete Questtopic" +msgstr "Thema löschen" + +#: views/html/library/delete.tpl:12 +#, php-format +msgid "Should the Questtopic “%s” really be deleted?" +msgstr "Soll das Thema „%s“ wirklich gelöscht werden?" + +#: views/html/library/edit.tpl:11 views/html/library/topic.tpl:13 +msgid "Edit Questtopic" +msgstr "Thema bearbeiten" + +#: views/html/library/edit.tpl:49 +msgid "Edit Questsubtopics" +msgstr "Unterthemen bearbeiten" + +#: views/html/library/edit.tpl:89 +msgid "Create new Questsubtopic" +msgstr "Neues Unterthema erstellen" + +#: views/html/library/index.tpl:12 +msgid "Create new Questtopic" +msgstr "Neues Thema erstellen" + +#: views/html/library/index.tpl:15 #, php-format msgid "Library description, %s, %s" msgstr "" @@ -857,13 +904,17 @@ msgstr "" "Umfang der Bibliothek, spiele also regelmäßig weiter und schalte so Quest " "für Quest alle Inhalte frei." -#: views/html/library/index.tpl:12 +#: views/html/library/index.tpl:17 #, php-format msgid "Total progress: %d %%" msgstr "Gesamtfortschritt: %d%%" -#: views/html/library/topic.tpl:13 -msgid "Manage topic" +#: views/html/library/manage.tpl:27 +msgid "Add Quest" +msgstr "Quest hinzufügen" + +#: views/html/library/topic.tpl:15 +msgid "Manage Questtopic" msgstr "Thema verwalten" #: views/html/menu/index.tpl:2 views/html/users/create.tpl:5 @@ -1278,9 +1329,6 @@ msgstr "Rollen" #~ msgid "Character type" #~ msgstr "Charaktertyp" -#~ msgid "Questtopics" -#~ msgstr "Themen" - #~ msgid "Questname" #~ msgstr "Questname" diff --git a/models/QuesttopicsModel.inc b/models/QuesttopicsModel.inc index 31328572..4c7810bc 100644 --- a/models/QuesttopicsModel.inc +++ b/models/QuesttopicsModel.inc @@ -59,6 +59,30 @@ } + /** + * Get a Questtopic by its ID. + * + * @param int $questtopicId ID of Questtopic + * @return array Questtopic data + */ + public function getQuesttopicById($questtopicId) + { + $data = $this->db->query( + 'SELECT id, title, url '. + 'FROM questtopics '. + 'WHERE id = ?', + 'i', + $questtopicId + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($questtopicId); + } + + + return $data[0]; + } + + /** * Get all Questtopics for a Seminary. * @@ -70,7 +94,8 @@ return $this->db->query( 'SELECT id, title, url '. 'FROM questtopics '. - 'WHERE seminary_id = ?', + 'WHERE seminary_id = ? '. + 'ORDER BY title ASC', 'i', $seminaryId ); @@ -162,7 +187,8 @@ 'SELECT DISTINCT id, questtopic_id, title, url '. 'FROM quests_questsubtopics '. 'INNER JOIN questsubtopics ON questsubtopics.id = quests_questsubtopics.questsubtopic_id '. - 'WHERE quests_questsubtopics.quest_id = ?', + 'WHERE quests_questsubtopics.quest_id = ? '. + 'ORDER BY questsubtopics.title ASC', 'i', $questId ); @@ -209,6 +235,166 @@ $this->db->setAutocommit(true); } + + /** + * Check if a Questtopic title already exists. + * + * @param string $title Questtopic title to check + * @param int $questtopicId Do not check this ID (for editing) + * @return boolean Whether Questtopic title exists or not + */ + public function questtopicTitleExists($title, $questtopicId=null) + { + $data = $this->db->query( + 'SELECT id '. + 'FROM questtopics '. + 'WHERE title = ? OR url = ?', + 'ss', + $title, + \nre\core\Linker::createLinkParam($title) + ); + + return (!empty($data) && (is_null($questtopicId) || $questtopicId != $data[0]['id'])); + } + + + /** + * Create a new Questtopic for a Seminary. + * + * @param int $userId ID of creating user + * @param int $seminaryId ID of Seminary + * @param string $title Title for new Questtopic + * @return int ID of newly created Questtopic + */ + public function createQuesttopic($userId, $seminaryId, $title) + { + $this->db->query( + 'INSERT INTO questtopics '. + '(created_user_id, seminary_id, title, url) '. + 'VALUES '. + '(?, ?, ?, ?) ', + 'iiss', + $userId, + $seminaryId, + $title, + \nre\core\Linker::createLinkParam($title) + ); + + return $this->db->getInsertId(); + } + + + /** + * Edit a Questtopic. + * + * @param int $questtopicId ID of Questtopic to edit + * @param string $title New title of Questtopic + */ + public function editQuesttopic($questtopicId, $title) + { + $this->db->query( + 'UPDATE questtopics '. + 'SET title = ?, url = ? '. + 'WHERE id = ?', + 'ssi', + $title, + \nre\core\Linker::createLinkParam($title), + $questtopicId + ); + } + + + /** + * Delete a Questtopic. + * + * @param int $questtopicId ID of Questtopic to delete + */ + public function deleteQuesttopic($questtopicId) + { + $this->db->query('DELETE FROM questtopics WHERE id = ?', 'i', $questtopicId); + } + + + /** + * Check if a Questsubtopic title already exists. + * + * @param int $questtopicId ID of Questtopic + * @param string $title Questsubtopic title to check + * @param int $questsubtopicId Do not check this ID (for editing) + * @return boolean Whether Questsubtopic title exists or not + */ + public function questsubtopicTitleExists($questtopicId, $title, $questsubtopicId=null) + { + $data = $this->db->query( + 'SELECT id '. + 'FROM questsubtopics '. + 'WHERE questtopic_id = ? AND (title = ? OR url = ?)', + 'iss', + $questtopicId, + $title, + \nre\core\Linker::createLinkParam($title) + ); + + return (!empty($data) && (is_null($questsubtopicId) || $questsubtopicId != $data[0]['id'])); + } + + + /** + * Create a new Questsubtopic for a Questtopic. + * + * @param int $userId ID of creating user + * @param int $questtopicId ID of Qusttopic + * @param string $title Title for new Questtopic + * @return int ID of newly created Questsubtopic + */ + public function createQuestsubtopic($userId, $questtopicId, $title) + { + $this->db->query( + 'INSERT INTO questsubtopics '. + '(created_user_id, questtopic_id, title, url) '. + 'VALUES '. + '(?, ?, ?, ?) ', + 'iiss', + $userId, + $questtopicId, + $title, + \nre\core\Linker::createLinkParam($title) + ); + + return $this->db->getInsertId(); + } + + + /** + * Edit a Questsubtopic. + * + * @param int $questsubtopicId ID of Questsubtopic to edit + * @param string $title New title of Questsubtopic + */ + public function editQuestsubtopic($questsubtopicId, $title) + { + $this->db->query( + 'UPDATE questsubtopics '. + 'SET title = ?, url = ? '. + 'WHERE id = ?', + 'ssi', + $title, + \nre\core\Linker::createLinkParam($title), + $questsubtopicId + ); + } + + + /** + * Delete a Questsubtopic. + * + * @param int $questsubtopicId ID of Questsubtopic to delete + */ + public function deleteQuestsubtopic($questtopicId) + { + $this->db->query('DELETE FROM questsubtopics WHERE id = ?', 'i', $questtopicId); + } + } ?> diff --git a/views/html/library/create.tpl b/views/html/library/create.tpl new file mode 100644 index 00000000..b1282434 --- /dev/null +++ b/views/html/library/create.tpl @@ -0,0 +1,47 @@ + +
+ +
+ + +

+ + + + +
+
+ + /> +
+ +
diff --git a/views/html/library/delete.tpl b/views/html/library/delete.tpl new file mode 100644 index 00000000..5f9f3b7d --- /dev/null +++ b/views/html/library/delete.tpl @@ -0,0 +1,16 @@ + +
+ +
+ + + +

+ +
+ + +
diff --git a/views/html/library/edit.tpl b/views/html/library/edit.tpl new file mode 100644 index 00000000..2083eb76 --- /dev/null +++ b/views/html/library/edit.tpl @@ -0,0 +1,125 @@ + +
+ +
+ + + +

+ + + +
+
+ + /> +
+ +
+ +

+
+ &$title) : ?> + + + + /> + checked="checked" /> +
+ + + +
+ +

+ + + +
+
+
+ +
diff --git a/views/html/library/index.tpl b/views/html/library/index.tpl index 8b42b8e9..2d1aaeb7 100644 --- a/views/html/library/index.tpl +++ b/views/html/library/index.tpl @@ -7,6 +7,11 @@
  • + 0) : ?> + +

    0) ? round($totalCharacterQuestcount/$totalQuestcount*100) : 0) ?>

    diff --git a/views/html/library/managetopic.tpl b/views/html/library/manage.tpl similarity index 100% rename from views/html/library/managetopic.tpl rename to views/html/library/manage.tpl diff --git a/views/html/library/topic.tpl b/views/html/library/topic.tpl index fa6711d0..0a737e65 100644 --- a/views/html/library/topic.tpl +++ b/views/html/library/topic.tpl @@ -10,7 +10,9 @@

    0) : ?>