diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 12624ab0..aeafd57e 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -73,7 +73,8 @@ array('css/?(.*)', 'css/$1?layout=stylesheet', false), array('users/([^/]+)/(edit|delete)', 'users/$2/$1', true), array('users/(?!(index|login|logout|create|edit|delete))', 'users/user/$1', true), - array('seminaries/(.+)', 'seminaries/seminary/$1', false) + array('seminaries/([^/]+)/(edit|delete)', 'seminaries/$2/$1', true), + array('seminaries/(?!(index|create|edit|delete))', 'seminaries/seminary/$1', true) ); diff --git a/controllers/SeminariesController.inc b/controllers/SeminariesController.inc index 4a9581bf..7e307087 100644 --- a/controllers/SeminariesController.inc +++ b/controllers/SeminariesController.inc @@ -82,6 +82,103 @@ $this->set('seminary', $seminary); } + + /** + * Action: create. + * + * Create a new seminary. + */ + public function create() + { + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create'))) + { + // Create new seminary + var_dump($this->Auth->getUserId()); + $seminaryId = $this->Seminaries->createSeminary( + $this->request->getPostParam('title'), + $this->Auth->getUserId() + ); + + // Redirect to seminary + $user = $this->Seminaries->getSeminaryById($seminaryId); + $this->redirect($this->linker->link(array($seminary['url']), 1)); + } + } + + + /** + * Action: edit. + * + * Edit a seminary. + * + * @throws IdNotFoundException + * @param string $seminaryUrl URL-Title of a seminary + */ + public function edit($seminaryUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Check request method + if($this->request->getRequestMethod() == 'POST') + { + // Save changes + if(!empty($this->request->getPostParam('save'))) + { + // Edit seminary + $this->Seminaries->editSeminary( + $seminary['id'], + $this->request->getPostParam('title') + ); + $seminary = $this->Seminaries->getSeminaryById($seminary['id']); + } + + + // Redirect to entry + $this->redirect($this->linker->link(array($seminary['url']), 1)); + } + + + // Pass data to view + $this->set('seminary', $seminary); + } + + + /** + * Action: delete. + * + * Delete a seminary. + * + * @throws IdNotFoundException + * @param string $seminaryUrl URL-Title of a seminary + */ + public function delete($seminaryUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Check request method + if($this->request->getRequestMethod() == 'POST') + { + // Check confirmation + if(!empty($this->request->getPostParam('delete'))) + { + // Delete seminary + $this->Seminaries->deleteSeminary($seminary['id']); + + // Redirect to overview + $this->redirect($this->linker->link(null, 1)); + } + + // Redirect to entry + $this->redirect($this->linker->link(array('seminary', $seminary['url']), 1)); + } + + + // Show confirmation + $this->set('seminary', $seminary); + } + } ?> diff --git a/controllers/UsersController.inc b/controllers/UsersController.inc index aea5ffbb..d8b44ccd 100644 --- a/controllers/UsersController.inc +++ b/controllers/UsersController.inc @@ -167,10 +167,11 @@ $this->request->getPostParam('email'), $this->request->getPostParam('password') ); + $user = $this->Users->getUserById($user['id']); } - // Redirect to user + // Redirect to entry $this->redirect($this->linker->link(array($user['url']), 1)); } @@ -197,7 +198,7 @@ if($this->request->getRequestMethod() == 'POST') { // Check confirmation - if($this->request->getPostParam('delete') == 'delete') + if(!empty($this->request->getPostParam('delete'))) { // Delete user $this->Users->deleteUser($user['id']); 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 cb455ec1..621bc112 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 c42c969d..8d264180 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-01-25 20:20+0100\n" -"PO-Revision-Date: 2014-01-25 20:20+0100\n" +"POT-Creation-Date: 2014-01-25 20:52+0100\n" +"PO-Revision-Date: 2014-01-25 20:52+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -25,6 +25,8 @@ msgstr "Benutzer" #: ../../../views/html/menu/index.tpl:3 #: ../../../views/html/seminaries/seminary.tpl:1 #: ../../../views/html/seminaries/index.tpl:1 +#: ../../../views/html/seminaries/edit.tpl:1 +#: ../../../views/html/seminaries/delete.tpl:1 #: ../../../views/html/seminaries/create.tpl:1 msgid "Seminaries" msgstr "Kurse" @@ -52,11 +54,15 @@ msgstr "Benutzername" msgid "Password" msgstr "Passwort" -#: ../../../views/html/users/user.tpl:4 ../../../views/html/users/delete.tpl:2 +#: ../../../views/html/users/user.tpl:4 ../../../views/html/users/edit.tpl:2 +msgid "Edit user" +msgstr "Benutzer bearbeiten" + +#: ../../../views/html/users/user.tpl:5 ../../../views/html/users/delete.tpl:2 msgid "Delete user" msgstr "Benutzer löschen" -#: ../../../views/html/users/user.tpl:7 ../../../views/html/users/index.tpl:10 +#: ../../../views/html/users/user.tpl:8 ../../../views/html/users/index.tpl:10 #, php-format msgid "registered on %s" msgstr "registriert am %s" @@ -65,10 +71,6 @@ msgstr "registriert am %s" msgid "Create new user" msgstr "Neuen Benutzer erstellen" -#: ../../../views/html/users/edit.tpl:2 -msgid "Edit user" -msgstr "Benutzer bearbeiten" - #: ../../../views/html/users/edit.tpl:8 ../../../views/html/users/edit.tpl:9 #: ../../../views/html/users/create.tpl:8 #: ../../../views/html/users/create.tpl:9 @@ -76,10 +78,9 @@ msgid "E‑Mail-Address" msgstr "E‑Mail-Adresse" #: ../../../views/html/users/edit.tpl:13 -#: ../../../views/html/users/create.tpl:13 -#: ../../../views/html/seminaries/create.tpl:9 -msgid "create" -msgstr "erstellen" +#: ../../../views/html/seminaries/edit.tpl:9 +msgid "save" +msgstr "speichern" #: ../../../views/html/users/delete.tpl:4 #, php-format @@ -87,10 +88,12 @@ msgid "Should the user “%s” (%s) really be deleted?" msgstr "Soll der Benutzer „%s“ (%s) wirklich gelöscht werden?" #: ../../../views/html/users/delete.tpl:6 +#: ../../../views/html/seminaries/delete.tpl:6 msgid "delete" msgstr "löschen" #: ../../../views/html/users/delete.tpl:7 +#: ../../../views/html/seminaries/delete.tpl:7 msgid "cancel" msgstr "abbrechen" @@ -98,11 +101,26 @@ msgstr "abbrechen" msgid "New user" msgstr "Neuer Benutzer" +#: ../../../views/html/users/create.tpl:13 +#: ../../../views/html/seminaries/create.tpl:9 +msgid "create" +msgstr "erstellen" + #: ../../../views/html/error/index.tpl:1 msgid "Error" msgstr "Fehler" #: ../../../views/html/seminaries/seminary.tpl:4 +#: ../../../views/html/seminaries/edit.tpl:2 +msgid "Edit seminary" +msgstr "Kurs bearbeiten" + +#: ../../../views/html/seminaries/seminary.tpl:5 +#: ../../../views/html/seminaries/delete.tpl:2 +msgid "Delete seminary" +msgstr "Kurs löschen" + +#: ../../../views/html/seminaries/seminary.tpl:8 #: ../../../views/html/seminaries/index.tpl:10 #, php-format msgid "created by %s on %s" @@ -112,15 +130,22 @@ msgstr "erstellt von %s am %s" msgid "Create new seminary" msgstr "Neuen Kurs erstellen" -#: ../../../views/html/seminaries/create.tpl:2 -msgid "New seminary" -msgstr "Neuer Kurs" - +#: ../../../views/html/seminaries/edit.tpl:6 +#: ../../../views/html/seminaries/edit.tpl:7 #: ../../../views/html/seminaries/create.tpl:6 #: ../../../views/html/seminaries/create.tpl:7 msgid "Title" msgstr "Titel" +#: ../../../views/html/seminaries/delete.tpl:4 +#, php-format +msgid "Should the seminary “%s” really be deleted?" +msgstr "Soll der Kurs „%s“ wirklich gelöscht werden?" + +#: ../../../views/html/seminaries/create.tpl:2 +msgid "New seminary" +msgstr "Neuer Kurs" + #: ../../../views/html/introduction/index.tpl:1 msgid "Introduction" msgstr "Einführung" diff --git a/models/SeminariesModel.inc b/models/SeminariesModel.inc index c4ae7954..03ccc2f0 100644 --- a/models/SeminariesModel.inc +++ b/models/SeminariesModel.inc @@ -99,6 +99,63 @@ return $seminary[0]; } + + /** + * Create a new seminary. + * + * @param string $title Title of seminary to create + * @param int $userId ID of creating user + * @return int ID of the newly created seminary + */ + public function createSeminary($title, $userId) + { + $this->db->query( + 'INSERT INTO seminaries '. + '(created_user_id, title, url) '. + 'VALUES '. + '(?, ?, ?)', + 'iss', + $userId, + $title, + \nre\core\Linker::createLinkParam($title) + ); + + + return $this->db->getInsertId(); + } + + + /** + * Edit a seminary. + * + * @throws DatamodelException + * @param int $seminaryId ID of the seminary to delete + * @param string $title New title of seminary + */ + public function editSeminary($seminaryId, $title) + { + $this->db->query( + 'UPDATE seminaries '. + 'SET title = ?, url = ? '. + 'WHERE id = ?', + 'ssi', + $title, + \nre\core\Linker::createLinkParam($title), + $seminaryId + ); + } + + + /** + * Delete a seminary. + * + * @param int $seminaryId ID of the seminary to delete + */ + public function deleteSeminary($seminaryId) + { + $this->db->query('DELETE FROM seminaries WHERE id = ?', 'i', $seminaryId); + } + } ?> diff --git a/models/UsersModel.inc b/models/UsersModel.inc index 576bc1a2..0456a7ec 100644 --- a/models/UsersModel.inc +++ b/models/UsersModel.inc @@ -155,6 +155,7 @@ * Edit a user. * * @throws DatamodelException + * @param int $userId ID of the user to delete * @param string $username New name of user * @param string $email Changed e‑mail-address of user * @param string $password Changed plaintext password of user @@ -165,10 +166,12 @@ // Update user data $this->db->query( 'UPDATE users '. - 'SET username = ?, email = ? '. + 'SET username = ?, url = ?, email = ? '. 'WHERE id = ?', - 'ssi', - $sername, $email, + 'sssi', + $username, + \nre\core\Linker::createLinkParam($username), + $email, $userId ); @@ -214,7 +217,7 @@ * @param string $password Plaintext password * @return string Hashed password */ - private function hash($password) + public function hash($password) { return password_hash($password, PASSWORD_DEFAULT); } diff --git a/views/html/seminaries/create.tpl b/views/html/seminaries/create.tpl new file mode 100644 index 00000000..823eec70 --- /dev/null +++ b/views/html/seminaries/create.tpl @@ -0,0 +1,10 @@ +
=sprintf(_('created by %s on %s'), $seminary['creator']['username'], $dateFormatter->format(new \DateTime($seminary['created'])))?>
diff --git a/views/html/users/create.tpl b/views/html/users/create.tpl index caffac41..8536804d 100644 --- a/views/html/users/create.tpl +++ b/views/html/users/create.tpl @@ -2,7 +2,7 @@