From 45cd7e795d9e0475cf2fd5c85e2440876419441c Mon Sep 17 00:00:00 2001
From: oliver
Date: Tue, 12 May 2015 09:49:53 +0200
Subject: [PATCH] replace tabs with spaces
---
.htaccess | 64 +-
agents/bottomlevel/MailreceiverAgent.inc | 68 +-
agents/bottomlevel/MenuAgent.inc | 72 +-
.../QuestgroupshierarchypathAgent.inc | 68 +-
agents/bottomlevel/SeminarybarAgent.inc | 68 +-
agents/bottomlevel/SeminarymenuAgent.inc | 68 +-
agents/bottomlevel/UserrolesAgent.inc | 68 +-
agents/intermediate/AchievementsAgent.inc | 66 +-
agents/intermediate/CharactergroupsAgent.inc | 66 +-
.../CharactergroupsquestsAgent.inc | 66 +-
agents/intermediate/CharactersAgent.inc | 88 +-
agents/intermediate/CharactertypesAgent.inc | 66 +-
agents/intermediate/ErrorAgent.inc | 66 +-
agents/intermediate/IntroductionAgent.inc | 66 +-
agents/intermediate/LibraryAgent.inc | 66 +-
agents/intermediate/MailAgent.inc | 66 +-
agents/intermediate/MapAgent.inc | 66 +-
agents/intermediate/MediaAgent.inc | 68 +-
agents/intermediate/QuestgroupsAgent.inc | 176 +-
.../QuestgroupshierarchyAgent.inc | 38 +-
agents/intermediate/QuestsAgent.inc | 216 +-
agents/intermediate/SeminariesAgent.inc | 66 +-
agents/intermediate/UploadsAgent.inc | 68 +-
agents/intermediate/UsersAgent.inc | 90 +-
agents/intermediate/XplevelsAgent.inc | 66 +-
agents/toplevel/AjaxAgent.inc | 152 +-
agents/toplevel/BinaryAgent.inc | 94 +-
agents/toplevel/FaultAgent.inc | 68 +-
agents/toplevel/HtmlAgent.inc | 106 +-
agents/toplevel/HtmlmailAgent.inc | 96 +-
agents/toplevel/TextmailAgent.inc | 99 +-
app/Controller.inc | 254 +-
app/Model.inc | 76 +-
app/TextFormatter.inc | 290 +-
app/Utils.inc | 420 +--
app/agents/QuesttypeAgent.inc | 528 +--
app/agents/ToplevelAgent.inc | 78 +-
app/apis/MailApi.inc | 396 +--
app/controllers/IntermediateController.inc | 386 +--
app/controllers/QuesttypeController.inc | 628 ++--
app/controllers/SeminaryController.inc | 648 ++--
app/exceptions/FileCopyException.inc | 146 +-
app/exceptions/FileUploadException.inc | 150 +-
app/exceptions/MailingException.inc | 150 +-
app/exceptions/MaxFilesizeException.inc | 100 +-
.../QuesttypeAgentNotFoundException.inc | 152 +-
.../QuesttypeAgentNotValidException.inc | 150 +-
.../QuesttypeControllerNotFoundException.inc | 152 +-
.../QuesttypeControllerNotValidException.inc | 152 +-
.../QuesttypeModelNotFoundException.inc | 152 +-
.../QuesttypeModelNotValidException.inc | 152 +-
.../SubmissionNotValidException.inc | 150 +-
app/exceptions/WrongFiletypeException.inc | 150 +-
app/lib/PHPMailer.inc | 66 +-
app/lib/PHPMailerAutoload.inc | 68 +-
app/lib/Password.inc | 62 +-
app/lib/SMTP.inc | 66 +-
app/models/QuesttypeModel.inc | 300 +-
app/requests/MailRequest.inc | 176 +-
app/responses/MailResponse.inc | 102 +-
app/views/QuesttypeView.inc | 144 +-
controllers/AchievementsController.inc | 1842 +++++-----
controllers/AjaxController.inc | 96 +-
controllers/BinaryController.inc | 66 +-
controllers/CharactergroupsController.inc | 1510 ++++-----
.../CharactergroupsquestsController.inc | 1224 +++----
controllers/CharactersController.inc | 1380 ++++----
controllers/CharactertypesController.inc | 770 ++---
controllers/ErrorController.inc | 94 +-
controllers/FaultController.inc | 66 +-
controllers/HtmlController.inc | 214 +-
controllers/HtmlmailController.inc | 100 +-
controllers/IntroductionController.inc | 66 +-
controllers/LibraryController.inc | 1018 +++---
controllers/MailController.inc | 264 +-
controllers/MailreceiverController.inc | 70 +-
controllers/MapController.inc | 118 +-
controllers/MediaController.inc | 1158 +++----
controllers/MenuController.inc | 96 +-
controllers/QuestgroupsController.inc | 1384 ++++----
.../QuestgroupshierarchyController.inc | 682 ++--
.../QuestgroupshierarchypathController.inc | 174 +-
controllers/QuestsController.inc | 2974 ++++++++---------
controllers/SeminariesController.inc | 1072 +++---
controllers/SeminarybarController.inc | 170 +-
controllers/SeminarymenuController.inc | 98 +-
controllers/TextmailController.inc | 102 +-
controllers/UploadsController.inc | 626 ++--
controllers/UserrolesController.inc | 86 +-
controllers/UsersController.inc | 1242 +++----
controllers/XplevelsController.inc | 358 +-
.../components/AchievementComponent.inc | 74 +-
controllers/components/AuthComponent.inc | 150 +-
.../components/NotificationComponent.inc | 208 +-
.../components/QuesttypedataComponent.inc | 26 +-
.../components/ValidationComponent.inc | 358 +-
models/AchievementsModel.inc | 2274 ++++++-------
models/AvatarsModel.inc | 338 +-
models/CharactergroupsModel.inc | 1004 +++---
models/CharactergroupsquestsModel.inc | 776 ++---
models/CharacterrolesModel.inc | 192 +-
models/CharactersModel.inc | 1386 ++++----
models/CharactertypesModel.inc | 410 +--
models/MapModel.inc | 74 +-
models/MediaModel.inc | 988 +++---
models/QuestgroupsModel.inc | 1734 +++++-----
models/QuestgroupshierarchyModel.inc | 654 ++--
models/QuestgrouptextsModel.inc | 228 +-
models/QuestsModel.inc | 1408 ++++----
models/QuesttextsModel.inc | 658 ++--
models/QuesttopicsModel.inc | 794 ++---
models/QuesttypesModel.inc | 146 +-
models/SeminariesModel.inc | 578 ++--
models/SeminarycharacterfieldsModel.inc | 252 +-
models/UploadsModel.inc | 298 +-
models/UserrolesModel.inc | 232 +-
models/UsersModel.inc | 794 ++---
models/XplevelsModel.inc | 374 +--
.../bossfight/BossfightQuesttypeAgent.inc | 42 +-
.../BossfightQuesttypeController.inc | 562 ++--
.../bossfight/BossfightQuesttypeModel.inc | 372 +--
questtypes/bossfight/html/edittask.tpl | 72 +-
questtypes/bossfight/html/quest.tpl | 36 +-
questtypes/bossfight/html/submission.tpl | 52 +-
.../choiceinput/ChoiceinputQuesttypeAgent.inc | 42 +-
.../ChoiceinputQuesttypeController.inc | 584 ++--
.../choiceinput/ChoiceinputQuesttypeModel.inc | 568 ++--
questtypes/choiceinput/html/edittask.tpl | 324 +-
questtypes/choiceinput/html/quest.tpl | 30 +-
questtypes/choiceinput/html/submission.tpl | 24 +-
.../crossword/CrosswordQuesttypeAgent.inc | 42 +-
.../CrosswordQuesttypeController.inc | 750 ++---
.../crossword/CrosswordQuesttypeModel.inc | 182 +-
questtypes/crossword/html/quest.tpl | 218 +-
questtypes/crossword/html/submission.tpl | 84 +-
.../dragndrop/DragndropQuesttypeAgent.inc | 42 +-
.../DragndropQuesttypeController.inc | 436 +--
.../dragndrop/DragndropQuesttypeModel.inc | 386 +--
questtypes/dragndrop/html/edittask.tpl | 46 +-
questtypes/dragndrop/html/quest.tpl | 30 +-
questtypes/dragndrop/html/submission.tpl | 20 +-
.../MultiplechoiceQuesttypeAgent.inc | 42 +-
.../MultiplechoiceQuesttypeController.inc | 732 ++--
.../MultiplechoiceQuesttypeModel.inc | 514 +--
questtypes/multiplechoice/html/edittask.tpl | 240 +-
questtypes/multiplechoice/html/quest.tpl | 38 +-
questtypes/multiplechoice/html/submission.tpl | 28 +-
questtypes/submit/SubmitQuesttypeAgent.inc | 42 +-
.../submit/SubmitQuesttypeController.inc | 472 +--
questtypes/submit/SubmitQuesttypeModel.inc | 284 +-
questtypes/submit/html/quest.tpl | 78 +-
questtypes/submit/html/submission.tpl | 52 +-
.../textinput/TextinputQuesttypeAgent.inc | 42 +-
.../TextinputQuesttypeController.inc | 592 ++--
.../textinput/TextinputQuesttypeModel.inc | 426 +--
questtypes/textinput/html/edittask.tpl | 196 +-
questtypes/textinput/html/quest.tpl | 22 +-
questtypes/textinput/html/submission.tpl | 16 +-
views/ajax/characters/index.tpl | 42 +-
views/ajax/quests/index.tpl | 66 +-
views/ajax/users/index.tpl | 46 +-
views/fault/fault.tpl | 12 +-
views/html/achievements/conditions.tpl | 284 +-
views/html/achievements/create.tpl | 190 +-
views/html/achievements/delete.tpl | 10 +-
views/html/achievements/edit.tpl | 198 +-
views/html/achievements/index.tpl | 152 +-
views/html/achievements/manage.tpl | 36 +-
views/html/html.tpl | 222 +-
views/htmlmail/htmlmail.tpl | 18 +-
www/.htaccess | 12 +-
www/error403.html | 8 +-
www/error404.html | 8 +-
www/error500.html | 8 +-
www/js/dnd.js | 52 +-
www/js/misc.js | 76 +-
176 files changed, 27369 insertions(+), 27364 deletions(-)
diff --git a/.htaccess b/.htaccess
index c1167dbf..258afda9 100644
--- a/.htaccess
+++ b/.htaccess
@@ -5,40 +5,46 @@ ErrorDocument 404 /www/error404.html
ErrorDocument 500 /www/error500.html
+
- Require all granted
-
-
- Require all denied
-
-
- Require all denied
-
-
- Require all denied
-
+ Require all granted
+
+
+ Require all denied
+
+
+
+ Require all denied
+
+
+
+ Require all denied
+
+
- Allow From All
-
-
- Order Deny,Allow
- Deny From All
-
-
- Order Deny,Allow
- Deny From All
-
-
- Order Deny,Allow
- Deny From All
-
+ Allow From All
+
+
+ Order Deny,Allow
+ Deny From All
+
+
+
+ Order Deny,Allow
+ Deny From All
+
+
+
+ Order Deny,Allow
+ Deny From All
+
- RewriteEngine On
-
- RewriteBase /
- RewriteRule ^(.*)$ www/$1 [L]
+ RewriteEngine On
+
+ RewriteBase /
+ RewriteRule ^(.*)$ www/$1 [L]
diff --git a/agents/bottomlevel/MailreceiverAgent.inc b/agents/bottomlevel/MailreceiverAgent.inc
index 5ebffd3a..2321e34a 100644
--- a/agents/bottomlevel/MailreceiverAgent.inc
+++ b/agents/bottomlevel/MailreceiverAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\bottomlevel;
-
-
- /**
- * Agent to generate a mail receiver salutation.
- *
- * @author Oliver Hanraths
- */
- class MailreceiverAgent extends \nre\agents\BottomlevelAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\bottomlevel;
+
+
+ /**
+ * Agent to generate a mail receiver salutation.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailreceiverAgent extends \nre\agents\BottomlevelAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/bottomlevel/MenuAgent.inc b/agents/bottomlevel/MenuAgent.inc
index 0f0dc60d..724cce6e 100644
--- a/agents/bottomlevel/MenuAgent.inc
+++ b/agents/bottomlevel/MenuAgent.inc
@@ -1,40 +1,40 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\bottomlevel;
-
-
- /**
- * Agent to display a menu.
- *
- * @author Oliver Hanraths
- */
- class MenuAgent extends \nre\agents\BottomlevelAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- // Add Seminary menu
- $this->addSubAgent('Seminarymenu');
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\bottomlevel;
+
+
+ /**
+ * Agent to display a menu.
+ *
+ * @author Oliver Hanraths
+ */
+ class MenuAgent extends \nre\agents\BottomlevelAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ // Add Seminary menu
+ $this->addSubAgent('Seminarymenu');
+ }
+
+ }
?>
diff --git a/agents/bottomlevel/QuestgroupshierarchypathAgent.inc b/agents/bottomlevel/QuestgroupshierarchypathAgent.inc
index 36b84474..43dba806 100644
--- a/agents/bottomlevel/QuestgroupshierarchypathAgent.inc
+++ b/agents/bottomlevel/QuestgroupshierarchypathAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\bottomlevel;
-
-
- /**
- * Agent to display the Questgroups hierarchy path.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupshierarchypathAgent extends \nre\agents\BottomlevelAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\bottomlevel;
+
+
+ /**
+ * Agent to display the Questgroups hierarchy path.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupshierarchypathAgent extends \nre\agents\BottomlevelAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/bottomlevel/SeminarybarAgent.inc b/agents/bottomlevel/SeminarybarAgent.inc
index 2f43e474..62a30ccd 100644
--- a/agents/bottomlevel/SeminarybarAgent.inc
+++ b/agents/bottomlevel/SeminarybarAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\bottomlevel;
-
-
- /**
- * Agent to display a sidebar with Seminary related information.
- *
- * @author Oliver Hanraths
- */
- class SeminarybarAgent extends \nre\agents\BottomlevelAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\bottomlevel;
+
+
+ /**
+ * Agent to display a sidebar with Seminary related information.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminarybarAgent extends \nre\agents\BottomlevelAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/bottomlevel/SeminarymenuAgent.inc b/agents/bottomlevel/SeminarymenuAgent.inc
index 1c55e419..9367cf7d 100644
--- a/agents/bottomlevel/SeminarymenuAgent.inc
+++ b/agents/bottomlevel/SeminarymenuAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\bottomlevel;
-
-
- /**
- * Agent to display a menu with Seminary related links.
- *
- * @author Oliver Hanraths
- */
- class SeminarymenuAgent extends \nre\agents\BottomlevelAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\bottomlevel;
+
+
+ /**
+ * Agent to display a menu with Seminary related links.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminarymenuAgent extends \nre\agents\BottomlevelAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/bottomlevel/UserrolesAgent.inc b/agents/bottomlevel/UserrolesAgent.inc
index 1186eff4..791846cd 100644
--- a/agents/bottomlevel/UserrolesAgent.inc
+++ b/agents/bottomlevel/UserrolesAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\bottomlevel;
-
-
- /**
- * Agent to display and manage userroles.
- *
- * @author Oliver Hanraths
- */
- class UserrolesAgent extends \nre\agents\BottomlevelAgent
- {
-
-
-
-
- /**
- * Action: user.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function user(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\bottomlevel;
+
+
+ /**
+ * Agent to display and manage userroles.
+ *
+ * @author Oliver Hanraths
+ */
+ class UserrolesAgent extends \nre\agents\BottomlevelAgent
+ {
+
+
+
+
+ /**
+ * Action: user.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function user(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/AchievementsAgent.inc b/agents/intermediate/AchievementsAgent.inc
index de829ee1..fe7e5b4c 100644
--- a/agents/intermediate/AchievementsAgent.inc
+++ b/agents/intermediate/AchievementsAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to list Achievements.
- *
- * @author Oliver Hanraths
- */
- class AchievementsAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to list Achievements.
+ *
+ * @author Oliver Hanraths
+ */
+ class AchievementsAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/CharactergroupsAgent.inc b/agents/intermediate/CharactergroupsAgent.inc
index 02b8244a..10f560ee 100644
--- a/agents/intermediate/CharactergroupsAgent.inc
+++ b/agents/intermediate/CharactergroupsAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to display Character groups.
- *
- * @author Oliver Hanraths
- */
- class CharactergroupsAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to display Character groups.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactergroupsAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/CharactergroupsquestsAgent.inc b/agents/intermediate/CharactergroupsquestsAgent.inc
index 3e5e17d1..12b1bf7c 100644
--- a/agents/intermediate/CharactergroupsquestsAgent.inc
+++ b/agents/intermediate/CharactergroupsquestsAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to display Character groups Quests.
- *
- * @author Oliver Hanraths
- */
- class CharactergroupsquestsAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to display Character groups Quests.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactergroupsquestsAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/CharactersAgent.inc b/agents/intermediate/CharactersAgent.inc
index 0bbfa315..15779ded 100644
--- a/agents/intermediate/CharactersAgent.inc
+++ b/agents/intermediate/CharactersAgent.inc
@@ -1,49 +1,49 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to list registered Characters and their data.
- *
- * @author Oliver Hanraths
- */
- class CharactersAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
-
- /**
- * Action: character.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function character(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to list registered Characters and their data.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactersAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+
+ /**
+ * Action: character.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function character(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/CharactertypesAgent.inc b/agents/intermediate/CharactertypesAgent.inc
index 8c2693bb..0d298f47 100644
--- a/agents/intermediate/CharactertypesAgent.inc
+++ b/agents/intermediate/CharactertypesAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to handle Charactertyes of a Seminary.
- *
- * @author Oliver Hanraths
- */
- class CharactertypesAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to handle Charactertyes of a Seminary.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactertypesAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/ErrorAgent.inc b/agents/intermediate/ErrorAgent.inc
index 5554c417..94b170a8 100644
--- a/agents/intermediate/ErrorAgent.inc
+++ b/agents/intermediate/ErrorAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to show an error page.
- *
- * @author Oliver Hanraths
- */
- class ErrorAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to show an error page.
+ *
+ * @author Oliver Hanraths
+ */
+ class ErrorAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/IntroductionAgent.inc b/agents/intermediate/IntroductionAgent.inc
index 1ee6483a..1b5ebd8b 100644
--- a/agents/intermediate/IntroductionAgent.inc
+++ b/agents/intermediate/IntroductionAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to show an introduction page.
- *
- * @author Oliver Hanraths
- */
- class IntroductionAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to show an introduction page.
+ *
+ * @author Oliver Hanraths
+ */
+ class IntroductionAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/LibraryAgent.inc b/agents/intermediate/LibraryAgent.inc
index b3105be9..7d8b1f72 100644
--- a/agents/intermediate/LibraryAgent.inc
+++ b/agents/intermediate/LibraryAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to list Quest topics.
- *
- * @author Oliver Hanraths
- */
- class LibraryAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to list Quest topics.
+ *
+ * @author Oliver Hanraths
+ */
+ class LibraryAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/MailAgent.inc b/agents/intermediate/MailAgent.inc
index 34dcc512..f221f3fb 100644
--- a/agents/intermediate/MailAgent.inc
+++ b/agents/intermediate/MailAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to generate a mail-message.
- *
- * @author Oliver Hanraths
- */
- class MailAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to generate a mail-message.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/MapAgent.inc b/agents/intermediate/MapAgent.inc
index 1fd0eb00..2d6b47cf 100644
--- a/agents/intermediate/MapAgent.inc
+++ b/agents/intermediate/MapAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to display a map.
- *
- * @author Oliver Hanraths
- */
- class MapAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to display a map.
+ *
+ * @author Oliver Hanraths
+ */
+ class MapAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/MediaAgent.inc b/agents/intermediate/MediaAgent.inc
index 550380a8..89e773b2 100644
--- a/agents/intermediate/MediaAgent.inc
+++ b/agents/intermediate/MediaAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
-
- /**
- * Agent to process and show media.
- *
- * @author Oliver Hanraths
- */
- class MediaAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to process and show media.
+ *
+ * @author Oliver Hanraths
+ */
+ class MediaAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/QuestgroupsAgent.inc b/agents/intermediate/QuestgroupsAgent.inc
index 7f71eafa..54ab9708 100644
--- a/agents/intermediate/QuestgroupsAgent.inc
+++ b/agents/intermediate/QuestgroupsAgent.inc
@@ -1,99 +1,99 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to display Questgroups.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupsAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: questgroup.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function questgroup(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
- }
-
-
- /**
- * Action: edit.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function edit(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
- }
+ namespace hhu\z\agents\intermediate;
- /**
- * Action: edittexts.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function edittexts(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
- }
-
-
- /**
- * Action: moveup.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function moveup(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
- }
+ /**
+ * Agent to display Questgroups.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupsAgent extends \nre\agents\IntermediateAgent
+ {
- /**
- * Action: movedown.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function movedown(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
- }
- /**
- * Action: delete.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function delete(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
- }
-
- }
+ /**
+ * Action: questgroup.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function questgroup(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function edit(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
+ }
+
+
+ /**
+ * Action: edittexts.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function edittexts(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
+ }
+
+
+ /**
+ * Action: moveup.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function moveup(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
+ }
+
+
+ /**
+ * Action: movedown.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function movedown(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function delete(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4));
+ }
+
+ }
?>
diff --git a/agents/intermediate/QuestgroupshierarchyAgent.inc b/agents/intermediate/QuestgroupshierarchyAgent.inc
index b84f3953..7ede785a 100644
--- a/agents/intermediate/QuestgroupshierarchyAgent.inc
+++ b/agents/intermediate/QuestgroupshierarchyAgent.inc
@@ -1,24 +1,24 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to manage Questgroupshierarchy.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupshierarchyAgent extends \nre\agents\IntermediateAgent
- {
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to manage Questgroupshierarchy.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupshierarchyAgent extends \nre\agents\IntermediateAgent
+ {
+ }
?>
diff --git a/agents/intermediate/QuestsAgent.inc b/agents/intermediate/QuestsAgent.inc
index 1485d090..f3d64a66 100644
--- a/agents/intermediate/QuestsAgent.inc
+++ b/agents/intermediate/QuestsAgent.inc
@@ -1,123 +1,123 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to display Quests.
- *
- * @author Oliver Hanraths
- */
- class QuestsAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: quest.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function quest(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
-
-
- /**
- * Action: submissions.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function submissions(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
-
-
- /**
- * Action: submission.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function submission(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
+ namespace hhu\z\agents\intermediate;
- /**
- * Action: create.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function create(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
+ /**
+ * Agent to display Quests.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestsAgent extends \nre\agents\IntermediateAgent
+ {
- /**
- * Action: edit.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function edit(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
- /**
- * Action: edittask.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function edittask(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
+ /**
+ * Action: quest.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function quest(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
- /**
- * Action: edittexts.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function edittexts(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
+ /**
+ * Action: submissions.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function submissions(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
- /**
- * Action: delete.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function delete(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
- }
-
- }
+ /**
+ * Action: submission.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function submission(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
+
+
+ /**
+ * Action: create.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function create(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function edit(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
+
+
+ /**
+ * Action: edittask.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function edittask(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
+
+
+ /**
+ * Action: edittexts.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function edittexts(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function delete(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Questgroupshierarchypath', 'index', $request->getParam(3), $request->getParam(4), true);
+ }
+
+ }
?>
diff --git a/agents/intermediate/SeminariesAgent.inc b/agents/intermediate/SeminariesAgent.inc
index 79901cfe..64e948d6 100644
--- a/agents/intermediate/SeminariesAgent.inc
+++ b/agents/intermediate/SeminariesAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to list registered seminaries.
- *
- * @author Oliver Hanraths
- */
- class SeminariesAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to list registered seminaries.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminariesAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/UploadsAgent.inc b/agents/intermediate/UploadsAgent.inc
index ef01077e..ff492f82 100644
--- a/agents/intermediate/UploadsAgent.inc
+++ b/agents/intermediate/UploadsAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
-
- /**
- * Agent to process and show user uploads.
- *
- * @author Oliver Hanraths
- */
- class UploadsAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to process and show user uploads.
+ *
+ * @author Oliver Hanraths
+ */
+ class UploadsAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/intermediate/UsersAgent.inc b/agents/intermediate/UsersAgent.inc
index 9ba74df3..c99d870e 100644
--- a/agents/intermediate/UsersAgent.inc
+++ b/agents/intermediate/UsersAgent.inc
@@ -1,50 +1,50 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to list registered users and their data.
- *
- * @author Oliver Hanraths
- */
- class UsersAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
-
- /**
- * Action: user.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function user(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubAgent('Userroles', 'user');
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to list registered users and their data.
+ *
+ * @author Oliver Hanraths
+ */
+ class UsersAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+
+ /**
+ * Action: user.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function user(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubAgent('Userroles', 'user');
+ }
+
+ }
?>
diff --git a/agents/intermediate/XplevelsAgent.inc b/agents/intermediate/XplevelsAgent.inc
index dff540f3..1d2e41ff 100644
--- a/agents/intermediate/XplevelsAgent.inc
+++ b/agents/intermediate/XplevelsAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\intermediate;
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Agent to handle XP-levels of a Seminary.
- *
- * @author Oliver Hanraths
- */
- class XplevelsAgent extends \nre\agents\IntermediateAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ namespace hhu\z\agents\intermediate;
+
+
+ /**
+ * Agent to handle XP-levels of a Seminary.
+ *
+ * @author Oliver Hanraths
+ */
+ class XplevelsAgent extends \nre\agents\IntermediateAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/toplevel/AjaxAgent.inc b/agents/toplevel/AjaxAgent.inc
index 1ced33f1..4b56cf98 100644
--- a/agents/toplevel/AjaxAgent.inc
+++ b/agents/toplevel/AjaxAgent.inc
@@ -1,80 +1,80 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\toplevel;
-
-
- /**
- * Agent to return a JSON-string used by AJAX.
- *
- * @author Oliver Hanraths
- */
- class AjaxAgent extends \hhu\z\agents\ToplevelAgent
- {
-
-
-
-
- /**
- * Construct a new AjaxAgent.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param \nre\core\Logger $log Logger instance
- */
- protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- parent::__construct($request, $response, $log);
-
-
- $this->setLanguage($request);
- }
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
-
-
-
- /**
- * Set requested language.
- *
- * @param \nre\core\Request $request Current request
- */
- private function setLanguage(\nre\core\Request $request)
- {
- // Set domain
- $domain = \nre\configs\AppConfig::$app['genericname'];
-
- // Get language
- $locale = $request->getGetParam('lang', 'language');
- if(is_null($locale)) {
- return;
- }
-
- // Load translation
- putenv("LC_ALL=$locale");
- setlocale(LC_ALL, $locale);
- bindtextdomain($domain, ROOT.DS.\nre\configs\AppConfig::$dirs['locale']);
- textdomain($domain);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\toplevel;
+
+
+ /**
+ * Agent to return a JSON-string used by AJAX.
+ *
+ * @author Oliver Hanraths
+ */
+ class AjaxAgent extends \hhu\z\agents\ToplevelAgent
+ {
+
+
+
+
+ /**
+ * Construct a new AjaxAgent.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param \nre\core\Logger $log Logger instance
+ */
+ protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ parent::__construct($request, $response, $log);
+
+
+ $this->setLanguage($request);
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+
+
+
+ /**
+ * Set requested language.
+ *
+ * @param \nre\core\Request $request Current request
+ */
+ private function setLanguage(\nre\core\Request $request)
+ {
+ // Set domain
+ $domain = \nre\configs\AppConfig::$app['genericname'];
+
+ // Get language
+ $locale = $request->getGetParam('lang', 'language');
+ if(is_null($locale)) {
+ return;
+ }
+
+ // Load translation
+ putenv("LC_ALL=$locale");
+ setlocale(LC_ALL, $locale);
+ bindtextdomain($domain, ROOT.DS.\nre\configs\AppConfig::$dirs['locale']);
+ textdomain($domain);
+ }
+
+ }
?>
diff --git a/agents/toplevel/BinaryAgent.inc b/agents/toplevel/BinaryAgent.inc
index 55d494e3..6130a1c0 100644
--- a/agents/toplevel/BinaryAgent.inc
+++ b/agents/toplevel/BinaryAgent.inc
@@ -1,51 +1,51 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\toplevel;
-
-
- /**
- * Agent to display binary data (e. g. images).
- *
- * @author Oliver Hanraths
- */
- class BinaryAgent extends \hhu\z\agents\ToplevelAgent
- {
-
-
-
-
- /**
- * Construct a new BinaryAgent.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param \nre\core\Logger $log Logger instance
- */
- protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- parent::__construct($request, $response, $log);
- }
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\toplevel;
+
+
+ /**
+ * Agent to display binary data (e. g. images).
+ *
+ * @author Oliver Hanraths
+ */
+ class BinaryAgent extends \hhu\z\agents\ToplevelAgent
+ {
+
+
+
+
+ /**
+ * Construct a new BinaryAgent.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param \nre\core\Logger $log Logger instance
+ */
+ protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ parent::__construct($request, $response, $log);
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/toplevel/FaultAgent.inc b/agents/toplevel/FaultAgent.inc
index d289c041..dc4b101b 100644
--- a/agents/toplevel/FaultAgent.inc
+++ b/agents/toplevel/FaultAgent.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\toplevel;
-
-
- /**
- * Agent to display a toplevel error page.
- *
- * @author Oliver Hanraths
- */
- class FaultAgent extends \nre\agents\ToplevelAgent
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\toplevel;
+
+
+ /**
+ * Agent to display a toplevel error page.
+ *
+ * @author Oliver Hanraths
+ */
+ class FaultAgent extends \nre\agents\ToplevelAgent
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ }
+
+ }
?>
diff --git a/agents/toplevel/HtmlAgent.inc b/agents/toplevel/HtmlAgent.inc
index 34abd31d..49ccb552 100644
--- a/agents/toplevel/HtmlAgent.inc
+++ b/agents/toplevel/HtmlAgent.inc
@@ -1,58 +1,58 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\toplevel;
-
-
- /**
- * Agent to display a HTML-page.
- *
- * @author Oliver Hanraths
- */
- class HtmlAgent extends \hhu\z\agents\ToplevelAgent
- {
-
-
-
-
- /**
- * Construct a new HtmlAgent.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param \nre\core\Logger $log Logger instance
- */
- protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- parent::__construct($request, $response, $log);
-
-
- $this->setLanguage($request);
- }
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- // Add menu
- $this->addSubAgent('Menu');
-
- // Add Seminary sidebar
- $this->addSubAgent('Seminarybar');
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\toplevel;
+
+
+ /**
+ * Agent to display a HTML-page.
+ *
+ * @author Oliver Hanraths
+ */
+ class HtmlAgent extends \hhu\z\agents\ToplevelAgent
+ {
+
+
+
+
+ /**
+ * Construct a new HtmlAgent.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param \nre\core\Logger $log Logger instance
+ */
+ protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ parent::__construct($request, $response, $log);
+
+
+ $this->setLanguage($request);
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ // Add menu
+ $this->addSubAgent('Menu');
+
+ // Add Seminary sidebar
+ $this->addSubAgent('Seminarybar');
+ }
diff --git a/agents/toplevel/HtmlmailAgent.inc b/agents/toplevel/HtmlmailAgent.inc
index 001886cd..c0d9cad5 100644
--- a/agents/toplevel/HtmlmailAgent.inc
+++ b/agents/toplevel/HtmlmailAgent.inc
@@ -1,52 +1,52 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\toplevel;
-
-
- /**
- * Agent for generating a HTML-mail message.
- *
- * @author Oliver Hanraths
- */
- class HtmlmailAgent extends \hhu\z\agents\ToplevelAgent
- {
-
-
-
-
- /**
- * Construct a new HtmlmailAgent.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param \nre\core\Logger $log Logger instance
- */
- protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- parent::__construct($request, $response, $log);
- }
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubagent('mailreceiver', 'index', $request->getParam(3));
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\toplevel;
+
+
+ /**
+ * Agent for generating a HTML-mail message.
+ *
+ * @author Oliver Hanraths
+ */
+ class HtmlmailAgent extends \hhu\z\agents\ToplevelAgent
+ {
+
+
+
+
+ /**
+ * Construct a new HtmlmailAgent.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param \nre\core\Logger $log Logger instance
+ */
+ protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ parent::__construct($request, $response, $log);
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubagent('mailreceiver', 'index', $request->getParam(3));
+ }
+
+ }
?>
diff --git a/agents/toplevel/TextmailAgent.inc b/agents/toplevel/TextmailAgent.inc
index ec4c34b2..85c20d13 100644
--- a/agents/toplevel/TextmailAgent.inc
+++ b/agents/toplevel/TextmailAgent.inc
@@ -1,54 +1,53 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents\toplevel;
-
-
- /**
- * Agent for generating a simple text-mail message.
- *
- * @author Oliver Hanraths
- */
- class TextmailAgent extends \hhu\z\agents\ToplevelAgent
- {
-
-
-
-
- /**
- * Construct a new TextmailAgent.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param \nre\core\Logger $log Logger instance
- */
- protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- parent::__construct($request, $response, $log);
- }
-
-
-
-
- /**
- * Action: index.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function index(\nre\core\Request $request, \nre\core\Response $response)
- {
- $this->addSubagent('mailreceiver', 'index', $request->getParam(3));
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents\toplevel;
+
+ /**
+ * Agent for generating a simple text-mail message.
+ *
+ * @author Oliver Hanraths
+ */
+ class TextmailAgent extends \hhu\z\agents\ToplevelAgent
+ {
+
+
+
+
+ /**
+ * Construct a new TextmailAgent.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param \nre\core\Logger $log Logger instance
+ */
+ protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ parent::__construct($request, $response, $log);
+ }
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function index(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ $this->addSubagent('mailreceiver', 'index', $request->getParam(3));
+ }
+
+ }
?>
diff --git a/app/Controller.inc b/app/Controller.inc
index 3603db23..eaf4dc32 100644
--- a/app/Controller.inc
+++ b/app/Controller.inc
@@ -1,134 +1,134 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z;
-
-
- /**
- * Abstract class for implementing an application Controller.
- *
- * @author Oliver Hanraths
- */
- abstract class Controller extends \nre\core\Controller
- {
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('auth');
-
- /**
- * Logger instance
- *
- * @var \nre\core\Logger
- */
- protected $log = null;
- /**
- * Linker instance
- *
- * @var \nre\core\Linker
- */
- protected $linker = null;
-
-
-
-
- /**
- * Construct a new application Controller.
- *
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @param string $layoutName Name of the current Layout
- * @param string $action Current Action
- * @param \nre\core\Agent $agent Corresponding Agent
- */
- public function __construct($layoutName, $action, $agent)
- {
- parent::__construct($layoutName, $action, $agent);
-
- // Create logger
- $this->log = new \nre\core\Logger();
- }
-
-
-
- /**
- * Prefilter that is executed before running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Create linker
- $this->linker = new \nre\core\Linker($request);
- $this->set('linker', $this->linker);
-
- // Create text formatter
- $this->set('t', new \hhu\z\TextFormatter($this->linker));
-
- // Create date and time and number formatter
- $this->set('dateFormatter', new \IntlDateFormatter(
- //\nre\core\Config::getDefault('locale'),
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z;
+
+
+ /**
+ * Abstract class for implementing an application Controller.
+ *
+ * @author Oliver Hanraths
+ */
+ abstract class Controller extends \nre\core\Controller
+ {
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('auth');
+
+ /**
+ * Logger instance
+ *
+ * @var \nre\core\Logger
+ */
+ protected $log = null;
+ /**
+ * Linker instance
+ *
+ * @var \nre\core\Linker
+ */
+ protected $linker = null;
+
+
+
+
+ /**
+ * Construct a new application Controller.
+ *
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @param string $layoutName Name of the current Layout
+ * @param string $action Current Action
+ * @param \nre\core\Agent $agent Corresponding Agent
+ */
+ public function __construct($layoutName, $action, $agent)
+ {
+ parent::__construct($layoutName, $action, $agent);
+
+ // Create logger
+ $this->log = new \nre\core\Logger();
+ }
+
+
+
+ /**
+ * Prefilter that is executed before running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Create linker
+ $this->linker = new \nre\core\Linker($request);
+ $this->set('linker', $this->linker);
+
+ // Create text formatter
+ $this->set('t', new \hhu\z\TextFormatter($this->linker));
+
+ // Create date and time and number formatter
+ $this->set('dateFormatter', new \IntlDateFormatter(
+ //\nre\core\Config::getDefault('locale'),
\Locale::getDefault(),
- \IntlDateFormatter::MEDIUM,
- \IntlDateFormatter::NONE,
- NULL
- ));
- $this->set('timeFormatter', new \IntlDateFormatter(
- //\nre\core\Config::getDefault('locale'),
+ \IntlDateFormatter::MEDIUM,
+ \IntlDateFormatter::NONE,
+ NULL
+ ));
+ $this->set('timeFormatter', new \IntlDateFormatter(
+ //\nre\core\Config::getDefault('locale'),
\Locale::getDefault(),
- \IntlDateFormatter::NONE,
- \IntlDateFormatter::SHORT,
- NULL
- ));
- $this->set('numberFormatter', new \NumberFormatter(
- //\nre\core\Config::getDefault('locale'),
+ \IntlDateFormatter::NONE,
+ \IntlDateFormatter::SHORT,
+ NULL
+ ));
+ $this->set('numberFormatter', new \NumberFormatter(
+ //\nre\core\Config::getDefault('locale'),
\Locale::getDefault(),
- \NumberFormatter::DEFAULT_STYLE
- ));
- }
-
-
- /**
- * Postfilter that is executed after running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::postFilter($request, $response);
- }
-
-
-
-
- /**
- * Log an error.
- *
- * @param string $message Error message to log
- * @param int $logMode Log mode (optional)
- */
- protected function log($message, $logMode=\nre\core\Logger::LOGMODE_AUTO)
- {
- $this->log->log($message, $logMode);
- }
-
- }
+ \NumberFormatter::DEFAULT_STYLE
+ ));
+ }
+
+
+ /**
+ * Postfilter that is executed after running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::postFilter($request, $response);
+ }
+
+
+
+
+ /**
+ * Log an error.
+ *
+ * @param string $message Error message to log
+ * @param int $logMode Log mode (optional)
+ */
+ protected function log($message, $logMode=\nre\core\Logger::LOGMODE_AUTO)
+ {
+ $this->log->log($message, $logMode);
+ }
+
+ }
?>
diff --git a/app/Model.inc b/app/Model.inc
index 84ccb7d7..9acc0835 100644
--- a/app/Model.inc
+++ b/app/Model.inc
@@ -1,42 +1,42 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z;
-
-
- /**
- * Abstract class for implementing an application Model.
- *
- * @author Oliver Hanraths
- */
- class Model extends \nre\models\DatabaseModel
- {
-
-
-
-
- /**
- * Construct a new application Model.
- *
- * @throws \nre\exceptions\DatamodelException
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- */
- public function __construct()
- {
- parent::__construct('mysqli', \nre\configs\AppConfig::$database);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z;
+
+
+ /**
+ * Abstract class for implementing an application Model.
+ *
+ * @author Oliver Hanraths
+ */
+ class Model extends \nre\models\DatabaseModel
+ {
+
+
+
+
+ /**
+ * Construct a new application Model.
+ *
+ * @throws \nre\exceptions\DatamodelException
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ */
+ public function __construct()
+ {
+ parent::__construct('mysqli', \nre\configs\AppConfig::$database);
+ }
+
+ }
?>
diff --git a/app/TextFormatter.inc b/app/TextFormatter.inc
index 71adba90..dd89cf20 100644
--- a/app/TextFormatter.inc
+++ b/app/TextFormatter.inc
@@ -1,149 +1,149 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z;
-
-
- /**
- * Class to format text with different syntax tags.
- *
- * @author Oliver Hanraths
- */
- class TextFormatter
- {
- /**
- * Linker to create links.
- *
- * @var \nre\core\Linker
- */
- private $linker;
- /**
- * Media-Model to retrieve media data
- *
- * @static
- * @var \nre\core\Model
- */
- private static $Media = null;
-
-
-
-
- /**
- * Create a new text formatter.
- *
- * @param \nre\core\Linker $linker Linker to create links with
- */
- public function __construct(\nre\core\Linker $linker)
- {
- $this->linker = $linker;
- }
-
-
-
-
- /**
- * Format a string.
- *
- * @param string $string String to format
- * @return string Formatted string
- */
- public function t($string)
- {
- // Remove chars
- $string = htmlspecialchars($string, ENT_NOQUOTES);
-
- // Important text
- $string = str_replace('[strong]', '', $string);
- $string = str_replace('[/strong]', '', $string);
-
- // Create tables
- $string = preg_replace('/(\[table\])\s+/u', '$1', $string);
- $string = preg_replace('/\s*(\[tr\])\s*/u', '$1', $string);
- $string = preg_replace('%\s+(\[/table\])%u', '$1', $string);
- $string = preg_replace('%\s*(\[/tr\])\s*%u', '$1', $string);
- $string = str_replace('[table]', '
', $string);
- $string = str_replace('[/table]', '
', $string);
- $string = str_replace('[tr]', '
', $string);
- $string = str_replace('[/tr]', '
', $string);
- $string = str_replace('[th]', '', $string);
- $string = str_replace('[/th]', ' | ', $string);
- $string = str_replace('[td]', '', $string);
- $string = str_replace('[/td]', ' | ', $string);
-
- // Create links
- $string = preg_replace('!(^|\s)"([^"]+)":(https?://[^\s]+)(\s|$)!i', '$1$2$4', $string);
- $string = preg_replace('!(^|\s)(https?://[^\s]+)(\s|$)!i', '$1$2$3', $string);
-
- // Handle Seminarymedia
- $seminarymedia = array();
- preg_match_all('/\[seminarymedia:(\d+)\]/iu', $string, $matches); //, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
- $seminarymediaIds = array_unique($matches[1]);
- foreach($seminarymediaIds as &$seminarymediaId)
- {
- $replacement = null;
- if(!is_null(\hhu\z\controllers\SeminaryController::$seminary) && $this->loadMediaModel())
- {
- try {
- $medium = self::$Media->getSeminaryMediaById($seminarymediaId);
- $replacement = sprintf(
- '
',
- $this->linker->link(array('media','seminary', \hhu\z\controllers\SeminaryController::$seminary['url'],$medium['url'])),
- $medium['description']
- );
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- }
- }
-
- $seminarymedia[$seminarymediaId] = $replacement;
- }
- foreach($seminarymedia as $seminarymediaId => $replacement) {
- $string = str_replace("[seminarymedia:$seminarymediaId]", $replacement, $string);
- }
-
-
- // Return processed string
- return nl2br($string);
- }
-
-
-
-
- /**
- * Load the Media-Model if it is not loaded
- *
- * @return boolean Whether the Media-Model has been loaded or not
- */
- private function loadMediaModel()
- {
- // Do not load Model if it has already been loaded
- if(!is_null(self::$Media)) {
- return true;
- }
-
- try {
- // Load class
- Model::load('media');
-
- // Construct Model
- self::$Media = Model::factory('media');
- }
- catch(\Exception $e) {
- }
-
-
- // Return whether Media-Model has been loaded or not
- return !is_null(self::$Media);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z;
+
+
+ /**
+ * Class to format text with different syntax tags.
+ *
+ * @author Oliver Hanraths
+ */
+ class TextFormatter
+ {
+ /**
+ * Linker to create links.
+ *
+ * @var \nre\core\Linker
+ */
+ private $linker;
+ /**
+ * Media-Model to retrieve media data
+ *
+ * @static
+ * @var \nre\core\Model
+ */
+ private static $Media = null;
+
+
+
+
+ /**
+ * Create a new text formatter.
+ *
+ * @param \nre\core\Linker $linker Linker to create links with
+ */
+ public function __construct(\nre\core\Linker $linker)
+ {
+ $this->linker = $linker;
+ }
+
+
+
+
+ /**
+ * Format a string.
+ *
+ * @param string $string String to format
+ * @return string Formatted string
+ */
+ public function t($string)
+ {
+ // Remove chars
+ $string = htmlspecialchars($string, ENT_NOQUOTES);
+
+ // Important text
+ $string = str_replace('[strong]', '', $string);
+ $string = str_replace('[/strong]', '', $string);
+
+ // Create tables
+ $string = preg_replace('/(\[table\])\s+/u', '$1', $string);
+ $string = preg_replace('/\s*(\[tr\])\s*/u', '$1', $string);
+ $string = preg_replace('%\s+(\[/table\])%u', '$1', $string);
+ $string = preg_replace('%\s*(\[/tr\])\s*%u', '$1', $string);
+ $string = str_replace('[table]', '', $string);
+ $string = str_replace('[/table]', '
', $string);
+ $string = str_replace('[tr]', '
', $string);
+ $string = str_replace('[/tr]', '
', $string);
+ $string = str_replace('[th]', '', $string);
+ $string = str_replace('[/th]', ' | ', $string);
+ $string = str_replace('[td]', '', $string);
+ $string = str_replace('[/td]', ' | ', $string);
+
+ // Create links
+ $string = preg_replace('!(^|\s)"([^"]+)":(https?://[^\s]+)(\s|$)!i', '$1$2$4', $string);
+ $string = preg_replace('!(^|\s)(https?://[^\s]+)(\s|$)!i', '$1$2$3', $string);
+
+ // Handle Seminarymedia
+ $seminarymedia = array();
+ preg_match_all('/\[seminarymedia:(\d+)\]/iu', $string, $matches); //, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
+ $seminarymediaIds = array_unique($matches[1]);
+ foreach($seminarymediaIds as &$seminarymediaId)
+ {
+ $replacement = null;
+ if(!is_null(\hhu\z\controllers\SeminaryController::$seminary) && $this->loadMediaModel())
+ {
+ try {
+ $medium = self::$Media->getSeminaryMediaById($seminarymediaId);
+ $replacement = sprintf(
+ '
',
+ $this->linker->link(array('media','seminary', \hhu\z\controllers\SeminaryController::$seminary['url'],$medium['url'])),
+ $medium['description']
+ );
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ }
+ }
+
+ $seminarymedia[$seminarymediaId] = $replacement;
+ }
+ foreach($seminarymedia as $seminarymediaId => $replacement) {
+ $string = str_replace("[seminarymedia:$seminarymediaId]", $replacement, $string);
+ }
+
+
+ // Return processed string
+ return nl2br($string);
+ }
+
+
+
+
+ /**
+ * Load the Media-Model if it is not loaded
+ *
+ * @return boolean Whether the Media-Model has been loaded or not
+ */
+ private function loadMediaModel()
+ {
+ // Do not load Model if it has already been loaded
+ if(!is_null(self::$Media)) {
+ return true;
+ }
+
+ try {
+ // Load class
+ Model::load('media');
+
+ // Construct Model
+ self::$Media = Model::factory('media');
+ }
+ catch(\Exception $e) {
+ }
+
+
+ // Return whether Media-Model has been loaded or not
+ return !is_null(self::$Media);
+ }
+
+ }
?>
diff --git a/app/Utils.inc b/app/Utils.inc
index 397eb029..401fea8c 100644
--- a/app/Utils.inc
+++ b/app/Utils.inc
@@ -1,214 +1,214 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z;
-
-
- /**
- * Class for implementing utility methods.
- *
- * @author Oliver Hanraths
- */
- class Utils
- {
-
-
- /**
- * Mask HTML-chars for save output.
- *
- * @static
- * @param string $string String to be masked
- * @return string Masked string
- */
- public static function t($string)
- {
- return nl2br(htmlspecialchars($string));
- }
-
-
- /**
- * ‚htmlspecialchars‘ with support for UTF-8.
- *
- * @static
- * @param string $string String to be masked
- * @return string Masked string
- */
- public static function htmlspecialchars_utf8($string)
- {
- return htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
- }
-
-
- /**
- * Cut a string to the given length but only word boundaries.
- *
- * @static
- * @param string $string String to cut
- * @param int $length Length to cut string
- * @param int $scope Maximum length to cut string regardless word boundaries
- * @return string Cutted string
- */
- public static function shortenString($string, $length, $scope)
- {
- // Determine length
- $length = min($length, strlen($string));
-
- // Look for word boundary
- if(($pos = strpos($string, ' ', $length)) !== false)
- {
- // Check if boundary is outside of scope
- if($pos > $length + $scope) {
- $pos = strrpos(substr($string, 0, $pos), ' ');
- }
- }
- else {
- $pos = strlen($string);
- }
-
-
- // Cut string and return it
- return substr($string, 0, $pos);
- }
-
-
- /**
- * Send an e‑mail.
- *
- * @throws \hhu\z\exceptions\MailingException
- * @param mixed $to One (string) or many (array) receivers
- * @param string $messageAction Message Action
- * @param boolean $html Whether mail should be formatted as HTML or not
- * @param array $params Parameters to pass
- * @param \nre\core\Linker $linker Linker instance
- */
- public static function sendMail($to, $messageAction, $html=false, $params=null, $linker=null)
- {
- // Check configuration
- if(
- empty(\nre\configs\AppConfig::$mail['host']) ||
- empty(\nre\configs\AppConfig::$mail['port']) ||
- empty(\nre\configs\AppConfig::$mail['username'])
- ) {
- return;
- }
-
- // Load classes
- \hhu\z\lib\PHPMailerAutoload::load();
- \hhu\z\lib\PHPMailer::load();
- \hhu\z\lib\SMTP::load();
-
- // Create mailer
- $mail = new \PHPMailer();
-
- // Configure mailer
- $mail->isSMTP();
- $mail->Host = \nre\configs\AppConfig::$mail['host'];
- $mail->Port = \nre\configs\AppConfig::$mail['port'];
- $mail->SMTPAuth = true;
- $mail->Username = \nre\configs\AppConfig::$mail['username'];
- $mail->Password = \nre\configs\AppConfig::$mail['password'];
- $mail->SMTPSecure = \nre\configs\AppConfig::$mail['secure'];
-
- // Set properties
- $mail->CharSet = 'UTF-8';
- $mail->From = \nre\configs\AppConfig::$app['mailsender'];
- $mail->FromName = \nre\configs\AppConfig::$app['name'];
- if(!is_array($to)) {
- $to = array($to);
- }
- foreach($to as &$receiver) {
- $mail->addAddress($receiver);
- }
- if($html) {
- $mail->isHTML(true);
- }
-
- // Create message
- try {
- // Create MailApi
- $mailApi = new \hhu\z\apis\MailApi();
- if(!is_null($linker)) {
- $mailApi->setLinker($linker);
- }
- $mailApi->setMessage($messageAction);
- $mailApi->setParams($params);
- if($html) {
- $mailApi->setHTML();
- }
-
- // Render message
- $exception = $mailApi->run();
- if(!is_null($exception)) {
- return $exception;
- }
- $mail->Subject = $mailApi->getSubject();
- $mail->Body = $mailApi->render();
-
- // Try to render alternativ plaintext message
- if($html)
- {
- $mailApi->setHTML(false);
-
- // Render message
- $exception = $mailApi->run();
- if(is_null($exception))
- {
- try {
- $mail->AltBody = $mailApi->render();
- }
- catch(\nre\core\Exception $e) {
- // No alternative plaintext available
- }
- }
- }
- }
- catch(\nre\core\Exception $e) {
- throw new \hhu\z\exceptions\MailingException($e->getMessage());
- }
-
-
- // Return status
- if(!$mail->send()) {
- throw new \hhu\z\exceptions\MailingException($mail->ErrorInfo);
- }
- }
-
-
- /**
- * Detect Mimetype of a file.
- *
- * @param string $filename Name of file to detect Mimetype of
- * @param string $defaultMimetype Default Mimetype to use
- * @return string Detected Mimetype of file
- */
- public static function getMimetype($filename, $defaultMimetype=null)
- {
- $mimetype = (!is_null($defaultMimetype)) ? $defaultMimetype : 'application/octet-stream';
- // Use Fileinfo
- if(class_exists('\finfo'))
- {
- $finfo = new \finfo(FILEINFO_MIME_TYPE);
- if(!is_null($finfo)) {
- $mimetype = $finfo->file($filename);
- }
- }
- // Use deprecated mime_content_type()
- elseif(function_exists('mime_content_type')) {
- $mimetype = mime_content_type($filename);
- }
-
-
- return $mimetype;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z;
+
+
+ /**
+ * Class for implementing utility methods.
+ *
+ * @author Oliver Hanraths
+ */
+ class Utils
+ {
+
+
+ /**
+ * Mask HTML-chars for save output.
+ *
+ * @static
+ * @param string $string String to be masked
+ * @return string Masked string
+ */
+ public static function t($string)
+ {
+ return nl2br(htmlspecialchars($string));
+ }
+
+
+ /**
+ * ‚htmlspecialchars‘ with support for UTF-8.
+ *
+ * @static
+ * @param string $string String to be masked
+ * @return string Masked string
+ */
+ public static function htmlspecialchars_utf8($string)
+ {
+ return htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
+ }
+
+
+ /**
+ * Cut a string to the given length but only word boundaries.
+ *
+ * @static
+ * @param string $string String to cut
+ * @param int $length Length to cut string
+ * @param int $scope Maximum length to cut string regardless word boundaries
+ * @return string Cutted string
+ */
+ public static function shortenString($string, $length, $scope)
+ {
+ // Determine length
+ $length = min($length, strlen($string));
+
+ // Look for word boundary
+ if(($pos = strpos($string, ' ', $length)) !== false)
+ {
+ // Check if boundary is outside of scope
+ if($pos > $length + $scope) {
+ $pos = strrpos(substr($string, 0, $pos), ' ');
+ }
+ }
+ else {
+ $pos = strlen($string);
+ }
+
+
+ // Cut string and return it
+ return substr($string, 0, $pos);
+ }
+
+
+ /**
+ * Send an e‑mail.
+ *
+ * @throws \hhu\z\exceptions\MailingException
+ * @param mixed $to One (string) or many (array) receivers
+ * @param string $messageAction Message Action
+ * @param boolean $html Whether mail should be formatted as HTML or not
+ * @param array $params Parameters to pass
+ * @param \nre\core\Linker $linker Linker instance
+ */
+ public static function sendMail($to, $messageAction, $html=false, $params=null, $linker=null)
+ {
+ // Check configuration
+ if(
+ empty(\nre\configs\AppConfig::$mail['host']) ||
+ empty(\nre\configs\AppConfig::$mail['port']) ||
+ empty(\nre\configs\AppConfig::$mail['username'])
+ ) {
+ return;
+ }
+
+ // Load classes
+ \hhu\z\lib\PHPMailerAutoload::load();
+ \hhu\z\lib\PHPMailer::load();
+ \hhu\z\lib\SMTP::load();
+
+ // Create mailer
+ $mail = new \PHPMailer();
+
+ // Configure mailer
+ $mail->isSMTP();
+ $mail->Host = \nre\configs\AppConfig::$mail['host'];
+ $mail->Port = \nre\configs\AppConfig::$mail['port'];
+ $mail->SMTPAuth = true;
+ $mail->Username = \nre\configs\AppConfig::$mail['username'];
+ $mail->Password = \nre\configs\AppConfig::$mail['password'];
+ $mail->SMTPSecure = \nre\configs\AppConfig::$mail['secure'];
+
+ // Set properties
+ $mail->CharSet = 'UTF-8';
+ $mail->From = \nre\configs\AppConfig::$app['mailsender'];
+ $mail->FromName = \nre\configs\AppConfig::$app['name'];
+ if(!is_array($to)) {
+ $to = array($to);
+ }
+ foreach($to as &$receiver) {
+ $mail->addAddress($receiver);
+ }
+ if($html) {
+ $mail->isHTML(true);
+ }
+
+ // Create message
+ try {
+ // Create MailApi
+ $mailApi = new \hhu\z\apis\MailApi();
+ if(!is_null($linker)) {
+ $mailApi->setLinker($linker);
+ }
+ $mailApi->setMessage($messageAction);
+ $mailApi->setParams($params);
+ if($html) {
+ $mailApi->setHTML();
+ }
+
+ // Render message
+ $exception = $mailApi->run();
+ if(!is_null($exception)) {
+ return $exception;
+ }
+ $mail->Subject = $mailApi->getSubject();
+ $mail->Body = $mailApi->render();
+
+ // Try to render alternativ plaintext message
+ if($html)
+ {
+ $mailApi->setHTML(false);
+
+ // Render message
+ $exception = $mailApi->run();
+ if(is_null($exception))
+ {
+ try {
+ $mail->AltBody = $mailApi->render();
+ }
+ catch(\nre\core\Exception $e) {
+ // No alternative plaintext available
+ }
+ }
+ }
+ }
+ catch(\nre\core\Exception $e) {
+ throw new \hhu\z\exceptions\MailingException($e->getMessage());
+ }
+
+
+ // Return status
+ if(!$mail->send()) {
+ throw new \hhu\z\exceptions\MailingException($mail->ErrorInfo);
+ }
+ }
+
+
+ /**
+ * Detect Mimetype of a file.
+ *
+ * @param string $filename Name of file to detect Mimetype of
+ * @param string $defaultMimetype Default Mimetype to use
+ * @return string Detected Mimetype of file
+ */
+ public static function getMimetype($filename, $defaultMimetype=null)
+ {
+ $mimetype = (!is_null($defaultMimetype)) ? $defaultMimetype : 'application/octet-stream';
+ // Use Fileinfo
+ if(class_exists('\finfo'))
+ {
+ $finfo = new \finfo(FILEINFO_MIME_TYPE);
+ if(!is_null($finfo)) {
+ $mimetype = $finfo->file($filename);
+ }
+ }
+ // Use deprecated mime_content_type()
+ elseif(function_exists('mime_content_type')) {
+ $mimetype = mime_content_type($filename);
+ }
+
+
+ return $mimetype;
+ }
+
+ }
?>
diff --git a/app/agents/QuesttypeAgent.inc b/app/agents/QuesttypeAgent.inc
index 60a8d9ac..f13d6786 100644
--- a/app/agents/QuesttypeAgent.inc
+++ b/app/agents/QuesttypeAgent.inc
@@ -1,268 +1,268 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents;
-
-
- /**
- * Abstract class for implementing a QuesttypeAgent.
- *
- * @author Oliver Hanraths
- */
- abstract class QuesttypeAgent extends \nre\agents\BottomlevelAgent
- {
- /**
- * Current request
- *
- * @var \nre\core\Request
- */
- private $request;
- /**
- * Current response
- *
- * @var \nre\core\Response
- */
- private $response;
-
-
-
-
- /**
- * Load a QuesttypeAgent.
- *
- * @static
- * @throws \hhu\z\exceptions\QuesttypeAgentNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeAgentNotValidException
- * @param string $questtypeName Name of the QuesttypeAgent to load
- */
- public static function load($questtypeName)
- {
- // Determine full classname
- $className = self::getClassName($questtypeName);
-
- try {
- // Load class
- static::loadClass($questtypeName, $className);
-
- // Validate class
- static::checkClass($className, get_class());
- }
- catch(\nre\exceptions\ClassNotValidException $e) {
- throw new \hhu\z\exceptions\QuesttypeAgentNotValidException($e->getClassName());
- }
- catch(\nre\exceptions\ClassNotFoundException $e) {
- throw new \hhu\z\exceptions\QuesttypeAgentNotFoundException($e->getClassName());
- }
- }
-
-
- /**
- * Instantiate a QuesttypeAgent (Factory Pattern).
- *
- * @static
- * @throws \nre\exceptions\DatamodelException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
- * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
- * @param string $questtypeName Name of the QuesttypeAgent to instantiate
- * @param Request $request Current request
- * @param Response $response Current respone
- * @param Logger $log Log-system
- */
- public static function factory($questtypeName, \nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- // Determine full classname
- $className = self::getClassName($questtypeName);
-
- // Construct and return Questmodule
- return new $className($request, $response, $log);
- }
-
-
- /**
- * Determine the Agent-classname for the given Questtype-name.
- *
- * @static
- * @param string $questtypeName Questtype-name to get Agent-classname of
- * @param string $agentType Agent type of given Agent name
- * @return string Classname for the Questtype-name
- */
- private static function getClassName($questtypeName, $agentType=null)
- {
- $className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'agent');
-
-
- return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
- }
-
-
- /**
- * Load the class of a QuesttypeAgent.
- *
- * @static
- * @throws \nre\exceptions\ClassNotFoundException
- * @param string $questtypeName Name of the QuesttypeAgent to load
- * @param string $fullClassName Name of the class to load
- */
- private static function loadClass($questtypeName, $fullClassName)
- {
- // Determine folder to look in
- $className = explode('\\', $fullClassName);
- $className = array_pop($className);
-
- // Determine filename
- $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
-
- // Check file
- if(!file_exists($fileName))
- {
- throw new \nre\exceptions\ClassNotFoundException(
- $fullClassName
- );
- }
-
- // Include file
- include_once($fileName);
- }
-
-
- /**
- * Check inheritance of the QuesttypeAgent-class.
- *
- * @static
- * @throws \nre\exceptions\ClassNotValidException
- * @param string $className Name of the class to check
- * @param string $parentClassName Name of the parent class
- */
- public static function checkClass($className, $parentClassName)
- {
- // Check if class is subclass of parent class
- if(!is_subclass_of($className, $parentClassName)) {
- throw new \nre\exceptions\ClassNotValidException(
- $className
- );
- }
- }
-
-
-
-
- /**
- * Construct a new QuesttypeAgent.
- *
- * @throws \nre\exceptions\DatamodelException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
- * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param \nre\core\Logger $log Log-system
- */
- protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- // Store values
- $this->request = $request;
- $this->response = $response;
-
-
- // Call parent constructor
- parent::__construct($request, $response, $log);
- }
-
-
-
-
- /**
- * Save the answers of a Character for a Quest.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- * @param array $character Current Character data
- * @param array $answers Character answers for the Quest
- */
- public function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
- {
- $this->controller->saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
- }
-
-
- /**
- * Check if answers of a Character for a Quest match the correct ones.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- * @param array $character Current Character data
- * @param array $answers Character answers for the Quest
- */
- public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
- {
- return $this->controller->matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
- }
-
-
-
-
- /**
- * Load the Controller of this Agent.
- *
- * @throws \nre\exceptions\DatamodelException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
- * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
- */
- protected function loadController()
- {
- // Determine Controller name
- $controllerName = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::getClassName(get_class($this)));
-
- // Determine ToplevelAgent
- $toplevelAgentName = $this->response->getParam(0);
- if(is_null($toplevelAgentName)) {
- $toplevelAgentName = $this->request->getParam(0, 'toplevel');
- $this->response->addParam($toplevelAgentName);
- }
-
- // Determine Action
- $action = $this->response->getParam(2);
- if(is_null($action)) {
- $action = $this->request->getParam(2, 'action');
- $this->response->addParam($action);
- }
-
-
- // Load Controller
- \hhu\z\controllers\QuesttypeController::load($controllerName);
-
- // Construct Controller
- $this->controller = \hhu\z\controllers\QuesttypeController::factory($controllerName, $toplevelAgentName, $action, $this);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents;
+
+
+ /**
+ * Abstract class for implementing a QuesttypeAgent.
+ *
+ * @author Oliver Hanraths
+ */
+ abstract class QuesttypeAgent extends \nre\agents\BottomlevelAgent
+ {
+ /**
+ * Current request
+ *
+ * @var \nre\core\Request
+ */
+ private $request;
+ /**
+ * Current response
+ *
+ * @var \nre\core\Response
+ */
+ private $response;
+
+
+
+
+ /**
+ * Load a QuesttypeAgent.
+ *
+ * @static
+ * @throws \hhu\z\exceptions\QuesttypeAgentNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeAgentNotValidException
+ * @param string $questtypeName Name of the QuesttypeAgent to load
+ */
+ public static function load($questtypeName)
+ {
+ // Determine full classname
+ $className = self::getClassName($questtypeName);
+
+ try {
+ // Load class
+ static::loadClass($questtypeName, $className);
+
+ // Validate class
+ static::checkClass($className, get_class());
+ }
+ catch(\nre\exceptions\ClassNotValidException $e) {
+ throw new \hhu\z\exceptions\QuesttypeAgentNotValidException($e->getClassName());
+ }
+ catch(\nre\exceptions\ClassNotFoundException $e) {
+ throw new \hhu\z\exceptions\QuesttypeAgentNotFoundException($e->getClassName());
+ }
+ }
+
+
+ /**
+ * Instantiate a QuesttypeAgent (Factory Pattern).
+ *
+ * @static
+ * @throws \nre\exceptions\DatamodelException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
+ * @param string $questtypeName Name of the QuesttypeAgent to instantiate
+ * @param Request $request Current request
+ * @param Response $response Current respone
+ * @param Logger $log Log-system
+ */
+ public static function factory($questtypeName, \nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ // Determine full classname
+ $className = self::getClassName($questtypeName);
+
+ // Construct and return Questmodule
+ return new $className($request, $response, $log);
+ }
+
+
+ /**
+ * Determine the Agent-classname for the given Questtype-name.
+ *
+ * @static
+ * @param string $questtypeName Questtype-name to get Agent-classname of
+ * @param string $agentType Agent type of given Agent name
+ * @return string Classname for the Questtype-name
+ */
+ private static function getClassName($questtypeName, $agentType=null)
+ {
+ $className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'agent');
+
+
+ return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
+ }
+
+
+ /**
+ * Load the class of a QuesttypeAgent.
+ *
+ * @static
+ * @throws \nre\exceptions\ClassNotFoundException
+ * @param string $questtypeName Name of the QuesttypeAgent to load
+ * @param string $fullClassName Name of the class to load
+ */
+ private static function loadClass($questtypeName, $fullClassName)
+ {
+ // Determine folder to look in
+ $className = explode('\\', $fullClassName);
+ $className = array_pop($className);
+
+ // Determine filename
+ $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
+
+ // Check file
+ if(!file_exists($fileName))
+ {
+ throw new \nre\exceptions\ClassNotFoundException(
+ $fullClassName
+ );
+ }
+
+ // Include file
+ include_once($fileName);
+ }
+
+
+ /**
+ * Check inheritance of the QuesttypeAgent-class.
+ *
+ * @static
+ * @throws \nre\exceptions\ClassNotValidException
+ * @param string $className Name of the class to check
+ * @param string $parentClassName Name of the parent class
+ */
+ public static function checkClass($className, $parentClassName)
+ {
+ // Check if class is subclass of parent class
+ if(!is_subclass_of($className, $parentClassName)) {
+ throw new \nre\exceptions\ClassNotValidException(
+ $className
+ );
+ }
+ }
+
+
+
+
+ /**
+ * Construct a new QuesttypeAgent.
+ *
+ * @throws \nre\exceptions\DatamodelException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param \nre\core\Logger $log Log-system
+ */
+ protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ // Store values
+ $this->request = $request;
+ $this->response = $response;
+
+
+ // Call parent constructor
+ parent::__construct($request, $response, $log);
+ }
+
+
+
+
+ /**
+ * Save the answers of a Character for a Quest.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ * @param array $character Current Character data
+ * @param array $answers Character answers for the Quest
+ */
+ public function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
+ {
+ $this->controller->saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
+ }
+
+
+ /**
+ * Check if answers of a Character for a Quest match the correct ones.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ * @param array $character Current Character data
+ * @param array $answers Character answers for the Quest
+ */
+ public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
+ {
+ return $this->controller->matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
+ }
+
+
+
+
+ /**
+ * Load the Controller of this Agent.
+ *
+ * @throws \nre\exceptions\DatamodelException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
+ */
+ protected function loadController()
+ {
+ // Determine Controller name
+ $controllerName = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::getClassName(get_class($this)));
+
+ // Determine ToplevelAgent
+ $toplevelAgentName = $this->response->getParam(0);
+ if(is_null($toplevelAgentName)) {
+ $toplevelAgentName = $this->request->getParam(0, 'toplevel');
+ $this->response->addParam($toplevelAgentName);
+ }
+
+ // Determine Action
+ $action = $this->response->getParam(2);
+ if(is_null($action)) {
+ $action = $this->request->getParam(2, 'action');
+ $this->response->addParam($action);
+ }
+
+
+ // Load Controller
+ \hhu\z\controllers\QuesttypeController::load($controllerName);
+
+ // Construct Controller
+ $this->controller = \hhu\z\controllers\QuesttypeController::factory($controllerName, $toplevelAgentName, $action, $this);
+ }
+
+ }
?>
diff --git a/app/agents/ToplevelAgent.inc b/app/agents/ToplevelAgent.inc
index c77c8b21..10a72d85 100644
--- a/app/agents/ToplevelAgent.inc
+++ b/app/agents/ToplevelAgent.inc
@@ -1,43 +1,43 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\agents;
-
-
- /**
- * Abstract class for implementing an application Controller.
- *
- * @author Oliver Hanraths
- */
- abstract class ToplevelAgent extends \nre\agents\ToplevelAgent
- {
-
-
-
-
- /**
- * Construct a new ToplevlAgent
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param \nre\core\Logger $log Logger instance
- */
- protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
- {
- parent::__construct($request, $response, $log);
-
-
- // Set timezone
- date_default_timezone_set(\nre\configs\AppConfig::$app['timeZone']);
- }
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\agents;
+
+
+ /**
+ * Abstract class for implementing an application Controller.
+ *
+ * @author Oliver Hanraths
+ */
+ abstract class ToplevelAgent extends \nre\agents\ToplevelAgent
+ {
+
+
+
+
+ /**
+ * Construct a new ToplevlAgent
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param \nre\core\Logger $log Logger instance
+ */
+ protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
+ {
+ parent::__construct($request, $response, $log);
+
+
+ // Set timezone
+ date_default_timezone_set(\nre\configs\AppConfig::$app['timeZone']);
+ }
+ }
?>
diff --git a/app/apis/MailApi.inc b/app/apis/MailApi.inc
index 721bc547..bc8dbd1c 100644
--- a/app/apis/MailApi.inc
+++ b/app/apis/MailApi.inc
@@ -1,202 +1,202 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\apis;
-
-
- /**
- * MailApi-implementation.
- *
- * This class runs and renders e‑mail text and subject.
- *
- * @author Oliver Hanraths
- */
- class MailApi extends \nre\core\Api
- {
-
-
-
-
- /**
- * Construct a new MailApi.
- */
- public function __construct()
- {
- parent::__construct(
- new \hhu\z\requests\MailRequest(),
- new \hhu\z\responses\MailResponse()
- );
-
- // Set ToplevelAgent
- $this->request->addParam(\nre\configs\AppConfig::$defaults['toplevel-mail']);
- $this->request->addParam(\nre\configs\AppConfig::$defaults['intermediate-mail']);
- }
-
-
-
-
- /**
- * Set linker instance for creating links.
- *
- * @param \nre\core\Linker $linker Linker instance for creating links
- */
- public function setLinker(\nre\core\Linker $linker)
- {
- $this->request->setLinker($linker);
- }
-
-
- /**
- * Use a ToplevelAgent for HTML-mail
- *
- * @param bool $html Whether to use HTML or not
- */
- public function setHTML($html=true)
- {
- // Save params
- $params = $this->request->getParams(1);
-
- // Set ToplevelAgent
- $this->request->clearParams();
- if($html) {
- $this->request->addParam(\nre\configs\AppConfig::$defaults['toplevel-htmlmail']);
- }
- else {
- $this->request->addParam(\nre\configs\AppConfig::$defaults['toplevel-mail']);
- }
-
- // Restore params
- if(!empty($params)) {
- $this->addParams($params);
- }
- }
-
-
- /**
- * Set the Action for the message to render.
- *
- * @param string $messageAgent Agent to handle the message
- */
- public function setMessage($messageAgent)
- {
- // Save params
- $params = $this->request->getParams(3);
-
- // Set messageAgent
- $this->request->clearParams(2);
- $this->request->addParam($messageAgent);
-
- // Restore params
- if(!empty($params)) {
- $this->addParams($params);
- }
- }
-
-
- /**
- * Set additional params to pass to the Action.
- *
- * @param array $params Additional params to set
- */
- public function setParams($params)
- {
- // Add placeholder params
- for($i=3; $irequest->getParams()); $i++) {
- $this->request->addParam(null);
- }
-
- // Set params
- call_user_func_array(
- array(
- $this->request,
- 'addParams'
- ),
- $params
- );
- }
-
-
- /**
- * Return the subject set by the Controller.
- *
- * @return string Subject set by Controller
- */
- public function getSubject()
- {
- return $this->response->getSubject();
- }
-
-
- /**
- * Run mailtext generation.
- *
- * This method runs the generation of mailtext.
- *
- * @return \Exception Occured exception or null
- */
- public function run()
- {
- // Set response
- $this->response->clearParams();
- foreach($this->request->getParams() as $param) {
- $this->response->addParam($param);
- }
-
- // Run
- try {
- $exception = parent::run();
-
-
- return $exception;
- }
- catch(\nre\Exception $e) {
- return $e;
- }
- }
-
-
- /**
- * Render output.
- *
- * @return string Rendered output
- */
- public function render()
- {
- // Generate output
- parent::render();
-
-
- // Return output
- return $this->response->getOutput();
- }
-
-
-
-
- /**
- * Add multiple request params.
- *
- * @param array $params Request params to add
- */
- private function addParams($params)
- {
- call_user_func_array(
- array(
- $this->request,
- 'addParams'
- ),
- $params
- );
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\apis;
+
+
+ /**
+ * MailApi-implementation.
+ *
+ * This class runs and renders e‑mail text and subject.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailApi extends \nre\core\Api
+ {
+
+
+
+
+ /**
+ * Construct a new MailApi.
+ */
+ public function __construct()
+ {
+ parent::__construct(
+ new \hhu\z\requests\MailRequest(),
+ new \hhu\z\responses\MailResponse()
+ );
+
+ // Set ToplevelAgent
+ $this->request->addParam(\nre\configs\AppConfig::$defaults['toplevel-mail']);
+ $this->request->addParam(\nre\configs\AppConfig::$defaults['intermediate-mail']);
+ }
+
+
+
+
+ /**
+ * Set linker instance for creating links.
+ *
+ * @param \nre\core\Linker $linker Linker instance for creating links
+ */
+ public function setLinker(\nre\core\Linker $linker)
+ {
+ $this->request->setLinker($linker);
+ }
+
+
+ /**
+ * Use a ToplevelAgent for HTML-mail
+ *
+ * @param bool $html Whether to use HTML or not
+ */
+ public function setHTML($html=true)
+ {
+ // Save params
+ $params = $this->request->getParams(1);
+
+ // Set ToplevelAgent
+ $this->request->clearParams();
+ if($html) {
+ $this->request->addParam(\nre\configs\AppConfig::$defaults['toplevel-htmlmail']);
+ }
+ else {
+ $this->request->addParam(\nre\configs\AppConfig::$defaults['toplevel-mail']);
+ }
+
+ // Restore params
+ if(!empty($params)) {
+ $this->addParams($params);
+ }
+ }
+
+
+ /**
+ * Set the Action for the message to render.
+ *
+ * @param string $messageAgent Agent to handle the message
+ */
+ public function setMessage($messageAgent)
+ {
+ // Save params
+ $params = $this->request->getParams(3);
+
+ // Set messageAgent
+ $this->request->clearParams(2);
+ $this->request->addParam($messageAgent);
+
+ // Restore params
+ if(!empty($params)) {
+ $this->addParams($params);
+ }
+ }
+
+
+ /**
+ * Set additional params to pass to the Action.
+ *
+ * @param array $params Additional params to set
+ */
+ public function setParams($params)
+ {
+ // Add placeholder params
+ for($i=3; $irequest->getParams()); $i++) {
+ $this->request->addParam(null);
+ }
+
+ // Set params
+ call_user_func_array(
+ array(
+ $this->request,
+ 'addParams'
+ ),
+ $params
+ );
+ }
+
+
+ /**
+ * Return the subject set by the Controller.
+ *
+ * @return string Subject set by Controller
+ */
+ public function getSubject()
+ {
+ return $this->response->getSubject();
+ }
+
+
+ /**
+ * Run mailtext generation.
+ *
+ * This method runs the generation of mailtext.
+ *
+ * @return \Exception Occured exception or null
+ */
+ public function run()
+ {
+ // Set response
+ $this->response->clearParams();
+ foreach($this->request->getParams() as $param) {
+ $this->response->addParam($param);
+ }
+
+ // Run
+ try {
+ $exception = parent::run();
+
+
+ return $exception;
+ }
+ catch(\nre\Exception $e) {
+ return $e;
+ }
+ }
+
+
+ /**
+ * Render output.
+ *
+ * @return string Rendered output
+ */
+ public function render()
+ {
+ // Generate output
+ parent::render();
+
+
+ // Return output
+ return $this->response->getOutput();
+ }
+
+
+
+
+ /**
+ * Add multiple request params.
+ *
+ * @param array $params Request params to add
+ */
+ private function addParams($params)
+ {
+ call_user_func_array(
+ array(
+ $this->request,
+ 'addParams'
+ ),
+ $params
+ );
+ }
+
+ }
?>
diff --git a/app/controllers/IntermediateController.inc b/app/controllers/IntermediateController.inc
index 49da3fc2..923bc1b3 100644
--- a/app/controllers/IntermediateController.inc
+++ b/app/controllers/IntermediateController.inc
@@ -1,197 +1,197 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Abstract class for implementing a Controller of an IntermediateAgent.
- *
- * @author Oliver Hanraths
- */
- abstract class IntermediateController extends \hhu\z\Controller
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('users', 'userroles', 'seminaries', 'characters');
- /**
- * Current user
- *
- * @var array
- */
- public static $user = null;
- /**
- * Title information
- *
- * @var array
- */
- private $title = array();
-
-
-
-
- /**
- * Construct a new IntermediateController.
- *
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @param string $layoutName Name of the current Layout
- * @param string $action Current Action
- * @param \nre\core\Agent $agent Corresponding Agent
- */
- public function __construct($layoutName, $action, $agent)
- {
- parent::__construct($layoutName, $action, $agent);
- }
-
-
-
- /**
- * Prefilter that is executed before running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Get userdata
- try {
- self::$user = $this->Users->getUserById($this->Auth->getUserId());
- self::$user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById(self::$user['id']));
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- }
-
- // Check permissions
- $this->checkPermission($request, $response);
-
- // Set userdata
- $this->set('loggedUser', self::$user);
- }
-
-
- /**
- * Postfilter that is executed after running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::postFilter($request, $response);
- }
-
-
- /**
- * Return current title information.
- *
- * @return string Title information
- */
- public function getTitle()
- {
- return $this->title;
- }
-
-
-
-
- /**
- * Add a piece of information to the current title.
- *
- * @param string $title Title information
- */
- protected function addTitle($title)
- {
- $this->title[] = $title;
- }
-
-
- /**
- * Add a piece of information to the current title and localize
- * it.
- *
- * @param string $title Title information
- */
- protected function addTitleLocalized($title)
- {
- $title = gettext($title);
-
- $args = func_get_args();
- if(count($args) > 0) {
- $title = call_user_func_array(
- 'sprintf',
- array_merge(
- array($title),
- array_slice($args, 1)
- )
- );
- }
-
-
- $this->title[] = $title;
- }
-
-
-
-
- /**
- * Check user permissions.
- *
- * @throws \nre\exceptions\AccessDeniedException
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- private function checkPermission(\nre\core\Request $request, \nre\core\Response $response)
- {
- // Determine user
- $userRoles = array('guest');
- if(!is_null(self::$user)) {
- $userRoles = self::$user['roles'];
- }
-
-
- // Do not check error pages
- if($response->getParam(0, 'toplevel') == \nre\core\Config::getDefault('toplevel-error')) {
- return;
- }
- if($response->getParam(1, 'intermediate') == \nre\core\Config::getDefault('intermediate-error')) {
- return;
- }
-
- // Determine permissions of Intermediate Controller for current action
- $controller = $this->agent->controller;
- $action = $this->request->getParam(2, 'action');
- if(!property_exists($controller, 'permissions')) {
- return; // Allow if nothing is specified
- }
- if(!array_key_exists($action, $controller->permissions)) {
- return; // Allow if Action is not specified
- }
- $permissions = $controller->permissions[$action];
-
-
- // Check permissions
- if(count(array_intersect($userRoles, $permissions)) == 0) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Abstract class for implementing a Controller of an IntermediateAgent.
+ *
+ * @author Oliver Hanraths
+ */
+ abstract class IntermediateController extends \hhu\z\Controller
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('users', 'userroles', 'seminaries', 'characters');
+ /**
+ * Current user
+ *
+ * @var array
+ */
+ public static $user = null;
+ /**
+ * Title information
+ *
+ * @var array
+ */
+ private $title = array();
+
+
+
+
+ /**
+ * Construct a new IntermediateController.
+ *
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @param string $layoutName Name of the current Layout
+ * @param string $action Current Action
+ * @param \nre\core\Agent $agent Corresponding Agent
+ */
+ public function __construct($layoutName, $action, $agent)
+ {
+ parent::__construct($layoutName, $action, $agent);
+ }
+
+
+
+ /**
+ * Prefilter that is executed before running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Get userdata
+ try {
+ self::$user = $this->Users->getUserById($this->Auth->getUserId());
+ self::$user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById(self::$user['id']));
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ }
+
+ // Check permissions
+ $this->checkPermission($request, $response);
+
+ // Set userdata
+ $this->set('loggedUser', self::$user);
+ }
+
+
+ /**
+ * Postfilter that is executed after running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::postFilter($request, $response);
+ }
+
+
+ /**
+ * Return current title information.
+ *
+ * @return string Title information
+ */
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+
+
+
+ /**
+ * Add a piece of information to the current title.
+ *
+ * @param string $title Title information
+ */
+ protected function addTitle($title)
+ {
+ $this->title[] = $title;
+ }
+
+
+ /**
+ * Add a piece of information to the current title and localize
+ * it.
+ *
+ * @param string $title Title information
+ */
+ protected function addTitleLocalized($title)
+ {
+ $title = gettext($title);
+
+ $args = func_get_args();
+ if(count($args) > 0) {
+ $title = call_user_func_array(
+ 'sprintf',
+ array_merge(
+ array($title),
+ array_slice($args, 1)
+ )
+ );
+ }
+
+
+ $this->title[] = $title;
+ }
+
+
+
+
+ /**
+ * Check user permissions.
+ *
+ * @throws \nre\exceptions\AccessDeniedException
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ private function checkPermission(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ // Determine user
+ $userRoles = array('guest');
+ if(!is_null(self::$user)) {
+ $userRoles = self::$user['roles'];
+ }
+
+
+ // Do not check error pages
+ if($response->getParam(0, 'toplevel') == \nre\core\Config::getDefault('toplevel-error')) {
+ return;
+ }
+ if($response->getParam(1, 'intermediate') == \nre\core\Config::getDefault('intermediate-error')) {
+ return;
+ }
+
+ // Determine permissions of Intermediate Controller for current action
+ $controller = $this->agent->controller;
+ $action = $this->request->getParam(2, 'action');
+ if(!property_exists($controller, 'permissions')) {
+ return; // Allow if nothing is specified
+ }
+ if(!array_key_exists($action, $controller->permissions)) {
+ return; // Allow if Action is not specified
+ }
+ $permissions = $controller->permissions[$action];
+
+
+ // Check permissions
+ if(count(array_intersect($userRoles, $permissions)) == 0) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ }
+
+ }
?>
diff --git a/app/controllers/QuesttypeController.inc b/app/controllers/QuesttypeController.inc
index bdccb4cd..50eaac2d 100644
--- a/app/controllers/QuesttypeController.inc
+++ b/app/controllers/QuesttypeController.inc
@@ -1,320 +1,320 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Abstract class for implementing a QuesttypeController.
- *
- * @author Oliver Hanraths
- */
- abstract class QuesttypeController extends \hhu\z\Controller
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'questgroups', 'quests', 'characters');
-
-
-
-
- /**
- * Save the answers of a Character for a Quest.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- * @param array $character Current Character data
- * @param array $answers Character answers for the Quest
- */
- public abstract function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
-
-
- /**
- * Save additional data for the answers of a Character for a Quest.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- * @param array $character Current Character data
- * @param array $data Additional (POST-) data
- */
- public abstract function saveDataForCharacterAnswers($seminary, $questgroup, $quest, $character, $data);
-
-
- /**
- * Check if answers of a Character for a Quest match the correct ones.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- * @param array $character Current Character data
- * @param array $answers Character answers for the Quest
- * @return boolean True/false for a right/wrong answer or null for moderator evaluation
- */
- public abstract function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
-
-
- /**
- * Action: quest.
- *
- * Show the task of a Quest.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- * @param array $character Current Character data
- * @param \Exception $exception Character submission exception
- */
- public abstract function quest($seminary, $questgroup, $quest, $character, $exception);
-
-
- /**
- * Action: submission.
- *
- * Show the submission of a Character for a Quest.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- * @param array $character Current Character data
- */
- public abstract function submission($seminary, $questgroup, $quest, $character);
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
- /**
- * Action: edittask.
- *
- * Edit the task of a Quest.
- *
- * @param array $seminary Current Seminary data
- * @param array $questgroup Current Questgroup data
- * @param array $quest Current Quest data
- */
- public abstract function edittask($seminary, $questgroup, $quest);
-
-
-
-
- /**
- * Load a QuesttypeController.
- *
- * @static
- * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
- * @param string $controllerName Name of the QuesttypeController to load
- */
- public static function load($controllerName)
- {
- // Determine full classname
- $className = self::getClassName($controllerName);
-
- try {
- // Load class
- static::loadClass($controllerName, $className);
-
- // Validate class
- static::checkClass($className, get_class());
- }
- catch(\nre\exceptions\ClassNotValidException $e) {
- throw new \hhu\z\exceptions\QuesttypeControllerNotValidException($e->getClassName());
- }
- catch(\nre\exceptions\ClassNotFoundException $e) {
- throw new \hhu\z\exceptions\QuesttypeControllerNotFoundException($e->getClassName());
- }
- }
-
-
- /**
- * Instantiate a QuesttypeController (Factory Pattern).
- *
- * @static
- * @throws \nre\exceptions\DatamodelException
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- * @param string $controllerName Name of the QuesttypeController to instantiate
- * @param string $layoutName Name of the current Layout
- * @param string $action Current Action
- * @param \nre\core\Agent $agent Corresponding Agent
- */
- public static function factory($controllerName, $layoutName, $action, $agent)
- {
- // Determine full classname
- $className = self::getClassName($controllerName);
-
- // Construct and return Controller
- return new $className($layoutName, $action, $agent);
- }
-
-
- /**
- * Determine the Controller-classname for the given Questtype-name.
- *
- * @static
- * @param string $questtypeName Questtype-name to get Controller-classname of
- * @return string Classname for the Questtype-name
- */
- private static function getClassName($questtypeName)
- {
- $className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'controller');
-
-
- return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
- }
-
-
- /**
- * Load the class of a QuesttypeController
- *
- * @static
- * @throws \nre\exceptions\ClassNotFoundException
- * @param string $questtypeName Name of the QuesttypeController to load
- * @param string $fullClassName Name of the class to load
- */
- private static function loadClass($questtypeName, $fullClassName)
- {
- // Determine folder to look in
- $className = explode('\\', $fullClassName);
- $className = array_pop($className);
-
- // Determine filename
- $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
-
- // Check file
- if(!file_exists($fileName))
- {
- throw new \nre\exceptions\ClassNotFoundException(
- $fullClassName
- );
- }
-
- // Include file
- include_once($fileName);
- }
-
-
- /**
- * Check inheritance of the QuesttypeController-class.
- *
- * @static
- * @throws \nre\exceptions\ClassNotValidException
- * @param string $className Name of the class to check
- * @param string $parentClassName Name of the parent class
- */
- public static function checkClass($className, $parentClassName)
- {
- // Check if class is subclass of parent class
- if(!is_subclass_of($className, $parentClassName)) {
- throw new \nre\exceptions\ClassNotValidException(
- $className
- );
- }
- }
-
-
-
-
- /**
- * Construct a new application Controller.
- *
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- * @param string $layoutName Name of the current Layout
- * @param string $action Current Action
- * @param Agent $agent Corresponding Agent
- */
- public function __construct($layoutName, $action, $agent)
- {
- parent::__construct($layoutName, $action, $agent);
- }
-
-
-
-
- /**
- * Load the Models of this Controller.
- *
- * @throws \nre\exceptions\DatamodelException
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- */
- protected function loadModels()
- {
- // Load default models
- parent::loadModels();
-
- // Load QuesttypeModel
- $this->loadModel();
- }
-
-
- /**
- * Load the Model of the Questtype.
- *
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- */
- private function loadModel()
- {
- // Determine Model
- $model = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class($this))));
-
- // Load class
- \hhu\z\models\QuesttypeModel::load($model);
-
- // Construct Model
- $modelName = ucfirst(strtolower($model));
- $this->$modelName = \hhu\z\models\QuesttypeModel::factory($model);
- }
-
-
- /**
- * Load the View of this QuesttypeController.
- *
- * @throws \nre\exceptions\ViewNotFoundException
- * @param string $layoutName Name of the current Layout
- * @param string $action Current Action
- */
- protected function loadView($layoutName, $action)
- {
- // Check Layout name
- if(is_null($layoutName)) {
- return;
- }
-
- // Determine controller name
- $controllerName = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::getClassName(get_class($this)));
-
-
- // Load view
- $this->view = \hhu\z\views\QuesttypeView::loadAndFactory($layoutName, $controllerName, $action);
- }
-
- }
+ /**
+ * Abstract class for implementing a QuesttypeController.
+ *
+ * @author Oliver Hanraths
+ */
+ abstract class QuesttypeController extends \hhu\z\Controller
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'questgroups', 'quests', 'characters');
+
+
+
+
+ /**
+ * Save the answers of a Character for a Quest.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ * @param array $character Current Character data
+ * @param array $answers Character answers for the Quest
+ */
+ public abstract function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
+
+
+ /**
+ * Save additional data for the answers of a Character for a Quest.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ * @param array $character Current Character data
+ * @param array $data Additional (POST-) data
+ */
+ public abstract function saveDataForCharacterAnswers($seminary, $questgroup, $quest, $character, $data);
+
+
+ /**
+ * Check if answers of a Character for a Quest match the correct ones.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ * @param array $character Current Character data
+ * @param array $answers Character answers for the Quest
+ * @return boolean True/false for a right/wrong answer or null for moderator evaluation
+ */
+ public abstract function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
+
+
+ /**
+ * Action: quest.
+ *
+ * Show the task of a Quest.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ * @param array $character Current Character data
+ * @param \Exception $exception Character submission exception
+ */
+ public abstract function quest($seminary, $questgroup, $quest, $character, $exception);
+
+
+ /**
+ * Action: submission.
+ *
+ * Show the submission of a Character for a Quest.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ * @param array $character Current Character data
+ */
+ public abstract function submission($seminary, $questgroup, $quest, $character);
+
+
+ /**
+ * Action: edittask.
+ *
+ * Edit the task of a Quest.
+ *
+ * @param array $seminary Current Seminary data
+ * @param array $questgroup Current Questgroup data
+ * @param array $quest Current Quest data
+ */
+ public abstract function edittask($seminary, $questgroup, $quest);
+
+
+
+
+ /**
+ * Load a QuesttypeController.
+ *
+ * @static
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeControllerNotValidException
+ * @param string $controllerName Name of the QuesttypeController to load
+ */
+ public static function load($controllerName)
+ {
+ // Determine full classname
+ $className = self::getClassName($controllerName);
+
+ try {
+ // Load class
+ static::loadClass($controllerName, $className);
+
+ // Validate class
+ static::checkClass($className, get_class());
+ }
+ catch(\nre\exceptions\ClassNotValidException $e) {
+ throw new \hhu\z\exceptions\QuesttypeControllerNotValidException($e->getClassName());
+ }
+ catch(\nre\exceptions\ClassNotFoundException $e) {
+ throw new \hhu\z\exceptions\QuesttypeControllerNotFoundException($e->getClassName());
+ }
+ }
+
+
+ /**
+ * Instantiate a QuesttypeController (Factory Pattern).
+ *
+ * @static
+ * @throws \nre\exceptions\DatamodelException
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ * @param string $controllerName Name of the QuesttypeController to instantiate
+ * @param string $layoutName Name of the current Layout
+ * @param string $action Current Action
+ * @param \nre\core\Agent $agent Corresponding Agent
+ */
+ public static function factory($controllerName, $layoutName, $action, $agent)
+ {
+ // Determine full classname
+ $className = self::getClassName($controllerName);
+
+ // Construct and return Controller
+ return new $className($layoutName, $action, $agent);
+ }
+
+
+ /**
+ * Determine the Controller-classname for the given Questtype-name.
+ *
+ * @static
+ * @param string $questtypeName Questtype-name to get Controller-classname of
+ * @return string Classname for the Questtype-name
+ */
+ private static function getClassName($questtypeName)
+ {
+ $className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'controller');
+
+
+ return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
+ }
+
+
+ /**
+ * Load the class of a QuesttypeController
+ *
+ * @static
+ * @throws \nre\exceptions\ClassNotFoundException
+ * @param string $questtypeName Name of the QuesttypeController to load
+ * @param string $fullClassName Name of the class to load
+ */
+ private static function loadClass($questtypeName, $fullClassName)
+ {
+ // Determine folder to look in
+ $className = explode('\\', $fullClassName);
+ $className = array_pop($className);
+
+ // Determine filename
+ $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
+
+ // Check file
+ if(!file_exists($fileName))
+ {
+ throw new \nre\exceptions\ClassNotFoundException(
+ $fullClassName
+ );
+ }
+
+ // Include file
+ include_once($fileName);
+ }
+
+
+ /**
+ * Check inheritance of the QuesttypeController-class.
+ *
+ * @static
+ * @throws \nre\exceptions\ClassNotValidException
+ * @param string $className Name of the class to check
+ * @param string $parentClassName Name of the parent class
+ */
+ public static function checkClass($className, $parentClassName)
+ {
+ // Check if class is subclass of parent class
+ if(!is_subclass_of($className, $parentClassName)) {
+ throw new \nre\exceptions\ClassNotValidException(
+ $className
+ );
+ }
+ }
+
+
+
+
+ /**
+ * Construct a new application Controller.
+ *
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ * @param string $layoutName Name of the current Layout
+ * @param string $action Current Action
+ * @param Agent $agent Corresponding Agent
+ */
+ public function __construct($layoutName, $action, $agent)
+ {
+ parent::__construct($layoutName, $action, $agent);
+ }
+
+
+
+
+ /**
+ * Load the Models of this Controller.
+ *
+ * @throws \nre\exceptions\DatamodelException
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ */
+ protected function loadModels()
+ {
+ // Load default models
+ parent::loadModels();
+
+ // Load QuesttypeModel
+ $this->loadModel();
+ }
+
+
+ /**
+ * Load the Model of the Questtype.
+ *
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ */
+ private function loadModel()
+ {
+ // Determine Model
+ $model = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class($this))));
+
+ // Load class
+ \hhu\z\models\QuesttypeModel::load($model);
+
+ // Construct Model
+ $modelName = ucfirst(strtolower($model));
+ $this->$modelName = \hhu\z\models\QuesttypeModel::factory($model);
+ }
+
+
+ /**
+ * Load the View of this QuesttypeController.
+ *
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @param string $layoutName Name of the current Layout
+ * @param string $action Current Action
+ */
+ protected function loadView($layoutName, $action)
+ {
+ // Check Layout name
+ if(is_null($layoutName)) {
+ return;
+ }
+
+ // Determine controller name
+ $controllerName = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::getClassName(get_class($this)));
+
+
+ // Load view
+ $this->view = \hhu\z\views\QuesttypeView::loadAndFactory($layoutName, $controllerName, $action);
+ }
+
+ }
?>
diff --git a/app/controllers/SeminaryController.inc b/app/controllers/SeminaryController.inc
index 34fbcb44..3ce4211c 100644
--- a/app/controllers/SeminaryController.inc
+++ b/app/controllers/SeminaryController.inc
@@ -1,328 +1,328 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Abstract class for implementing a Controller for a Seminary and its
- * concepts.
- *
- * @author Oliver Hanraths
- */
- abstract class SeminaryController extends \hhu\z\controllers\IntermediateController
- {
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('achievement', 'auth', 'notification');
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'characters', 'characterroles', 'xplevels', 'avatars', 'achievements');
- /**
- * Current Seminary
- *
- * var array
- */
- public static $seminary = null;
- /**
- * Character of current user and Seminary
- *
- * @var array
- */
- public static $character = null;
-
-
-
-
- /**
- * Construct a new Seminary Controller.
- *
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \nre\exceptions\ModelNotValidException
- * @throws \nre\exceptions\ModelNotFoundException
- * @throws \nre\exceptions\ViewNotFoundException
- * @param string $layoutName Name of the current Layout
- * @param string $action Current Action
- * @param \nre\core\Agent $agent Corresponding Agent
- */
- public function __construct($layoutName, $action, $agent)
- {
- parent::__construct($layoutName, $action, $agent);
- }
-
-
-
- /**
- * Prefilter that is executed before running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Get Seminary and Character data
- try {
- self::$seminary = $this->Seminaries->getSeminaryByUrl($this->request->getParam(3));
- if(!is_null(self::$user))
- {
- self::$character = $this->Characters->getCharacterForUserAndSeminary(self::$user['id'], self::$seminary['id']);
- self::$character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById(self::$character['id']));
- try {
- self::$character['xplevel'] = $this->Xplevels->getXPLevelById(self::$character['xplevel_id']);
- self::$character['avatar'] = $this->Avatars->getAvatarByTypeAndLevel(self::$seminary['id'], self::$character['charactertype_url'], self::$character['xplevel']['level']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // No Avatar available
- }
- }
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- }
-
- // Check permissions
- $this->checkPermission($request, $response);
-
- // Check achievements
- $this->checkAchievements($request, $response, 'date');
- $this->checkAchievements($request, $response, 'achievement');
-
- // Set Seminary and Character data
- $this->set('loggedSeminary', self::$seminary);
- $this->set('loggedCharacter', self::$character);
- }
-
-
- /**
- * Postfilter that is executed after running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::postFilter($request, $response);
- }
-
-
-
- /**
- * Check user permissions.
- *
- * @throws AccessDeniedException
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- private function checkPermission(\nre\core\Request $request, \nre\core\Response $response)
- {
- // Do not check index page
- if(is_null($request->getParam(3))) {
- return;
- }
-
-
- // Determine permissions for current action
- $action = $this->request->getParam(2, 'action');
- if(!property_exists($this, 'seminaryPermissions')) {
- return; // Allow if nothing is specified
- }
- if(!array_key_exists($action, $this->seminaryPermissions)) {
- return; // Allow if Action is not specified
- }
- $permissions = $this->seminaryPermissions[$action];
-
-
- // Check permissions
- if(is_null(self::$character) || !array_key_exists('characterroles', self::$character) || count(array_intersect(self::$character['characterroles'], $permissions)) == 0) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- }
-
-
- /**
- * Check for newly achieved Achievements.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- * @param array $checkConditions Conditions to check
- */
- protected function checkAchievements(\nre\core\Request $request, \nre\core\Response $response, $checkConditions=null)
- {
- // Do not check MediaController
- if($this->request->getParam(0, 'toplevel') != \nre\configs\AppConfig::$defaults['toplevel']) {
- return;
- }
-
- // Check if Character is present
- if(is_null(self::$character)) {
- return;
- }
-
- // Set conditions to check
- if(!is_null($checkConditions) && !is_array($checkConditions)) {
- $checkConditions = array($checkConditions);
- }
-
- // Get unachieved Achievments
- $achievements = $this->Achievements->getUnachhievedAchievementsForCharacter(self::$seminary['id'], self::$character['id']);
- if(in_array('user', self::$character['characterroles'])) {
- $achievements = array_merge($achievements, $this->Achievements->getUnachievedOnlyOnceAchievementsForSeminary(self::$seminary['id']));
- }
-
- // Check conditions
- foreach($achievements as &$achievement)
- {
- // Check condition to test
- if(!is_null($checkConditions) && !in_array($achievement['condition'], $checkConditions)) {
- continue;
- }
-
- // Check deadline
- if(!is_null($achievement['deadline']) && $achievement['deadline'] < date('Y-m-d H:i:s')) {
- continue;
- }
-
- // Get conditions
- $conditions = array();
- $progress = 0;
- switch($achievement['condition'])
- {
- // Date conditions
- case 'date':
- $conditionsDate = $this->Achievements->getAchievementConditionsDate($achievement['id']);
- foreach($conditionsDate as &$condition)
- {
- $conditions[] = array(
- 'func' => 'checkAchievementConditionDate',
- 'params' => array(
- $condition['select']
- )
- );
- }
- break;
- // Character conditions
- case 'character':
- $conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
- foreach($conditionsCharacter as &$condition)
- {
- $conditions[] = array(
- 'func' => 'checkAchievementConditionCharacter',
- 'params' => array(
- $condition['field'],
- $condition['value'],
- self::$character['id']
- )
- );
- }
- break;
- // Quest conditions
- case 'quest':
- $conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
- foreach($conditionsQuest as &$condition)
- {
- $conditions[] = array(
- 'func' => 'checkAchievementConditionQuest',
- 'params' => array(
- $condition['field'],
- $condition['count'],
- $condition['value'],
- $condition['status'],
- $condition['groupby'],
- $condition['quest_id'],
- self::$character['id']
- )
- );
- }
- break;
- // Achievement conditions
- case 'achievement':
- $conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
- foreach($conditionsAchievement as &$condition)
- {
- $conditions[] = array(
- 'func' => 'checkAchievementConditionAchievement',
- 'params' => array(
- $condition['field'],
- $condition['count'],
- $condition['value'],
- $condition['groupby'],
- $condition['meta_achievement_id'],
- self::$character['id']
- )
- );
- }
- break;
- }
-
- // Do not achieve Achievements without conditions
- if(empty($conditions)) {
- continue;
- }
-
- // Check conditions
- $achieved = ($achievement['all_conditions'] == 1);
- foreach($conditions as &$condition)
- {
- // Calculate result of condition
- $result = call_user_func_array(
- array(
- $this->Achievements,
- $condition['func']
- ),
- $condition['params']
- );
-
- // The overall result and abort if possible
- if($achievement['all_conditions'])
- {
- if(!$result) {
- $achieved = false;
- break;
- }
- }
- else
- {
- if($result) {
- $achieved = true;
- break;
- }
- }
-
- }
-
- // Achievement achieved
- if($achieved)
- {
- // Set status
- $this->Achievements->setAchievementAchieved($achievement['id'], self::$character['id']);
-
- // Add notification
- $this->Notification->addNotification(
- \hhu\z\controllers\components\NotificationComponent::TYPE_ACHIEVEMENT,
- $achievement['title'],
- $this->linker->link(array('achievements', 'index', self::$seminary['url']), 0, true, null, true, $achievement['url']),
- (!is_null($achievement['achieved_achievementsmedia_id']) ? $this->linker->link(array('media','achievement',self::$seminary['url'],$achievement['url'])) : null)
- );
- }
- }
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Abstract class for implementing a Controller for a Seminary and its
+ * concepts.
+ *
+ * @author Oliver Hanraths
+ */
+ abstract class SeminaryController extends \hhu\z\controllers\IntermediateController
+ {
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('achievement', 'auth', 'notification');
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'characters', 'characterroles', 'xplevels', 'avatars', 'achievements');
+ /**
+ * Current Seminary
+ *
+ * var array
+ */
+ public static $seminary = null;
+ /**
+ * Character of current user and Seminary
+ *
+ * @var array
+ */
+ public static $character = null;
+
+
+
+
+ /**
+ * Construct a new Seminary Controller.
+ *
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \nre\exceptions\ModelNotValidException
+ * @throws \nre\exceptions\ModelNotFoundException
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @param string $layoutName Name of the current Layout
+ * @param string $action Current Action
+ * @param \nre\core\Agent $agent Corresponding Agent
+ */
+ public function __construct($layoutName, $action, $agent)
+ {
+ parent::__construct($layoutName, $action, $agent);
+ }
+
+
+
+ /**
+ * Prefilter that is executed before running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Get Seminary and Character data
+ try {
+ self::$seminary = $this->Seminaries->getSeminaryByUrl($this->request->getParam(3));
+ if(!is_null(self::$user))
+ {
+ self::$character = $this->Characters->getCharacterForUserAndSeminary(self::$user['id'], self::$seminary['id']);
+ self::$character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById(self::$character['id']));
+ try {
+ self::$character['xplevel'] = $this->Xplevels->getXPLevelById(self::$character['xplevel_id']);
+ self::$character['avatar'] = $this->Avatars->getAvatarByTypeAndLevel(self::$seminary['id'], self::$character['charactertype_url'], self::$character['xplevel']['level']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // No Avatar available
+ }
+ }
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ }
+
+ // Check permissions
+ $this->checkPermission($request, $response);
+
+ // Check achievements
+ $this->checkAchievements($request, $response, 'date');
+ $this->checkAchievements($request, $response, 'achievement');
+
+ // Set Seminary and Character data
+ $this->set('loggedSeminary', self::$seminary);
+ $this->set('loggedCharacter', self::$character);
+ }
+
+
+ /**
+ * Postfilter that is executed after running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::postFilter($request, $response);
+ }
+
+
+
+ /**
+ * Check user permissions.
+ *
+ * @throws AccessDeniedException
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ private function checkPermission(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ // Do not check index page
+ if(is_null($request->getParam(3))) {
+ return;
+ }
+
+
+ // Determine permissions for current action
+ $action = $this->request->getParam(2, 'action');
+ if(!property_exists($this, 'seminaryPermissions')) {
+ return; // Allow if nothing is specified
+ }
+ if(!array_key_exists($action, $this->seminaryPermissions)) {
+ return; // Allow if Action is not specified
+ }
+ $permissions = $this->seminaryPermissions[$action];
+
+
+ // Check permissions
+ if(is_null(self::$character) || !array_key_exists('characterroles', self::$character) || count(array_intersect(self::$character['characterroles'], $permissions)) == 0) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ }
+
+
+ /**
+ * Check for newly achieved Achievements.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ * @param array $checkConditions Conditions to check
+ */
+ protected function checkAchievements(\nre\core\Request $request, \nre\core\Response $response, $checkConditions=null)
+ {
+ // Do not check MediaController
+ if($this->request->getParam(0, 'toplevel') != \nre\configs\AppConfig::$defaults['toplevel']) {
+ return;
+ }
+
+ // Check if Character is present
+ if(is_null(self::$character)) {
+ return;
+ }
+
+ // Set conditions to check
+ if(!is_null($checkConditions) && !is_array($checkConditions)) {
+ $checkConditions = array($checkConditions);
+ }
+
+ // Get unachieved Achievments
+ $achievements = $this->Achievements->getUnachhievedAchievementsForCharacter(self::$seminary['id'], self::$character['id']);
+ if(in_array('user', self::$character['characterroles'])) {
+ $achievements = array_merge($achievements, $this->Achievements->getUnachievedOnlyOnceAchievementsForSeminary(self::$seminary['id']));
+ }
+
+ // Check conditions
+ foreach($achievements as &$achievement)
+ {
+ // Check condition to test
+ if(!is_null($checkConditions) && !in_array($achievement['condition'], $checkConditions)) {
+ continue;
+ }
+
+ // Check deadline
+ if(!is_null($achievement['deadline']) && $achievement['deadline'] < date('Y-m-d H:i:s')) {
+ continue;
+ }
+
+ // Get conditions
+ $conditions = array();
+ $progress = 0;
+ switch($achievement['condition'])
+ {
+ // Date conditions
+ case 'date':
+ $conditionsDate = $this->Achievements->getAchievementConditionsDate($achievement['id']);
+ foreach($conditionsDate as &$condition)
+ {
+ $conditions[] = array(
+ 'func' => 'checkAchievementConditionDate',
+ 'params' => array(
+ $condition['select']
+ )
+ );
+ }
+ break;
+ // Character conditions
+ case 'character':
+ $conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
+ foreach($conditionsCharacter as &$condition)
+ {
+ $conditions[] = array(
+ 'func' => 'checkAchievementConditionCharacter',
+ 'params' => array(
+ $condition['field'],
+ $condition['value'],
+ self::$character['id']
+ )
+ );
+ }
+ break;
+ // Quest conditions
+ case 'quest':
+ $conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
+ foreach($conditionsQuest as &$condition)
+ {
+ $conditions[] = array(
+ 'func' => 'checkAchievementConditionQuest',
+ 'params' => array(
+ $condition['field'],
+ $condition['count'],
+ $condition['value'],
+ $condition['status'],
+ $condition['groupby'],
+ $condition['quest_id'],
+ self::$character['id']
+ )
+ );
+ }
+ break;
+ // Achievement conditions
+ case 'achievement':
+ $conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
+ foreach($conditionsAchievement as &$condition)
+ {
+ $conditions[] = array(
+ 'func' => 'checkAchievementConditionAchievement',
+ 'params' => array(
+ $condition['field'],
+ $condition['count'],
+ $condition['value'],
+ $condition['groupby'],
+ $condition['meta_achievement_id'],
+ self::$character['id']
+ )
+ );
+ }
+ break;
+ }
+
+ // Do not achieve Achievements without conditions
+ if(empty($conditions)) {
+ continue;
+ }
+
+ // Check conditions
+ $achieved = ($achievement['all_conditions'] == 1);
+ foreach($conditions as &$condition)
+ {
+ // Calculate result of condition
+ $result = call_user_func_array(
+ array(
+ $this->Achievements,
+ $condition['func']
+ ),
+ $condition['params']
+ );
+
+ // The overall result and abort if possible
+ if($achievement['all_conditions'])
+ {
+ if(!$result) {
+ $achieved = false;
+ break;
+ }
+ }
+ else
+ {
+ if($result) {
+ $achieved = true;
+ break;
+ }
+ }
+
+ }
+
+ // Achievement achieved
+ if($achieved)
+ {
+ // Set status
+ $this->Achievements->setAchievementAchieved($achievement['id'], self::$character['id']);
+
+ // Add notification
+ $this->Notification->addNotification(
+ \hhu\z\controllers\components\NotificationComponent::TYPE_ACHIEVEMENT,
+ $achievement['title'],
+ $this->linker->link(array('achievements', 'index', self::$seminary['url']), 0, true, null, true, $achievement['url']),
+ (!is_null($achievement['achieved_achievementsmedia_id']) ? $this->linker->link(array('media','achievement',self::$seminary['url'],$achievement['url'])) : null)
+ );
+ }
+ }
+ }
+
+ }
?>
diff --git a/app/exceptions/FileCopyException.inc b/app/exceptions/FileCopyException.inc
index 898cb7b1..485428ff 100644
--- a/app/exceptions/FileCopyException.inc
+++ b/app/exceptions/FileCopyException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: File copy went wrong
- *
- * @author Oliver Hanraths
- */
- class FileCopyException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 204;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'File copy went wrong';
-
- /**
- * Nested error
- *
- * @var array
- */
- private $nestedError;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param array $nestedError Nested error
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($nestedError, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: File copy went wrong
+ *
+ * @author Oliver Hanraths
+ */
+ class FileCopyException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 204;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'File copy went wrong';
+
+ /**
+ * Nested error
+ *
+ * @var array
+ */
+ private $nestedError;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param array $nestedError Nested error
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($nestedError, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
$code,
$nestedError['message']
- );
-
- // Store values
- $this->nestedError = $nestedError;
- }
-
-
-
-
- /**
- * Get nested error.
- *
- * @return Nested error
- */
- public function getNestedError()
- {
- return $this->nestedError;
- }
-
- }
+ );
+
+ // Store values
+ $this->nestedError = $nestedError;
+ }
+
+
+
+
+ /**
+ * Get nested error.
+ *
+ * @return Nested error
+ */
+ public function getNestedError()
+ {
+ return $this->nestedError;
+ }
+
+ }
?>
diff --git a/app/exceptions/FileUploadException.inc b/app/exceptions/FileUploadException.inc
index c4c6b922..340bd61a 100644
--- a/app/exceptions/FileUploadException.inc
+++ b/app/exceptions/FileUploadException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: File upload went wrong
- *
- * @author Oliver Hanraths
- */
- class FileUploadException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 203;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'File upload went wrong';
-
- /**
- * Nested message
- *
- * @var string
- */
- private $nestedMessage;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $nestedMessage Nested message
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($nestedMessage=null, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $nestedMessage
- );
-
- // Store values
- $this->nestedMessage = $nestedMessage;
- }
-
-
-
-
- /**
- * Get nested message.
- *
- * @return Nested message
- */
- public function getNestedMessage()
- {
- return $this->nestedMessage;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: File upload went wrong
+ *
+ * @author Oliver Hanraths
+ */
+ class FileUploadException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 203;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'File upload went wrong';
+
+ /**
+ * Nested message
+ *
+ * @var string
+ */
+ private $nestedMessage;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $nestedMessage Nested message
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($nestedMessage=null, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $nestedMessage
+ );
+
+ // Store values
+ $this->nestedMessage = $nestedMessage;
+ }
+
+
+
+
+ /**
+ * Get nested message.
+ *
+ * @return Nested message
+ */
+ public function getNestedMessage()
+ {
+ return $this->nestedMessage;
+ }
+
+ }
?>
diff --git a/app/exceptions/MailingException.inc b/app/exceptions/MailingException.inc
index d68f8149..a6ff9736 100644
--- a/app/exceptions/MailingException.inc
+++ b/app/exceptions/MailingException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception during sending of an e‑mail.
- *
- * @author Oliver Hanraths
- */
- class MailingException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 300;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'Error sending e‑mail';
-
- /**
- * Nested error message
- *
- * @var string
- */
- private $error;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param int $error Nested error message
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($error, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $error
- );
-
- // Store values
- $this->error = $error;
- }
-
-
-
-
- /**
- * Get nested error message.
- *
- * @return string Nested error message
- */
- public function getError()
- {
- return $this->error;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception during sending of an e‑mail.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailingException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 300;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'Error sending e‑mail';
+
+ /**
+ * Nested error message
+ *
+ * @var string
+ */
+ private $error;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param int $error Nested error message
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($error, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $error
+ );
+
+ // Store values
+ $this->error = $error;
+ }
+
+
+
+
+ /**
+ * Get nested error message.
+ *
+ * @return string Nested error message
+ */
+ public function getError()
+ {
+ return $this->error;
+ }
+
+ }
?>
diff --git a/app/exceptions/MaxFilesizeException.inc b/app/exceptions/MaxFilesizeException.inc
index bc7a1383..0de53993 100644
--- a/app/exceptions/MaxFilesizeException.inc
+++ b/app/exceptions/MaxFilesizeException.inc
@@ -1,54 +1,54 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: File exceeds size maximum.
- *
- * @author Oliver Hanraths
- */
- class MaxFilesizeException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 202;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'File exceeds size maximum';
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code
- );
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: File exceeds size maximum.
+ *
+ * @author Oliver Hanraths
+ */
+ class MaxFilesizeException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 202;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'File exceeds size maximum';
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code
+ );
+ }
+
+ }
?>
diff --git a/app/exceptions/QuesttypeAgentNotFoundException.inc b/app/exceptions/QuesttypeAgentNotFoundException.inc
index 0aeaf298..b2b9dcb4 100644
--- a/app/exceptions/QuesttypeAgentNotFoundException.inc
+++ b/app/exceptions/QuesttypeAgentNotFoundException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: QuesttypeAgent not found.
- *
- * @author Oliver Hanraths
- */
- class QuesttypeAgentNotFoundException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 101;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'QuesttypeAgent not found';
-
- /**
- * Name of the class that was not found
- *
- * @var string
- */
- private $questtypeName;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $questtypeName Name of the QuesttypeAgent that was not found
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $questtypeName
- );
-
- // Store values
- $this->questtypeName = $questtypeName;
- }
-
-
-
-
- /**
- * Get the name of the QuesttypeAgent that was not found.
- *
- * @return string Name of the QuesttypeAgent that was not found
- */
- public function getClassName()
- {
- return $this->questtypeName;
- }
-
- }
+
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: QuesttypeAgent not found.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypeAgentNotFoundException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 101;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'QuesttypeAgent not found';
+
+ /**
+ * Name of the class that was not found
+ *
+ * @var string
+ */
+ private $questtypeName;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $questtypeName Name of the QuesttypeAgent that was not found
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $questtypeName
+ );
+
+ // Store values
+ $this->questtypeName = $questtypeName;
+ }
+
+
+
+
+ /**
+ * Get the name of the QuesttypeAgent that was not found.
+ *
+ * @return string Name of the QuesttypeAgent that was not found
+ */
+ public function getClassName()
+ {
+ return $this->questtypeName;
+ }
+
+ }
?>
diff --git a/app/exceptions/QuesttypeAgentNotValidException.inc b/app/exceptions/QuesttypeAgentNotValidException.inc
index 5efc8c3e..6e499919 100644
--- a/app/exceptions/QuesttypeAgentNotValidException.inc
+++ b/app/exceptions/QuesttypeAgentNotValidException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: QuesttypeAgent not valid.
- *
- * @author Oliver Hanraths
- */
- class QuesttypeAgentNotValidException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 102;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'QuesttypeAgent not valid';
-
- /**
- * Name of the invalid class
- *
- * @var string
- */
- private $questtypeName;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $questtypeName Name of the invalid QuesttypeAgent
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $questtypeName
- );
-
- // Store value
- $this->questtypeName = $questtypeName;
- }
-
-
-
-
- /**
- * Get the name of the invalid QuesttypeAgent.
- *
- * @return string Name of the invalid QuesttypeAgent
- */
- public function getClassName()
- {
- return $this->questtypeName;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: QuesttypeAgent not valid.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypeAgentNotValidException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 102;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'QuesttypeAgent not valid';
+
+ /**
+ * Name of the invalid class
+ *
+ * @var string
+ */
+ private $questtypeName;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $questtypeName Name of the invalid QuesttypeAgent
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $questtypeName
+ );
+
+ // Store value
+ $this->questtypeName = $questtypeName;
+ }
+
+
+
+
+ /**
+ * Get the name of the invalid QuesttypeAgent.
+ *
+ * @return string Name of the invalid QuesttypeAgent
+ */
+ public function getClassName()
+ {
+ return $this->questtypeName;
+ }
+
+ }
?>
diff --git a/app/exceptions/QuesttypeControllerNotFoundException.inc b/app/exceptions/QuesttypeControllerNotFoundException.inc
index e0447cc9..3787ebac 100644
--- a/app/exceptions/QuesttypeControllerNotFoundException.inc
+++ b/app/exceptions/QuesttypeControllerNotFoundException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: QuesttypeController not found.
- *
- * @author Oliver Hanraths
- */
- class QuesttypeControllerNotFoundException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 103;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'QuesttypeController not found';
-
- /**
- * Name of the class that was not found
- *
- * @var string
- */
- private $questtypeName;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $questtypeName Name of the QuesttypeController that was not found
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $questtypeName
- );
-
- // Store values
- $this->questtypeName = $questtypeName;
- }
-
-
-
-
- /**
- * Get the name of the QuesttypeController that was not found.
- *
- * @return string Name of the QuesttypeController that was not found
- */
- public function getClassName()
- {
- return $this->questtypeName;
- }
-
- }
+
+ /**
+ * The Legend of Z
+ *
+ * @author Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: QuesttypeController not found.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypeControllerNotFoundException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 103;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'QuesttypeController not found';
+
+ /**
+ * Name of the class that was not found
+ *
+ * @var string
+ */
+ private $questtypeName;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $questtypeName Name of the QuesttypeController that was not found
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $questtypeName
+ );
+
+ // Store values
+ $this->questtypeName = $questtypeName;
+ }
+
+
+
+
+ /**
+ * Get the name of the QuesttypeController that was not found.
+ *
+ * @return string Name of the QuesttypeController that was not found
+ */
+ public function getClassName()
+ {
+ return $this->questtypeName;
+ }
+
+ }
?>
diff --git a/app/exceptions/QuesttypeControllerNotValidException.inc b/app/exceptions/QuesttypeControllerNotValidException.inc
index f4ccbee1..3b0ef93d 100644
--- a/app/exceptions/QuesttypeControllerNotValidException.inc
+++ b/app/exceptions/QuesttypeControllerNotValidException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: QuesttypeController not valid.
- *
- * @author Oliver Hanraths
- */
- class QuesttypeControllerNotValidException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 104;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'QuesttypeController not valid';
-
- /**
- * Name of the invalid class
- *
- * @var string
- */
- private $questtypeName;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $questtypeName Name of the invalid QuesttypeController
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $questtypeName
- );
-
- // Store value
- $this->questtypeName = $questtypeName;
- }
-
-
-
-
- /**
- * Get the name of the invalid QuesttypeController.
- *
- * @return string Name of the invalid QuesttypeController
- */
- public function getClassName()
- {
- return $this->questtypeName;
- }
-
- }
+
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: QuesttypeController not valid.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypeControllerNotValidException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 104;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'QuesttypeController not valid';
+
+ /**
+ * Name of the invalid class
+ *
+ * @var string
+ */
+ private $questtypeName;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $questtypeName Name of the invalid QuesttypeController
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $questtypeName
+ );
+
+ // Store value
+ $this->questtypeName = $questtypeName;
+ }
+
+
+
+
+ /**
+ * Get the name of the invalid QuesttypeController.
+ *
+ * @return string Name of the invalid QuesttypeController
+ */
+ public function getClassName()
+ {
+ return $this->questtypeName;
+ }
+
+ }
?>
diff --git a/app/exceptions/QuesttypeModelNotFoundException.inc b/app/exceptions/QuesttypeModelNotFoundException.inc
index 9a6d2294..363013d6 100644
--- a/app/exceptions/QuesttypeModelNotFoundException.inc
+++ b/app/exceptions/QuesttypeModelNotFoundException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: QuesttypeModel not found.
- *
- * @author Oliver Hanraths
- */
- class QuesttypeModelNotFoundException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 105;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'QuesttypeModel not found';
-
- /**
- * Name of the class that was not found
- *
- * @var string
- */
- private $questtypeName;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $questtypeName Name of the QuesttypeModel that was not found
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $questtypeName
- );
-
- // Store values
- $this->questtypeName = $questtypeName;
- }
-
-
-
-
- /**
- * Get the name of the QuesttypeModel that was not found.
- *
- * @return string Name of the QuesttypeModel that was not found
- */
- public function getClassName()
- {
- return $this->questtypeName;
- }
-
- }
+
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: QuesttypeModel not found.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypeModelNotFoundException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 105;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'QuesttypeModel not found';
+
+ /**
+ * Name of the class that was not found
+ *
+ * @var string
+ */
+ private $questtypeName;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $questtypeName Name of the QuesttypeModel that was not found
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $questtypeName
+ );
+
+ // Store values
+ $this->questtypeName = $questtypeName;
+ }
+
+
+
+
+ /**
+ * Get the name of the QuesttypeModel that was not found.
+ *
+ * @return string Name of the QuesttypeModel that was not found
+ */
+ public function getClassName()
+ {
+ return $this->questtypeName;
+ }
+
+ }
?>
diff --git a/app/exceptions/QuesttypeModelNotValidException.inc b/app/exceptions/QuesttypeModelNotValidException.inc
index 911701e8..31a5248d 100644
--- a/app/exceptions/QuesttypeModelNotValidException.inc
+++ b/app/exceptions/QuesttypeModelNotValidException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: QuesttypeModel not valid.
- *
- * @author Oliver Hanraths
- */
- class QuesttypeModelNotValidException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 106;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'QuesttypeModel not valid';
-
- /**
- * Name of the invalid class
- *
- * @var string
- */
- private $questtypeName;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $questtypeName Name of the invalid QuesttypeModel
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $questtypeName
- );
-
- // Store value
- $this->questtypeName = $questtypeName;
- }
-
-
-
-
- /**
- * Get the name of the invalid QuesttypeModel.
- *
- * @return string Name of the invalid QuesttypeModel
- */
- public function getClassName()
- {
- return $this->questtypeName;
- }
-
- }
+
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: QuesttypeModel not valid.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypeModelNotValidException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 106;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'QuesttypeModel not valid';
+
+ /**
+ * Name of the invalid class
+ *
+ * @var string
+ */
+ private $questtypeName;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $questtypeName Name of the invalid QuesttypeModel
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($questtypeName, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $questtypeName
+ );
+
+ // Store value
+ $this->questtypeName = $questtypeName;
+ }
+
+
+
+
+ /**
+ * Get the name of the invalid QuesttypeModel.
+ *
+ * @return string Name of the invalid QuesttypeModel
+ */
+ public function getClassName()
+ {
+ return $this->questtypeName;
+ }
+
+ }
?>
diff --git a/app/exceptions/SubmissionNotValidException.inc b/app/exceptions/SubmissionNotValidException.inc
index 0902c78a..21cbee55 100644
--- a/app/exceptions/SubmissionNotValidException.inc
+++ b/app/exceptions/SubmissionNotValidException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: Character submission not valid.
- *
- * @author Oliver Hanraths
- */
- class SubmissionNotValidException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 200;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'Character submission not valid';
-
- /**
- * Nested exception
- *
- * @var Exception
- */
- private $nestedException;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $nestedException Nested exception
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($nestedException, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $nestedException
- );
-
- // Store value
- $this->nestedException = $nestedException;
- }
-
-
-
-
- /**
- * Get Nested exception.
- *
- * @return string Nested exception
- */
- public function getNestedException()
- {
- return $this->nestedException;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: Character submission not valid.
+ *
+ * @author Oliver Hanraths
+ */
+ class SubmissionNotValidException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 200;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'Character submission not valid';
+
+ /**
+ * Nested exception
+ *
+ * @var Exception
+ */
+ private $nestedException;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $nestedException Nested exception
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($nestedException, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $nestedException
+ );
+
+ // Store value
+ $this->nestedException = $nestedException;
+ }
+
+
+
+
+ /**
+ * Get Nested exception.
+ *
+ * @return string Nested exception
+ */
+ public function getNestedException()
+ {
+ return $this->nestedException;
+ }
+
+ }
?>
diff --git a/app/exceptions/WrongFiletypeException.inc b/app/exceptions/WrongFiletypeException.inc
index 13eb91df..8a734dc0 100644
--- a/app/exceptions/WrongFiletypeException.inc
+++ b/app/exceptions/WrongFiletypeException.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\exceptions;
-
-
- /**
- * Exception: File has wrong filetype.
- *
- * @author Oliver Hanraths
- */
- class WrongFiletypeException extends \nre\core\Exception
- {
- /**
- * Error code
- *
- * @var int
- */
- const CODE = 201;
- /**
- * Error message
- *
- * @var string
- */
- const MESSAGE = 'File has wrong type “%s”';
-
- /**
- * Type of file
- *
- * @var string
- */
- private $type;
-
-
-
-
- /**
- * Construct a new exception.
- *
- * @param string $type Type of file
- * @param string $message Error message
- * @param int $code Error code
- */
- function __construct($type, $message=self::MESSAGE, $code=self::CODE)
- {
- parent::__construct(
- $message,
- $code,
- $type
- );
-
- // Store values
- $this->type = $type;
- }
-
-
-
-
- /**
- * Get type of file.
- *
- * @return Type of file
- */
- public function getType()
- {
- return $this->type;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\exceptions;
+
+
+ /**
+ * Exception: File has wrong filetype.
+ *
+ * @author Oliver Hanraths
+ */
+ class WrongFiletypeException extends \nre\core\Exception
+ {
+ /**
+ * Error code
+ *
+ * @var int
+ */
+ const CODE = 201;
+ /**
+ * Error message
+ *
+ * @var string
+ */
+ const MESSAGE = 'File has wrong type “%s”';
+
+ /**
+ * Type of file
+ *
+ * @var string
+ */
+ private $type;
+
+
+
+
+ /**
+ * Construct a new exception.
+ *
+ * @param string $type Type of file
+ * @param string $message Error message
+ * @param int $code Error code
+ */
+ function __construct($type, $message=self::MESSAGE, $code=self::CODE)
+ {
+ parent::__construct(
+ $message,
+ $code,
+ $type
+ );
+
+ // Store values
+ $this->type = $type;
+ }
+
+
+
+
+ /**
+ * Get type of file.
+ *
+ * @return Type of file
+ */
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ }
?>
diff --git a/app/lib/PHPMailer.inc b/app/lib/PHPMailer.inc
index 157db77a..cceaf430 100644
--- a/app/lib/PHPMailer.inc
+++ b/app/lib/PHPMailer.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\lib
- {
-
-
- /**
- * Class to ensure that Compatibility library below is loaded.
- *
- * @author Oliver Hanraths
- */
- class PHPMailer
- {
-
- /**
- * Call this function to ensure this file is loaded.
- */
- public static function load()
- {
- }
-
- }
-
- }
-
- namespace {
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\lib
+ {
+
+
+ /**
+ * Class to ensure that Compatibility library below is loaded.
+ *
+ * @author Oliver Hanraths
+ */
+ class PHPMailer
+ {
+
+ /**
+ * Call this function to ensure this file is loaded.
+ */
+ public static function load()
+ {
+ }
+
+ }
+
+ }
+
+ namespace {
/**
* PHPMailer - PHP email creation and transport class.
diff --git a/app/lib/PHPMailerAutoload.inc b/app/lib/PHPMailerAutoload.inc
index 1bfc950e..58186b67 100644
--- a/app/lib/PHPMailerAutoload.inc
+++ b/app/lib/PHPMailerAutoload.inc
@@ -1,39 +1,39 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\lib
- {
-
-
- /**
- * Class to ensure that Compatibility library below is loaded.
- *
- * @author Oliver Hanraths
- */
- class PHPMailerAutoload
- {
-
- /**
- * Call this function to ensure this file is loaded.
- */
- public static function load()
- {
- }
-
- }
-
- }
-
- namespace {
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\lib
+ {
+
+
+ /**
+ * Class to ensure that Compatibility library below is loaded.
+ *
+ * @author Oliver Hanraths
+ */
+ class PHPMailerAutoload
+ {
+
+ /**
+ * Call this function to ensure this file is loaded.
+ */
+ public static function load()
+ {
+ }
+
+ }
+
+ }
+
+ namespace {
+
/**
* PHPMailer SPL autoloader.
* PHP Version 5
diff --git a/app/lib/Password.inc b/app/lib/Password.inc
index f9acf7d5..e038403a 100644
--- a/app/lib/Password.inc
+++ b/app/lib/Password.inc
@@ -1,37 +1,37 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\lib
- {
-
-
- /**
- * Class to ensure that Compatibility library below is loaded.
- *
- * @author Oliver Hanraths
- */
- class Password
- {
-
- /**
- * Call this function to ensure this file is loaded.
- */
- public static function load()
- {
- }
-
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\lib
+ {
+
+
+ /**
+ * Class to ensure that Compatibility library below is loaded.
+ *
+ * @author Oliver Hanraths
+ */
+ class Password
+ {
+
+ /**
+ * Call this function to ensure this file is loaded.
+ */
+ public static function load()
+ {
+ }
+
+ }
+
+ }
diff --git a/app/lib/SMTP.inc b/app/lib/SMTP.inc
index b616373e..18d2ee10 100644
--- a/app/lib/SMTP.inc
+++ b/app/lib/SMTP.inc
@@ -1,38 +1,38 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\lib
- {
-
-
- /**
- * Class to ensure that Compatibility library below is loaded.
- *
- * @author Oliver Hanraths
- */
- class SMTP
- {
-
- /**
- * Call this function to ensure this file is loaded.
- */
- public static function load()
- {
- }
-
- }
-
- }
-
- namespace {
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\lib
+ {
+
+
+ /**
+ * Class to ensure that Compatibility library below is loaded.
+ *
+ * @author Oliver Hanraths
+ */
+ class SMTP
+ {
+
+ /**
+ * Call this function to ensure this file is loaded.
+ */
+ public static function load()
+ {
+ }
+
+ }
+
+ }
+
+ namespace {
/**
* PHPMailer RFC821 SMTP email transport class.
diff --git a/app/models/QuesttypeModel.inc b/app/models/QuesttypeModel.inc
index fdeafe81..5829dcf3 100644
--- a/app/models/QuesttypeModel.inc
+++ b/app/models/QuesttypeModel.inc
@@ -1,31 +1,31 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Abstract class for implementing a QuesttypeModel.
- *
- * @author Oliver Hanraths
- */
- abstract class QuesttypeModel extends \hhu\z\Model
- {
-
-
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Abstract class for implementing a QuesttypeModel.
+ *
+ * @author Oliver Hanraths
+ */
+ abstract class QuesttypeModel extends \hhu\z\Model
+ {
+
+
+
/**
* Copy a Quest.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceQuestId ID of Quest to copy from
* @param int $targetQuestId ID of Quest to copy to
@@ -34,132 +34,132 @@
public abstract function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds);
- /**
- * Load a Model.
- *
- * @static
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @param string $modelName Name of the QuesttypeModel to load
- */
- public static function load($modelName)
- {
- // Determine full classname
- $className = self::getClassName($modelName);
-
- try {
- // Load class
- static::loadClass($modelName, $className);
-
- // Validate class
- static::checkClass($className, get_class());
- }
- catch(\nre\exceptions\ClassNotValidException $e) {
- throw new \hhu\z\exceptions\QuesttypeModelNotValidException($e->getClassName());
- }
- catch(\nre\exceptions\ClassNotFoundException $e) {
- throw new \hhu\z\exceptions\QuesttypeModelNotFoundException($e->getClassName());
- }
- }
-
-
- /**
- * Instantiate a QuesttypeModel (Factory Pattern).
- *
- * @static
- * @param string $questtypeName Name of the QuesttypeModel to instantiate
- */
- public static function factory($questtypeName)
- {
- // Determine full classname
- $className = self::getClassName($questtypeName);
-
- // Construct and return Model
- return new $className();
- }
-
-
- /**
- * Determine the Model-classname for the given Questtype-name.
- *
- * @static
- * @param string $questtypeName Questtype-name to get Model-classname of
- * @return string Classname for the Questtype-name
- */
- private static function getClassName($questtypeName)
- {
- $className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'model');
-
-
- return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
- }
-
-
- /**
- * Load the class of a QuesttypeModel.
- *
- * @static
- * @throws \nre\exceptions\ClassNotFoundException
- * @param string $questtypeName Name of the QuesttypeModel to load
- * @param string $fullClassName Name of the class to load
- */
- private static function loadClass($questtypeName, $fullClassName)
- {
- // Determine folder to look in
- $className = explode('\\', $fullClassName);
- $className = array_pop($className);
-
- // Determine filename
- $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
-
- // Check file
- if(!file_exists($fileName))
- {
- throw new \nre\exceptions\ClassNotFoundException(
- $fullClassName
- );
- }
-
- // Include file
- include_once($fileName);
- }
-
-
- /**
- * Check inheritance of the QuesttypeModel-class.
- *
- * @static
- * @throws \nre\exceptions\ClassNotValidException
- * @param string $className Name of the class to check
- * @param string $parentClassName Name of the parent class
- */
- public static function checkClass($className, $parentClassName)
- {
- // Check if class is subclass of parent class
- if(!is_subclass_of($className, $parentClassName)) {
- throw new \nre\exceptions\ClassNotValidException(
- $className
- );
- }
- }
-
-
-
-
- /**
- * Construct a new QuesttypeModel.
- *
- * @throws \nre\exceptions\DatamodelException
- * @throws \nre\exceptions\DriverNotFoundException
- * @throws \nre\exceptions\DriverNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
- * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- }
+ /**
+ * Load a Model.
+ *
+ * @static
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @param string $modelName Name of the QuesttypeModel to load
+ */
+ public static function load($modelName)
+ {
+ // Determine full classname
+ $className = self::getClassName($modelName);
+
+ try {
+ // Load class
+ static::loadClass($modelName, $className);
+
+ // Validate class
+ static::checkClass($className, get_class());
+ }
+ catch(\nre\exceptions\ClassNotValidException $e) {
+ throw new \hhu\z\exceptions\QuesttypeModelNotValidException($e->getClassName());
+ }
+ catch(\nre\exceptions\ClassNotFoundException $e) {
+ throw new \hhu\z\exceptions\QuesttypeModelNotFoundException($e->getClassName());
+ }
+ }
+
+
+ /**
+ * Instantiate a QuesttypeModel (Factory Pattern).
+ *
+ * @static
+ * @param string $questtypeName Name of the QuesttypeModel to instantiate
+ */
+ public static function factory($questtypeName)
+ {
+ // Determine full classname
+ $className = self::getClassName($questtypeName);
+
+ // Construct and return Model
+ return new $className();
+ }
+
+
+ /**
+ * Determine the Model-classname for the given Questtype-name.
+ *
+ * @static
+ * @param string $questtypeName Questtype-name to get Model-classname of
+ * @return string Classname for the Questtype-name
+ */
+ private static function getClassName($questtypeName)
+ {
+ $className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'model');
+
+
+ return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
+ }
+
+
+ /**
+ * Load the class of a QuesttypeModel.
+ *
+ * @static
+ * @throws \nre\exceptions\ClassNotFoundException
+ * @param string $questtypeName Name of the QuesttypeModel to load
+ * @param string $fullClassName Name of the class to load
+ */
+ private static function loadClass($questtypeName, $fullClassName)
+ {
+ // Determine folder to look in
+ $className = explode('\\', $fullClassName);
+ $className = array_pop($className);
+
+ // Determine filename
+ $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
+
+ // Check file
+ if(!file_exists($fileName))
+ {
+ throw new \nre\exceptions\ClassNotFoundException(
+ $fullClassName
+ );
+ }
+
+ // Include file
+ include_once($fileName);
+ }
+
+
+ /**
+ * Check inheritance of the QuesttypeModel-class.
+ *
+ * @static
+ * @throws \nre\exceptions\ClassNotValidException
+ * @param string $className Name of the class to check
+ * @param string $parentClassName Name of the parent class
+ */
+ public static function checkClass($className, $parentClassName)
+ {
+ // Check if class is subclass of parent class
+ if(!is_subclass_of($className, $parentClassName)) {
+ throw new \nre\exceptions\ClassNotValidException(
+ $className
+ );
+ }
+ }
+
+
+
+
+ /**
+ * Construct a new QuesttypeModel.
+ *
+ * @throws \nre\exceptions\DatamodelException
+ * @throws \nre\exceptions\DriverNotFoundException
+ * @throws \nre\exceptions\DriverNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotValidException
+ * @throws \hhu\z\exceptions\QuesttypeModelNotFoundException
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ }
?>
diff --git a/app/requests/MailRequest.inc b/app/requests/MailRequest.inc
index baaf02ab..c15c0842 100644
--- a/app/requests/MailRequest.inc
+++ b/app/requests/MailRequest.inc
@@ -1,92 +1,92 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\requests;
-
-
- /**
- * Representation of a mail-request.
- *
- * @author Oliver Hanraths
- */
- class MailRequest extends \nre\core\Request
- {
- /**
- * Linker
- *
- * @var \nre\core\Linker
- */
- private $linker = null;
-
-
-
-
- /**
- * Add a parameter.
- *
- * @param mixed $value Value of parameter
- */
- public function addParam($value)
- {
- $this->params[] = $value;
- }
-
-
- /**
- * Add multiple parameters.
- *
- * @param mixed $value1 Value of first parameter
- * @param mixed … Values of further parameters
- */
- public function addParams($value1)
- {
- $this->params = array_merge(
- $this->params,
- func_get_args()
- );
- }
-
-
- /**
- * Delete all stored parameters (from offset on).
- *
- * @param int $offset Offset-index
- */
- public function clearParams($offset=0)
- {
- $this->params = array_slice($this->params, 0, $offset);
- }
-
-
- /**
- * Set linker instance for creating links.
- *
- * @param Linker $linker Linker instance for creating links
- */
- public function setLinker(\nre\core\Linker $linker)
- {
- $this->linker = $linker;
- }
-
-
- /**
- * Get linker instance for creating links.
- *
- * @return \nre\core\Linker Linker instance for creating links
- */
- public function getLinker()
- {
- return $this->linker;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\requests;
+
+
+ /**
+ * Representation of a mail-request.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailRequest extends \nre\core\Request
+ {
+ /**
+ * Linker
+ *
+ * @var \nre\core\Linker
+ */
+ private $linker = null;
+
+
+
+
+ /**
+ * Add a parameter.
+ *
+ * @param mixed $value Value of parameter
+ */
+ public function addParam($value)
+ {
+ $this->params[] = $value;
+ }
+
+
+ /**
+ * Add multiple parameters.
+ *
+ * @param mixed $value1 Value of first parameter
+ * @param mixed … Values of further parameters
+ */
+ public function addParams($value1)
+ {
+ $this->params = array_merge(
+ $this->params,
+ func_get_args()
+ );
+ }
+
+
+ /**
+ * Delete all stored parameters (from offset on).
+ *
+ * @param int $offset Offset-index
+ */
+ public function clearParams($offset=0)
+ {
+ $this->params = array_slice($this->params, 0, $offset);
+ }
+
+
+ /**
+ * Set linker instance for creating links.
+ *
+ * @param Linker $linker Linker instance for creating links
+ */
+ public function setLinker(\nre\core\Linker $linker)
+ {
+ $this->linker = $linker;
+ }
+
+
+ /**
+ * Get linker instance for creating links.
+ *
+ * @return \nre\core\Linker Linker instance for creating links
+ */
+ public function getLinker()
+ {
+ return $this->linker;
+ }
+
+ }
?>
diff --git a/app/responses/MailResponse.inc b/app/responses/MailResponse.inc
index 71ced1bc..b7d21a27 100644
--- a/app/responses/MailResponse.inc
+++ b/app/responses/MailResponse.inc
@@ -1,55 +1,55 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\responses;
-
-
- /**
- * Representation of a mail-response.
- *
- * @author Oliver Hanraths
- */
- class MailResponse extends \nre\core\Response
- {
- /**
- * Mail subject
- *
- * @var string
- */
- private $subject = null;
-
-
-
-
- /**
- * Set subject.
- *
- * @param string $subject Subject to set
- */
- public function setSubject($subject)
- {
- $this->subject = $subject;
- }
-
-
- /**
- * Get subject.
- *
- * @return string Subject
- */
- public function getSubject()
- {
- return $this->subject;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\responses;
+
+
+ /**
+ * Representation of a mail-response.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailResponse extends \nre\core\Response
+ {
+ /**
+ * Mail subject
+ *
+ * @var string
+ */
+ private $subject = null;
+
+
+
+
+ /**
+ * Set subject.
+ *
+ * @param string $subject Subject to set
+ */
+ public function setSubject($subject)
+ {
+ $this->subject = $subject;
+ }
+
+
+ /**
+ * Get subject.
+ *
+ * @return string Subject
+ */
+ public function getSubject()
+ {
+ return $this->subject;
+ }
+
+ }
?>
diff --git a/app/views/QuesttypeView.inc b/app/views/QuesttypeView.inc
index 234147be..c42e2000 100644
--- a/app/views/QuesttypeView.inc
+++ b/app/views/QuesttypeView.inc
@@ -1,76 +1,76 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\views;
-
-
- /**
- * Abstract class for implementing a QuesttypeView.
- *
- * @author Oliver Hanraths
- */
- class QuesttypeView extends \nre\core\View
- {
-
-
-
-
- /**
- * Load and instantiate the QuesttypeView of a QuesttypeAgent.
- *
- * @throws \nre\exceptions\ViewNotFoundException
- * @param string $layoutName Name of Layout in use
- * @param string $agentName Name of the Agent
- * @param string $action Current Action
- * @param bool $isToplevel Agent is a ToplevelAgent
- */
- public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false)
- {
- return new QuesttypeView($layoutName, $agentName, $action, $isToplevel);
- }
-
-
-
-
- /**
- * Construct a new QuesttypeView.
- *
- * @throws \nre\exceptions\ViewNotFoundException
- * @param string $layoutName Name of Layout in use
- * @param string $agentName Name of the Agent
- * @param string $action Current Action
- * @param bool $isToplevel Agent is a ToplevelAgent
- */
- protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false)
- {
- // Create template filename
- // LayoutName
- $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($agentName).DS.strtolower($layoutName).DS;
-
- // Action
- $fileName .= strtolower($action);
-
- // File extension
- $fileName .= \nre\configs\CoreConfig::getFileExt('views');
-
-
- // Check template file
- if(!file_exists($fileName)) {
- throw new \nre\exceptions\ViewNotFoundException($fileName);
- }
-
- // Save filename
- $this->templateFilename = $fileName;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\views;
+
+
+ /**
+ * Abstract class for implementing a QuesttypeView.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypeView extends \nre\core\View
+ {
+
+
+
+
+ /**
+ * Load and instantiate the QuesttypeView of a QuesttypeAgent.
+ *
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @param string $layoutName Name of Layout in use
+ * @param string $agentName Name of the Agent
+ * @param string $action Current Action
+ * @param bool $isToplevel Agent is a ToplevelAgent
+ */
+ public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false)
+ {
+ return new QuesttypeView($layoutName, $agentName, $action, $isToplevel);
+ }
+
+
+
+
+ /**
+ * Construct a new QuesttypeView.
+ *
+ * @throws \nre\exceptions\ViewNotFoundException
+ * @param string $layoutName Name of Layout in use
+ * @param string $agentName Name of the Agent
+ * @param string $action Current Action
+ * @param bool $isToplevel Agent is a ToplevelAgent
+ */
+ protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false)
+ {
+ // Create template filename
+ // LayoutName
+ $fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($agentName).DS.strtolower($layoutName).DS;
+
+ // Action
+ $fileName .= strtolower($action);
+
+ // File extension
+ $fileName .= \nre\configs\CoreConfig::getFileExt('views');
+
+
+ // Check template file
+ if(!file_exists($fileName)) {
+ throw new \nre\exceptions\ViewNotFoundException($fileName);
+ }
+
+ // Save filename
+ $this->templateFilename = $fileName;
+ }
+
+ }
?>
diff --git a/controllers/AchievementsController.inc b/controllers/AchievementsController.inc
index 4f52b91d..1084fc3a 100644
--- a/controllers/AchievementsController.inc
+++ b/controllers/AchievementsController.inc
@@ -1,960 +1,960 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to list Achievements.
- *
- * @author Oliver Hanraths
- */
- class AchievementsController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('achievements', 'seminaries', 'media', 'characters', 'quests');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'create' => array('admin', 'moderator', 'user'),
- 'moveup' => array('admin', 'moderator', 'user'),
- 'movedown' => array('admin', 'moderator', 'user'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'conditions' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'create' => array('admin'),
- 'moveup' => array('admin', 'moderator'),
- 'movedown' => array('admin', 'moderator'),
- 'edit' => array('admin', 'moderator'),
- 'conditions' => array('admin', 'moderator'),
- 'delete' => array('admin')
- );
-
-
-
-
- /**
- * Action: index.
- *
- * List Achievements of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- */
- public function index($seminaryUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character
- $character = SeminaryController::$character;
-
- // Get seldom Achievements
- $seldomAchievements = $this->Achievements->getSeldomAchievements($seminary['id'], \nre\configs\AppConfig::$misc['achievements_range'], false);
- foreach($seldomAchievements as &$achievement) {
- $achievement['achieved'] = $this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id']);
- }
-
- // Get Characters with the most Achievements
- $successfulCharacters = $this->Characters->getCharactersWithMostAchievements($seminary['id'], \nre\configs\AppConfig::$misc['achievements_range'], false);
-
- // Get total count of Achievements for Seminary
- $achievementsCount = $this->Achievements->getAchievementsCountForSeminary($seminary['id'], false);
-
- // Get achieved Achievements
- $achievedAchievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
-
- // Get unachieved Achievements
- $unachievedAchievements = array_merge(
- $this->Achievements->getUnachhievedAchievementsForCharacter($seminary['id'], $character['id'], false, false),
- $this->Achievements->getUnachievedOnlyOnceAchievementsForSeminary($seminary['id'])
- );
- usort($unachievedAchievements, function($a, $b) {
- if($a['pos'] == $b['pos']) {
- return 0;
- }
- return ($a['pos'] > $b['pos']) ? 1 : -1;
- });
- foreach($unachievedAchievements as &$achievement)
- {
- // Get Character progress
- if($achievement['progress'])
- {
- $conditions = array();
- switch($achievement['condition'])
- {
- // Character conditions
- case 'character':
- $conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
- foreach($conditionsCharacter as &$condition)
- {
- $conditions[] = array(
- 'func' => 'getAchievementConditionCharacterProgress',
- 'params' => array(
- $condition['field'],
- $condition['value'],
- $character['id']
- )
- );
- }
- break;
- // Quest conditions
- case 'quest':
- $conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
- foreach($conditionsQuest as &$condition)
- {
- $conditions[] = array(
- 'func' => 'getAchievementConditionQuestProgress',
- 'params' => array(
- $condition['field'],
- $condition['count'],
- $condition['value'],
- $condition['status'],
- $condition['groupby'],
- $condition['quest_id'],
- $character['id']
- )
- );
- }
- break;
- // Achievement conditions
- case 'achievement':
- $conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
- foreach($conditionsAchievement as &$condition)
- {
- $conditions[] = array(
- 'func' => 'getAchievementConditionAchievementProgress',
- 'params' => array(
- $condition['field'],
- $condition['count'],
- $condition['value'],
- $condition['groupby'],
- $condition['meta_achievement_id'],
- $character['id']
- )
- );
- }
- break;
- }
-
- $characterProgresses = array();
- foreach($conditions as &$condition)
- {
- // Calculate progress of condition
- $characterProgresses[] = call_user_func_array(
- array(
- $this->Achievements,
- $condition['func']
- ),
- $condition['params']
- );
- }
-
- $achievement['characterProgress'] = array_sum($characterProgresses) / count($characterProgresses);
- }
- }
-
- // Get ranking
- $character['rank'] = $this->Achievements->getCountRank($seminary['id'], count($achievedAchievements));
-
-
- // Set title
- $this->addTitleLocalized('Achievements');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('character', $character);
- $this->set('seldomAchievements', $seldomAchievements);
- $this->set('successfulCharacters', $successfulCharacters);
- $this->set('achievementsCount', $achievementsCount);
- $this->set('achievedAchievements', $achievedAchievements);
- $this->set('unachievedAchievements', $unachievedAchievements);
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
- /**
- * Action: manage.
- *
- * Manage Achievements of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- */
- public function manage($seminaryUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Achievements
- $achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
+ /**
+ * Controller of the Agent to list Achievements.
+ *
+ * @author Oliver Hanraths
+ */
+ class AchievementsController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('achievements', 'seminaries', 'media', 'characters', 'quests');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin', 'moderator', 'user'),
+ 'moveup' => array('admin', 'moderator', 'user'),
+ 'movedown' => array('admin', 'moderator', 'user'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'conditions' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin'),
+ 'moveup' => array('admin', 'moderator'),
+ 'movedown' => array('admin', 'moderator'),
+ 'edit' => array('admin', 'moderator'),
+ 'conditions' => array('admin', 'moderator'),
+ 'delete' => array('admin')
+ );
- // Set title
- $this->addTitleLocalized('Manage Achievements');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('achievements', $achievements);
- }
- /**
- * Action: create.
- *
- * Create a new Achievement.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- */
- public function create($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ /**
+ * Action: index.
+ *
+ * List Achievements of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ */
+ public function index($seminaryUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
- // Get Achievements conditions
- $conditions = $this->Achievements->getAchievementsConditions();
+ // Get Character
+ $character = SeminaryController::$character;
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+ // Get seldom Achievements
+ $seldomAchievements = $this->Achievements->getSeldomAchievements($seminary['id'], \nre\configs\AppConfig::$misc['achievements_range'], false);
+ foreach($seldomAchievements as &$achievement) {
+ $achievement['achieved'] = $this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id']);
+ }
- // Values
- $title = '';
- $description = '';
- $progress = 0;
- $hidden = 0;
- $onlyOnce = 0;
- $allConditions = 1;
- $deadline = '';
- $condition = $conditions[0]['condition'];
- $fields = array('title', 'deadline');
- $validation = array();
+ // Get Characters with the most Achievements
+ $successfulCharacters = $this->Characters->getCharactersWithMostAchievements($seminary['id'], \nre\configs\AppConfig::$misc['achievements_range'], false);
- // Create Achievement
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $title = $this->request->getPostParam('title');
- if($this->Achievements->achievementTitleExists($seminary['id'], $title)) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $description = $this->request->getPostParam('description');
- $progress = !is_null($this->request->getPostParam('progress'));
- $hidden = !is_null($this->request->getPostParam('hidden'));
- $onlyOnce = !is_null($this->request->getPostParam('only_once'));
- $allConditions = !is_null($this->request->getPostParam('all_conditions'));
- $deadline = $this->request->getPostParam('deadline');
- $condition = $this->request->getPostParam('condition');
+ // Get total count of Achievements for Seminary
+ $achievementsCount = $this->Achievements->getAchievementsCountForSeminary($seminary['id'], false);
- // Validate condition
- $conditionIndex = null;
- foreach($conditions as $index => &$c) {
- if($condition == $c['condition']) {
- $conditionIndex = $index;
- }
- }
- if(is_null($conditionIndex)) {
- throw new \nre\exceptions\ParamsNotValidException($condition);
- }
+ // Get achieved Achievements
+ $achievedAchievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
- // Validate images
- $images = array(
- 'unachieved_image' => null,
- 'achieved_image' => null
- );
- foreach($images as $key => $image)
- {
- if(!empty($_FILES) && array_key_exists($key, $_FILES) && $_FILES[$key]['error'] != UPLOAD_ERR_NO_FILE)
- {
- $images[$key] = $_FILES[$key];
-
- // Check error
- if($images[$key]['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'image', 'error', $image[$key]['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $images[$key]['mimetype'] = \hhu\z\Utils::getMimetype($images[$key]['tmp_name'], $images[$key]['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $images[$key]['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'image', 'mimetype', $images[$key]['mimetype']);
- }
- elseif($images[$key]['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'image', 'size', $mediaMimetype['size']);
- }
- }
- }
+ // Get unachieved Achievements
+ $unachievedAchievements = array_merge(
+ $this->Achievements->getUnachhievedAchievementsForCharacter($seminary['id'], $character['id'], false, false),
+ $this->Achievements->getUnachievedOnlyOnceAchievementsForSeminary($seminary['id'])
+ );
+ usort($unachievedAchievements, function($a, $b) {
+ if($a['pos'] == $b['pos']) {
+ return 0;
+ }
+ return ($a['pos'] > $b['pos']) ? 1 : -1;
+ });
+ foreach($unachievedAchievements as &$achievement)
+ {
+ // Get Character progress
+ if($achievement['progress'])
+ {
+ $conditions = array();
+ switch($achievement['condition'])
+ {
+ // Character conditions
+ case 'character':
+ $conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
+ foreach($conditionsCharacter as &$condition)
+ {
+ $conditions[] = array(
+ 'func' => 'getAchievementConditionCharacterProgress',
+ 'params' => array(
+ $condition['field'],
+ $condition['value'],
+ $character['id']
+ )
+ );
+ }
+ break;
+ // Quest conditions
+ case 'quest':
+ $conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
+ foreach($conditionsQuest as &$condition)
+ {
+ $conditions[] = array(
+ 'func' => 'getAchievementConditionQuestProgress',
+ 'params' => array(
+ $condition['field'],
+ $condition['count'],
+ $condition['value'],
+ $condition['status'],
+ $condition['groupby'],
+ $condition['quest_id'],
+ $character['id']
+ )
+ );
+ }
+ break;
+ // Achievement conditions
+ case 'achievement':
+ $conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
+ foreach($conditionsAchievement as &$condition)
+ {
+ $conditions[] = array(
+ 'func' => 'getAchievementConditionAchievementProgress',
+ 'params' => array(
+ $condition['field'],
+ $condition['count'],
+ $condition['value'],
+ $condition['groupby'],
+ $condition['meta_achievement_id'],
+ $character['id']
+ )
+ );
+ }
+ break;
+ }
- // Create Achievement
- if($validation === true)
- {
- $achievementId = $this->Achievements->createAchievement(
- $this->Auth->getUserId(),
- $seminary['id'],
- $conditions[$conditionIndex]['id'],
- $title,
- $description,
- $progress,
- $hidden,
- $onlyOnce,
- $allConditions,
- (!empty($deadline)) ? $deadline : NULL
- );
- $achievement = $this->Achievements->getAchievementById($achievementId);
+ $characterProgresses = array();
+ foreach($conditions as &$condition)
+ {
+ // Calculate progress of condition
+ $characterProgresses[] = call_user_func_array(
+ array(
+ $this->Achievements,
+ $condition['func']
+ ),
+ $condition['params']
+ );
+ }
- // Upload images
- foreach($images as $key => &$image)
- {
- if(!is_null($image))
- {
- $image['media_id'] = $this->Media->createAchievementMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('achievement-%d', $achievement['id']).(substr($key, 0, 2) == 'un' ? '-locked' : NULL),
- '',
- $image['mimetype'],
- $image['tmp_name']
- );
- }
- }
- if(!is_null($images['unachieved_image']) && $images['unachieved_image']['media_id'] !== false) {
- $this->Achievements->setUnachievedMediaForAchievement($achievement['id'], $images['unachieved_image']['media_id']);
- }
- if(!is_null($images['achieved_image']) && $images['achieved_image']['media_id'] !== false) {
- $this->Achievements->setAchievedMediaForAchievement($achievement['id'], $images['achieved_image']['media_id']);
- }
+ $achievement['characterProgress'] = array_sum($characterProgresses) / count($characterProgresses);
+ }
+ }
- // Redirect to condition editing
- $this->redirect($this->linker->link(array('conditions', $seminary['url'], $achievement['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
+ // Get ranking
+ $character['rank'] = $this->Achievements->getCountRank($seminary['id'], count($achievedAchievements));
- // Set title
- $this->addTitleLocalized('Create Achievement');
- $this->addTitle($seminary['title']);
+ // Set title
+ $this->addTitleLocalized('Achievements');
+ $this->addTitle($seminary['title']);
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('title', $title);
- $this->set('description', $description);
- $this->set('progress', $progress);
- $this->set('hidden', $hidden);
- $this->set('onlyOnce', $onlyOnce);
- $this->set('allConditions', $allConditions);
- $this->set('deadline', $deadline);
- $this->set('condition', $condition);
- $this->set('conditions', $conditions);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: moveup.
- *
- * Move an Achievement up (decrement position).
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $achievementUrl URL-title of Achievement
- */
- public function moveup($seminaryUrl, $achievementUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Achievement
- $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
-
- // Set position
- $this->Achievements->moveAchievement($achievement, true);
-
-
- // Redirect
- $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
- }
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('character', $character);
+ $this->set('seldomAchievements', $seldomAchievements);
+ $this->set('successfulCharacters', $successfulCharacters);
+ $this->set('achievementsCount', $achievementsCount);
+ $this->set('achievedAchievements', $achievedAchievements);
+ $this->set('unachievedAchievements', $unachievedAchievements);
+ }
- /**
- * Action: movedown.
- *
- * Move an Achievement down (increment position).
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $achievementUrl URL-title of Achievement
- */
- public function movedown($seminaryUrl, $achievementUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Achievement
- $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
-
- // Set position
- $this->Achievements->moveAchievement($achievement, false);
-
-
- // Redirect
- $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
- }
+ /**
+ * Action: manage.
+ *
+ * Manage Achievements of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ */
+ public function manage($seminaryUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Achievements
+ $achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
- /**
- * Action: edit.
- *
- * Edit an Achievement.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $achievementUrl URL-title of Achievement to edit
- */
- public function edit($seminaryUrl, $achievementUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ // Set title
+ $this->addTitleLocalized('Manage Achievements');
+ $this->addTitle($seminary['title']);
- // Get Achievement
- $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
-
- // Get Achievements conditions
- $conditions = $this->Achievements->getAchievementsConditions();
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
-
- // Values
- $title = $achievement['title'];
- $description = $achievement['description'];
- $progress = $achievement['progress'];
- $hidden = $achievement['hidden'];
- $onlyOnce = $achievement['only_once'];
- $allConditions = $achievement['all_conditions'];
- $deadline = $achievement['deadline'];
- $condition = $achievement['condition'];
- $fields = array('title', 'deadline');
- $validation = array();
-
- // Edit Achievement
- if($this->request->getRequestMethod() == 'POST' && (!is_null($this->request->getPostParam('edit')) || !is_null($this->request->getPostParam('edit-conditions'))))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $title = $this->request->getPostParam('title');
- if($this->Achievements->achievementTitleExists($seminary['id'], $title, $achievement['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $description = $this->request->getPostParam('description');
- $progress = !is_null($this->request->getPostParam('progress'));
- $hidden = !is_null($this->request->getPostParam('hidden'));
- $onlyOnce = !is_null($this->request->getPostParam('only_once'));
- $allConditions = !is_null($this->request->getPostParam('all_conditions'));
- $deadline = $this->request->getPostParam('deadline');
- $condition = $this->request->getPostParam('condition');
-
- // Validate condition
- $conditionIndex = null;
- foreach($conditions as $index => &$c) {
- if($condition == $c['condition']) {
- $conditionIndex = $index;
- }
- }
- if(is_null($conditionIndex)) {
- throw new \nre\exceptions\ParamsNotValidException($condition);
- }
-
- // Validate images
- $images = array(
- 'unachieved_image' => null,
- 'achieved_image' => null
- );
- foreach($images as $key => $image)
- {
- if(!empty($_FILES) && array_key_exists($key, $_FILES) && $_FILES[$key]['error'] != UPLOAD_ERR_NO_FILE)
- {
- $images[$key] = $_FILES[$key];
-
- // Check error
- if($images[$key]['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'image', 'error', $image[$key]['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $images[$key]['mimetype'] = \hhu\z\Utils::getMimetype($images[$key]['tmp_name'], $images[$key]['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $images[$key]['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'image', 'mimetype', $images[$key]['mimetype']);
- }
- elseif($images[$key]['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'image', 'size', $mediaMimetype['size']);
- }
- }
- }
-
- // Edit Achievement
- if($validation === true)
- {
- $this->Achievements->editAchievement(
- $achievement['id'],
- $conditions[$conditionIndex]['id'],
- $title,
- $description,
- $progress,
- $hidden,
- $onlyOnce,
- $allConditions,
- (!empty($deadline)) ? $deadline : NULL
- );
-
- // Remove old conditions
- if($conditions[$conditionIndex]['condition'] != $achievement['condition'])
- {
- var_dump("remove");
- switch($achievement['condition'])
- {
- // Date conditions
- case 'date':
- foreach($this->Achievements->getAchievementConditionsDate($achievement['id']) as $c) {
- $this->Achievements->deleteAchievementConditionDate($c['id']);
- }
- break;
- // Character conditions
- case 'character':
- foreach($this->Achievements->getAchievementConditionsCharacter($achievement['id']) as $c) {
- $this->Achievements->deleteAchievementConditionCharacter($c['id']);
- }
- break;
- // Quest conditions
- case 'quest':
- foreach($this->Achievements->getAchievementConditionsQuest($achievement['id']) as $c) {
- $this->Achievements->deleteAchievementConditionQuest($c['id']);
- }
- break;
- // Achievement conditions
- case 'achievement':
- foreach($this->Achievements->getAchievementConditionsAchievement($achievement['id']) as $c) {
- $this->Achievements->deleteAchievementConditionAchievement($c['id']);
- }
- break;
- }
- }
-
- // Upload images
- foreach($images as $key => &$image)
- {
- if(!is_null($image))
- {
- $image['media_id'] = $this->Media->createAchievementMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('achievement-%d', $achievement['id']).(substr($key, 0, 2) == 'un' ? '-locked' : NULL),
- '',
- $image['mimetype'],
- $image['tmp_name']
- );
- }
- }
- if(!is_null($images['unachieved_image']) && $images['unachieved_image']['media_id'] !== false) {
- $this->Achievements->setUnachievedMediaForAchievement($achievement['id'], $images['unachieved_image']['media_id']);
- }
- if(!is_null($images['achieved_image']) && $images['achieved_image']['media_id'] !== false) {
- $this->Achievements->setAchievedMediaForAchievement($achievement['id'], $images['achieved_image']['media_id']);
- }
-
- // Redirect
- if(!is_null($this->request->getPostParam('edit-conditions'))) {
- // To condition editing
- $this->redirect($this->linker->link(array('conditions', $seminary['url'], $achievement['url']), 1));
- }
- else {
- // To overview
- $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
- }
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('achievements', $achievements);
+ }
- // Set title
- $this->addTitleLocalized('Edit Achievement');
- $this->addTitle($seminary['title']);
+ /**
+ * Action: create.
+ *
+ * Create a new Achievement.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ */
+ public function create($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('achievement', $achievement);
- $this->set('title', $title);
- $this->set('description', $description);
- $this->set('progress', $progress);
- $this->set('hidden', $hidden);
- $this->set('onlyOnce', $onlyOnce);
- $this->set('allConditions', $allConditions);
- $this->set('deadline', $deadline);
- $this->set('condition', $condition);
- $this->set('conditions', $conditions);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
+ // Get Achievements conditions
+ $conditions = $this->Achievements->getAchievementsConditions();
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $title = '';
+ $description = '';
+ $progress = 0;
+ $hidden = 0;
+ $onlyOnce = 0;
+ $allConditions = 1;
+ $deadline = '';
+ $condition = $conditions[0]['condition'];
+ $fields = array('title', 'deadline');
+ $validation = array();
+
+ // Create Achievement
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $title = $this->request->getPostParam('title');
+ if($this->Achievements->achievementTitleExists($seminary['id'], $title)) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $description = $this->request->getPostParam('description');
+ $progress = !is_null($this->request->getPostParam('progress'));
+ $hidden = !is_null($this->request->getPostParam('hidden'));
+ $onlyOnce = !is_null($this->request->getPostParam('only_once'));
+ $allConditions = !is_null($this->request->getPostParam('all_conditions'));
+ $deadline = $this->request->getPostParam('deadline');
+ $condition = $this->request->getPostParam('condition');
+
+ // Validate condition
+ $conditionIndex = null;
+ foreach($conditions as $index => &$c) {
+ if($condition == $c['condition']) {
+ $conditionIndex = $index;
+ }
+ }
+ if(is_null($conditionIndex)) {
+ throw new \nre\exceptions\ParamsNotValidException($condition);
+ }
+
+ // Validate images
+ $images = array(
+ 'unachieved_image' => null,
+ 'achieved_image' => null
+ );
+ foreach($images as $key => $image)
+ {
+ if(!empty($_FILES) && array_key_exists($key, $_FILES) && $_FILES[$key]['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $images[$key] = $_FILES[$key];
+
+ // Check error
+ if($images[$key]['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'image', 'error', $image[$key]['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $images[$key]['mimetype'] = \hhu\z\Utils::getMimetype($images[$key]['tmp_name'], $images[$key]['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $images[$key]['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'image', 'mimetype', $images[$key]['mimetype']);
+ }
+ elseif($images[$key]['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'image', 'size', $mediaMimetype['size']);
+ }
+ }
+ }
+
+ // Create Achievement
+ if($validation === true)
+ {
+ $achievementId = $this->Achievements->createAchievement(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $conditions[$conditionIndex]['id'],
+ $title,
+ $description,
+ $progress,
+ $hidden,
+ $onlyOnce,
+ $allConditions,
+ (!empty($deadline)) ? $deadline : NULL
+ );
+ $achievement = $this->Achievements->getAchievementById($achievementId);
+
+ // Upload images
+ foreach($images as $key => &$image)
+ {
+ if(!is_null($image))
+ {
+ $image['media_id'] = $this->Media->createAchievementMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('achievement-%d', $achievement['id']).(substr($key, 0, 2) == 'un' ? '-locked' : NULL),
+ '',
+ $image['mimetype'],
+ $image['tmp_name']
+ );
+ }
+ }
+ if(!is_null($images['unachieved_image']) && $images['unachieved_image']['media_id'] !== false) {
+ $this->Achievements->setUnachievedMediaForAchievement($achievement['id'], $images['unachieved_image']['media_id']);
+ }
+ if(!is_null($images['achieved_image']) && $images['achieved_image']['media_id'] !== false) {
+ $this->Achievements->setAchievedMediaForAchievement($achievement['id'], $images['achieved_image']['media_id']);
+ }
+
+ // Redirect to condition editing
+ $this->redirect($this->linker->link(array('conditions', $seminary['url'], $achievement['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
- /**
- * Action: conditions.
- *
- * Edit conditions of an Achievement.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $achievementUrl URL-title of Achievement to edit
- */
- public function conditions($seminaryUrl, $achievementUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ // Set title
+ $this->addTitleLocalized('Create Achievement');
+ $this->addTitle($seminary['title']);
- // Get Achievement
- $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
-
- // Get conditions
- $conditions = array();
- switch($achievement['condition'])
- {
- // Date conditions
- case 'date':
- $conditions = $this->Achievements->getAchievementConditionsDate($achievement['id']);
- break;
- // Character conditions
- case 'character':
- $conditions = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
- break;
- // Quest conditions
- case 'quest':
- $conditions = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
- break;
- // Achievement conditions
- case 'achievement':
- $conditions = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
- break;
- }
-
- // Values
- $characterFields = array(
- 'id', 'created', 'user_id', 'name', 'url', 'xps', 'quest_xps', 'avatar_id',
- 'charactertype_id', 'charactertype_name', 'charactertype_url',
- 'xplevel_id', 'xplevel'
- );
- $questFields = array(
- 'id', 'quest_id', 'character_id', 'created', 'status'
- );
- $achievementFields = array(
- 'achievement_id', 'character_id', 'created'
- );
- $quests = $this->Quests->getQuestsForSeminary($seminary['id']);
- $achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
- $deletes = array();
-
- // Save conditions
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get entered conditions
- $selectedConditions = $this->request->getPostParam('conditions');
- $deletes = $this->request->getPostParam('deletes');
- if(!is_array($deletes)) {
- $deletes = array();
- }
-
- // Edit or delete conditions
- foreach($conditions as &$condition)
- {
- $selectedCondition = $selectedConditions[$condition['id']];
- switch($achievement['condition'])
- {
- // Date conditions
- case 'date':
- if(array_key_exists($condition['id'], $deletes)) {
- $this->Achievements->deleteAchievementConditionDate($condition['id']);
- }
- else {
- $this->Achievements->editAchievementConditionDate(
- $condition['id'],
- $selectedCondition['select']
- );
- }
- break;
- // Character conditions
- case 'character':
- if(array_key_exists($condition['id'], $deletes)) {
- $this->Achievements->deleteAchievementConditionCharacter($condition['id']);
- }
- else {
- $this->Achievements->editAchievementConditionCharacter(
- $condition['id'],
- $selectedCondition['field'],
- $selectedCondition['value']
- );
- }
- break;
- // Quest conditions
- case 'quest':
- if(array_key_exists($condition['id'], $deletes)) {
- $this->Achievements->deleteAchievementConditionQuest($condition['id']);
- }
- else
- {
- // Get selected Quest
- $questIndex = null;
- if(!empty($selectedCondition['quest'])) {
- foreach($quests as $index => &$quest) {
- if($quest['url'] == $selectedCondition['quest']) {
- $questIndex = $index;
- }
- }
- }
-
- // Edit condition
- $this->Achievements->editAchievementConditionQuest(
- $condition['id'],
- $selectedCondition['field'],
- array_key_exists('count', $selectedCondition),
- $selectedCondition['value'],
- (!is_null($questIndex)) ? $quests[$questIndex]['id'] : null,
- ($selectedCondition['status'] != '') ? $selectedCondition['status'] : null,
- (!empty($selectedCondition['groupby'])) ? $selectedCondition['groupby'] : null
- );
- }
- break;
- // Achievement conditions
- case 'achievement':
- if(array_key_exists($condition['id'], $deletes)) {
- $this->Achievements->deleteAchievementConditionAchievement($condition['id']);
- }
- else
- {
- // Get selected Achievement
- $achievmentIndex = null;
- if(!empty($selectedCondition['achievement'])) {
- foreach($achievements as $index => &$a) {
- if($a['url'] == $selectedCondition['achievement']) {
- $achievementIndex = $index;
- }
- }
- }
-
- // Edit condition
- $this->Achievements->editAchievementConditionAchievement(
- $condition['id'],
- $selectedCondition['field'],
- array_key_exists('count', $selectedCondition),
- $selectedCondition['value'],
- (!is_null($achievementIndex)) ? $achievements[$achievementIndex]['id'] : null,
- (!empty($selectedCondition['groupby'])) ? $selectedCondition['groupby'] : null
- );
- }
- break;
- }
- }
-
- // Add new condition
- if(array_key_exists('new', $selectedConditions))
- {
- $condition = $selectedConditions['new'];
- switch($achievement['condition'])
- {
- // Date conditions
- case 'date':
- if(!empty($condition['select'])) {
- $this->Achievements->addAchievementConditionDate(
- $this->Auth->getUserId(),
- $achievement['id'],
- $condition['select']
- );
- }
- break;
- // Character conditions
- case 'character':
- if(!empty($condition['value'])) {
- $this->Achievements->addAchievementConditionCharacter(
- $this->Auth->getUserId(),
- $achievement['id'],
- $condition['field'],
- $condition['value']
- );
- }
- break;
- // Quest conditions
- case 'quest':
- if(!empty($condition['value']))
- {
- // Get selected Quest
- $questIndex = null;
- if(!empty($condition['quest'])) {
- foreach($quests as $index => &$quest) {
- if($quest['url'] == $condition['quest']) {
- $questIndex = $index;
- }
- }
- }
-
- // Edit condition
- $this->Achievements->addAchievementConditionQuest(
- $this->Auth->getUserId(),
- $achievement['id'],
- $condition['field'],
- array_key_exists('count', $condition),
- $condition['value'],
- (!is_null($questIndex)) ? $quests[$questIndex]['id'] : null,
- ($condition['status'] != '') ? $condition['status'] : null,
- (!empty($condition['groupby'])) ? $condition['groupby'] : null
- );
- }
- break;
- // Achievement conditions
- case 'achievement':
- if(!empty($condition['value']))
- {
- // Get selected Achievement
- $achievmentIndex = null;
- if(!empty($selectedCondition['achievement'])) {
- foreach($achievements as $index => &$a) {
- if($a['url'] == $selectedCondition['achievement']) {
- $achievementIndex = $index;
- }
- }
- }
-
- // Edit condition
- $this->Achievements->addAchievementConditionAchievement(
- $this->Auth->getUserId(),
- $achievement['id'],
- $condition['field'],
- array_key_exists('count', $condition),
- $condition['value'],
- (!is_null($achievementIndex)) ? $achievements[$achievementIndex]['id'] : null,
- (!empty($condition['groupby'])) ? $condition['groupby'] : null
- );
- }
- break;
- }
- }
-
- // Redirect to overview
- $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
- }
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('title', $title);
+ $this->set('description', $description);
+ $this->set('progress', $progress);
+ $this->set('hidden', $hidden);
+ $this->set('onlyOnce', $onlyOnce);
+ $this->set('allConditions', $allConditions);
+ $this->set('deadline', $deadline);
+ $this->set('condition', $condition);
+ $this->set('conditions', $conditions);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
- // Set title
- $this->addTitleLocalized('Edit Achievement conditions');
- $this->addTitle($seminary['title']);
+ /**
+ * Action: moveup.
+ *
+ * Move an Achievement up (decrement position).
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $achievementUrl URL-title of Achievement
+ */
+ public function moveup($seminaryUrl, $achievementUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('achievement', $achievement);
- $this->set('conditions', $conditions);
- $this->set('characterFields', $characterFields);
- $this->set('questFields', $questFields);
- $this->set('quests', $quests);
- $this->set('achievementFields', $achievementFields);
- $this->set('achievements', $achievements);
- $this->set('deletes', $deletes);
- }
+ // Get Achievement
+ $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
+
+ // Set position
+ $this->Achievements->moveAchievement($achievement, true);
- /**
- * Action: delete.
- *
- * Delete an Achievement.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $achievementUrl URL-title of Achievement
- */
- public function delete($seminaryUrl, $achievementUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ // Redirect
+ $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
+ }
- // Get Achievement
- $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete seminary
- $this->Achievements->deleteAchievement($achievement);
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('manage', $seminary['url']), 1));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Delete seminary');
-
- // Show confirmation
- $this->set('seminary', $seminary);
- $this->set('achievement', $achievement);
- }
- }
+
+ /**
+ * Action: movedown.
+ *
+ * Move an Achievement down (increment position).
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $achievementUrl URL-title of Achievement
+ */
+ public function movedown($seminaryUrl, $achievementUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Achievement
+ $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
+
+ // Set position
+ $this->Achievements->moveAchievement($achievement, false);
+
+
+ // Redirect
+ $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * Edit an Achievement.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $achievementUrl URL-title of Achievement to edit
+ */
+ public function edit($seminaryUrl, $achievementUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Achievement
+ $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
+
+ // Get Achievements conditions
+ $conditions = $this->Achievements->getAchievementsConditions();
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $title = $achievement['title'];
+ $description = $achievement['description'];
+ $progress = $achievement['progress'];
+ $hidden = $achievement['hidden'];
+ $onlyOnce = $achievement['only_once'];
+ $allConditions = $achievement['all_conditions'];
+ $deadline = $achievement['deadline'];
+ $condition = $achievement['condition'];
+ $fields = array('title', 'deadline');
+ $validation = array();
+
+ // Edit Achievement
+ if($this->request->getRequestMethod() == 'POST' && (!is_null($this->request->getPostParam('edit')) || !is_null($this->request->getPostParam('edit-conditions'))))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $title = $this->request->getPostParam('title');
+ if($this->Achievements->achievementTitleExists($seminary['id'], $title, $achievement['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $description = $this->request->getPostParam('description');
+ $progress = !is_null($this->request->getPostParam('progress'));
+ $hidden = !is_null($this->request->getPostParam('hidden'));
+ $onlyOnce = !is_null($this->request->getPostParam('only_once'));
+ $allConditions = !is_null($this->request->getPostParam('all_conditions'));
+ $deadline = $this->request->getPostParam('deadline');
+ $condition = $this->request->getPostParam('condition');
+
+ // Validate condition
+ $conditionIndex = null;
+ foreach($conditions as $index => &$c) {
+ if($condition == $c['condition']) {
+ $conditionIndex = $index;
+ }
+ }
+ if(is_null($conditionIndex)) {
+ throw new \nre\exceptions\ParamsNotValidException($condition);
+ }
+
+ // Validate images
+ $images = array(
+ 'unachieved_image' => null,
+ 'achieved_image' => null
+ );
+ foreach($images as $key => $image)
+ {
+ if(!empty($_FILES) && array_key_exists($key, $_FILES) && $_FILES[$key]['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $images[$key] = $_FILES[$key];
+
+ // Check error
+ if($images[$key]['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'image', 'error', $image[$key]['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $images[$key]['mimetype'] = \hhu\z\Utils::getMimetype($images[$key]['tmp_name'], $images[$key]['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $images[$key]['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'image', 'mimetype', $images[$key]['mimetype']);
+ }
+ elseif($images[$key]['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'image', 'size', $mediaMimetype['size']);
+ }
+ }
+ }
+
+ // Edit Achievement
+ if($validation === true)
+ {
+ $this->Achievements->editAchievement(
+ $achievement['id'],
+ $conditions[$conditionIndex]['id'],
+ $title,
+ $description,
+ $progress,
+ $hidden,
+ $onlyOnce,
+ $allConditions,
+ (!empty($deadline)) ? $deadline : NULL
+ );
+
+ // Remove old conditions
+ if($conditions[$conditionIndex]['condition'] != $achievement['condition'])
+ {
+ var_dump("remove");
+ switch($achievement['condition'])
+ {
+ // Date conditions
+ case 'date':
+ foreach($this->Achievements->getAchievementConditionsDate($achievement['id']) as $c) {
+ $this->Achievements->deleteAchievementConditionDate($c['id']);
+ }
+ break;
+ // Character conditions
+ case 'character':
+ foreach($this->Achievements->getAchievementConditionsCharacter($achievement['id']) as $c) {
+ $this->Achievements->deleteAchievementConditionCharacter($c['id']);
+ }
+ break;
+ // Quest conditions
+ case 'quest':
+ foreach($this->Achievements->getAchievementConditionsQuest($achievement['id']) as $c) {
+ $this->Achievements->deleteAchievementConditionQuest($c['id']);
+ }
+ break;
+ // Achievement conditions
+ case 'achievement':
+ foreach($this->Achievements->getAchievementConditionsAchievement($achievement['id']) as $c) {
+ $this->Achievements->deleteAchievementConditionAchievement($c['id']);
+ }
+ break;
+ }
+ }
+
+ // Upload images
+ foreach($images as $key => &$image)
+ {
+ if(!is_null($image))
+ {
+ $image['media_id'] = $this->Media->createAchievementMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('achievement-%d', $achievement['id']).(substr($key, 0, 2) == 'un' ? '-locked' : NULL),
+ '',
+ $image['mimetype'],
+ $image['tmp_name']
+ );
+ }
+ }
+ if(!is_null($images['unachieved_image']) && $images['unachieved_image']['media_id'] !== false) {
+ $this->Achievements->setUnachievedMediaForAchievement($achievement['id'], $images['unachieved_image']['media_id']);
+ }
+ if(!is_null($images['achieved_image']) && $images['achieved_image']['media_id'] !== false) {
+ $this->Achievements->setAchievedMediaForAchievement($achievement['id'], $images['achieved_image']['media_id']);
+ }
+
+ // Redirect
+ if(!is_null($this->request->getPostParam('edit-conditions'))) {
+ // To condition editing
+ $this->redirect($this->linker->link(array('conditions', $seminary['url'], $achievement['url']), 1));
+ }
+ else {
+ // To overview
+ $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
+ }
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('Edit Achievement');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('achievement', $achievement);
+ $this->set('title', $title);
+ $this->set('description', $description);
+ $this->set('progress', $progress);
+ $this->set('hidden', $hidden);
+ $this->set('onlyOnce', $onlyOnce);
+ $this->set('allConditions', $allConditions);
+ $this->set('deadline', $deadline);
+ $this->set('condition', $condition);
+ $this->set('conditions', $conditions);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: conditions.
+ *
+ * Edit conditions of an Achievement.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $achievementUrl URL-title of Achievement to edit
+ */
+ public function conditions($seminaryUrl, $achievementUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Achievement
+ $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
+
+ // Get conditions
+ $conditions = array();
+ switch($achievement['condition'])
+ {
+ // Date conditions
+ case 'date':
+ $conditions = $this->Achievements->getAchievementConditionsDate($achievement['id']);
+ break;
+ // Character conditions
+ case 'character':
+ $conditions = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
+ break;
+ // Quest conditions
+ case 'quest':
+ $conditions = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
+ break;
+ // Achievement conditions
+ case 'achievement':
+ $conditions = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
+ break;
+ }
+
+ // Values
+ $characterFields = array(
+ 'id', 'created', 'user_id', 'name', 'url', 'xps', 'quest_xps', 'avatar_id',
+ 'charactertype_id', 'charactertype_name', 'charactertype_url',
+ 'xplevel_id', 'xplevel'
+ );
+ $questFields = array(
+ 'id', 'quest_id', 'character_id', 'created', 'status'
+ );
+ $achievementFields = array(
+ 'achievement_id', 'character_id', 'created'
+ );
+ $quests = $this->Quests->getQuestsForSeminary($seminary['id']);
+ $achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
+ $deletes = array();
+
+ // Save conditions
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get entered conditions
+ $selectedConditions = $this->request->getPostParam('conditions');
+ $deletes = $this->request->getPostParam('deletes');
+ if(!is_array($deletes)) {
+ $deletes = array();
+ }
+
+ // Edit or delete conditions
+ foreach($conditions as &$condition)
+ {
+ $selectedCondition = $selectedConditions[$condition['id']];
+ switch($achievement['condition'])
+ {
+ // Date conditions
+ case 'date':
+ if(array_key_exists($condition['id'], $deletes)) {
+ $this->Achievements->deleteAchievementConditionDate($condition['id']);
+ }
+ else {
+ $this->Achievements->editAchievementConditionDate(
+ $condition['id'],
+ $selectedCondition['select']
+ );
+ }
+ break;
+ // Character conditions
+ case 'character':
+ if(array_key_exists($condition['id'], $deletes)) {
+ $this->Achievements->deleteAchievementConditionCharacter($condition['id']);
+ }
+ else {
+ $this->Achievements->editAchievementConditionCharacter(
+ $condition['id'],
+ $selectedCondition['field'],
+ $selectedCondition['value']
+ );
+ }
+ break;
+ // Quest conditions
+ case 'quest':
+ if(array_key_exists($condition['id'], $deletes)) {
+ $this->Achievements->deleteAchievementConditionQuest($condition['id']);
+ }
+ else
+ {
+ // Get selected Quest
+ $questIndex = null;
+ if(!empty($selectedCondition['quest'])) {
+ foreach($quests as $index => &$quest) {
+ if($quest['url'] == $selectedCondition['quest']) {
+ $questIndex = $index;
+ }
+ }
+ }
+
+ // Edit condition
+ $this->Achievements->editAchievementConditionQuest(
+ $condition['id'],
+ $selectedCondition['field'],
+ array_key_exists('count', $selectedCondition),
+ $selectedCondition['value'],
+ (!is_null($questIndex)) ? $quests[$questIndex]['id'] : null,
+ ($selectedCondition['status'] != '') ? $selectedCondition['status'] : null,
+ (!empty($selectedCondition['groupby'])) ? $selectedCondition['groupby'] : null
+ );
+ }
+ break;
+ // Achievement conditions
+ case 'achievement':
+ if(array_key_exists($condition['id'], $deletes)) {
+ $this->Achievements->deleteAchievementConditionAchievement($condition['id']);
+ }
+ else
+ {
+ // Get selected Achievement
+ $achievmentIndex = null;
+ if(!empty($selectedCondition['achievement'])) {
+ foreach($achievements as $index => &$a) {
+ if($a['url'] == $selectedCondition['achievement']) {
+ $achievementIndex = $index;
+ }
+ }
+ }
+
+ // Edit condition
+ $this->Achievements->editAchievementConditionAchievement(
+ $condition['id'],
+ $selectedCondition['field'],
+ array_key_exists('count', $selectedCondition),
+ $selectedCondition['value'],
+ (!is_null($achievementIndex)) ? $achievements[$achievementIndex]['id'] : null,
+ (!empty($selectedCondition['groupby'])) ? $selectedCondition['groupby'] : null
+ );
+ }
+ break;
+ }
+ }
+
+ // Add new condition
+ if(array_key_exists('new', $selectedConditions))
+ {
+ $condition = $selectedConditions['new'];
+ switch($achievement['condition'])
+ {
+ // Date conditions
+ case 'date':
+ if(!empty($condition['select'])) {
+ $this->Achievements->addAchievementConditionDate(
+ $this->Auth->getUserId(),
+ $achievement['id'],
+ $condition['select']
+ );
+ }
+ break;
+ // Character conditions
+ case 'character':
+ if(!empty($condition['value'])) {
+ $this->Achievements->addAchievementConditionCharacter(
+ $this->Auth->getUserId(),
+ $achievement['id'],
+ $condition['field'],
+ $condition['value']
+ );
+ }
+ break;
+ // Quest conditions
+ case 'quest':
+ if(!empty($condition['value']))
+ {
+ // Get selected Quest
+ $questIndex = null;
+ if(!empty($condition['quest'])) {
+ foreach($quests as $index => &$quest) {
+ if($quest['url'] == $condition['quest']) {
+ $questIndex = $index;
+ }
+ }
+ }
+
+ // Edit condition
+ $this->Achievements->addAchievementConditionQuest(
+ $this->Auth->getUserId(),
+ $achievement['id'],
+ $condition['field'],
+ array_key_exists('count', $condition),
+ $condition['value'],
+ (!is_null($questIndex)) ? $quests[$questIndex]['id'] : null,
+ ($condition['status'] != '') ? $condition['status'] : null,
+ (!empty($condition['groupby'])) ? $condition['groupby'] : null
+ );
+ }
+ break;
+ // Achievement conditions
+ case 'achievement':
+ if(!empty($condition['value']))
+ {
+ // Get selected Achievement
+ $achievmentIndex = null;
+ if(!empty($selectedCondition['achievement'])) {
+ foreach($achievements as $index => &$a) {
+ if($a['url'] == $selectedCondition['achievement']) {
+ $achievementIndex = $index;
+ }
+ }
+ }
+
+ // Edit condition
+ $this->Achievements->addAchievementConditionAchievement(
+ $this->Auth->getUserId(),
+ $achievement['id'],
+ $condition['field'],
+ array_key_exists('count', $condition),
+ $condition['value'],
+ (!is_null($achievementIndex)) ? $achievements[$achievementIndex]['id'] : null,
+ (!empty($condition['groupby'])) ? $condition['groupby'] : null
+ );
+ }
+ break;
+ }
+ }
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('Edit Achievement conditions');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('achievement', $achievement);
+ $this->set('conditions', $conditions);
+ $this->set('characterFields', $characterFields);
+ $this->set('questFields', $questFields);
+ $this->set('quests', $quests);
+ $this->set('achievementFields', $achievementFields);
+ $this->set('achievements', $achievements);
+ $this->set('deletes', $deletes);
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * Delete an Achievement.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $achievementUrl URL-title of Achievement
+ */
+ public function delete($seminaryUrl, $achievementUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Achievement
+ $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete seminary
+ $this->Achievements->deleteAchievement($achievement);
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('manage', $seminary['url']), 1));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete seminary');
+
+ // Show confirmation
+ $this->set('seminary', $seminary);
+ $this->set('achievement', $achievement);
+ }
+ }
?>
diff --git a/controllers/AjaxController.inc b/controllers/AjaxController.inc
index 9ed801df..3e824c25 100644
--- a/controllers/AjaxController.inc
+++ b/controllers/AjaxController.inc
@@ -1,52 +1,52 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the AjaxAgent to return a JSON-string used by AJAX.
- *
- * @author Oliver Hanraths
- */
- class AjaxController extends \hhu\z\Controller
- {
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Set content-type
- $this->response->addHeader("Content-type: application/json; charset=utf-8");
- }
-
-
- /**
- * Action: index.
- *
- * Create the JSON-string.
- */
- public function index()
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the AjaxAgent to return a JSON-string used by AJAX.
+ *
+ * @author Oliver Hanraths
+ */
+ class AjaxController extends \hhu\z\Controller
+ {
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Set content-type
+ $this->response->addHeader("Content-type: application/json; charset=utf-8");
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * Create the JSON-string.
+ */
+ public function index()
+ {
+ }
+
+ }
?>
diff --git a/controllers/BinaryController.inc b/controllers/BinaryController.inc
index 0d4396ef..9f7d6eda 100644
--- a/controllers/BinaryController.inc
+++ b/controllers/BinaryController.inc
@@ -1,37 +1,37 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the BinaryAgent to show binary data.
- *
- * @author Oliver Hanraths
- */
- class BinaryController extends \hhu\z\controllers\IntermediateController
- {
-
-
-
-
- /**
- * Action: index.
- *
- * Create binary data.
- */
- public function index()
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the BinaryAgent to show binary data.
+ *
+ * @author Oliver Hanraths
+ */
+ class BinaryController extends \hhu\z\controllers\IntermediateController
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * Create binary data.
+ */
+ public function index()
+ {
+ }
+
+ }
?>
diff --git a/controllers/CharactergroupsController.inc b/controllers/CharactergroupsController.inc
index e09e9487..d6aee656 100644
--- a/controllers/CharactergroupsController.inc
+++ b/controllers/CharactergroupsController.inc
@@ -1,759 +1,759 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the CharactergroupsAgent to display Character groups.
- *
- * @author Oliver Hanraths
- */
- class CharactergroupsController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'characters', 'avatars', 'media');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'groupsgroup' => array('admin', 'moderator', 'user'),
- 'creategroupsgroup' => array('admin', 'moderator', 'user'),
- 'editgroupsgroup' => array('admin', 'moderator', 'user'),
- 'deletegroupsgroup' => array('admin', 'moderator', 'user'),
- 'group' => array('admin', 'moderator', 'user'),
- 'managegroup' => array('admin', 'moderator', 'user'),
- 'creategroup' => array('admin', 'moderator', 'user'),
- 'editgroup' => array('admin', 'moderator', 'user'),
- 'deletegroup' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'groupsgroup' => array('admin', 'moderator', 'user'),
- 'creategroupsgroup' => array('admin', 'moderator'),
- 'editgroupsgroup' => array('admin', 'moderator'),
- 'deletegroupsgroup' => array('admin', 'moderator'),
- 'group' => array('admin', 'moderator', 'user'),
- 'managegroup' => array('admin', 'moderator'),
- 'creategroup' => array('admin', 'moderator'),
- 'editgroup' => array('admin', 'moderator', 'user'),
- 'deletegroup' => array('admin', 'moderator')
- );
-
-
-
-
- /**
- * Action: index.
- *
- * Show Character groups-groups for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function index($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-groups
- $groupsgroups = $this->Charactergroups->getGroupsroupsForSeminary($seminary['id']);
-
-
- // Set titile
- $this->addTitleLocalized('Character Groups');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroups', $groupsgroups);
- }
-
-
- /**
- * Action: groupsgroups.
- *
- * Show Character groups for a Character groups-group of a
- * Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- */
- public function groupsgroup($seminaryUrl, $groupsgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character groups
- $groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id'], 'xps');
-
- // Get Character groups-group Quests
- $quests = $this->Charactergroupsquests->getQuestsForCharactergroupsgroup($groupsgroup['id']);
-
-
- // Set titile
- $this->addTitle($groupsgroup['name']);
- $this->addTitleLocalized('Character Groups');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('groups', $groups);
- $this->set('quests', $quests);
- }
-
-
- /**
- * Action: creategroupsgroups.
- *
- * Create a new Character groups-group for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function creategroupsgroup($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Values
- $charactergroupsgroupname = '';
- $preferred = false;
- $fields = array('charactergroupsgroupname');
- $validation = array();
-
- // Create a new Character groups-group
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $charactergroupsgroupname = $this->request->getPostParam('charactergroupsgroupname');
- if($this->Charactergroups->characterGroupsgroupNameExists($charactergroupsgroupname)) {
- $validation = $this->Validation->addValidationResult($validation, 'charactergroupsgroupname', 'exist', true);
- }
- $preferred = !is_null($this->request->getPostParam('preferred'));
-
- // Create groups-group
- if($validation === true)
- {
- $groupsgroupId = $this->Charactergroups->createGroupsgroup(
- $this->Auth->getUserId(),
- $seminary['id'],
- $charactergroupsgroupname,
- $preferred
- );
-
- // Redirect to groups-group page
- $groupsgroup = $this->Charactergroups->getGroupsgroupById($groupsgroupId);
- $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('New Character groups-group');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('charactergroupsgroupname', $charactergroupsgroupname);
- $this->set('preferred', $preferred);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: editgroupsgroups.
- *
- * Edit a Character groups-group of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- */
- public function editgroupsgroup($seminaryUrl, $groupsgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Values
- $charactergroupsgroupname = $groupsgroup['name'];
- $preferred = $groupsgroup['preferred'];
- $fields = array('charactergroupsgroupname');
- $validation = array();
-
- // Edit Character groups-group
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $charactergroupsgroupname = $this->request->getPostParam('charactergroupsgroupname');
- if($this->Charactergroups->characterGroupsgroupNameExists($charactergroupsgroupname, $groupsgroup['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'charactergroupsgroupname', 'exist', true);
- }
- $preferred = !is_null($this->request->getPostParam('preferred'));
-
- // Edit groups-group
- if($validation === true)
- {
- $this->Charactergroups->editGroupsgroup(
- $groupsgroup['id'],
- $charactergroupsgroupname,
- $preferred
- );
-
- // Redirect to user page
- $groupsgroup = $this->Charactergroups->getGroupsgroupById($groupsgroup['id']);
- $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('Edit Character groups-group');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('charactergroupsgroupname', $charactergroupsgroupname);
- $this->set('preferred', $preferred);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: deletegroupsgroups.
- *
- * Delete a Character groups-group of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- */
- public function deletegroupsgroup($seminaryUrl, $groupsgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete seminary
- $this->Charactergroups->deleteGroupsgroup($groupsgroup['id']);
-
- // Redirect to overview
- $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Delete Character groups-group');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- }
-
-
- /**
- * Action: group.
- *
- * Show a Character group for a Character groups-group of a
- * Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $groupUrl URL-Title of a Character group
- */
- public function group($seminaryUrl, $groupsgroupUrl, $groupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character group
- $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
- $group['characters'] = $this->Characters->getCharactersForGroup($group['id']);
- $group['rank'] = $this->Charactergroups->getXPRank($groupsgroup['id'], $group['xps']);
-
- // Get Character avatars
- foreach($group['characters'] as &$character)
- {
- $avatar = $this->Avatars->getAvatarById($character['avatar_id']);
- if(!is_null($avatar['small_avatarpicture_id'])) {
- $character['small_avatar'] = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
- }
- }
-
- // Get Character groups Quests
- $quests = $this->Charactergroupsquests->getQuestsForGroup($group['id']);
-
-
- // Set titile
- $this->addTitle($group['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('group', $group);
- $this->set('quests', $quests);
- }
-
-
- /**
- * Action: managegroup.
- *
- * Manage a Character group for a Character groups-group of a
- * Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $groupUrl URL-Title of a Character group
- */
- public function managegroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character group
- $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
-
- // Manage
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0) // && !is_null($this->request->getPostParam('characters')) && count($this->request->getPostParam('characters')) > 0)
- {
- $actions = $this->request->getPostParam('actions');
- $action = array_keys($actions)[0];
- $selectedCharacters = $this->request->getPostParam('characters');
-
- switch($action)
- {
- // Add Characters to group
- case 'addcharacters':
- foreach($selectedCharacters as &$characterId) {
- $this->Charactergroups->addCharacterToCharactergroup($group['id'], $characterId);
- }
- break;
- // Remove Characters from group
- case 'removecharacters':
- foreach($selectedCharacters as &$characterId) {
- $this->Charactergroups->removeCharacterFromCharactergroup($group['id'], $characterId);
- }
- break;
- }
- }
-
- // Get additional data for group
- $group['characters'] = $this->Characters->getCharactersForGroup($group['id']);
- $group['rank'] = $this->Charactergroups->getXPRank($groupsgroup['id'], $group['xps']);
-
- // Get Character avatars
- foreach($group['characters'] as &$character)
- {
- $avatar = $this->Avatars->getAvatarById($character['avatar_id']);
- if(!is_null($avatar['small_avatarpicture_id'])) {
- $character['small_avatar'] = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
- }
- }
-
- // Get Character groups Quests
- $quests = $this->Charactergroupsquests->getQuestsForGroup($group['id']);
-
- // Get all Characters of Seminary
- $groupCharacterIds = array_map(function($c) { return $c['id']; }, $group['characters']);
- $seminaryCharacters = $this->Characters->getCharactersForSeminary($seminary['id'], true);
- $characters = array();
- foreach($seminaryCharacters as &$character) {
- if(!in_array($character['id'], $groupCharacterIds)) {
- $characters[] = $character;
- }
- }
-
-
- // Set titile
- $this->addTitle($group['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('group', $group);
- $this->set('quests', $quests);
- $this->set('characters', $characters);
- }
-
-
- /**
- * Action: creategroup.
- *
- * Create a Character group for a Character groups-group of a
- * Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- */
- public function creategroup($seminaryUrl, $groupsgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
-
- // Values
- $charactergroupname = '';
- $motto = '';
- $fields = array('charactergroupname', 'motto');
- $validation = array();
-
- // Create a new Character groups-group
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $charactergroupname = $this->request->getPostParam('charactergroupname');
- if($this->Charactergroups->characterGroupNameExists($charactergroupname)) {
- $validation = $this->Validation->addValidationResult($validation, 'charactergroupname', 'exist', true);
- }
- $motto = $this->request->getPostParam('motto');
-
- // Validate icon
- $icon = null;
- if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $icon = $_FILES['icon'];
-
- // Check error
- if($icon['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $icon['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
- }
- elseif($icon['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
- }
- }
-
- // Create group
- if($validation === true)
- {
- $groupId = $this->Charactergroups->createGroup(
- $this->Auth->getUserId(),
- $groupsgroup['id'],
- $charactergroupname,
- $motto
- );
- $group = $this->Charactergroups->getGroupById($groupId);
-
- // Upload icon
- if(!is_null($icon))
- {
- $mediaId = $this->Media->createCharactergroupMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('charactergroup-%s', $group['url']),
- '',
- $icon['mimetype'],
- $icon['tmp_name']
- );
- if($mediaId !== false) {
- $this->Charactergroups->setMediaForGroup($group['id'], $mediaId);
- }
- }
-
- // Redirect to group page
- $this->redirect($this->linker->link(array('group', $seminary['url'], $groupsgroup['url'], $group['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set title
- $this->addTitleLocalized('New %s Character group', $groupsgroup['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('charactergroupname', $charactergroupname);
- $this->set('motto', $motto);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: editgroup.
- *
- * Edit a Character group for a Character groups-group of a
- * Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $groupUrl URL-Title of a Character group
- */
- public function editgroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character group
- $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
- $group['characters'] = $this->Characters->getCharactersForGroup($group['id']);
-
- // Check permission
- if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) == 0 && !in_array(\hhu\z\controllers\SeminaryController::$character['id'], array_map(function($c) { return $c['id']; }, $group['characters']))) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
-
- // Values
- $charactergroupname = $group['name'];
- $motto = $group['motto'];
- $fields = array('charactergroupname', 'motto');
- $validation = array();
-
- // Edit Character group
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $charactergroupname = (count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) ? $this->request->getPostParam('charactergroupname') : $group['name'];
- if($this->Charactergroups->characterGroupNameExists($charactergroupname, $group['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'charactergroupname', 'exist', true);
- }
- $motto = $this->request->getPostParam('motto');
-
- // Validate icon
- $icon = null;
- if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $icon = $_FILES['icon'];
-
- // Check error
- if($icon['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $icon['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
- }
- elseif($icon['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
- }
- }
-
- // Edit group
- if($validation === true)
- {
- $this->Charactergroups->editGroup(
- $group['id'],
- $charactergroupname,
- $motto
- );
- $group = $this->Charactergroups->getGroupById($group['id']);
-
- // Upload icon
- if(!is_null($icon))
- {
- $mediaId = $this->Media->createCharactergroupMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('charactergroup-%s', $group['url']),
- '',
- $icon['mimetype'],
- $icon['tmp_name']
- );
- if($mediaId !== false) {
- $this->Charactergroups->setMediaForGroup($group['id'], $mediaId);
- }
- }
-
- // Redirect to user page
- $this->redirect($this->linker->link(array('group', $seminary['url'], $groupsgroup['url'], $group['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set title
- $this->addTitleLocalized('Edit %s Character group', $groupsgroup['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('group', $group);
- $this->set('charactergroupname', $charactergroupname);
- $this->set('motto', $motto);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: deletegroup.
- *
- * Delete a Character group for a Character groups-group of a
- * Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $groupUrl URL-Title of a Character group
- */
- public function deletegroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character group
- $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete seminary
- $this->Charactergroups->deleteGroup($group['id']);
-
- // Redirect to overview
- $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('group', $seminary['url'], $groupsgroup['url'], $group['url']), 1));
- }
-
-
- // Set title
- $this->addTitleLocalized('Delete %s Character group', $groupsgroup['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('group', $group);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the CharactergroupsAgent to display Character groups.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactergroupsController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'characters', 'avatars', 'media');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'groupsgroup' => array('admin', 'moderator', 'user'),
+ 'creategroupsgroup' => array('admin', 'moderator', 'user'),
+ 'editgroupsgroup' => array('admin', 'moderator', 'user'),
+ 'deletegroupsgroup' => array('admin', 'moderator', 'user'),
+ 'group' => array('admin', 'moderator', 'user'),
+ 'managegroup' => array('admin', 'moderator', 'user'),
+ 'creategroup' => array('admin', 'moderator', 'user'),
+ 'editgroup' => array('admin', 'moderator', 'user'),
+ 'deletegroup' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'groupsgroup' => array('admin', 'moderator', 'user'),
+ 'creategroupsgroup' => array('admin', 'moderator'),
+ 'editgroupsgroup' => array('admin', 'moderator'),
+ 'deletegroupsgroup' => array('admin', 'moderator'),
+ 'group' => array('admin', 'moderator', 'user'),
+ 'managegroup' => array('admin', 'moderator'),
+ 'creategroup' => array('admin', 'moderator'),
+ 'editgroup' => array('admin', 'moderator', 'user'),
+ 'deletegroup' => array('admin', 'moderator')
+ );
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * Show Character groups-groups for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function index($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-groups
+ $groupsgroups = $this->Charactergroups->getGroupsroupsForSeminary($seminary['id']);
+
+
+ // Set titile
+ $this->addTitleLocalized('Character Groups');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroups', $groupsgroups);
+ }
+
+
+ /**
+ * Action: groupsgroups.
+ *
+ * Show Character groups for a Character groups-group of a
+ * Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ */
+ public function groupsgroup($seminaryUrl, $groupsgroupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character groups
+ $groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id'], 'xps');
+
+ // Get Character groups-group Quests
+ $quests = $this->Charactergroupsquests->getQuestsForCharactergroupsgroup($groupsgroup['id']);
+
+
+ // Set titile
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitleLocalized('Character Groups');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('groups', $groups);
+ $this->set('quests', $quests);
+ }
+
+
+ /**
+ * Action: creategroupsgroups.
+ *
+ * Create a new Character groups-group for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function creategroupsgroup($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Values
+ $charactergroupsgroupname = '';
+ $preferred = false;
+ $fields = array('charactergroupsgroupname');
+ $validation = array();
+
+ // Create a new Character groups-group
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $charactergroupsgroupname = $this->request->getPostParam('charactergroupsgroupname');
+ if($this->Charactergroups->characterGroupsgroupNameExists($charactergroupsgroupname)) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactergroupsgroupname', 'exist', true);
+ }
+ $preferred = !is_null($this->request->getPostParam('preferred'));
+
+ // Create groups-group
+ if($validation === true)
+ {
+ $groupsgroupId = $this->Charactergroups->createGroupsgroup(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $charactergroupsgroupname,
+ $preferred
+ );
+
+ // Redirect to groups-group page
+ $groupsgroup = $this->Charactergroups->getGroupsgroupById($groupsgroupId);
+ $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('New Character groups-group');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('charactergroupsgroupname', $charactergroupsgroupname);
+ $this->set('preferred', $preferred);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: editgroupsgroups.
+ *
+ * Edit a Character groups-group of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ */
+ public function editgroupsgroup($seminaryUrl, $groupsgroupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Values
+ $charactergroupsgroupname = $groupsgroup['name'];
+ $preferred = $groupsgroup['preferred'];
+ $fields = array('charactergroupsgroupname');
+ $validation = array();
+
+ // Edit Character groups-group
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $charactergroupsgroupname = $this->request->getPostParam('charactergroupsgroupname');
+ if($this->Charactergroups->characterGroupsgroupNameExists($charactergroupsgroupname, $groupsgroup['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactergroupsgroupname', 'exist', true);
+ }
+ $preferred = !is_null($this->request->getPostParam('preferred'));
+
+ // Edit groups-group
+ if($validation === true)
+ {
+ $this->Charactergroups->editGroupsgroup(
+ $groupsgroup['id'],
+ $charactergroupsgroupname,
+ $preferred
+ );
+
+ // Redirect to user page
+ $groupsgroup = $this->Charactergroups->getGroupsgroupById($groupsgroup['id']);
+ $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Character groups-group');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('charactergroupsgroupname', $charactergroupsgroupname);
+ $this->set('preferred', $preferred);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: deletegroupsgroups.
+ *
+ * Delete a Character groups-group of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ */
+ public function deletegroupsgroup($seminaryUrl, $groupsgroupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete seminary
+ $this->Charactergroups->deleteGroupsgroup($groupsgroup['id']);
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete Character groups-group');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ }
+
+
+ /**
+ * Action: group.
+ *
+ * Show a Character group for a Character groups-group of a
+ * Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $groupUrl URL-Title of a Character group
+ */
+ public function group($seminaryUrl, $groupsgroupUrl, $groupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character group
+ $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
+ $group['characters'] = $this->Characters->getCharactersForGroup($group['id']);
+ $group['rank'] = $this->Charactergroups->getXPRank($groupsgroup['id'], $group['xps']);
+
+ // Get Character avatars
+ foreach($group['characters'] as &$character)
+ {
+ $avatar = $this->Avatars->getAvatarById($character['avatar_id']);
+ if(!is_null($avatar['small_avatarpicture_id'])) {
+ $character['small_avatar'] = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
+ }
+ }
+
+ // Get Character groups Quests
+ $quests = $this->Charactergroupsquests->getQuestsForGroup($group['id']);
+
+
+ // Set titile
+ $this->addTitle($group['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('group', $group);
+ $this->set('quests', $quests);
+ }
+
+
+ /**
+ * Action: managegroup.
+ *
+ * Manage a Character group for a Character groups-group of a
+ * Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $groupUrl URL-Title of a Character group
+ */
+ public function managegroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character group
+ $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
+
+ // Manage
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0) // && !is_null($this->request->getPostParam('characters')) && count($this->request->getPostParam('characters')) > 0)
+ {
+ $actions = $this->request->getPostParam('actions');
+ $action = array_keys($actions)[0];
+ $selectedCharacters = $this->request->getPostParam('characters');
+
+ switch($action)
+ {
+ // Add Characters to group
+ case 'addcharacters':
+ foreach($selectedCharacters as &$characterId) {
+ $this->Charactergroups->addCharacterToCharactergroup($group['id'], $characterId);
+ }
+ break;
+ // Remove Characters from group
+ case 'removecharacters':
+ foreach($selectedCharacters as &$characterId) {
+ $this->Charactergroups->removeCharacterFromCharactergroup($group['id'], $characterId);
+ }
+ break;
+ }
+ }
+
+ // Get additional data for group
+ $group['characters'] = $this->Characters->getCharactersForGroup($group['id']);
+ $group['rank'] = $this->Charactergroups->getXPRank($groupsgroup['id'], $group['xps']);
+
+ // Get Character avatars
+ foreach($group['characters'] as &$character)
+ {
+ $avatar = $this->Avatars->getAvatarById($character['avatar_id']);
+ if(!is_null($avatar['small_avatarpicture_id'])) {
+ $character['small_avatar'] = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
+ }
+ }
+
+ // Get Character groups Quests
+ $quests = $this->Charactergroupsquests->getQuestsForGroup($group['id']);
+
+ // Get all Characters of Seminary
+ $groupCharacterIds = array_map(function($c) { return $c['id']; }, $group['characters']);
+ $seminaryCharacters = $this->Characters->getCharactersForSeminary($seminary['id'], true);
+ $characters = array();
+ foreach($seminaryCharacters as &$character) {
+ if(!in_array($character['id'], $groupCharacterIds)) {
+ $characters[] = $character;
+ }
+ }
+
+
+ // Set titile
+ $this->addTitle($group['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('group', $group);
+ $this->set('quests', $quests);
+ $this->set('characters', $characters);
+ }
+
+
+ /**
+ * Action: creategroup.
+ *
+ * Create a Character group for a Character groups-group of a
+ * Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ */
+ public function creategroup($seminaryUrl, $groupsgroupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
+
+ // Values
+ $charactergroupname = '';
+ $motto = '';
+ $fields = array('charactergroupname', 'motto');
+ $validation = array();
+
+ // Create a new Character groups-group
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $charactergroupname = $this->request->getPostParam('charactergroupname');
+ if($this->Charactergroups->characterGroupNameExists($charactergroupname)) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactergroupname', 'exist', true);
+ }
+ $motto = $this->request->getPostParam('motto');
+
+ // Validate icon
+ $icon = null;
+ if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $icon = $_FILES['icon'];
+
+ // Check error
+ if($icon['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $icon['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
+ }
+ elseif($icon['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Create group
+ if($validation === true)
+ {
+ $groupId = $this->Charactergroups->createGroup(
+ $this->Auth->getUserId(),
+ $groupsgroup['id'],
+ $charactergroupname,
+ $motto
+ );
+ $group = $this->Charactergroups->getGroupById($groupId);
+
+ // Upload icon
+ if(!is_null($icon))
+ {
+ $mediaId = $this->Media->createCharactergroupMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('charactergroup-%s', $group['url']),
+ '',
+ $icon['mimetype'],
+ $icon['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Charactergroups->setMediaForGroup($group['id'], $mediaId);
+ }
+ }
+
+ // Redirect to group page
+ $this->redirect($this->linker->link(array('group', $seminary['url'], $groupsgroup['url'], $group['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('New %s Character group', $groupsgroup['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('charactergroupname', $charactergroupname);
+ $this->set('motto', $motto);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: editgroup.
+ *
+ * Edit a Character group for a Character groups-group of a
+ * Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $groupUrl URL-Title of a Character group
+ */
+ public function editgroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character group
+ $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
+ $group['characters'] = $this->Characters->getCharactersForGroup($group['id']);
+
+ // Check permission
+ if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) == 0 && !in_array(\hhu\z\controllers\SeminaryController::$character['id'], array_map(function($c) { return $c['id']; }, $group['characters']))) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
+
+ // Values
+ $charactergroupname = $group['name'];
+ $motto = $group['motto'];
+ $fields = array('charactergroupname', 'motto');
+ $validation = array();
+
+ // Edit Character group
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $charactergroupname = (count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) ? $this->request->getPostParam('charactergroupname') : $group['name'];
+ if($this->Charactergroups->characterGroupNameExists($charactergroupname, $group['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactergroupname', 'exist', true);
+ }
+ $motto = $this->request->getPostParam('motto');
+
+ // Validate icon
+ $icon = null;
+ if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $icon = $_FILES['icon'];
+
+ // Check error
+ if($icon['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $icon['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
+ }
+ elseif($icon['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Edit group
+ if($validation === true)
+ {
+ $this->Charactergroups->editGroup(
+ $group['id'],
+ $charactergroupname,
+ $motto
+ );
+ $group = $this->Charactergroups->getGroupById($group['id']);
+
+ // Upload icon
+ if(!is_null($icon))
+ {
+ $mediaId = $this->Media->createCharactergroupMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('charactergroup-%s', $group['url']),
+ '',
+ $icon['mimetype'],
+ $icon['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Charactergroups->setMediaForGroup($group['id'], $mediaId);
+ }
+ }
+
+ // Redirect to user page
+ $this->redirect($this->linker->link(array('group', $seminary['url'], $groupsgroup['url'], $group['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('Edit %s Character group', $groupsgroup['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('group', $group);
+ $this->set('charactergroupname', $charactergroupname);
+ $this->set('motto', $motto);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: deletegroup.
+ *
+ * Delete a Character group for a Character groups-group of a
+ * Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $groupUrl URL-Title of a Character group
+ */
+ public function deletegroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character group
+ $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete seminary
+ $this->Charactergroups->deleteGroup($group['id']);
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(array('groupsgroup', $seminary['url'], $groupsgroup['url']), 1));
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('group', $seminary['url'], $groupsgroup['url'], $group['url']), 1));
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('Delete %s Character group', $groupsgroup['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('group', $group);
+ }
+
+ }
?>
diff --git a/controllers/CharactergroupsquestsController.inc b/controllers/CharactergroupsquestsController.inc
index f4ba8916..4f2006bc 100644
--- a/controllers/CharactergroupsquestsController.inc
+++ b/controllers/CharactergroupsquestsController.inc
@@ -1,189 +1,189 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the CharactergroupsquestsAgent to display Character
- * groups Quests.
- *
- * @author Oliver Hanraths
- */
- class CharactergroupsquestsController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'media', 'questgroups', 'uploads');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'quest' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'quest' => array('admin', 'moderator', 'user')
- );
-
-
-
-
- /**
- * Action: quest.
- *
- * Show a Character groups Quest for a Character groups-group
- * of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $questUrl URL-Title of a Character groups Quest
- */
- public function quest($seminaryUrl, $groupsgroupUrl, $questUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character groups-group Quests
- $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']);
- $questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']);
-
- // Get Character groups-groups
- $groups = $this->Charactergroups->getGroupsForQuest($quest['id']);
-
- // Get uploads
- $uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
- foreach($uploads as &$upload) {
- $upload['upload'] = $this->Uploads->getSeminaryuploadById($upload['seminaryupload_id']);
- }
-
-
- // Set title
- $this->addTitle($quest['title']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('quest', $quest);
- $this->set('questgroup', $questgroup);
- $this->set('groups', $groups);
- $this->set('uploads', $uploads);
- }
-
-
- /**
- * Action: manage.
- *
- * Manage a Character groups Quest for a Character groups-group
- * of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $questUrl URL-Title of a Character groups Quest
- */
- public function manage($seminaryUrl, $groupsgroupUrl, $questUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character groups-group Quests
- $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']);
- $questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']);
-
- // Get Character groups
- $groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']);
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['charactergroupsquests'];
-
- // Manage
- $validation = array();
- if($this->request->getRequestMethod() == 'POST')
- {
- // Upload media
- if(!is_null($this->request->getPostParam('setmedia')))
- {
- $file = $_FILES['media'];
-
- // Check error
- if($file['error'] !== 0 || empty($file['tmp_name'])) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $file['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $file['mimetype'] = \hhu\z\Utils::getMimetype($file['tmp_name'], $file['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $file['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $file['mimetype']);
- }
- elseif($file['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']);
- }
-
- // Upload media
- if($validation === true || empty($valiadion))
- {
- // Create filename
- $filename = sprintf(
- '%s-%d-%s.%s',
- 'charactergroupsquest',
- $quest['id'],
- date('Ymd-His'),
- mb_substr($file['name'], strrpos($file['name'], '.')+1)
- );
-
- // Upload file
- $this->Charactergroupsquests->uploadMediaForQuest($this->Auth->getUserId(), $seminary['id'], $quest['id'], $file, $filename);
- }
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the CharactergroupsquestsAgent to display Character
+ * groups Quests.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactergroupsquestsController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'media', 'questgroups', 'uploads');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'quest' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'quest' => array('admin', 'moderator', 'user')
+ );
+
+
+
+
+ /**
+ * Action: quest.
+ *
+ * Show a Character groups Quest for a Character groups-group
+ * of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $questUrl URL-Title of a Character groups Quest
+ */
+ public function quest($seminaryUrl, $groupsgroupUrl, $questUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character groups-group Quests
+ $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']);
+ $questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']);
+
+ // Get Character groups-groups
+ $groups = $this->Charactergroups->getGroupsForQuest($quest['id']);
+
+ // Get uploads
+ $uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
+ foreach($uploads as &$upload) {
+ $upload['upload'] = $this->Uploads->getSeminaryuploadById($upload['seminaryupload_id']);
+ }
+
+
+ // Set title
+ $this->addTitle($quest['title']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('quest', $quest);
+ $this->set('questgroup', $questgroup);
+ $this->set('groups', $groups);
+ $this->set('uploads', $uploads);
+ }
+
+
+ /**
+ * Action: manage.
+ *
+ * Manage a Character groups Quest for a Character groups-group
+ * of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $questUrl URL-Title of a Character groups Quest
+ */
+ public function manage($seminaryUrl, $groupsgroupUrl, $questUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character groups-group Quests
+ $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']);
+ $questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']);
+
+ // Get Character groups
+ $groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']);
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['charactergroupsquests'];
+
+ // Manage
+ $validation = array();
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Upload media
+ if(!is_null($this->request->getPostParam('setmedia')))
+ {
+ $file = $_FILES['media'];
+
+ // Check error
+ if($file['error'] !== 0 || empty($file['tmp_name'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $file['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $file['mimetype'] = \hhu\z\Utils::getMimetype($file['tmp_name'], $file['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $file['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $file['mimetype']);
+ }
+ elseif($file['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']);
+ }
+
+ // Upload media
+ if($validation === true || empty($valiadion))
+ {
+ // Create filename
+ $filename = sprintf(
+ '%s-%d-%s.%s',
+ 'charactergroupsquest',
+ $quest['id'],
+ date('Ymd-His'),
+ mb_substr($file['name'], strrpos($file['name'], '.')+1)
+ );
+
+ // Upload file
+ $this->Charactergroupsquests->uploadMediaForQuest($this->Auth->getUserId(), $seminary['id'], $quest['id'], $file, $filename);
+ }
+ }
// Delete media
- if(!is_null($this->request->getPostParam('deletemedia')))
+ if(!is_null($this->request->getPostParam('deletemedia')))
{
$uploadIds = $this->request->getPostParam('uploads');
var_dump($uploadIds);
@@ -191,435 +191,435 @@
$this->Uploads->deleteSeminaryupload($uploadId);
}
}
-
- // Set XPs of Character groups for this Character groups Quest
- if(!is_null($this->request->getPostParam('setxps')))
- {
- $xps = $this->request->getPostParam('xps');
- foreach($groups as &$group)
- {
- if(array_key_exists($group['url'], $xps) && $xps[$group['url']] != 'null')
- {
- $xpsFactor = intval($xps[$group['url']]) / $quest['xps'];
- $this->Charactergroupsquests->setXPsOfGroupForQuest($quest['id'], $group['id'], $xpsFactor);
- }
- else {
- $this->Charactergroupsquests->deleteGroupForQuest($quest['id'], $group['id']);
- }
- }
- }
-
- // Redirect to Quest page
- if($validation === true || empty($validation)) {
- $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
- }
- }
-
- // Get icon
- $questmedia = null;
- if(!is_null($quest['questsmedia_id'])) {
- $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
- }
-
- // Get uploads
- $uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
- foreach($uploads as &$upload) {
- $upload['upload'] = $this->Uploads->getSeminaryuploadById($upload['seminaryupload_id']);
- }
-
-
- // Set XPs for Groups
- foreach($groups as &$group) {
- $group['quest_group'] = $this->Charactergroupsquests->getXPsOfGroupForQuest($quest['id'], $group['id']);
- }
-
-
- // Set title
- $this->addTitle($quest['title']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('quest', $quest);
- $this->set('uploads', $uploads);
- $this->set('mimetypes', $mimetypes);
- $this->set('questgroup', $questgroup);
- $this->set('groups', $groups);
- $this->set('media', $questmedia);
- $this->set('validation', $validation);
- }
-
-
- /**
- * Action: create.
- *
- * Create a new Character groups Quest for a Character
- * groups-group of a Seminary.
- *
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- */
- public function create($seminaryUrl, $groupsgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Questgroups
- $questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
-
- // Values
- $title = '';
- $xps = 0;
- $description = '';
- $rules = '';
- $wonText = '';
- $lostText = '';
- $fields = array('title', 'xps');
- $validation = array();
-
- // Create a new Character groups Quest
- 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->Charactergroupsquests->characterGroupsQuestTitleExists($title)) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $xps = $this->request->getPostParam('xps');
- $description = $this->request->getPostParam('description');
- $rules = $this->request->getPostParam('rules');
- $wonText = $this->request->getPostParam('wonText');
- $lostText = $this->request->getPostParam('lostText');
-
- // Validate icon
- $icon = null;
- if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $icon = $_FILES['icon'];
-
- // Check error
- if($icon['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $icon['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
- }
- elseif($icon['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
- }
- }
-
- // Validate Questgroup
- $questgroupIndex = null;
- foreach($questgroups as $index => &$questgroup)
- {
- $questgroup['selected'] = ($questgroup['url'] == $this->request->getPostParam('questgroup'));
- if($questgroup['selected']) {
- $questgroupIndex = $index;
- }
- }
- if(is_null($questgroupIndex)) {
- throw new \nre\exceptions\ParamsNotValidException($questgroup);
- }
-
- // Create groups Quest
- if($validation === true)
- {
- $questId = $this->Charactergroupsquests->createQuest(
- $this->Auth->getUserId(),
- $groupsgroup['id'],
- $questgroups[$questgroupIndex]['id'],
- $title,
- $description,
- $xps,
- $rules,
- $wonText,
- $lostText
- );
- $quest = $this->Charactergroupsquests->getQuestById($questId);
-
- // Upload icon
- if(!is_null($icon))
- {
- $mediaId = $this->Media->createQuestMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('charactergroupsquest-%s', $quest['url']),
- '',
- $icon['mimetype'],
- $icon['tmp_name']
- );
- if($mediaId !== false) {
- $this->Charactergroupsquests->setMediaForQuest($quest['id'], $mediaId);
- }
- }
-
- // Redirect to Quest page
- $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set title
- $this->addTitleLocalized('New %s-Quest', $groupsgroup['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('questgroups', $questgroups);
- $this->set('title', $title);
- $this->set('xps', $xps);
- $this->set('description', $description);
- $this->set('rules', $rules);
- $this->set('wonText', $wonText);
- $this->set('lostText', $lostText);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: edit.
- *
- * Edit a Character groups Quest of a Character groups-group
- * of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $questUrl URL-Title of a Character groups Quest
- */
- public function edit($seminaryUrl, $groupsgroupUrl, $questUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character groups-group Quests
- $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
-
- // Get Questgroups
- $questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
- foreach($questgroups as $index => &$questgroup) {
- $questgroup['selected'] = ($questgroup['id'] == $quest['questgroups_id']);
- }
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
-
- // Values
- $title = $quest['title'];
- $xps = $quest['xps'];
- $description = $quest['description'];
- $rules = $quest['rules'];
- $wonText = $quest['won_text'];
- $lostText = $quest['lost_text'];
- $fields = array('title', 'xps');
- $validation = array();
-
- // Edit Character group
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $title = $this->request->getPostParam('title');
- if($this->Charactergroupsquests->characterGroupsQuestTitleExists($title, $quest['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $xps = $this->request->getPostParam('xps');
- $description = $this->request->getPostParam('description');
- $rules = $this->request->getPostParam('rules');
- $wonText = $this->request->getPostParam('wonText');
- $lostText = $this->request->getPostParam('lostText');
-
- // Validate icon
- $icon = null;
- if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $icon = $_FILES['icon'];
-
- // Check error
- if($icon['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $icon['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
- }
- elseif($icon['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
- }
- }
-
- // Validate Questgroup
- $questgroupIndex = null;
- foreach($questgroups as $index => &$questgroup)
- {
- $questgroup['selected'] = ($questgroup['url'] == $this->request->getPostParam('questgroup'));
- if($questgroup['selected']) {
- $questgroupIndex = $index;
- }
- }
- if(is_null($questgroupIndex)) {
- throw new \nre\exceptions\ParamsNotValidException($questgroup);
- }
-
- // Edit groups Quest
- if($validation === true)
- {
- $this->Charactergroupsquests->editQuest(
- $quest['id'],
- $groupsgroup['id'],
- $questgroups[$questgroupIndex]['id'],
- $title,
- $description,
- $xps,
- $rules,
- $wonText,
- $lostText
- );
- $quest = $this->Charactergroupsquests->getQuestById($quest['id']);
-
- // Upload icon
- if(!is_null($icon))
- {
- $mediaId = $this->Media->createQuestMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('charactergroupsquest-%s', $quest['url']),
- '',
- $icon['mimetype'],
- $icon['tmp_name']
- );
- if($mediaId !== false) {
- $this->Charactergroupsquests->setMediaForQuest($quest['id'], $mediaId);
- }
- }
-
- // Redirect to Quest page
- $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set title
- $this->addTitleLocalized('Edit %s-Quest', $groupsgroup['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('quest', $quest);
- $this->set('questgroups', $questgroups);
- $this->set('title', $title);
- $this->set('xps', $xps);
- $this->set('description', $description);
- $this->set('rules', $rules);
- $this->set('wonText', $wonText);
- $this->set('lostText', $lostText);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: delete.
- *
- * Delete a Character groups Quest of a Character groups-group
- * of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $questUrl URL-Title of a Character groups Quest
- */
- public function delete($seminaryUrl, $groupsgroupUrl, $questUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character groups-group Quests
- $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete seminary
- $this->Charactergroupsquests->deleteQuest($quest['id']);
-
- // Redirect to overview
- $this->redirect($this->linker->link(array('charactergroups', 'groupsgroup', $seminary['url'], $groupsgroup['url'])));
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
- }
-
-
- // Set title
- $this->addTitleLocalized('Delete %s-Quest', $groupsgroup['name']);
- $this->addTitle($groupsgroup['name']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('groupsgroup', $groupsgroup);
- $this->set('quest', $quest);
- }
-
- }
+
+ // Set XPs of Character groups for this Character groups Quest
+ if(!is_null($this->request->getPostParam('setxps')))
+ {
+ $xps = $this->request->getPostParam('xps');
+ foreach($groups as &$group)
+ {
+ if(array_key_exists($group['url'], $xps) && $xps[$group['url']] != 'null')
+ {
+ $xpsFactor = intval($xps[$group['url']]) / $quest['xps'];
+ $this->Charactergroupsquests->setXPsOfGroupForQuest($quest['id'], $group['id'], $xpsFactor);
+ }
+ else {
+ $this->Charactergroupsquests->deleteGroupForQuest($quest['id'], $group['id']);
+ }
+ }
+ }
+
+ // Redirect to Quest page
+ if($validation === true || empty($validation)) {
+ $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
+ }
+ }
+
+ // Get icon
+ $questmedia = null;
+ if(!is_null($quest['questsmedia_id'])) {
+ $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
+ }
+
+ // Get uploads
+ $uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
+ foreach($uploads as &$upload) {
+ $upload['upload'] = $this->Uploads->getSeminaryuploadById($upload['seminaryupload_id']);
+ }
+
+
+ // Set XPs for Groups
+ foreach($groups as &$group) {
+ $group['quest_group'] = $this->Charactergroupsquests->getXPsOfGroupForQuest($quest['id'], $group['id']);
+ }
+
+
+ // Set title
+ $this->addTitle($quest['title']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('quest', $quest);
+ $this->set('uploads', $uploads);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('questgroup', $questgroup);
+ $this->set('groups', $groups);
+ $this->set('media', $questmedia);
+ $this->set('validation', $validation);
+ }
+
+
+ /**
+ * Action: create.
+ *
+ * Create a new Character groups Quest for a Character
+ * groups-group of a Seminary.
+ *
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ */
+ public function create($seminaryUrl, $groupsgroupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Questgroups
+ $questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
+
+ // Values
+ $title = '';
+ $xps = 0;
+ $description = '';
+ $rules = '';
+ $wonText = '';
+ $lostText = '';
+ $fields = array('title', 'xps');
+ $validation = array();
+
+ // Create a new Character groups Quest
+ 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->Charactergroupsquests->characterGroupsQuestTitleExists($title)) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $xps = $this->request->getPostParam('xps');
+ $description = $this->request->getPostParam('description');
+ $rules = $this->request->getPostParam('rules');
+ $wonText = $this->request->getPostParam('wonText');
+ $lostText = $this->request->getPostParam('lostText');
+
+ // Validate icon
+ $icon = null;
+ if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $icon = $_FILES['icon'];
+
+ // Check error
+ if($icon['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $icon['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
+ }
+ elseif($icon['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Validate Questgroup
+ $questgroupIndex = null;
+ foreach($questgroups as $index => &$questgroup)
+ {
+ $questgroup['selected'] = ($questgroup['url'] == $this->request->getPostParam('questgroup'));
+ if($questgroup['selected']) {
+ $questgroupIndex = $index;
+ }
+ }
+ if(is_null($questgroupIndex)) {
+ throw new \nre\exceptions\ParamsNotValidException($questgroup);
+ }
+
+ // Create groups Quest
+ if($validation === true)
+ {
+ $questId = $this->Charactergroupsquests->createQuest(
+ $this->Auth->getUserId(),
+ $groupsgroup['id'],
+ $questgroups[$questgroupIndex]['id'],
+ $title,
+ $description,
+ $xps,
+ $rules,
+ $wonText,
+ $lostText
+ );
+ $quest = $this->Charactergroupsquests->getQuestById($questId);
+
+ // Upload icon
+ if(!is_null($icon))
+ {
+ $mediaId = $this->Media->createQuestMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('charactergroupsquest-%s', $quest['url']),
+ '',
+ $icon['mimetype'],
+ $icon['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Charactergroupsquests->setMediaForQuest($quest['id'], $mediaId);
+ }
+ }
+
+ // Redirect to Quest page
+ $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('New %s-Quest', $groupsgroup['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('questgroups', $questgroups);
+ $this->set('title', $title);
+ $this->set('xps', $xps);
+ $this->set('description', $description);
+ $this->set('rules', $rules);
+ $this->set('wonText', $wonText);
+ $this->set('lostText', $lostText);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * Edit a Character groups Quest of a Character groups-group
+ * of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $questUrl URL-Title of a Character groups Quest
+ */
+ public function edit($seminaryUrl, $groupsgroupUrl, $questUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character groups-group Quests
+ $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
+
+ // Get Questgroups
+ $questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
+ foreach($questgroups as $index => &$questgroup) {
+ $questgroup['selected'] = ($questgroup['id'] == $quest['questgroups_id']);
+ }
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
+
+ // Values
+ $title = $quest['title'];
+ $xps = $quest['xps'];
+ $description = $quest['description'];
+ $rules = $quest['rules'];
+ $wonText = $quest['won_text'];
+ $lostText = $quest['lost_text'];
+ $fields = array('title', 'xps');
+ $validation = array();
+
+ // Edit Character group
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $title = $this->request->getPostParam('title');
+ if($this->Charactergroupsquests->characterGroupsQuestTitleExists($title, $quest['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $xps = $this->request->getPostParam('xps');
+ $description = $this->request->getPostParam('description');
+ $rules = $this->request->getPostParam('rules');
+ $wonText = $this->request->getPostParam('wonText');
+ $lostText = $this->request->getPostParam('lostText');
+
+ // Validate icon
+ $icon = null;
+ if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $icon = $_FILES['icon'];
+
+ // Check error
+ if($icon['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $icon['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
+ }
+ elseif($icon['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Validate Questgroup
+ $questgroupIndex = null;
+ foreach($questgroups as $index => &$questgroup)
+ {
+ $questgroup['selected'] = ($questgroup['url'] == $this->request->getPostParam('questgroup'));
+ if($questgroup['selected']) {
+ $questgroupIndex = $index;
+ }
+ }
+ if(is_null($questgroupIndex)) {
+ throw new \nre\exceptions\ParamsNotValidException($questgroup);
+ }
+
+ // Edit groups Quest
+ if($validation === true)
+ {
+ $this->Charactergroupsquests->editQuest(
+ $quest['id'],
+ $groupsgroup['id'],
+ $questgroups[$questgroupIndex]['id'],
+ $title,
+ $description,
+ $xps,
+ $rules,
+ $wonText,
+ $lostText
+ );
+ $quest = $this->Charactergroupsquests->getQuestById($quest['id']);
+
+ // Upload icon
+ if(!is_null($icon))
+ {
+ $mediaId = $this->Media->createQuestMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('charactergroupsquest-%s', $quest['url']),
+ '',
+ $icon['mimetype'],
+ $icon['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Charactergroupsquests->setMediaForQuest($quest['id'], $mediaId);
+ }
+ }
+
+ // Redirect to Quest page
+ $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('Edit %s-Quest', $groupsgroup['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('quest', $quest);
+ $this->set('questgroups', $questgroups);
+ $this->set('title', $title);
+ $this->set('xps', $xps);
+ $this->set('description', $description);
+ $this->set('rules', $rules);
+ $this->set('wonText', $wonText);
+ $this->set('lostText', $lostText);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * Delete a Character groups Quest of a Character groups-group
+ * of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $questUrl URL-Title of a Character groups Quest
+ */
+ public function delete($seminaryUrl, $groupsgroupUrl, $questUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character groups-group Quests
+ $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete seminary
+ $this->Charactergroupsquests->deleteQuest($quest['id']);
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(array('charactergroups', 'groupsgroup', $seminary['url'], $groupsgroup['url'])));
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('Delete %s-Quest', $groupsgroup['name']);
+ $this->addTitle($groupsgroup['name']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('groupsgroup', $groupsgroup);
+ $this->set('quest', $quest);
+ }
+
+ }
?>
diff --git a/controllers/CharactersController.inc b/controllers/CharactersController.inc
index 96eaedb3..00180832 100644
--- a/controllers/CharactersController.inc
+++ b/controllers/CharactersController.inc
@@ -1,695 +1,695 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to list registered users and their data.
- *
- * @author Oliver Hanraths
- */
- class CharactersController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'seminarycharacterfields', 'avatars', 'media', 'quests', 'questgroups', 'questtopics', 'xplevels');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'character' => array('admin', 'moderator', 'user'),
- 'register' => array('admin', 'moderator', 'user'),
- 'manage' => array('admin', 'moderator', 'user'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'index' => array('admin', 'moderator'),
- 'character' => array('admin', 'moderator', 'user'),
- 'manage' => array('admin', 'moderator'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator')
- );
-
-
-
-
- /**
- * Action: index.
- *
- * List registered Characters for a Seminary
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $all Whether to list all Characters at once or not (optional)
- */
- public function index($seminaryUrl, $all=null)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Seminarycharacterfields
- $characterfields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
-
- // Set sort order and page
- $sortorder = 'name';
- $charactername = null;
- $page = 1;
- if($this->request->getRequestMethod() == 'GET')
- {
- $sortorder = $this->request->getGetParam('sortorder');
- $sortorder = !empty($sortorder) ? $sortorder : 'name';
- $charactername = (!is_null($this->request->getGetParam('charactername'))) ? $this->request->getGetParam('charactername') : $charactername;
- $page = $this->request->getGetParam('page');
- $page = !empty($page) ? intval($page) : 1;
- }
-
- // Get registered Characters
- $limit = ($all != 'all') ? \nre\configs\AppConfig::$misc['lists_limit'] : null;
- $offset = ($all != 'all') ? max((intval($page) - 1), 0) * $limit : 0;
- $charactersCount = $this->Characters->getCharactersForSeminaryCount($seminary['id'], $charactername);
- $characters = $this->Characters->getCharactersForSeminarySorted($seminary['id'], $sortorder, $charactername, $limit, $offset);
- foreach($characters as &$character)
- {
- $character['user'] = $this->Users->getUserById($character['user_id']);
- $character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
- $character['characterfields'] = array();
- foreach($this->Seminarycharacterfields->getFieldsForCharacter($character['id']) as $value) {
- $character['characterfields'][$value['url']] = $value;
- }
- try {
- $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // No XP-level
- }
- try {
- $character['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $character['charactertype_url'], $character['xplevel']['level']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // No Avatar available
- }
- }
-
-
- // Set titile
- $this->addTitleLocalized('Characters');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('characters', $characters);
- $this->set('charactersCount', $charactersCount);
- $this->set('characterfields', $characterfields);
- $this->set('sortorder', $sortorder);
- $this->set('charactername', $charactername);
- $this->set('all', $all);
- $this->set('page', $page);
- $this->set('limit', $limit);
- }
-
-
- /**
- * Action: character.
- *
- * Show a Charater and its details.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $characterUrl URL-name of a Charater
- */
- public function character($seminaryUrl, $characterUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
- $seminary['achievable_xps'] = $this->Seminaries->getTotalXPs($seminary['id']);
-
- // Get Character
- $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
- try {
- $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // No XP-level
- }
- $character['rank'] = $this->Characters->getXPRank($seminary['id'], $character['xps']);
-
- // Get User
- $user = $this->Users->getUserById($character['user_id']);
-
- // Get Character groups
- $groups = $this->Charactergroups->getGroupsForCharacter($character['id']);
- foreach($groups as &$group) {
- $group['groupsgroup'] = $this->Charactergroups->getGroupsgroupById($group['charactergroupsgroup_id']);
- }
-
- // Get Achievements
- $achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
-
- // Get Achievements with deadline (milestones)
- $milestones = $this->Achievements->getDeadlineAchievements($seminary['id']);
- foreach($milestones as &$milestone) {
- $milestone['achieved'] = $this->Achievements->hasCharacterAchievedAchievement($milestone['id'], $character['id']);
- }
-
- // Get ranking
- $ranking = array(
- 'superior' => $this->Characters->getSuperiorCharacters($seminary['id'], $character['xps'], \nre\configs\AppConfig::$misc['ranking_range']),
- 'inferior' => $this->Characters->getInferiorCharacters($seminary['id'], $character['id'], $character['xps'], \nre\configs\AppConfig::$misc['ranking_range'])
- );
-
- // Get Quest topics
- $questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
- foreach($questtopics as &$questtopic)
- {
- $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
- $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
- }
-
- // Get “last” Quest
- $lastQuest = null;
- if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0)
- {
- $lastQuest = $this->Quests->getLastQuestForCharacter($character['id']);
- if(!is_null($lastQuest)) {
- $lastQuest['questgroup'] = $this->Questgroups->getQuestgroupById($lastQuest['questgroup_id']);
- }
- }
-
-
- // Set titile
- $this->addTitle($character['name']);
- $this->addTitleLocalized('Characters');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('character', $character);
- $this->set('user', $user);
- $this->set('groups', $groups);
- $this->set('achievements', $achievements);
- $this->set('milestones', $milestones);
- $this->set('ranking', $ranking);
- $this->set('questtopics', $questtopics);
- $this->set('lastQuest', $lastQuest);
- }
-
-
- /**
- * Acton: register.
- *
- * Register a new character for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @throws \nre\exceptions\ParamsNotValidException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function register($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Check for already existing Character
- try {
- $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
- throw new \nre\exceptions\AccessDeniedException();
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // This should be the case
- }
-
-
- // Character types
- $types = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
-
- // Character fields
- $fields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
-
- // Register Character
- $charactername = '';
- $validation = true;
- $fieldsValidation = true;
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
- {
- // Validate Character properties
- $validation = $this->Validation->validateParams($this->request->getPostParams(), array('charactername'));
- $charactername = $this->request->getPostParam('charactername');
- if($this->Characters->characterNameExists($charactername)) {
- $validation = $this->Validation->addValidationResult($validation, 'charactername', 'exist', true);
- }
-
- // Validate type
- $typeIndex = null;
- foreach($types as $index => &$type)
- {
- $type['selected'] = ($type['url'] == $this->request->getPostParam('type'));
- if($type['selected']) {
- $typeIndex = $index;
- }
- }
- if(is_null($typeIndex)) {
- $validation = $this->Validation->addValidationResult($validation, 'type', 'exist', false);
- }
-
- // Validate fields
- $fieldsValues = $this->request->getPostParam('fields');
- foreach($fields as &$field)
- {
- if(!array_key_exists($field['url'], $fieldsValues)) {
- throw new \nre\exceptions\ParamsNotValidException($index);
- }
- $field['uservalue'] = $fieldsValues[$field['url']];
- if($field['required'])
- {
- $fieldValidation = $this->Validation->validate($fieldsValues[$field['url']], array('regex'=>$field['regex']));
- if($fieldValidation !== true)
- {
- if(!is_array($fieldsValidation)) {
- $fieldsValidation = array();
- }
- $fieldsValidation[$field['url']] = $fieldValidation;
- }
- }
- }
-
- // Register
- if($validation === true && $fieldsValidation === true)
- {
- $characterId = $this->Characters->createCharacter($this->Auth->getUserId(), $types[$typeIndex]['id'], $charactername);
- $character = $this->Characters->getCharacterById($characterId);
-
- // Add Seminary fields
- foreach($fields as &$field) {
- if(!empty($fieldsValues[$field['url']])) {
- $this->Seminarycharacterfields->setSeminaryFieldOfCharacter($field['id'], $characterId, $fieldsValues[$field['url']]);
- }
- }
-
- // Set roles for owners and admins
- if(in_array('admin', \hhu\z\controllers\IntermediateController::$user['roles']) || $seminary['created_user_id'] == \hhu\z\controllers\IntermediateController::$user['id']) {
- $this->Characterroles->addCharacterroleToCharacter($characterId, 'admin');
- }
-
- // Send mail
- $this->sendRegistrationMail($character);
-
- // Redirect
- $this->redirect($this->linker->link(array('seminaries')));
- }
- }
-
- // Get XP-levels
- $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
-
- // Get Avatars
- if(count($xplevels) > 0)
- {
- foreach($types as &$type)
- {
- try {
- $type['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $type['url'], $xplevels[0]['level']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // No Avatar available
- }
- }
- }
-
-
- // Set titile
- $this->addTitleLocalized('Create Character');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('types', $types);
- $this->set('fields', $fields);
- $this->set('charactername', $charactername);
- $this->set('validation', $validation);
- $this->set('fieldsValidation', $fieldsValidation);
- $this->set('xplevels', $xplevels);
- }
-
-
- /**
- * Action: manage.
- *
- * Manage Characters.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function manage($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Set sort order and page
-
- $selectedCharacters = array();
- $sortorder = 'name';
- if($this->request->getRequestMethod() == 'POST')
- {
- // Set sortorder
- $sortorder = $this->request->getPostParam('sortorder');
- $sortorder = !empty($sortorder) ? $sortorder : 'name';
-
- // Do action
- $selectedCharacters = $this->request->getPostParam('characters');
- if(!is_array($selectedCharacters)) {
- $selectedCharacters = array();
- }
- if(!is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0 && !is_null($this->request->getPostParam('characters')) && count($this->request->getPostParam('characters')) > 0)
- {
- $actions = $this->request->getPostParam('actions');
- $action = array_keys($actions)[0];
-
- switch($action)
- {
- // Add/remove role to/from Characters
- case 'addrole':
- case 'removerole':
- // Determine role and check permissions
- $role = null;
- switch($actions[$action])
- {
- case _('Admin'):
- if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- $role = 'admin';
- break;
- case _('Moderator'):
- if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- $role = 'moderator';
- break;
- case _('User'):
- if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) <= 0) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- $role = 'user';
- break;
- }
-
- // Add role
- if($action == 'addrole') {
- foreach($selectedCharacters as &$characterId) {
- $this->Characterroles->addCharacterroleToCharacter($characterId, $role);
- }
- }
- // Remove role
- else {
- foreach($selectedCharacters as &$characterId) {
- $this->Characterroles->removeCharacterroleFromCharacter($characterId, $role);
- }
- }
- break;
- }
- }
- }
-
- // Get Seminarycharacterfields
- $characterfields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
-
- // Get registered Characters
- $characters = $this->Characters->getCharactersForSeminarySorted($seminary['id'], $sortorder);
- foreach($characters as &$character)
- {
- $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
- $character['user'] = $this->Users->getUserById($character['user_id']);
- $character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
- $character['characterfields'] = array();
- foreach($this->Seminarycharacterfields->getFieldsForCharacter($character['id']) as $value) {
- $character['characterfields'][$value['url']] = $value;
- }
- }
-
-
- // Set titile
- $this->addTitleLocalized('Manage Characters');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('characters', $characters);
- $this->set('characterfields', $characterfields);
- $this->set('selectedCharacters', $selectedCharacters);
- $this->set('sortorder', $sortorder);
- }
-
-
- /**
- * Acton: edit.
- *
- * Edit a new character for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @throws \nre\exceptions\ParamsNotValidException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $characterUrl URL-name of a Charater
- */
- public function edit($seminaryUrl, $characterUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character
- $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
-
- // Check permissions
- if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) == 0 && $character['id'] != \hhu\z\controllers\SeminaryController::$character['id']) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Get User
- $user = $this->Users->getUserById($character['user_id']);
-
- // Character types
- $types = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
- foreach($types as &$type) {
- $type['selected'] = ($type['url'] == $character['charactertype_url']);
- }
-
- // Character fields
- $fields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
- foreach($fields as &$field)
- {
- $userValue = $this->Seminarycharacterfields->getSeminaryFieldOfCharacter($field['id'], $character['id']);
- if(!empty($userValue)) {
- $field['uservalue'] = $userValue['value'];
- }
- }
-
- // Values
- $charactername = $character['name'];
- $validation = array();
- $fieldsValidation = true;
-
- // Edit Character
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Validate Character properties
- $validation = $this->Validation->validateParams($this->request->getPostParams(), array('charactername'));
- $charactername = (count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) ? $this->request->getPostParam('charactername') : $character['name'];
- if($this->Characters->characterNameExists($charactername, $character['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'charactername', 'exist', true);
- }
-
- // Validate type
- $typeIndex = null;
- foreach($types as $index => &$type)
- {
- $type['selected'] = (count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) ? ($type['url'] == $this->request->getPostParam('type')) : ($type['url'] == $character['charactertype_url']);
- if($type['selected']) {
- $typeIndex = $index;
- }
- }
- if(is_null($typeIndex)) {
- $validation = $this->Validation->addValidationResult($validation, 'type', 'exist', false);
- }
-
- // Validate fields
- $fieldsValues = $this->request->getPostParam('fields');
- foreach($fields as &$field)
- {
- if(!array_key_exists($field['url'], $fieldsValues)) {
- throw new \nre\exceptions\ParamsNotValidException($index);
- }
- $field['uservalue'] = $fieldsValues[$field['url']];
- if($field['required'])
- {
- $fieldValidation = $this->Validation->validate($fieldsValues[$field['url']], array('regex'=>$field['regex']));
- if($fieldValidation !== true)
- {
- if(!is_array($fieldsValidation)) {
- $fieldsValidation = array();
- }
- $fieldsValidation[$field['url']] = $fieldValidation;
- }
- }
- }
-
- // Edit
- if($validation === true && $fieldsValidation === true)
- {
- $this->Characters->editCharacter(
- $character['id'],
- $types[$typeIndex]['id'],
- $charactername
- );
-
- // Set Seminary fields
- foreach($fields as &$field) {
- if(!empty($fieldsValues[$field['url']])) {
- $this->Seminarycharacterfields->setSeminaryFieldOfCharacter($field['id'], $character['id'], $fieldsValues[$field['url']]);
- }
- }
-
- // Redirect
- $character = $this->Characters->getCharacterById($character['id']);
- $this->redirect($this->linker->link(array('character', $seminary['url'], $character['url']), 1));
- }
- }
-
- // Get XP-levels
- $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- // Get validation settings
- $validationSettings = array();
- $validationSettings['charactername'] = \nre\configs\AppConfig::$validation['charactername'];
-
-
- // Set titile
- $this->addTitleLocalized('Edit Character');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('types', $types);
- $this->set('fields', $fields);
- $this->set('charactername', $charactername);
- $this->set('validation', $validation);
- $this->set('fieldsValidation', $fieldsValidation);
- $this->set('validationSettings', $validationSettings);
- $this->set('xplevels', $xplevels);
- }
-
-
- /**
- * Action: delete.
- *
- * Delete a Character.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $characterUrl URL-name of a Charater
- */
- public function delete($seminaryUrl, $characterUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character
- $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
-
- // Get User
- $user = $this->Users->getUserById($character['user_id']);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete Character
- $this->Characters->deleteCharacter($character['id']);
-
- // Redirect to overview
- $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('index', $seminary['url'], $character['url']), 1));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Delete Character');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('character', $character);
- $this->set('user', $user);
- }
-
-
-
-
- /**
- * Send mail for new Character registration.
- *
- * @param arary $newCharacter Newly registered Character
- */
- private function sendRegistrationMail($newCharacter)
- {
- // Get Seminary moderators
- $characters = $this->Characters->getCharactersWithCharacterRole(self::$seminary['id'], 'moderator');
-
- // Send notification mail
- try {
- foreach($characters as &$character)
- {
- $moderator = $this->Users->getUserById($character['user_id']);
- if($moderator['mailing']) {
- \hhu\z\Utils::sendMail(
- $moderator['email'],
- 'characterregistration',
- true,
- array(
- $moderator,
- \hhu\z\controllers\SeminaryController::$seminary,
- \hhu\z\controllers\IntermediateController::$user,
- $newCharacter
- ),
- $this->linker
- );
- }
- }
- }
- catch(\hhu\z\exceptions\MailingException $e) {
- $this->log($e->getMessage());
- }
- }
-
- }
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to list registered users and their data.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactersController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'seminarycharacterfields', 'avatars', 'media', 'quests', 'questgroups', 'questtopics', 'xplevels');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'character' => array('admin', 'moderator', 'user'),
+ 'register' => array('admin', 'moderator', 'user'),
+ 'manage' => array('admin', 'moderator', 'user'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'index' => array('admin', 'moderator'),
+ 'character' => array('admin', 'moderator', 'user'),
+ 'manage' => array('admin', 'moderator'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator')
+ );
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * List registered Characters for a Seminary
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $all Whether to list all Characters at once or not (optional)
+ */
+ public function index($seminaryUrl, $all=null)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Seminarycharacterfields
+ $characterfields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
+
+ // Set sort order and page
+ $sortorder = 'name';
+ $charactername = null;
+ $page = 1;
+ if($this->request->getRequestMethod() == 'GET')
+ {
+ $sortorder = $this->request->getGetParam('sortorder');
+ $sortorder = !empty($sortorder) ? $sortorder : 'name';
+ $charactername = (!is_null($this->request->getGetParam('charactername'))) ? $this->request->getGetParam('charactername') : $charactername;
+ $page = $this->request->getGetParam('page');
+ $page = !empty($page) ? intval($page) : 1;
+ }
+
+ // Get registered Characters
+ $limit = ($all != 'all') ? \nre\configs\AppConfig::$misc['lists_limit'] : null;
+ $offset = ($all != 'all') ? max((intval($page) - 1), 0) * $limit : 0;
+ $charactersCount = $this->Characters->getCharactersForSeminaryCount($seminary['id'], $charactername);
+ $characters = $this->Characters->getCharactersForSeminarySorted($seminary['id'], $sortorder, $charactername, $limit, $offset);
+ foreach($characters as &$character)
+ {
+ $character['user'] = $this->Users->getUserById($character['user_id']);
+ $character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
+ $character['characterfields'] = array();
+ foreach($this->Seminarycharacterfields->getFieldsForCharacter($character['id']) as $value) {
+ $character['characterfields'][$value['url']] = $value;
+ }
+ try {
+ $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // No XP-level
+ }
+ try {
+ $character['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $character['charactertype_url'], $character['xplevel']['level']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // No Avatar available
+ }
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Characters');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('characters', $characters);
+ $this->set('charactersCount', $charactersCount);
+ $this->set('characterfields', $characterfields);
+ $this->set('sortorder', $sortorder);
+ $this->set('charactername', $charactername);
+ $this->set('all', $all);
+ $this->set('page', $page);
+ $this->set('limit', $limit);
+ }
+
+
+ /**
+ * Action: character.
+ *
+ * Show a Charater and its details.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $characterUrl URL-name of a Charater
+ */
+ public function character($seminaryUrl, $characterUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ $seminary['achievable_xps'] = $this->Seminaries->getTotalXPs($seminary['id']);
+
+ // Get Character
+ $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
+ try {
+ $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // No XP-level
+ }
+ $character['rank'] = $this->Characters->getXPRank($seminary['id'], $character['xps']);
+
+ // Get User
+ $user = $this->Users->getUserById($character['user_id']);
+
+ // Get Character groups
+ $groups = $this->Charactergroups->getGroupsForCharacter($character['id']);
+ foreach($groups as &$group) {
+ $group['groupsgroup'] = $this->Charactergroups->getGroupsgroupById($group['charactergroupsgroup_id']);
+ }
+
+ // Get Achievements
+ $achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
+
+ // Get Achievements with deadline (milestones)
+ $milestones = $this->Achievements->getDeadlineAchievements($seminary['id']);
+ foreach($milestones as &$milestone) {
+ $milestone['achieved'] = $this->Achievements->hasCharacterAchievedAchievement($milestone['id'], $character['id']);
+ }
+
+ // Get ranking
+ $ranking = array(
+ 'superior' => $this->Characters->getSuperiorCharacters($seminary['id'], $character['xps'], \nre\configs\AppConfig::$misc['ranking_range']),
+ 'inferior' => $this->Characters->getInferiorCharacters($seminary['id'], $character['id'], $character['xps'], \nre\configs\AppConfig::$misc['ranking_range'])
+ );
+
+ // Get Quest topics
+ $questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
+ foreach($questtopics as &$questtopic)
+ {
+ $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
+ $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
+ }
+
+ // Get “last” Quest
+ $lastQuest = null;
+ if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0)
+ {
+ $lastQuest = $this->Quests->getLastQuestForCharacter($character['id']);
+ if(!is_null($lastQuest)) {
+ $lastQuest['questgroup'] = $this->Questgroups->getQuestgroupById($lastQuest['questgroup_id']);
+ }
+ }
+
+
+ // Set titile
+ $this->addTitle($character['name']);
+ $this->addTitleLocalized('Characters');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('character', $character);
+ $this->set('user', $user);
+ $this->set('groups', $groups);
+ $this->set('achievements', $achievements);
+ $this->set('milestones', $milestones);
+ $this->set('ranking', $ranking);
+ $this->set('questtopics', $questtopics);
+ $this->set('lastQuest', $lastQuest);
+ }
+
+
+ /**
+ * Acton: register.
+ *
+ * Register a new character for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @throws \nre\exceptions\ParamsNotValidException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function register($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Check for already existing Character
+ try {
+ $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // This should be the case
+ }
+
+
+ // Character types
+ $types = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
+
+ // Character fields
+ $fields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
+
+ // Register Character
+ $charactername = '';
+ $validation = true;
+ $fieldsValidation = true;
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
+ {
+ // Validate Character properties
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), array('charactername'));
+ $charactername = $this->request->getPostParam('charactername');
+ if($this->Characters->characterNameExists($charactername)) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactername', 'exist', true);
+ }
+
+ // Validate type
+ $typeIndex = null;
+ foreach($types as $index => &$type)
+ {
+ $type['selected'] = ($type['url'] == $this->request->getPostParam('type'));
+ if($type['selected']) {
+ $typeIndex = $index;
+ }
+ }
+ if(is_null($typeIndex)) {
+ $validation = $this->Validation->addValidationResult($validation, 'type', 'exist', false);
+ }
+
+ // Validate fields
+ $fieldsValues = $this->request->getPostParam('fields');
+ foreach($fields as &$field)
+ {
+ if(!array_key_exists($field['url'], $fieldsValues)) {
+ throw new \nre\exceptions\ParamsNotValidException($index);
+ }
+ $field['uservalue'] = $fieldsValues[$field['url']];
+ if($field['required'])
+ {
+ $fieldValidation = $this->Validation->validate($fieldsValues[$field['url']], array('regex'=>$field['regex']));
+ if($fieldValidation !== true)
+ {
+ if(!is_array($fieldsValidation)) {
+ $fieldsValidation = array();
+ }
+ $fieldsValidation[$field['url']] = $fieldValidation;
+ }
+ }
+ }
+
+ // Register
+ if($validation === true && $fieldsValidation === true)
+ {
+ $characterId = $this->Characters->createCharacter($this->Auth->getUserId(), $types[$typeIndex]['id'], $charactername);
+ $character = $this->Characters->getCharacterById($characterId);
+
+ // Add Seminary fields
+ foreach($fields as &$field) {
+ if(!empty($fieldsValues[$field['url']])) {
+ $this->Seminarycharacterfields->setSeminaryFieldOfCharacter($field['id'], $characterId, $fieldsValues[$field['url']]);
+ }
+ }
+
+ // Set roles for owners and admins
+ if(in_array('admin', \hhu\z\controllers\IntermediateController::$user['roles']) || $seminary['created_user_id'] == \hhu\z\controllers\IntermediateController::$user['id']) {
+ $this->Characterroles->addCharacterroleToCharacter($characterId, 'admin');
+ }
+
+ // Send mail
+ $this->sendRegistrationMail($character);
+
+ // Redirect
+ $this->redirect($this->linker->link(array('seminaries')));
+ }
+ }
+
+ // Get XP-levels
+ $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
+
+ // Get Avatars
+ if(count($xplevels) > 0)
+ {
+ foreach($types as &$type)
+ {
+ try {
+ $type['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $type['url'], $xplevels[0]['level']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // No Avatar available
+ }
+ }
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Create Character');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('types', $types);
+ $this->set('fields', $fields);
+ $this->set('charactername', $charactername);
+ $this->set('validation', $validation);
+ $this->set('fieldsValidation', $fieldsValidation);
+ $this->set('xplevels', $xplevels);
+ }
+
+
+ /**
+ * Action: manage.
+ *
+ * Manage Characters.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function manage($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Set sort order and page
+
+ $selectedCharacters = array();
+ $sortorder = 'name';
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Set sortorder
+ $sortorder = $this->request->getPostParam('sortorder');
+ $sortorder = !empty($sortorder) ? $sortorder : 'name';
+
+ // Do action
+ $selectedCharacters = $this->request->getPostParam('characters');
+ if(!is_array($selectedCharacters)) {
+ $selectedCharacters = array();
+ }
+ if(!is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0 && !is_null($this->request->getPostParam('characters')) && count($this->request->getPostParam('characters')) > 0)
+ {
+ $actions = $this->request->getPostParam('actions');
+ $action = array_keys($actions)[0];
+
+ switch($action)
+ {
+ // Add/remove role to/from Characters
+ case 'addrole':
+ case 'removerole':
+ // Determine role and check permissions
+ $role = null;
+ switch($actions[$action])
+ {
+ case _('Admin'):
+ if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ $role = 'admin';
+ break;
+ case _('Moderator'):
+ if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ $role = 'moderator';
+ break;
+ case _('User'):
+ if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) <= 0) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ $role = 'user';
+ break;
+ }
+
+ // Add role
+ if($action == 'addrole') {
+ foreach($selectedCharacters as &$characterId) {
+ $this->Characterroles->addCharacterroleToCharacter($characterId, $role);
+ }
+ }
+ // Remove role
+ else {
+ foreach($selectedCharacters as &$characterId) {
+ $this->Characterroles->removeCharacterroleFromCharacter($characterId, $role);
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ // Get Seminarycharacterfields
+ $characterfields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
+
+ // Get registered Characters
+ $characters = $this->Characters->getCharactersForSeminarySorted($seminary['id'], $sortorder);
+ foreach($characters as &$character)
+ {
+ $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
+ $character['user'] = $this->Users->getUserById($character['user_id']);
+ $character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
+ $character['characterfields'] = array();
+ foreach($this->Seminarycharacterfields->getFieldsForCharacter($character['id']) as $value) {
+ $character['characterfields'][$value['url']] = $value;
+ }
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Manage Characters');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('characters', $characters);
+ $this->set('characterfields', $characterfields);
+ $this->set('selectedCharacters', $selectedCharacters);
+ $this->set('sortorder', $sortorder);
+ }
+
+
+ /**
+ * Acton: edit.
+ *
+ * Edit a new character for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @throws \nre\exceptions\ParamsNotValidException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $characterUrl URL-name of a Charater
+ */
+ public function edit($seminaryUrl, $characterUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character
+ $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
+
+ // Check permissions
+ if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) == 0 && $character['id'] != \hhu\z\controllers\SeminaryController::$character['id']) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Get User
+ $user = $this->Users->getUserById($character['user_id']);
+
+ // Character types
+ $types = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
+ foreach($types as &$type) {
+ $type['selected'] = ($type['url'] == $character['charactertype_url']);
+ }
+
+ // Character fields
+ $fields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
+ foreach($fields as &$field)
+ {
+ $userValue = $this->Seminarycharacterfields->getSeminaryFieldOfCharacter($field['id'], $character['id']);
+ if(!empty($userValue)) {
+ $field['uservalue'] = $userValue['value'];
+ }
+ }
+
+ // Values
+ $charactername = $character['name'];
+ $validation = array();
+ $fieldsValidation = true;
+
+ // Edit Character
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Validate Character properties
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), array('charactername'));
+ $charactername = (count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) ? $this->request->getPostParam('charactername') : $character['name'];
+ if($this->Characters->characterNameExists($charactername, $character['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactername', 'exist', true);
+ }
+
+ // Validate type
+ $typeIndex = null;
+ foreach($types as $index => &$type)
+ {
+ $type['selected'] = (count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) ? ($type['url'] == $this->request->getPostParam('type')) : ($type['url'] == $character['charactertype_url']);
+ if($type['selected']) {
+ $typeIndex = $index;
+ }
+ }
+ if(is_null($typeIndex)) {
+ $validation = $this->Validation->addValidationResult($validation, 'type', 'exist', false);
+ }
+
+ // Validate fields
+ $fieldsValues = $this->request->getPostParam('fields');
+ foreach($fields as &$field)
+ {
+ if(!array_key_exists($field['url'], $fieldsValues)) {
+ throw new \nre\exceptions\ParamsNotValidException($index);
+ }
+ $field['uservalue'] = $fieldsValues[$field['url']];
+ if($field['required'])
+ {
+ $fieldValidation = $this->Validation->validate($fieldsValues[$field['url']], array('regex'=>$field['regex']));
+ if($fieldValidation !== true)
+ {
+ if(!is_array($fieldsValidation)) {
+ $fieldsValidation = array();
+ }
+ $fieldsValidation[$field['url']] = $fieldValidation;
+ }
+ }
+ }
+
+ // Edit
+ if($validation === true && $fieldsValidation === true)
+ {
+ $this->Characters->editCharacter(
+ $character['id'],
+ $types[$typeIndex]['id'],
+ $charactername
+ );
+
+ // Set Seminary fields
+ foreach($fields as &$field) {
+ if(!empty($fieldsValues[$field['url']])) {
+ $this->Seminarycharacterfields->setSeminaryFieldOfCharacter($field['id'], $character['id'], $fieldsValues[$field['url']]);
+ }
+ }
+
+ // Redirect
+ $character = $this->Characters->getCharacterById($character['id']);
+ $this->redirect($this->linker->link(array('character', $seminary['url'], $character['url']), 1));
+ }
+ }
+
+ // Get XP-levels
+ $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
+
+ // Get validation settings
+ $validationSettings = array();
+ $validationSettings['charactername'] = \nre\configs\AppConfig::$validation['charactername'];
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Character');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('types', $types);
+ $this->set('fields', $fields);
+ $this->set('charactername', $charactername);
+ $this->set('validation', $validation);
+ $this->set('fieldsValidation', $fieldsValidation);
+ $this->set('validationSettings', $validationSettings);
+ $this->set('xplevels', $xplevels);
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * Delete a Character.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $characterUrl URL-name of a Charater
+ */
+ public function delete($seminaryUrl, $characterUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character
+ $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
+
+ // Get User
+ $user = $this->Users->getUserById($character['user_id']);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete Character
+ $this->Characters->deleteCharacter($character['id']);
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('index', $seminary['url'], $character['url']), 1));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete Character');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('character', $character);
+ $this->set('user', $user);
+ }
+
+
+
+
+ /**
+ * Send mail for new Character registration.
+ *
+ * @param arary $newCharacter Newly registered Character
+ */
+ private function sendRegistrationMail($newCharacter)
+ {
+ // Get Seminary moderators
+ $characters = $this->Characters->getCharactersWithCharacterRole(self::$seminary['id'], 'moderator');
+
+ // Send notification mail
+ try {
+ foreach($characters as &$character)
+ {
+ $moderator = $this->Users->getUserById($character['user_id']);
+ if($moderator['mailing']) {
+ \hhu\z\Utils::sendMail(
+ $moderator['email'],
+ 'characterregistration',
+ true,
+ array(
+ $moderator,
+ \hhu\z\controllers\SeminaryController::$seminary,
+ \hhu\z\controllers\IntermediateController::$user,
+ $newCharacter
+ ),
+ $this->linker
+ );
+ }
+ }
+ }
+ catch(\hhu\z\exceptions\MailingException $e) {
+ $this->log($e->getMessage());
+ }
+ }
+
+ }
?>
diff --git a/controllers/CharactertypesController.inc b/controllers/CharactertypesController.inc
index 60b3dbf3..26610baa 100644
--- a/controllers/CharactertypesController.inc
+++ b/controllers/CharactertypesController.inc
@@ -1,406 +1,406 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the CharactertypesAgent to handle Charactertyes of a
- * Seminary.
- *
- * @author Oliver Hanraths
- */
- class CharactertypesController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('charactertypes', 'xplevels', 'avatars', 'media');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'create' => array('admin', 'moderator', 'user'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator', 'user')
- );
-
-
-
-
- /**
- * Action: index.
- *
- * List Character types.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function index($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- // Check permissions
- if(
- (is_null(self::$character) && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0) &&
- $seminary['created_user_id'] != self::$user['id']
- ) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Get Character types
- $charactertypes = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
-
- // Get Avatars
- $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
- if(count($xplevels) > 0)
- {
- foreach($charactertypes as &$type)
- {
- try {
- $type['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $type['url'], $xplevels[0]['level']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // No Avatar available
- }
- }
- }
+ namespace hhu\z\controllers;
- // Set titile
- $this->addTitleLocalized('Charactertypes');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('xplevels', $xplevels);
- $this->set('charactertypes', $charactertypes);
- }
+ /**
+ * Controller of the CharactertypesAgent to handle Charactertyes of a
+ * Seminary.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactertypesController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('charactertypes', 'xplevels', 'avatars', 'media');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin', 'moderator', 'user'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator', 'user')
+ );
- /**
- * Action: create.
- *
- * Create new Character type for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function create($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Check permissions
- if(
- $seminary['created_user_id'] != self::$user['id'] &&
- (is_null(self::$character) && count(array_intersect(array('admin'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0)
- ) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Values
- $name = '';
- $fields = array('charactertypename');
- $validation = array();
-
- // Create new Charactertype
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $name = $this->request->getPostParam('charactertypename');
- if($this->Charactertypes->charactertypeNameExists($seminary['id'], $name)) {
- $validation = $this->Validation->addValidationResult($validation, 'charactertypename', 'exist', true);
- }
-
- // Create new Charactertype
- if($validation === true)
- {
- $charactertypeId = $this->Charactertypes->createCharactertype(
- $this->Auth->getUserId(),
- $seminary['id'],
- $name
- );
- $charactertype = $this->Charactertypes->getCharactertypeById($charactertypeId);
-
- // Redirect to editing
- $this->redirect($this->linker->link(array('edit', $seminary['url'], $charactertype['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
- // Set titile
- $this->addTitleLocalized('Create new Charactertype');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('name', $name);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
+ /**
+ * Action: index.
+ *
+ * List Character types.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function index($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Check permissions
+ if(
+ (is_null(self::$character) && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0) &&
+ $seminary['created_user_id'] != self::$user['id']
+ ) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Get Character types
+ $charactertypes = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
+
+ // Get Avatars
+ $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
+ if(count($xplevels) > 0)
+ {
+ foreach($charactertypes as &$type)
+ {
+ try {
+ $type['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $type['url'], $xplevels[0]['level']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // No Avatar available
+ }
+ }
+ }
- /**
- * Action: edit.
- *
- * Edit Character type for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of a Seminary
- * @param string $charactertypeUrl URL-title of Character type
- */
- public function edit($seminaryUrl, $charactertypeUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ // Set titile
+ $this->addTitleLocalized('Charactertypes');
+ $this->addTitle($seminary['title']);
- // Check permissions
- if(
- $seminary['created_user_id'] != self::$user['id'] &&
- (is_null(self::$character) && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0)
- ) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Get Character type
- $charactertype = $this->Charactertypes->getCharactertypeByUrl($seminary['id'], $charactertypeUrl);
-
- // XP-levels
- $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
- foreach($xplevels as &$xplevel)
- {
- try {
- $xplevel['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $charactertype['url'], $xplevel['level']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- // No Avatar available
- }
- }
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
-
- // Values
- $name = $charactertype['name'];
- $fields = array('charactertypename');
- $validation = array();
- $avatarVariants = array('portrait', 'avatar');
- $avatarsValidation = true;
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $name = $this->request->getPostParam('charactertypename');
- if($this->Charactertypes->charactertypeNameExists($seminary['id'], $name, $charactertype['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'charactertypename', 'exist', true);
- }
-
- // Validate and upload avatars
- if(array_key_exists('avatars', $_FILES))
- {
- foreach($xplevels as &$xplevel)
- {
- if(array_key_exists($xplevel['id'], $_FILES['avatars']['error']))
- {
- foreach($avatarVariants as &$variant)
- {
- if(array_key_exists($variant, $_FILES['avatars']['error'][$xplevel['id']]) && $_FILES['avatars']['error'][$xplevel['id']][$variant] !== UPLOAD_ERR_NO_FILE)
- {
- $avatar = array(
- 'name' => $_FILES['avatars']['name'][$xplevel['id']][$variant],
- 'type' => $_FILES['avatars']['type'][$xplevel['id']][$variant],
- 'tmp_name' => $_FILES['avatars']['tmp_name'][$xplevel['id']][$variant],
- 'error' => $_FILES['avatars']['error'][$xplevel['id']][$variant],
- 'size' => $_FILES['avatars']['size'][$xplevel['id']][$variant]
- );
- $avatarValidation = true;
-
- // Check error
- if($avatar['error'] !== UPLOAD_ERR_OK) {
- $avatarValidation = $this->Validation->addValidationResult($avatarValidation, 'avatar', 'error', $avatar['error']);
- }
-
- // Check mimetype
- $avatarMimetype = null;
- $avatar['mimetype'] = \hhu\z\Utils::getMimetype($avatar['tmp_name'], $avatar['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $avatar['mimetype']) {
- $avatarMimetype = $mimetype;
- break;
- }
- }
- if(is_null($avatarMimetype)) {
- $avatarValidation = $this->Validation->addValidationResult($avatarValidation, 'avatar', 'mimetype', $avatar['mimetype']);
- }
- elseif($avatar['size'] > $avatarMimetype['size']) {
- $avatarValidation = $this->Validation->addValidationResult($avatarValidation, 'avatar', 'size', $avatarMimetype['size']);
- }
-
- // Add validation result
- if(!$avatarValidation !== true)
- {
- if(!is_array($avatarsValidation)) {
- $avatarsValidation = array();
- }
- if(!array_key_exists($xplevel['id'], $avatarsValidation)) {
- $avatarsValidation[$xplevel['id']] = array();
- }
- $avatarsValidation[$xplevel['id']][$variant] = $avatarValidation;
- }
-
- // Upload avatar
- if($avatarValidation === true)
- {
- $avatar['media_id'] = $this->Media->createAvatarPicture(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('avatar-%d-%d-%s', $charactertype['id'], $xplevel['id'], $variant),
- '',
- $avatar['mimetype'],
- $avatar['tmp_name']
- );
-
- // Set avatar
- if($variant == 'portrait') {
- $this->Avatars->setAvatarPortraitForTypeAndLevel(
- $this->Auth->getUserId(),
- $charactertype['id'],
- $xplevel['id'],
- $avatar['media_id']
- );
- }
- else {
- $this->Avatars->setAvatarForTypeAndLevel(
- $this->Auth->getUserId(),
- $charactertype['id'],
- $xplevel['id'],
- $avatar['media_id']
- );
- }
- }
- }
- }
- }
- }
- }
-
- // Edit Charactertype
- if($validation === true && $avatarsValidation === true)
- {
- $this->Charactertypes->editCharactertype(
- $charactertype['id'],
- $name
- );
- $charactertype = $this->Charactertypes->getCharactertypeById($charactertype['id']);
-
- // Redirect to overview
- $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('xplevels', $xplevels);
+ $this->set('charactertypes', $charactertypes);
+ }
- // Set titile
- $this->addTitleLocalized('Edit Charactertype');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('charactertype', $charactertype);
- $this->set('xplevels', $xplevels);
- $this->set('name', $name);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('avatarsValidation', $avatarsValidation);
- $this->set('avatarVariants', $avatarVariants);
- $this->set('validationSettings', $validationSettings);
- }
+ /**
+ * Action: create.
+ *
+ * Create new Character type for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function create($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Check permissions
+ if(
+ $seminary['created_user_id'] != self::$user['id'] &&
+ (is_null(self::$character) && count(array_intersect(array('admin'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0)
+ ) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Values
+ $name = '';
+ $fields = array('charactertypename');
+ $validation = array();
+
+ // Create new Charactertype
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $name = $this->request->getPostParam('charactertypename');
+ if($this->Charactertypes->charactertypeNameExists($seminary['id'], $name)) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactertypename', 'exist', true);
+ }
+
+ // Create new Charactertype
+ if($validation === true)
+ {
+ $charactertypeId = $this->Charactertypes->createCharactertype(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $name
+ );
+ $charactertype = $this->Charactertypes->getCharactertypeById($charactertypeId);
+
+ // Redirect to editing
+ $this->redirect($this->linker->link(array('edit', $seminary['url'], $charactertype['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
- /**
- * Action: delete.
- *
- * Delete Character type for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of a Seminary
- * @param string $charactertypeUrl URL-title of Character type
- */
- public function delete($seminaryUrl, $charactertypeUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ // Set titile
+ $this->addTitleLocalized('Create new Charactertype');
+ $this->addTitle($seminary['title']);
- // Check permissions
- if(
- $seminary['created_user_id'] != self::$user['id'] &&
- (is_null(self::$character) && count(array_intersect(array('admin'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0)
- ) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Get Character type
- $charactertype = $this->Charactertypes->getCharactertypeByUrl($seminary['id'], $charactertypeUrl);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete Character type
- $this->Charactertypes->deleteCharactertype($charactertype['id']);
- }
-
- // Redirect to overview
- $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
- }
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('name', $name);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
- // Set titile
- $this->addTitleLocalized('Delete Charactertype');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('charactertype', $charactertype);
- }
-
- }
+ /**
+ * Action: edit.
+ *
+ * Edit Character type for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of a Seminary
+ * @param string $charactertypeUrl URL-title of Character type
+ */
+ public function edit($seminaryUrl, $charactertypeUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Check permissions
+ if(
+ $seminary['created_user_id'] != self::$user['id'] &&
+ (is_null(self::$character) && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0)
+ ) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Get Character type
+ $charactertype = $this->Charactertypes->getCharactertypeByUrl($seminary['id'], $charactertypeUrl);
+
+ // XP-levels
+ $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
+ foreach($xplevels as &$xplevel)
+ {
+ try {
+ $xplevel['avatar'] = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $charactertype['url'], $xplevel['level']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ // No Avatar available
+ }
+ }
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $name = $charactertype['name'];
+ $fields = array('charactertypename');
+ $validation = array();
+ $avatarVariants = array('portrait', 'avatar');
+ $avatarsValidation = true;
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $name = $this->request->getPostParam('charactertypename');
+ if($this->Charactertypes->charactertypeNameExists($seminary['id'], $name, $charactertype['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'charactertypename', 'exist', true);
+ }
+
+ // Validate and upload avatars
+ if(array_key_exists('avatars', $_FILES))
+ {
+ foreach($xplevels as &$xplevel)
+ {
+ if(array_key_exists($xplevel['id'], $_FILES['avatars']['error']))
+ {
+ foreach($avatarVariants as &$variant)
+ {
+ if(array_key_exists($variant, $_FILES['avatars']['error'][$xplevel['id']]) && $_FILES['avatars']['error'][$xplevel['id']][$variant] !== UPLOAD_ERR_NO_FILE)
+ {
+ $avatar = array(
+ 'name' => $_FILES['avatars']['name'][$xplevel['id']][$variant],
+ 'type' => $_FILES['avatars']['type'][$xplevel['id']][$variant],
+ 'tmp_name' => $_FILES['avatars']['tmp_name'][$xplevel['id']][$variant],
+ 'error' => $_FILES['avatars']['error'][$xplevel['id']][$variant],
+ 'size' => $_FILES['avatars']['size'][$xplevel['id']][$variant]
+ );
+ $avatarValidation = true;
+
+ // Check error
+ if($avatar['error'] !== UPLOAD_ERR_OK) {
+ $avatarValidation = $this->Validation->addValidationResult($avatarValidation, 'avatar', 'error', $avatar['error']);
+ }
+
+ // Check mimetype
+ $avatarMimetype = null;
+ $avatar['mimetype'] = \hhu\z\Utils::getMimetype($avatar['tmp_name'], $avatar['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $avatar['mimetype']) {
+ $avatarMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($avatarMimetype)) {
+ $avatarValidation = $this->Validation->addValidationResult($avatarValidation, 'avatar', 'mimetype', $avatar['mimetype']);
+ }
+ elseif($avatar['size'] > $avatarMimetype['size']) {
+ $avatarValidation = $this->Validation->addValidationResult($avatarValidation, 'avatar', 'size', $avatarMimetype['size']);
+ }
+
+ // Add validation result
+ if(!$avatarValidation !== true)
+ {
+ if(!is_array($avatarsValidation)) {
+ $avatarsValidation = array();
+ }
+ if(!array_key_exists($xplevel['id'], $avatarsValidation)) {
+ $avatarsValidation[$xplevel['id']] = array();
+ }
+ $avatarsValidation[$xplevel['id']][$variant] = $avatarValidation;
+ }
+
+ // Upload avatar
+ if($avatarValidation === true)
+ {
+ $avatar['media_id'] = $this->Media->createAvatarPicture(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('avatar-%d-%d-%s', $charactertype['id'], $xplevel['id'], $variant),
+ '',
+ $avatar['mimetype'],
+ $avatar['tmp_name']
+ );
+
+ // Set avatar
+ if($variant == 'portrait') {
+ $this->Avatars->setAvatarPortraitForTypeAndLevel(
+ $this->Auth->getUserId(),
+ $charactertype['id'],
+ $xplevel['id'],
+ $avatar['media_id']
+ );
+ }
+ else {
+ $this->Avatars->setAvatarForTypeAndLevel(
+ $this->Auth->getUserId(),
+ $charactertype['id'],
+ $xplevel['id'],
+ $avatar['media_id']
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Edit Charactertype
+ if($validation === true && $avatarsValidation === true)
+ {
+ $this->Charactertypes->editCharactertype(
+ $charactertype['id'],
+ $name
+ );
+ $charactertype = $this->Charactertypes->getCharactertypeById($charactertype['id']);
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Charactertype');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('charactertype', $charactertype);
+ $this->set('xplevels', $xplevels);
+ $this->set('name', $name);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('avatarsValidation', $avatarsValidation);
+ $this->set('avatarVariants', $avatarVariants);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * Delete Character type for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of a Seminary
+ * @param string $charactertypeUrl URL-title of Character type
+ */
+ public function delete($seminaryUrl, $charactertypeUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Check permissions
+ if(
+ $seminary['created_user_id'] != self::$user['id'] &&
+ (is_null(self::$character) && count(array_intersect(array('admin'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0)
+ ) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Get Character type
+ $charactertype = $this->Charactertypes->getCharactertypeByUrl($seminary['id'], $charactertypeUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete Character type
+ $this->Charactertypes->deleteCharactertype($charactertype['id']);
+ }
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(array('index', $seminary['url']), 1));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete Charactertype');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('charactertype', $charactertype);
+ }
+
+ }
?>
diff --git a/controllers/ErrorController.inc b/controllers/ErrorController.inc
index a27e3afd..61abb150 100644
--- a/controllers/ErrorController.inc
+++ b/controllers/ErrorController.inc
@@ -1,51 +1,51 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to show an error page.
- *
- * @author Oliver Hanraths
- */
- class ErrorController extends \hhu\z\Controller
- {
-
-
-
-
-
-
- /**
- * Action: index.
- *
- * Set HTTP-header and print an error message.
- *
- * @param int $httpStatusCode HTTP-statuscode of the error that occurred
- */
- public function index($httpStatusCode)
- {
- // Set HTTP-header
- if(!array_key_exists($httpStatusCode, \nre\core\WebUtils::$httpStrings)) {
- $httpStatusCode = 200;
- }
- $this->response->addHeader(\nre\core\WebUtils::getHttpHeader($httpStatusCode));
-
- // Display statuscode and message
- $this->set('code', $httpStatusCode);
- $this->set('string', \nre\core\WebUtils::$httpStrings[$httpStatusCode]);
- $this->set('userId', $this->Auth->getUserId());
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to show an error page.
+ *
+ * @author Oliver Hanraths
+ */
+ class ErrorController extends \hhu\z\Controller
+ {
+
+
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * Set HTTP-header and print an error message.
+ *
+ * @param int $httpStatusCode HTTP-statuscode of the error that occurred
+ */
+ public function index($httpStatusCode)
+ {
+ // Set HTTP-header
+ if(!array_key_exists($httpStatusCode, \nre\core\WebUtils::$httpStrings)) {
+ $httpStatusCode = 200;
+ }
+ $this->response->addHeader(\nre\core\WebUtils::getHttpHeader($httpStatusCode));
+
+ // Display statuscode and message
+ $this->set('code', $httpStatusCode);
+ $this->set('string', \nre\core\WebUtils::$httpStrings[$httpStatusCode]);
+ $this->set('userId', $this->Auth->getUserId());
+ }
+
+ }
?>
diff --git a/controllers/FaultController.inc b/controllers/FaultController.inc
index be01fea7..ba8f29da 100644
--- a/controllers/FaultController.inc
+++ b/controllers/FaultController.inc
@@ -1,37 +1,37 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to display a toplevel error page.
- *
- * @author Oliver Hanraths
- */
- class FaultController extends \nre\core\Controller
- {
-
-
-
-
- /**
- * Action: index.
- *
- * Show the error message.
- */
- public function index()
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to display a toplevel error page.
+ *
+ * @author Oliver Hanraths
+ */
+ class FaultController extends \nre\core\Controller
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * Show the error message.
+ */
+ public function index()
+ {
+ }
+
+ }
?>
diff --git a/controllers/HtmlController.inc b/controllers/HtmlController.inc
index 8c451441..c1402e9f 100644
--- a/controllers/HtmlController.inc
+++ b/controllers/HtmlController.inc
@@ -1,114 +1,114 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the HtmlAgent to display a HTML-page.
- *
- * @author Oliver Hanraths
- */
- class HtmlController extends \hhu\z\Controller
- {
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('notification');
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Set content-type
- $this->response->addHeader("Content-type: text/html; charset=utf-8");
- }
-
-
- /**
- * Postfilter that is executed after running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- // Get title
- $this->set('title', $this->getTitle());
- }
-
-
- /**
- * Action: index.
- *
- * Create the HTML-structure.
- */
- public function index()
- {
- // Set the name of the current IntermediateAgent as page title
- $this->set('title', $this->request->getParam(1, 'intermediate'));
-
- // Set userdata
- $this->set('loggedUser', IntermediateController::$user);
- $this->set('loggedSeminary', SeminaryController::$seminary);
- $this->set('loggedCharacter', SeminaryController::$character);
-
- // Set notifications
- $this->set('notifications', $this->Notification->getNotifications());
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the HtmlAgent to display a HTML-page.
+ *
+ * @author Oliver Hanraths
+ */
+ class HtmlController extends \hhu\z\Controller
+ {
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('notification');
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Set content-type
+ $this->response->addHeader("Content-type: text/html; charset=utf-8");
+ }
+
+
+ /**
+ * Postfilter that is executed after running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ // Get title
+ $this->set('title', $this->getTitle());
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * Create the HTML-structure.
+ */
+ public function index()
+ {
+ // Set the name of the current IntermediateAgent as page title
+ $this->set('title', $this->request->getParam(1, 'intermediate'));
+
+ // Set userdata
+ $this->set('loggedUser', IntermediateController::$user);
+ $this->set('loggedSeminary', SeminaryController::$seminary);
+ $this->set('loggedCharacter', SeminaryController::$character);
+
+ // Set notifications
+ $this->set('notifications', $this->Notification->getNotifications());
// Set some application data
$this->set('mailcontact', \nre\configs\AppConfig::$app['mailcontact']);
- }
-
-
-
-
- /**
- * Get title information from IntermediateController if possible
- * and create a title.
- *
- * @return string Title for the current page
- */
- private function getTitle()
- {
- $title = array();
-
- // Get title of IntermediateController
- $intermediateController = $this->agent->getIntermediateAgent()->controller;
- if($intermediateController instanceof \hhu\z\controllers\IntermediateController) {
- $title = $intermediateController->getTitle();
- }
- if(!is_array($title)) {
- $title = array($title);
- }
-
- // Add application name
- $title[] = \nre\configs\AppConfig::$app['name'];
-
-
- // Return title with delimiter
- return implode(\nre\configs\AppConfig::$misc['title_delimiter'], $title);
- }
-
- }
+ }
+
+
+
+
+ /**
+ * Get title information from IntermediateController if possible
+ * and create a title.
+ *
+ * @return string Title for the current page
+ */
+ private function getTitle()
+ {
+ $title = array();
+
+ // Get title of IntermediateController
+ $intermediateController = $this->agent->getIntermediateAgent()->controller;
+ if($intermediateController instanceof \hhu\z\controllers\IntermediateController) {
+ $title = $intermediateController->getTitle();
+ }
+ if(!is_array($title)) {
+ $title = array($title);
+ }
+
+ // Add application name
+ $title[] = \nre\configs\AppConfig::$app['name'];
+
+
+ // Return title with delimiter
+ return implode(\nre\configs\AppConfig::$misc['title_delimiter'], $title);
+ }
+
+ }
?>
diff --git a/controllers/HtmlmailController.inc b/controllers/HtmlmailController.inc
index 19640615..7fa8cf9f 100644
--- a/controllers/HtmlmailController.inc
+++ b/controllers/HtmlmailController.inc
@@ -1,54 +1,54 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the HtmlmailAgent for generating a HTML-mail message.
- *
- * @author Oliver Hanraths
- */
- class HtmlmailController extends \nre\core\Controller
- {
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
-
- // Set linker
- $this->set('linker', ($request instanceof \hhu\z\requests\MailRequest && !is_null($request->getLinker())) ? $request->getLinker() : null);
- }
-
-
- /**
- * Action: index.
- *
- * Create HTML-structure of mail message.
- */
- public function index()
- {
- $this->set('appname', \nre\configs\AppConfig::$app['name']);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the HtmlmailAgent for generating a HTML-mail message.
+ *
+ * @author Oliver Hanraths
+ */
+ class HtmlmailController extends \nre\core\Controller
+ {
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+
+ // Set linker
+ $this->set('linker', ($request instanceof \hhu\z\requests\MailRequest && !is_null($request->getLinker())) ? $request->getLinker() : null);
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * Create HTML-structure of mail message.
+ */
+ public function index()
+ {
+ $this->set('appname', \nre\configs\AppConfig::$app['name']);
+ }
+
+ }
?>
diff --git a/controllers/IntroductionController.inc b/controllers/IntroductionController.inc
index c1a07f41..97d34978 100644
--- a/controllers/IntroductionController.inc
+++ b/controllers/IntroductionController.inc
@@ -1,37 +1,37 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to show an introduction page.
- *
- * @author Oliver Hanraths
- */
- class IntroductionController extends \hhu\z\controllers\IntermediateController
- {
-
-
-
-
- /**
- * Action: index.
- */
- public function index()
- {
- // Pass data to view
- $this->set('userId', $this->Auth->getUserId());
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to show an introduction page.
+ *
+ * @author Oliver Hanraths
+ */
+ class IntroductionController extends \hhu\z\controllers\IntermediateController
+ {
+
+
+
+
+ /**
+ * Action: index.
+ */
+ public function index()
+ {
+ // Pass data to view
+ $this->set('userId', $this->Auth->getUserId());
+ }
+
+ }
?>
diff --git a/controllers/LibraryController.inc b/controllers/LibraryController.inc
index 0adfcdd8..2d1dbf69 100644
--- a/controllers/LibraryController.inc
+++ b/controllers/LibraryController.inc
@@ -1,513 +1,513 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the LibraryAgent to list Quest topics.
- *
- * @author Oliver Hanraths
- */
- class LibraryController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('questtopics', 'seminaries', 'quests', 'questgroups');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'topic' => 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
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'index' => array('admin', 'moderator', 'user', 'guest'),
- 'topic' => array('admin', 'moderator', 'user', 'guest'),
- 'manage' => array('admin', 'moderator'),
- 'create' => array('admin', 'moderator'),
- 'edit' => array('admin', 'moderator'),
- 'delete' => array('admin', 'moderator')
- );
-
-
-
-
- /**
- * Action: index.
- *
- * List Questtopics of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- */
- public function index($seminaryUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character
- $character = SeminaryController::$character;
-
- // Get Quest topics
- $totalQuestcount = 0;
- $totalCharacterQuestcount = 0;
- $questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
- foreach($questtopics as &$questtopic)
- {
- // Get Quest count
- $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
- $totalQuestcount += $questtopic['questcount'];
-
- // Get Character progress
- $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
- $totalCharacterQuestcount += $questtopic['characterQuestcount'];
- }
-
-
- // Set title
- $this->addTitleLocalized('Library');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('totalQuestcount', $totalQuestcount);
- $this->set('totalCharacterQuestcount', $totalCharacterQuestcount);
- $this->set('questtopics', $questtopics);
- }
-
-
- /**
- * Action: topic.
- *
- * Show a Questtopic and its Quests with Questsubtopics.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $eminaryUrl URL-Title of Seminary
- * @param string $questtopicUrl URL-Title of Questtopic
- */
- public function topic($seminaryUrl, $questtopicUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character
- $character = SeminaryController::$character;
-
- // Get Questtopic
- $questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl);
- $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
- $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
-
- // Get Quests
- $quests = array();
- foreach($this->Quests->getQuestsForQuesttopic($questtopic['id']) as $quest)
- {
- if($this->Quests->hasCharacterEnteredQuest($quest['id'], $character['id']) || count(array_intersect(array('admin', 'moderator'), self::$character['characterroles'])) > 0)
- {
- // Get Subtopics
- $quest['subtopics'] = $this->Questtopics->getQuestsubtopicsForQuest($quest['id']);
-
- $quests[] = $quest;
- }
- }
-
-
- // Set title
- $this->addTitle($questtopic['title']);
- $this->addTitleLocalized('Library');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questtopic', $questtopic);
- $this->set('quests', $quests);
- }
-
-
- /**
- * Action: manage.
- *
- * Manage a Questtopic and its Quests with Questsubtopics.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $eminaryUrl URL-Title of Seminary
- * @param string $questtopicUrl URL-Title of Questtopic
- */
- public function manage($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']);
-
- // Set Questsubtopics for Quests
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('questsubtopics')))
- {
- $selectedSubtopics = $this->request->getPostParam('questsubtopics');
-
- // Set subtopics of Quests
- $quests = $this->Quests->getQuestsForQuesttopic($questtopic['id']);
- foreach($quests as &$quest)
- {
- $subtopics = (array_key_exists($quest['id'], $selectedSubtopics)) ? $selectedSubtopics[$quest['id']] : array();
- $this->Questtopics->setQuestsubtopicsForQuest($quest['id'], array_keys($subtopics));
- }
-
- // Add Quest
- $addQuestId = $this->request->getPostParam('addquest');
- if(!empty($addQuestId))
- {
- $subtopics = (array_key_exists('addquest', $selectedSubtopics)) ? $selectedSubtopics['addquest'] : array();
- if(!empty($subtopics)) {
- $this->Questtopics->setQuestsubtopicsForQuest($addQuestId, array_keys($subtopics));
- }
- }
-
- // Redirect
- $this->redirect($this->linker->link(array('topic', $seminary['url'], $questtopic['url']), 1));
- }
-
- // Get Quests
- $quests = $this->Quests->getQuestsForQuesttopic($questtopic['id']);
- foreach($quests as &$quest)
- {
- // Get Subtopics
- $quest['subtopics'] = $this->Questtopics->getQuestsubtopicsForQuest($quest['id']);
- $quest['subtopics'] = array_map(function($t) { return $t['id']; }, $quest['subtopics']);
- }
-
- // Get all Quests
- $allQuests = $this->Quests->getQuestsForSeminary($seminary['id']);
-
-
- // Set title
- $this->addTitle($questtopic['title']);
- $this->addTitleLocalized('Library');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questtopic', $questtopic);
- $this->set('questsubtopics', $questsubtopics);
- $this->set('quests', $quests);
- $this->set('allQuests', $allQuests);
- }
-
-
- /**
- * Action: create.
- *
- * Create a new Questtopic for a Seminary.
- *
- * @throws \nre\exceptions\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 \nre\exceptions\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 \nre\exceptions\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);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the LibraryAgent to list Quest topics.
+ *
+ * @author Oliver Hanraths
+ */
+ class LibraryController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('questtopics', 'seminaries', 'quests', 'questgroups');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'topic' => 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
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'index' => array('admin', 'moderator', 'user', 'guest'),
+ 'topic' => array('admin', 'moderator', 'user', 'guest'),
+ 'manage' => array('admin', 'moderator'),
+ 'create' => array('admin', 'moderator'),
+ 'edit' => array('admin', 'moderator'),
+ 'delete' => array('admin', 'moderator')
+ );
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * List Questtopics of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ */
+ public function index($seminaryUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character
+ $character = SeminaryController::$character;
+
+ // Get Quest topics
+ $totalQuestcount = 0;
+ $totalCharacterQuestcount = 0;
+ $questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
+ foreach($questtopics as &$questtopic)
+ {
+ // Get Quest count
+ $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
+ $totalQuestcount += $questtopic['questcount'];
+
+ // Get Character progress
+ $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
+ $totalCharacterQuestcount += $questtopic['characterQuestcount'];
+ }
+
+
+ // Set title
+ $this->addTitleLocalized('Library');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('totalQuestcount', $totalQuestcount);
+ $this->set('totalCharacterQuestcount', $totalCharacterQuestcount);
+ $this->set('questtopics', $questtopics);
+ }
+
+
+ /**
+ * Action: topic.
+ *
+ * Show a Questtopic and its Quests with Questsubtopics.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $eminaryUrl URL-Title of Seminary
+ * @param string $questtopicUrl URL-Title of Questtopic
+ */
+ public function topic($seminaryUrl, $questtopicUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character
+ $character = SeminaryController::$character;
+
+ // Get Questtopic
+ $questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl);
+ $questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
+ $questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
+
+ // Get Quests
+ $quests = array();
+ foreach($this->Quests->getQuestsForQuesttopic($questtopic['id']) as $quest)
+ {
+ if($this->Quests->hasCharacterEnteredQuest($quest['id'], $character['id']) || count(array_intersect(array('admin', 'moderator'), self::$character['characterroles'])) > 0)
+ {
+ // Get Subtopics
+ $quest['subtopics'] = $this->Questtopics->getQuestsubtopicsForQuest($quest['id']);
+
+ $quests[] = $quest;
+ }
+ }
+
+
+ // Set title
+ $this->addTitle($questtopic['title']);
+ $this->addTitleLocalized('Library');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questtopic', $questtopic);
+ $this->set('quests', $quests);
+ }
+
+
+ /**
+ * Action: manage.
+ *
+ * Manage a Questtopic and its Quests with Questsubtopics.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $eminaryUrl URL-Title of Seminary
+ * @param string $questtopicUrl URL-Title of Questtopic
+ */
+ public function manage($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']);
+
+ // Set Questsubtopics for Quests
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('questsubtopics')))
+ {
+ $selectedSubtopics = $this->request->getPostParam('questsubtopics');
+
+ // Set subtopics of Quests
+ $quests = $this->Quests->getQuestsForQuesttopic($questtopic['id']);
+ foreach($quests as &$quest)
+ {
+ $subtopics = (array_key_exists($quest['id'], $selectedSubtopics)) ? $selectedSubtopics[$quest['id']] : array();
+ $this->Questtopics->setQuestsubtopicsForQuest($quest['id'], array_keys($subtopics));
+ }
+
+ // Add Quest
+ $addQuestId = $this->request->getPostParam('addquest');
+ if(!empty($addQuestId))
+ {
+ $subtopics = (array_key_exists('addquest', $selectedSubtopics)) ? $selectedSubtopics['addquest'] : array();
+ if(!empty($subtopics)) {
+ $this->Questtopics->setQuestsubtopicsForQuest($addQuestId, array_keys($subtopics));
+ }
+ }
+
+ // Redirect
+ $this->redirect($this->linker->link(array('topic', $seminary['url'], $questtopic['url']), 1));
+ }
+
+ // Get Quests
+ $quests = $this->Quests->getQuestsForQuesttopic($questtopic['id']);
+ foreach($quests as &$quest)
+ {
+ // Get Subtopics
+ $quest['subtopics'] = $this->Questtopics->getQuestsubtopicsForQuest($quest['id']);
+ $quest['subtopics'] = array_map(function($t) { return $t['id']; }, $quest['subtopics']);
+ }
+
+ // Get all Quests
+ $allQuests = $this->Quests->getQuestsForSeminary($seminary['id']);
+
+
+ // Set title
+ $this->addTitle($questtopic['title']);
+ $this->addTitleLocalized('Library');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questtopic', $questtopic);
+ $this->set('questsubtopics', $questsubtopics);
+ $this->set('quests', $quests);
+ $this->set('allQuests', $allQuests);
+ }
+
+
+ /**
+ * Action: create.
+ *
+ * Create a new Questtopic for a Seminary.
+ *
+ * @throws \nre\exceptions\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 \nre\exceptions\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 \nre\exceptions\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/controllers/MailController.inc b/controllers/MailController.inc
index 904a907f..ee8f2c98 100644
--- a/controllers/MailController.inc
+++ b/controllers/MailController.inc
@@ -1,136 +1,136 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the MailAgent to generate a mail message.
- *
- * @author Oliver Hanraths
- */
- class MailController extends \nre\core\Controller
- {
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
-
- // Set linker
- $this->set('linker', ($request instanceof \hhu\z\requests\MailRequest && !is_null($request->getLinker())) ? $request->getLinker() : null);
- }
-
-
- /**
- * Action: userregistration.
- *
- * Generate a mail message to notify of a new user registration.
- *
- * @param array $receiver User that the message will be send to
- * @param array $neUser Newly registered user
- */
- public function userregistration($receiver, $newUser)
- {
- // Set subject
- $this->response->setSubject(_('New user registration'));
-
-
- // Pass data to view
- $this->set('user', $newUser);
- }
-
-
- /**
- * Action: characterregistration.
- *
- * Generate a mail message to notify of a new Character
- * registration.
- *
- * @param array $receiver User that the message will be send to
- * @param array $seminary Seminary which the Character was created for
- * @param arary $user User of the newly registered Character
- * @param array $newCharacter Newly registered Character
- */
- public function characterregistration($receiver, $seminary, $user, $newCharacter)
- {
- // Set subject
- $this->response->setSubject(_('New Character registration'));
-
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('user', $user);
- $this->set('character', $newCharacter);
- }
-
-
- /**
- * Action: charactersubmission.
- *
- * Generate a mail message to notify of a new Character
- * submission for a Quest that needs to be valuated.
- *
- * @param array $receiver User that the message will be send to
- * @param array $seminary Seminary which the Quest belongs to
- * @param array $questgroup Questgroup of Quest
- * @param array $quest Quest the answer has been submitted for
- * @param array $character Character that send the submission
- */
- public function charactersubmission($receiver, $seminary, $questgroup, $quest, $character)
- {
- // Set subject
- $this->response->setSubject(_('New Character submission'));
-
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('quest', $quest);
- $this->set('character', $character);
- }
-
-
- /**
- * Action: charactersubmissionapproved.
- *
- * Generate a mail message to notify a Character that its
- * submission has been approved.
- *
- * @param array $receiver User that the message will be send to
- * @param array $seminary Seminary which the Quest belongs to
- * @param array $questgroup Questgroup of Quest
- * @param array $quest Quest the answer has been submitted for
- */
- public function charactersubmissionapproved($receiver, $seminary, $questgroup, $quest)
- {
- // Set subject
- $this->response->setSubject(_('Character submission approved'));
-
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('quest', $quest);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the MailAgent to generate a mail message.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailController extends \nre\core\Controller
+ {
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+
+ // Set linker
+ $this->set('linker', ($request instanceof \hhu\z\requests\MailRequest && !is_null($request->getLinker())) ? $request->getLinker() : null);
+ }
+
+
+ /**
+ * Action: userregistration.
+ *
+ * Generate a mail message to notify of a new user registration.
+ *
+ * @param array $receiver User that the message will be send to
+ * @param array $neUser Newly registered user
+ */
+ public function userregistration($receiver, $newUser)
+ {
+ // Set subject
+ $this->response->setSubject(_('New user registration'));
+
+
+ // Pass data to view
+ $this->set('user', $newUser);
+ }
+
+
+ /**
+ * Action: characterregistration.
+ *
+ * Generate a mail message to notify of a new Character
+ * registration.
+ *
+ * @param array $receiver User that the message will be send to
+ * @param array $seminary Seminary which the Character was created for
+ * @param arary $user User of the newly registered Character
+ * @param array $newCharacter Newly registered Character
+ */
+ public function characterregistration($receiver, $seminary, $user, $newCharacter)
+ {
+ // Set subject
+ $this->response->setSubject(_('New Character registration'));
+
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('user', $user);
+ $this->set('character', $newCharacter);
+ }
+
+
+ /**
+ * Action: charactersubmission.
+ *
+ * Generate a mail message to notify of a new Character
+ * submission for a Quest that needs to be valuated.
+ *
+ * @param array $receiver User that the message will be send to
+ * @param array $seminary Seminary which the Quest belongs to
+ * @param array $questgroup Questgroup of Quest
+ * @param array $quest Quest the answer has been submitted for
+ * @param array $character Character that send the submission
+ */
+ public function charactersubmission($receiver, $seminary, $questgroup, $quest, $character)
+ {
+ // Set subject
+ $this->response->setSubject(_('New Character submission'));
+
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('quest', $quest);
+ $this->set('character', $character);
+ }
+
+
+ /**
+ * Action: charactersubmissionapproved.
+ *
+ * Generate a mail message to notify a Character that its
+ * submission has been approved.
+ *
+ * @param array $receiver User that the message will be send to
+ * @param array $seminary Seminary which the Quest belongs to
+ * @param array $questgroup Questgroup of Quest
+ * @param array $quest Quest the answer has been submitted for
+ */
+ public function charactersubmissionapproved($receiver, $seminary, $questgroup, $quest)
+ {
+ // Set subject
+ $this->response->setSubject(_('Character submission approved'));
+
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('quest', $quest);
+ }
+
+ }
?>
diff --git a/controllers/MailreceiverController.inc b/controllers/MailreceiverController.inc
index 7ae92470..acd8d04c 100644
--- a/controllers/MailreceiverController.inc
+++ b/controllers/MailreceiverController.inc
@@ -1,39 +1,39 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the MailreceiverAgent to generate a mail receiver
- * salutation.
- *
- * @author Oliver Hanraths
- */
- class MailreceiverController extends \nre\core\Controller
- {
-
-
-
-
- /**
- * Action: index.
- *
- * @param $array $user User receiving mail
- */
- public function index($user)
- {
- $this->set('user', $user);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the MailreceiverAgent to generate a mail receiver
+ * salutation.
+ *
+ * @author Oliver Hanraths
+ */
+ class MailreceiverController extends \nre\core\Controller
+ {
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param $array $user User receiving mail
+ */
+ public function index($user)
+ {
+ $this->set('user', $user);
+ }
+
+ }
?>
diff --git a/controllers/MapController.inc b/controllers/MapController.inc
index 7dbb6ab4..d489fc57 100644
--- a/controllers/MapController.inc
+++ b/controllers/MapController.inc
@@ -1,62 +1,62 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the MapAgent to display a map.
- *
- * @author Oliver Hanraths
- */
- class MapController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'map');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'index' => array('admin', 'moderator', 'user')
- );
-
-
-
-
- /**
- * Action: index.
- *
- * Draw the map.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- */
- public function index($seminaryUrl)
- {
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the MapAgent to display a map.
+ *
+ * @author Oliver Hanraths
+ */
+ class MapController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'map');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'index' => array('admin', 'moderator', 'user')
+ );
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * Draw the map.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ */
+ public function index($seminaryUrl)
+ {
// Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
// Get map
$map = $this->Map->getMapOfSeminary($seminary['id']);
@@ -65,8 +65,8 @@
// Pass data to view
$this->set('seminary', $seminary);
$this->set('map', $map);
- }
-
- }
+ }
+
+ }
?>
diff --git a/controllers/MediaController.inc b/controllers/MediaController.inc
index a55cd94a..0336d6fb 100644
--- a/controllers/MediaController.inc
+++ b/controllers/MediaController.inc
@@ -1,162 +1,162 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the MediaAgent to process and show Media.
- *
- * @author Oliver Hanraths
- */
- class MediaController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user', 'guest'),
- 'seminarymoodpic' => array('admin', 'moderator', 'user'),
- 'seminarymap' => array('admin', 'moderator', 'user'),
- 'seminary' => array('admin', 'moderator', 'user'),
- 'avatar' => array('admin', 'moderator', 'user'),
- 'achievement' => array('admin', 'moderator', 'user'),
- 'charactergroup' => array('admin', 'moderator', 'user'),
- 'charactergroupsquest' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'seminary' => array('admin', 'moderator', 'user', 'guest'),
- 'achievement' => array('admin', 'moderator', 'user', 'guest'),
- 'charactergroup' => array('admin', 'moderator', 'user', 'guest'),
- 'charactergroupsquest' => array('admin', 'moderator', 'user', 'guest')
- );
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests', 'map');
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Set headers for caching control
- $response->addHeader("Pragma: public");
- $response->addHeader("Cache-control: must-revalidate");
- $response->addHeader("Date: ".gmdate(\DateTime::RFC822));
- }
-
-
- /**
- * Action: index
- *
- * Display a medium.
- *
- * @param string $mediaUrl URL-name of the medium
- * @param string $action Action for processing the media
- */
- public function index($mediaUrl, $action=null)
- {
- // Get Media
- $media = $this->Media->getMediaByUrl($mediaUrl);
-
- // Get file
- $file = $this->getMediaFile($media, $action);
- if(is_null($media)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
- }
-
-
- /**
- * Action: seminarymoodpic
- *
- * Display the moodpic for a category of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of the Seminary
- * @param string $category Category to show moodpic of
- * @param string $action Action for processing the media
- */
- public function seminarymoodpic($seminaryUrl, $category=null, $action=null)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Set index
- switch($category)
- {
- case null:
- $index = 'seminarymedia_id';
- break;
- case 'charactergroups':
- $index = 'charactergroups_seminarymedia_id';
- break;
- case 'achievements':
- $index = 'achievements_seminarymedia_id';
- break;
- case 'library':
- $index = 'library_seminarymedia_id';
- break;
- }
-
- // Get media
- $media = $this->Media->getSeminaryMediaById($seminary[$index]);
-
- // Get file
- $file = $this->getMediaFile($media, $action);
- if(is_null($file)) {
- return;
- }
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the MediaAgent to process and show Media.
+ *
+ * @author Oliver Hanraths
+ */
+ class MediaController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user', 'guest'),
+ 'seminarymoodpic' => array('admin', 'moderator', 'user'),
+ 'seminarymap' => array('admin', 'moderator', 'user'),
+ 'seminary' => array('admin', 'moderator', 'user'),
+ 'avatar' => array('admin', 'moderator', 'user'),
+ 'achievement' => array('admin', 'moderator', 'user'),
+ 'charactergroup' => array('admin', 'moderator', 'user'),
+ 'charactergroupsquest' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'seminary' => array('admin', 'moderator', 'user', 'guest'),
+ 'achievement' => array('admin', 'moderator', 'user', 'guest'),
+ 'charactergroup' => array('admin', 'moderator', 'user', 'guest'),
+ 'charactergroupsquest' => array('admin', 'moderator', 'user', 'guest')
+ );
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests', 'map');
+
+
/**
- * Action: seminarymap
- *
- * Display the map of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of the Seminary
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Set headers for caching control
+ $response->addHeader("Pragma: public");
+ $response->addHeader("Cache-control: must-revalidate");
+ $response->addHeader("Date: ".gmdate(\DateTime::RFC822));
+ }
+
+
+ /**
+ * Action: index
+ *
+ * Display a medium.
+ *
+ * @param string $mediaUrl URL-name of the medium
+ * @param string $action Action for processing the media
+ */
+ public function index($mediaUrl, $action=null)
+ {
+ // Get Media
+ $media = $this->Media->getMediaByUrl($mediaUrl);
+
+ // Get file
+ $file = $this->getMediaFile($media, $action);
+ if(is_null($media)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
+ }
+
+
+ /**
+ * Action: seminarymoodpic
+ *
+ * Display the moodpic for a category of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of the Seminary
+ * @param string $category Category to show moodpic of
+ * @param string $action Action for processing the media
+ */
+ public function seminarymoodpic($seminaryUrl, $category=null, $action=null)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Set index
+ switch($category)
+ {
+ case null:
+ $index = 'seminarymedia_id';
+ break;
+ case 'charactergroups':
+ $index = 'charactergroups_seminarymedia_id';
+ break;
+ case 'achievements':
+ $index = 'achievements_seminarymedia_id';
+ break;
+ case 'library':
+ $index = 'library_seminarymedia_id';
+ break;
+ }
+
+ // Get media
+ $media = $this->Media->getSeminaryMediaById($seminary[$index]);
+
+ // Get file
+ $file = $this->getMediaFile($media, $action);
+ if(is_null($file)) {
+ return;
+ }
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
+ }
+
+
+ /**
+ * Action: seminarymap
+ *
+ * Display the map of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of the Seminary
*/
public function seminarymap($seminaryUrl)
{
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
// Get map
$map = $this->Map->getMapOfSeminary($seminary['id']);
@@ -164,434 +164,434 @@
throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
}
- // Get media
- $media = $this->Media->getSeminaryMediaById($map['seminarymedia_id']);
-
- // Get file
- $file = $this->getMediaFile($media);
- if(is_null($file)) {
- return;
- }
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
+ // Get media
+ $media = $this->Media->getSeminaryMediaById($map['seminarymedia_id']);
+
+ // Get file
+ $file = $this->getMediaFile($media);
+ if(is_null($file)) {
+ return;
+ }
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
}
-
-
- /**
- * Action: seminary.
- *
- * Display a Seminary medium.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of the Seminary
- * @param string $mediaUrl URL-name of the medium
- * @param string $action Action for processing the media
- */
- public function seminary($seminaryUrl, $mediaUrl, $action=null)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Media
- $media = $this->Media->getSeminaryMediaByUrl($seminary['id'], $mediaUrl);
-
- // Get file
- $file = $this->getMediaFile($media, $action);
- if(is_null($file)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
- }
-
-
- /**
- * Action: avatar.
- *
- * Display an Avatar as full size or portrait.
- *
- * @throws \nre\exceptions\ParamsNotValidException
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of the Seminary
- * @param string $charactertypeUrl URL-title of Character type
- * @param int $xplevel XP-level
- * @param string $action Size to show (avatar or portrait)
- */
- public function avatar($seminaryUrl, $charactertypeUrl, $xplevel, $action='avatar')
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Avatar
- $avatar = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $charactertypeUrl, $xplevel);
-
- // Get media
- switch($action)
- {
- case null:
- case 'avatar':
- $media = $this->Media->getSeminaryMediaById($avatar['avatarpicture_id']);
- $file = $this->getMediaFile($media, 'avatar');
- break;
- case 'portrait':
- $media = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
- $file = $this->getMediaFile($media);
- break;
- default:
- throw new \nre\exceptions\ParamsNotValidException($action);
- break;
- }
-
- // Get file
- if(is_null($file)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
- }
-
-
- /**
- * Action: achievement
- *
- * Display the achievement of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of the Seminary
- * @param string $achievementUrl URL-title of the Achievement
- * @param string $action Action for processing the media
- */
- public function achievement($seminaryUrl, $achievementUrl, $locked=null)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character
- $character = SeminaryController::$character;
-
- // Get Achievement
- $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
-
- // Get media
- switch($locked)
- {
- case null:
- if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) == 0) {
- if(is_null($character) || !$this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id'])) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- }
- $index = 'achieved_achievementsmedia_id';
- break;
- case 'locked':
- $index = 'unachieved_achievementsmedia_id';
- break;
- default:
- throw new \nre\exceptions\ParamsNotValidException($locked);
- break;
- }
- if(is_null($achievement[$index])) {
- throw new \nre\exceptions\IdNotFoundException($achievementUrl);
- }
- $media = $this->Media->getSeminaryMediaById($achievement[$index]);
-
- // Get file
- $file = $this->getMediaFile($media, null);
- if(is_null($file)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
- }
-
-
- /**
- * Action: charactergroup
- *
- * Display the icon for a Character group of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $groupUrl URL-Title of a Character group
- */
- public function charactergroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character group
- $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
-
- // Check media
- if(is_null($group['charactergroupsmedia_id'])) {
- $this->redirect($this->linker->link(array('grafics','charactergroup.jpg')));
- }
-
- // Get media
- $media = $this->Media->getSeminaryMediaById($group['charactergroupsmedia_id']);
-
- // Get file
- $file = $this->getMediaFile($media, 'charactergroup');
- if(is_null($file)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
- }
-
-
- /**
- * Action: charactergroupsquest
- *
- * Display the icon for a Character groups Quest of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $questUrl URL-Title of a Character groups Quest
- */
- public function charactergroupsquest($seminaryUrl, $groupsgroupUrl, $questUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character groups Quests
- $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
-
- // Check media
- if(is_null($quest['questsmedia_id'])) {
- $this->redirect($this->linker->link(array('grafics','charactergroup.jpg')));
- }
-
- // Get media
- $media = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
-
- // Get file
- $file = $this->getMediaFile($media, 'charactergroupsquest');
- if(is_null($file)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('media', $media);
- $this->set('file', $file);
- }
-
-
-
-
- /**
- * Determine file information and set the HTTP-header for
- * caching accordingly.
- *
- * @param string $fileName Filename
- * @return boolean HTTP-status 304 was set (in cache)
- */
- private function setCacheHeaders($fileName)
- {
- // Determine last change of file
- $fileLastModified = gmdate('r', filemtime($fileName));
-
- // Generate E-Tag
- $fileEtag = hash('sha256', $fileLastModified.$fileName);
-
-
- // Set header
- $this->response->addHeader("Last-Modified: ".$fileLastModified);
- $this->response->addHeader("Etag: ".$fileEtag);
- // HTTP-status
- $headerModifiedSince = $this->request->getServerParam('HTTP_IF_MODIFIED_SINCE');
- $headerNoneMatch = $this->request->getServerParam('HTTP_IF_NONE_MATCH');
- if(
- !is_null($headerModifiedSince) && strtotime($fileLastModified) <= strtotime($headerModifiedSince) &&
- !is_null($headerNoneMatch) && $headerNoneMatch == $fileEtag
- ) {
- $this->response->setExit(true);
- $this->response->addHeader(\nre\core\WebUtils::getHttpHeader(304));
-
- return true;
- }
-
-
- return false;
- }
-
-
- /**
- * Determine the file for a medium and process it if necessary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @throws \nre\exceptions\ParamsNotValidException
- * @param array $media Medium to get file for
- * @param string $action Action for processing the media
- * @return object File for the medium (or null if medium is cached)
- */
- private function getMediaFile($media, $action=null)
- {
- // Get format
- $format = explode('/', $media['mimetype']);
- $format = $format[1];
-
- // Set content-type
- $this->response->addHeader("Content-type: ".$media['mimetype']."");
-
- // Set filename
- $media['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$media['id'];
- if(!file_exists($media['filename'])) {
- throw new \nre\exceptions\IdNotFoundException($media['id'].': '.$media['url']);
- }
-
- // Cache
- if($this->setCacheHeaders($media['filename'])) {
- return null;
- }
-
- // Load and process file
- $file = null;
- switch($action)
- {
- // No action
- case null:
- // Do not process the file
- $file = file_get_contents($media['filename']);
- break;
- case 'questgroup':
- if(!in_array(strtoupper($format), self::getImageTypes())) {
- $file = file_get_contents($media['filename']);
- }
- else
- {
- $file = self::resizeImage(
- $media['filename'],
- $format,
- \nre\configs\AppConfig::$media['questgroup']['width'],
- \nre\configs\AppConfig::$media['questgroup']['height']
- );
- }
- break;
- case 'avatar':
- $file = self::resizeImage(
- $media['filename'],
- $format,
- \nre\configs\AppConfig::$media['avatar']['width'],
- \nre\configs\AppConfig::$media['avatar']['height']
- );
- break;
- case 'charactergroup':
- $file = self::resizeImage(
- $media['filename'],
- $format,
- \nre\configs\AppConfig::$media['charactergroup']['width'],
- \nre\configs\AppConfig::$media['charactergroup']['height']
- );
- break;
- case 'charactergroupsquest':
- $file = self::resizeImage(
- $media['filename'],
- $format,
- \nre\configs\AppConfig::$media['charactergroupsquest']['width'],
- \nre\configs\AppConfig::$media['charactergroupsquest']['height']
- );
- break;
- default:
- throw new ParamsNotValidException($action);
- break;
- }
-
-
- // Return file
- return $file;
- }
-
-
- /**
- * Get supported image types.
- *
- * @return array List of supported image types
- */
- private static function getImageTypes()
- {
- $im = new \Imagick();
-
-
- return $im->queryFormats();
- }
-
-
- /**
- * Resize an image.
- *
- * @param string $fileName Absolute pathname of image to resize
- * @param string $mimeType Mimetype of target image
- * @param int $width Max. width to resize to
- * @param int $height Max. height to resize to
- * @return mixed Resized image
- */
- private static function resizeImage($fileName, $mimeType, $width, $height)
- {
- // Read image from cache
- $tempFileName = ROOT.DS.\nre\configs\AppConfig::$dirs['temporary'].DS.'media-'.basename($fileName).'-'.$width.'x'.$height;
- if(file_exists($tempFileName))
- {
- // Check age of file
- if(filemtime($fileName) > filemtime($tempFileName)) {
- // Too old, delete
- unlink($tempFileName);
- }
- else {
- // Valid, read and return
- return file_get_contents($tempFileName);
- }
- }
-
-
- // ImageMagick
- $im = new \Imagick($fileName);
-
- // Calculate new size
- $geometry = $im->getImageGeometry();
- if($geometry['width'] < $width) {
- $width = $geometry['width'];
- }
- if($geometry['height'] < $height) {
- $height = $geometry['width'];
- }
-
- // Process
- $im->thumbnailImage($width, $height, true);
- $im->contrastImage(1);
- $im->setImageFormat($mimeType);
-
- // Save temporary file
- $im->writeImage($tempFileName);
-
-
- // Return resized image
- return $im;
- }
-
- }
+
+
+ /**
+ * Action: seminary.
+ *
+ * Display a Seminary medium.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of the Seminary
+ * @param string $mediaUrl URL-name of the medium
+ * @param string $action Action for processing the media
+ */
+ public function seminary($seminaryUrl, $mediaUrl, $action=null)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Media
+ $media = $this->Media->getSeminaryMediaByUrl($seminary['id'], $mediaUrl);
+
+ // Get file
+ $file = $this->getMediaFile($media, $action);
+ if(is_null($file)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
+ }
+
+
+ /**
+ * Action: avatar.
+ *
+ * Display an Avatar as full size or portrait.
+ *
+ * @throws \nre\exceptions\ParamsNotValidException
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of the Seminary
+ * @param string $charactertypeUrl URL-title of Character type
+ * @param int $xplevel XP-level
+ * @param string $action Size to show (avatar or portrait)
+ */
+ public function avatar($seminaryUrl, $charactertypeUrl, $xplevel, $action='avatar')
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Avatar
+ $avatar = $this->Avatars->getAvatarByTypeAndLevel($seminary['id'], $charactertypeUrl, $xplevel);
+
+ // Get media
+ switch($action)
+ {
+ case null:
+ case 'avatar':
+ $media = $this->Media->getSeminaryMediaById($avatar['avatarpicture_id']);
+ $file = $this->getMediaFile($media, 'avatar');
+ break;
+ case 'portrait':
+ $media = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
+ $file = $this->getMediaFile($media);
+ break;
+ default:
+ throw new \nre\exceptions\ParamsNotValidException($action);
+ break;
+ }
+
+ // Get file
+ if(is_null($file)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
+ }
+
+
+ /**
+ * Action: achievement
+ *
+ * Display the achievement of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of the Seminary
+ * @param string $achievementUrl URL-title of the Achievement
+ * @param string $action Action for processing the media
+ */
+ public function achievement($seminaryUrl, $achievementUrl, $locked=null)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character
+ $character = SeminaryController::$character;
+
+ // Get Achievement
+ $achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
+
+ // Get media
+ switch($locked)
+ {
+ case null:
+ if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) == 0) {
+ if(is_null($character) || !$this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id'])) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ }
+ $index = 'achieved_achievementsmedia_id';
+ break;
+ case 'locked':
+ $index = 'unachieved_achievementsmedia_id';
+ break;
+ default:
+ throw new \nre\exceptions\ParamsNotValidException($locked);
+ break;
+ }
+ if(is_null($achievement[$index])) {
+ throw new \nre\exceptions\IdNotFoundException($achievementUrl);
+ }
+ $media = $this->Media->getSeminaryMediaById($achievement[$index]);
+
+ // Get file
+ $file = $this->getMediaFile($media, null);
+ if(is_null($file)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
+ }
+
+
+ /**
+ * Action: charactergroup
+ *
+ * Display the icon for a Character group of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $groupUrl URL-Title of a Character group
+ */
+ public function charactergroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character group
+ $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
+
+ // Check media
+ if(is_null($group['charactergroupsmedia_id'])) {
+ $this->redirect($this->linker->link(array('grafics','charactergroup.jpg')));
+ }
+
+ // Get media
+ $media = $this->Media->getSeminaryMediaById($group['charactergroupsmedia_id']);
+
+ // Get file
+ $file = $this->getMediaFile($media, 'charactergroup');
+ if(is_null($file)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
+ }
+
+
+ /**
+ * Action: charactergroupsquest
+ *
+ * Display the icon for a Character groups Quest of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $questUrl URL-Title of a Character groups Quest
+ */
+ public function charactergroupsquest($seminaryUrl, $groupsgroupUrl, $questUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character groups Quests
+ $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
+
+ // Check media
+ if(is_null($quest['questsmedia_id'])) {
+ $this->redirect($this->linker->link(array('grafics','charactergroup.jpg')));
+ }
+
+ // Get media
+ $media = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
+
+ // Get file
+ $file = $this->getMediaFile($media, 'charactergroupsquest');
+ if(is_null($file)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('media', $media);
+ $this->set('file', $file);
+ }
+
+
+
+
+ /**
+ * Determine file information and set the HTTP-header for
+ * caching accordingly.
+ *
+ * @param string $fileName Filename
+ * @return boolean HTTP-status 304 was set (in cache)
+ */
+ private function setCacheHeaders($fileName)
+ {
+ // Determine last change of file
+ $fileLastModified = gmdate('r', filemtime($fileName));
+
+ // Generate E-Tag
+ $fileEtag = hash('sha256', $fileLastModified.$fileName);
+
+
+ // Set header
+ $this->response->addHeader("Last-Modified: ".$fileLastModified);
+ $this->response->addHeader("Etag: ".$fileEtag);
+ // HTTP-status
+ $headerModifiedSince = $this->request->getServerParam('HTTP_IF_MODIFIED_SINCE');
+ $headerNoneMatch = $this->request->getServerParam('HTTP_IF_NONE_MATCH');
+ if(
+ !is_null($headerModifiedSince) && strtotime($fileLastModified) <= strtotime($headerModifiedSince) &&
+ !is_null($headerNoneMatch) && $headerNoneMatch == $fileEtag
+ ) {
+ $this->response->setExit(true);
+ $this->response->addHeader(\nre\core\WebUtils::getHttpHeader(304));
+
+ return true;
+ }
+
+
+ return false;
+ }
+
+
+ /**
+ * Determine the file for a medium and process it if necessary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @throws \nre\exceptions\ParamsNotValidException
+ * @param array $media Medium to get file for
+ * @param string $action Action for processing the media
+ * @return object File for the medium (or null if medium is cached)
+ */
+ private function getMediaFile($media, $action=null)
+ {
+ // Get format
+ $format = explode('/', $media['mimetype']);
+ $format = $format[1];
+
+ // Set content-type
+ $this->response->addHeader("Content-type: ".$media['mimetype']."");
+
+ // Set filename
+ $media['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$media['id'];
+ if(!file_exists($media['filename'])) {
+ throw new \nre\exceptions\IdNotFoundException($media['id'].': '.$media['url']);
+ }
+
+ // Cache
+ if($this->setCacheHeaders($media['filename'])) {
+ return null;
+ }
+
+ // Load and process file
+ $file = null;
+ switch($action)
+ {
+ // No action
+ case null:
+ // Do not process the file
+ $file = file_get_contents($media['filename']);
+ break;
+ case 'questgroup':
+ if(!in_array(strtoupper($format), self::getImageTypes())) {
+ $file = file_get_contents($media['filename']);
+ }
+ else
+ {
+ $file = self::resizeImage(
+ $media['filename'],
+ $format,
+ \nre\configs\AppConfig::$media['questgroup']['width'],
+ \nre\configs\AppConfig::$media['questgroup']['height']
+ );
+ }
+ break;
+ case 'avatar':
+ $file = self::resizeImage(
+ $media['filename'],
+ $format,
+ \nre\configs\AppConfig::$media['avatar']['width'],
+ \nre\configs\AppConfig::$media['avatar']['height']
+ );
+ break;
+ case 'charactergroup':
+ $file = self::resizeImage(
+ $media['filename'],
+ $format,
+ \nre\configs\AppConfig::$media['charactergroup']['width'],
+ \nre\configs\AppConfig::$media['charactergroup']['height']
+ );
+ break;
+ case 'charactergroupsquest':
+ $file = self::resizeImage(
+ $media['filename'],
+ $format,
+ \nre\configs\AppConfig::$media['charactergroupsquest']['width'],
+ \nre\configs\AppConfig::$media['charactergroupsquest']['height']
+ );
+ break;
+ default:
+ throw new ParamsNotValidException($action);
+ break;
+ }
+
+
+ // Return file
+ return $file;
+ }
+
+
+ /**
+ * Get supported image types.
+ *
+ * @return array List of supported image types
+ */
+ private static function getImageTypes()
+ {
+ $im = new \Imagick();
+
+
+ return $im->queryFormats();
+ }
+
+
+ /**
+ * Resize an image.
+ *
+ * @param string $fileName Absolute pathname of image to resize
+ * @param string $mimeType Mimetype of target image
+ * @param int $width Max. width to resize to
+ * @param int $height Max. height to resize to
+ * @return mixed Resized image
+ */
+ private static function resizeImage($fileName, $mimeType, $width, $height)
+ {
+ // Read image from cache
+ $tempFileName = ROOT.DS.\nre\configs\AppConfig::$dirs['temporary'].DS.'media-'.basename($fileName).'-'.$width.'x'.$height;
+ if(file_exists($tempFileName))
+ {
+ // Check age of file
+ if(filemtime($fileName) > filemtime($tempFileName)) {
+ // Too old, delete
+ unlink($tempFileName);
+ }
+ else {
+ // Valid, read and return
+ return file_get_contents($tempFileName);
+ }
+ }
+
+
+ // ImageMagick
+ $im = new \Imagick($fileName);
+
+ // Calculate new size
+ $geometry = $im->getImageGeometry();
+ if($geometry['width'] < $width) {
+ $width = $geometry['width'];
+ }
+ if($geometry['height'] < $height) {
+ $height = $geometry['width'];
+ }
+
+ // Process
+ $im->thumbnailImage($width, $height, true);
+ $im->contrastImage(1);
+ $im->setImageFormat($mimeType);
+
+ // Save temporary file
+ $im->writeImage($tempFileName);
+
+
+ // Return resized image
+ return $im;
+ }
+
+ }
?>
diff --git a/controllers/MenuController.inc b/controllers/MenuController.inc
index 2a506d71..353d5fc6 100644
--- a/controllers/MenuController.inc
+++ b/controllers/MenuController.inc
@@ -1,52 +1,52 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to display a menu.
- *
- * @author Oliver Hanraths
- */
- class MenuController extends \hhu\z\Controller
- {
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Set userdata
- $this->set('loggedUser', IntermediateController::$user);
- $this->set('loggedCharacter', SeminaryController::$character);
- $this->set('loggedSeminary', SeminaryController::$seminary);
- }
-
-
- /**
- * Action: index.
- */
- public function index()
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to display a menu.
+ *
+ * @author Oliver Hanraths
+ */
+ class MenuController extends \hhu\z\Controller
+ {
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Set userdata
+ $this->set('loggedUser', IntermediateController::$user);
+ $this->set('loggedCharacter', SeminaryController::$character);
+ $this->set('loggedSeminary', SeminaryController::$seminary);
+ }
+
+
+ /**
+ * Action: index.
+ */
+ public function index()
+ {
+ }
+
+ }
?>
diff --git a/controllers/QuestgroupsController.inc b/controllers/QuestgroupsController.inc
index b73b8e8d..6b53ac7c 100644
--- a/controllers/QuestgroupsController.inc
+++ b/controllers/QuestgroupsController.inc
@@ -1,590 +1,590 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the QuestgroupsAgent to display Questgroups.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupsController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'questgroupshierarchy', 'questgroups', 'questgrouptexts', 'quests', 'questtexts', 'media');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'questgroup' => array('admin', 'moderator', 'user'),
- 'create' => array('admin', 'moderator', 'user'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'edittexts' => array('admin', 'moderator', 'user'),
- 'moveup' => array('admin', 'moderator', 'user'),
- 'movedown' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'questgroup' => array('admin', 'moderator', 'user'),
- 'create' => array('admin'),
- 'edit' => array('admin', 'moderator'),
- 'edittexts' => array('admin', 'moderator'),
- 'moveup' => array('admin'),
- 'movedown' => array('admin'),
- 'delete' => array('admin')
- );
-
-
-
-
- /**
- * Action: questgroup.
- *
- * Display a Questgroup and its data.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $questgroupUrl URL-Title of a Questgroup
- */
- public function questgroup($seminaryUrl, $questgroupUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
-
- // Get Questgrouphierarchy
- $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
-
- // Get Character
- $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
-
- // Check permission
- if(count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
- {
- // Only check permissions if Character has not entered Quest before
- if(!$this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], $character['id']))
- {
- $previousQuestgroup = $this->Questgroups->getPreviousQuestgroup($seminary['id'], $questgroup['id']);
- if(!is_null($previousQuestgroup)) {
- if(!$this->Questgroups->hasCharacterSolvedQuestgroup($previousQuestgroup['id'], $character['id'])) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- }
- }
- }
-
- // Set status “entered”
- $this->Questgroups->setQuestgroupEntered($questgroup['id'], $character['id']);
-
- // Get child Questgroupshierarchy
- $childQuestgroupshierarchy = null;
- if(!empty($questgroup['hierarchy']))
- {
- $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['hierarchy']['id']);
- foreach($childQuestgroupshierarchy as &$hierarchy)
- {
- // Get Questgroups
- $hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
-
- // Get additional data
- foreach($hierarchy['questgroups'] as $i => &$group)
- {
- $group['solved'] = $this->Questgroups->hasCharacterSolvedQuestgroup($group['id'], $character['id']);
-
- // Check permission of Questgroups
- if($i >= 1 && count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
- {
- if(!$hierarchy['questgroups'][$i-1]['solved'])
- {
- $hierarchy['questgroups'] = array_slice($hierarchy['questgroups'], 0, $i);
- break;
- }
- }
-
- // Get Character XPs
- $group['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($group['id'], $character['id']);
-
- // Attach related Questgroups
- $group['relatedQuestgroups'] = array();
- $relatedQuestgroups = $this->Questgroups->getRelatedQuestsgroupsOfQuestgroup($group['id']);
- foreach($relatedQuestgroups as &$relatedQuestgroup) {
- if($this->Questgroups->hasCharacterEnteredQuestgroup($relatedQuestgroup['id'], $character['id'])) {
- $group['relatedQuestgroups'][] = $this->Questgroups->getQuestgroupById($relatedQuestgroup['id']);
- }
-
- }
- }
- }
- }
-
- // Get texts
- $questgroupTexts = $this->Questgrouptexts->getQuestgroupTexts($questgroup['id']);
-
- // Media
- $picture = null;
- if(!is_null($questgroup['questgroupspicture_id']))
- {
- $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
-
- // Get Quests
- $quests = array();
- if(count($childQuestgroupshierarchy) == 0)
- {
- $currentQuest = null;
- do {
- // Get next Quest
- if(is_null($currentQuest)) {
- $currentQuest = $this->Quests->getFirstQuestOfQuestgroup($questgroup['id']);
- }
- else {
- $nextQuests = $this->Quests->getNextQuests($currentQuest['id']);
- $currentQuest = null;
- foreach($nextQuests as &$nextQuest) {
- if($this->Quests->hasCharacterEnteredQuest($nextQuest['id'], $character['id'])) {
- $currentQuest = $nextQuest;
- break;
- }
- }
- }
-
- // Add additional data
- if(!is_null($currentQuest))
- {
- // Set status
- $currentQuest['solved'] = $this->Quests->hasCharacterSolvedQuest($currentQuest['id'], $character['id']);
-
- // Attach related Questgroups
- $currentQuest['relatedQuestgroups'] = array();
- $relatedQuestgroups = $this->Questgroups->getRelatedQuestsgroupsOfQuest($currentQuest['id']);
- foreach($relatedQuestgroups as &$relatedQuestgroup)
- {
- if($this->Questgroups->hasCharacterEnteredQuestgroup($relatedQuestgroup['id'], $character['id'])) {
- $currentQuest['relatedQuestgroups'][] = $this->Questgroups->getQuestgroupById($relatedQuestgroup['id']);
- }
- }
-
- // Add Quest to Quests
- $quests[] = $currentQuest;
- }
- }
- while(!is_null($currentQuest) && ($currentQuest['solved'] || count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) > 0));
- }
-
-
- // Set titile
- if(!is_null($questgroup['hierarchy'])) {
- $this->addTitle(sprintf('%s %d: %s', $questgroup['hierarchy']['title_singular'], $questgroup['hierarchy']['questgroup_pos'], $questgroup['title']));
- }
- else {
- $this->addTitle($questgroup['title']);
- }
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('childquestgroupshierarchy', $childQuestgroupshierarchy);
- $this->set('texts', $questgroupTexts);
- $this->set('picture', $picture);
- $this->set('quests', $quests);
- }
-
-
- /**
- * Action: create.
- *
- * Create a new Questgroup.
- *
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function create($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- // Values
- $selectedQuestgroupshierarchy = null;
- $selectedQuestgroup = null;
- $title = '';
- $fields = array('title');
- $validation = array();
-
- // Check request method
- 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->Questgroups->questgroupTitleExists($seminary['id'], $title)) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
-
- // Validate Questgroupshierarchy
- try {
- $selectedQuestgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $this->request->getPostParam('questgroupshierarchy'));
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- throw new \nre\exceptions\ParamsNotValidException($this->request->getPostParam('questgroupshierarchy'));
- }
-
- // Validate Questgroup
- if(!is_null($selectedQuestgroupshierarchy['parent_questgroupshierarchy_id'])) {
- try {
- $selectedQuestgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $this->request->getPostParam('questgroup'));
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- throw new \nre\exceptions\ParamsNotValidException($this->request->getPostParam('questgroups'));
- }
- }
-
- // Validate moodpic
- $moodpic = null;
- if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $moodpic = $_FILES['moodpic'];
-
- // Check error
- if($moodpic['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $moodpic['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
- }
- elseif($moodpic['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
- }
- }
-
- // Create new Questgroup
- if($validation === true)
- {
- $questgroupId = $this->Questgroups->createQuestgroup(
- $this->Auth->getUserId(),
- $seminary['id'],
- $title
- );
- $questgroup = $this->Questgroups->getQuestgroupById($questgroupId);
-
- // Add to Hierarchy
- $this->Questgroups->addQuestgroupToHierarchy(
- $questgroupId,
- $selectedQuestgroupshierarchy['id'],
- (!is_null($selectedQuestgroup)) ? $selectedQuestgroup['id'] : null
- );
-
- // Upload moodpic
- if(!is_null($moodpic))
- {
- $mediaId = $this->Media->createQuestgrouppicture(
- $this->Auth->getUserId(),
- $seminary['id'],
- $questgroup['id'],
- sprintf('questgroupmoodpic-%s', $questgroup['url']),
- '',
- $moodpic['mimetype'],
- $moodpic['tmp_name']
- );
- if($mediaId !== false) {
- $this->Questgroups->setMoodpicForQuestgroup($questgroup['id'], $mediaId);
- }
- }
-
-
- // Redirect to new Questgroup
- $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('Create Questgroup');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('mimetypes', $mimetypes);
- $this->set('questgroupshierarchy', $selectedQuestgroupshierarchy);
- $this->set('questgroup', $selectedQuestgroup);
- $this->set('title', $title);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
+ namespace hhu\z\controllers;
- /**
- * Action: edit.
- *
- * Edit a Questgroup.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of a Seminary
- * @param string $questgroupUrl URL-title of Questgroup to edit
- */
- public function edit($seminaryUrl, $questgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
-
- // Values
- $title = $questgroup['title'];
- $fields = array('title');
- $validation = array();
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $title = $this->request->getPostParam('title');
- if($this->Questgroups->questgroupTitleExists($seminary['id'], $title, $questgroup['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
-
- // Validate moodpic
- $moodpic = null;
- if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $moodpic = $_FILES['moodpic'];
-
- // Check error
- if($moodpic['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $moodpic['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
- }
- elseif($moodpic['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
- }
- }
-
- // Edit Questgroup
- if($validation === true)
- {
- $this->Questgroups->editQuestgroup(
- $questgroup['id'],
- $title
- );
- $questgroup = $this->Questgroups->getQuestgroupById($questgroup['id']);
-
- // Upload moodpic
- if(!is_null($moodpic))
- {
- $mediaId = $this->Media->createQuestgrouppicture(
- $this->Auth->getUserId(),
- $seminary['id'],
- $questgroup['id'],
- sprintf('questgroupmoodpic-%s', $questgroup['url']),
- '',
- $moodpic['mimetype'],
- $moodpic['tmp_name']
- );
- if($mediaId !== false) {
- $this->Questgroups->setMoodpicForQuestgroup($questgroup['id'], $mediaId);
- }
- }
-
-
- // Redirect to new Questgroup
- $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
- }
- }
-
- // Media
- $picture = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
+ /**
+ * Controller of the QuestgroupsAgent to display Questgroups.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupsController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'questgroupshierarchy', 'questgroups', 'questgrouptexts', 'quests', 'questtexts', 'media');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'questgroup' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin', 'moderator', 'user'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'edittexts' => array('admin', 'moderator', 'user'),
+ 'moveup' => array('admin', 'moderator', 'user'),
+ 'movedown' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'questgroup' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin'),
+ 'edit' => array('admin', 'moderator'),
+ 'edittexts' => array('admin', 'moderator'),
+ 'moveup' => array('admin'),
+ 'movedown' => array('admin'),
+ 'delete' => array('admin')
+ );
- // Set titile
- $this->addTitleLocalized('Edit Questgroup');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('picture', $picture);
- $this->set('title', $title);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
- /**
- * Action: edittexts.
- *
- * Edit the texts of a Questgroup.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of a Seminary
- * @param string $questgroupUrl URL-title of Questgroup to edit
- */
- public function edittexts($seminaryUrl, $questgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ /**
+ * Action: questgroup.
+ *
+ * Display a Questgroup and its data.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $questgroupUrl URL-Title of a Questgroup
+ */
+ public function questgroup($seminaryUrl, $questgroupUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- // Get Questgroup texts
- $questgroupTexts = $this->Questgrouptexts->getQuestgroupTexts($questgroup['id']);
+ // Get Questgrouphierarchy
+ $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+ // Get Character
+ $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
- // Check request method
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- $texts = $this->request->getPostParam('questgrouptexts');
- $deleteTexts = $this->request->getPostParam('deletes');
- if(!is_array($deleteTexts)) {
- $deleteTexts = array();
- }
+ // Check permission
+ if(count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
+ {
+ // Only check permissions if Character has not entered Quest before
+ if(!$this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], $character['id']))
+ {
+ $previousQuestgroup = $this->Questgroups->getPreviousQuestgroup($seminary['id'], $questgroup['id']);
+ if(!is_null($previousQuestgroup)) {
+ if(!$this->Questgroups->hasCharacterSolvedQuestgroup($previousQuestgroup['id'], $character['id'])) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ }
+ }
+ }
- // Edit or delete texts
- foreach($questgroupTexts as $text)
- {
- if(array_key_exists($text['id'], $deleteTexts))
- {
- $this->Questgrouptexts->deleteQuestgrouptext($text);
- unset($texts[$text['id']]);
- }
- elseif(array_key_exists($text['id'], $texts))
- {
- $this->Questgrouptexts->editQuestgrouptext($text['id'], $texts[$text['id']]);
- unset($texts[$text['id']]);
- }
- }
+ // Set status “entered”
+ $this->Questgroups->setQuestgroupEntered($questgroup['id'], $character['id']);
- // Add new texts
- foreach($texts as $text) {
- if(!empty($text)) {
- $this->Questgrouptexts->addQuestgrouptextToQuestgroup($this->Auth->getUserId(), $questgroup['id'], $text);
- }
- }
+ // Get child Questgroupshierarchy
+ $childQuestgroupshierarchy = null;
+ if(!empty($questgroup['hierarchy']))
+ {
+ $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['hierarchy']['id']);
+ foreach($childQuestgroupshierarchy as &$hierarchy)
+ {
+ // Get Questgroups
+ $hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
- // Redirect to Questgroup
- $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
- }
+ // Get additional data
+ foreach($hierarchy['questgroups'] as $i => &$group)
+ {
+ $group['solved'] = $this->Questgroups->hasCharacterSolvedQuestgroup($group['id'], $character['id']);
- // Media
- $picture = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
+ // Check permission of Questgroups
+ if($i >= 1 && count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
+ {
+ if(!$hierarchy['questgroups'][$i-1]['solved'])
+ {
+ $hierarchy['questgroups'] = array_slice($hierarchy['questgroups'], 0, $i);
+ break;
+ }
+ }
+
+ // Get Character XPs
+ $group['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($group['id'], $character['id']);
+
+ // Attach related Questgroups
+ $group['relatedQuestgroups'] = array();
+ $relatedQuestgroups = $this->Questgroups->getRelatedQuestsgroupsOfQuestgroup($group['id']);
+ foreach($relatedQuestgroups as &$relatedQuestgroup) {
+ if($this->Questgroups->hasCharacterEnteredQuestgroup($relatedQuestgroup['id'], $character['id'])) {
+ $group['relatedQuestgroups'][] = $this->Questgroups->getQuestgroupById($relatedQuestgroup['id']);
+ }
+
+ }
+ }
+ }
+ }
+
+ // Get texts
+ $questgroupTexts = $this->Questgrouptexts->getQuestgroupTexts($questgroup['id']);
+
+ // Media
+ $picture = null;
+ if(!is_null($questgroup['questgroupspicture_id']))
+ {
+ $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
- // Set titile
- $this->addTitleLocalized('Edit Questgroup texts');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('questgrouptexts', $questgroupTexts);
- $this->set('picture', $picture);
- $this->set('mimetypes', $mimetypes);
- }
+ // Get Quests
+ $quests = array();
+ if(count($childQuestgroupshierarchy) == 0)
+ {
+ $currentQuest = null;
+ do {
+ // Get next Quest
+ if(is_null($currentQuest)) {
+ $currentQuest = $this->Quests->getFirstQuestOfQuestgroup($questgroup['id']);
+ }
+ else {
+ $nextQuests = $this->Quests->getNextQuests($currentQuest['id']);
+ $currentQuest = null;
+ foreach($nextQuests as &$nextQuest) {
+ if($this->Quests->hasCharacterEnteredQuest($nextQuest['id'], $character['id'])) {
+ $currentQuest = $nextQuest;
+ break;
+ }
+ }
+ }
+
+ // Add additional data
+ if(!is_null($currentQuest))
+ {
+ // Set status
+ $currentQuest['solved'] = $this->Quests->hasCharacterSolvedQuest($currentQuest['id'], $character['id']);
+
+ // Attach related Questgroups
+ $currentQuest['relatedQuestgroups'] = array();
+ $relatedQuestgroups = $this->Questgroups->getRelatedQuestsgroupsOfQuest($currentQuest['id']);
+ foreach($relatedQuestgroups as &$relatedQuestgroup)
+ {
+ if($this->Questgroups->hasCharacterEnteredQuestgroup($relatedQuestgroup['id'], $character['id'])) {
+ $currentQuest['relatedQuestgroups'][] = $this->Questgroups->getQuestgroupById($relatedQuestgroup['id']);
+ }
+ }
+
+ // Add Quest to Quests
+ $quests[] = $currentQuest;
+ }
+ }
+ while(!is_null($currentQuest) && ($currentQuest['solved'] || count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) > 0));
+ }
- /**
- * Action: moveup.
- *
- * Move a Questgroup up (decrement position).
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $questgroupUrl URL-title of Questgroup
- */
- public function moveup($seminaryUrl, $questgroupUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('move')))
- {
+ // Set titile
+ if(!is_null($questgroup['hierarchy'])) {
+ $this->addTitle(sprintf('%s %d: %s', $questgroup['hierarchy']['title_singular'], $questgroup['hierarchy']['questgroup_pos'], $questgroup['title']));
+ }
+ else {
+ $this->addTitle($questgroup['title']);
+ }
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('childquestgroupshierarchy', $childQuestgroupshierarchy);
+ $this->set('texts', $questgroupTexts);
+ $this->set('picture', $picture);
+ $this->set('quests', $quests);
+ }
+
+
+ /**
+ * Action: create.
+ *
+ * Create a new Questgroup.
+ *
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function create($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $selectedQuestgroupshierarchy = null;
+ $selectedQuestgroup = null;
+ $title = '';
+ $fields = array('title');
+ $validation = array();
+
+ // Check request method
+ 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->Questgroups->questgroupTitleExists($seminary['id'], $title)) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+
+ // Validate Questgroupshierarchy
+ try {
+ $selectedQuestgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $this->request->getPostParam('questgroupshierarchy'));
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ throw new \nre\exceptions\ParamsNotValidException($this->request->getPostParam('questgroupshierarchy'));
+ }
+
+ // Validate Questgroup
+ if(!is_null($selectedQuestgroupshierarchy['parent_questgroupshierarchy_id'])) {
+ try {
+ $selectedQuestgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $this->request->getPostParam('questgroup'));
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ throw new \nre\exceptions\ParamsNotValidException($this->request->getPostParam('questgroups'));
+ }
+ }
+
+ // Validate moodpic
+ $moodpic = null;
+ if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $moodpic = $_FILES['moodpic'];
+
+ // Check error
+ if($moodpic['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $moodpic['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
+ }
+ elseif($moodpic['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Create new Questgroup
+ if($validation === true)
+ {
+ $questgroupId = $this->Questgroups->createQuestgroup(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $title
+ );
+ $questgroup = $this->Questgroups->getQuestgroupById($questgroupId);
+
+ // Add to Hierarchy
+ $this->Questgroups->addQuestgroupToHierarchy(
+ $questgroupId,
+ $selectedQuestgroupshierarchy['id'],
+ (!is_null($selectedQuestgroup)) ? $selectedQuestgroup['id'] : null
+ );
+
+ // Upload moodpic
+ if(!is_null($moodpic))
+ {
+ $mediaId = $this->Media->createQuestgrouppicture(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $questgroup['id'],
+ sprintf('questgroupmoodpic-%s', $questgroup['url']),
+ '',
+ $moodpic['mimetype'],
+ $moodpic['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Questgroups->setMoodpicForQuestgroup($questgroup['id'], $mediaId);
+ }
+ }
+
+
+ // Redirect to new Questgroup
+ $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Create Questgroup');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('questgroupshierarchy', $selectedQuestgroupshierarchy);
+ $this->set('questgroup', $selectedQuestgroup);
+ $this->set('title', $title);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * Edit a Questgroup.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of a Seminary
+ * @param string $questgroupUrl URL-title of Questgroup to edit
+ */
+ public function edit($seminaryUrl, $questgroupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $title = $questgroup['title'];
+ $fields = array('title');
+ $validation = array();
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $title = $this->request->getPostParam('title');
+ if($this->Questgroups->questgroupTitleExists($seminary['id'], $title, $questgroup['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+
+ // Validate moodpic
+ $moodpic = null;
+ if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $moodpic = $_FILES['moodpic'];
+
+ // Check error
+ if($moodpic['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $moodpic['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
+ }
+ elseif($moodpic['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Edit Questgroup
+ if($validation === true)
+ {
+ $this->Questgroups->editQuestgroup(
+ $questgroup['id'],
+ $title
+ );
+ $questgroup = $this->Questgroups->getQuestgroupById($questgroup['id']);
+
+ // Upload moodpic
+ if(!is_null($moodpic))
+ {
+ $mediaId = $this->Media->createQuestgrouppicture(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $questgroup['id'],
+ sprintf('questgroupmoodpic-%s', $questgroup['url']),
+ '',
+ $moodpic['mimetype'],
+ $moodpic['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Questgroups->setMoodpicForQuestgroup($questgroup['id'], $mediaId);
+ }
+ }
+
+
+ // Redirect to new Questgroup
+ $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
+ }
+ }
+
+ // Media
+ $picture = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Questgroup');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('picture', $picture);
+ $this->set('title', $title);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edittexts.
+ *
+ * Edit the texts of a Questgroup.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of a Seminary
+ * @param string $questgroupUrl URL-title of Questgroup to edit
+ */
+ public function edittexts($seminaryUrl, $questgroupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+
+ // Get Questgroup texts
+ $questgroupTexts = $this->Questgrouptexts->getQuestgroupTexts($questgroup['id']);
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ $texts = $this->request->getPostParam('questgrouptexts');
+ $deleteTexts = $this->request->getPostParam('deletes');
+ if(!is_array($deleteTexts)) {
+ $deleteTexts = array();
+ }
+
+ // Edit or delete texts
+ foreach($questgroupTexts as $text)
+ {
+ if(array_key_exists($text['id'], $deleteTexts))
+ {
+ $this->Questgrouptexts->deleteQuestgrouptext($text);
+ unset($texts[$text['id']]);
+ }
+ elseif(array_key_exists($text['id'], $texts))
+ {
+ $this->Questgrouptexts->editQuestgrouptext($text['id'], $texts[$text['id']]);
+ unset($texts[$text['id']]);
+ }
+ }
+
+ // Add new texts
+ foreach($texts as $text) {
+ if(!empty($text)) {
+ $this->Questgrouptexts->addQuestgrouptextToQuestgroup($this->Auth->getUserId(), $questgroup['id'], $text);
+ }
+ }
+
+ // Redirect to Questgroup
+ $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
+ }
+
+ // Media
+ $picture = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Questgroup texts');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('questgrouptexts', $questgroupTexts);
+ $this->set('picture', $picture);
+ $this->set('mimetypes', $mimetypes);
+ }
+
+
+ /**
+ * Action: moveup.
+ *
+ * Move a Questgroup up (decrement position).
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $questgroupUrl URL-title of Questgroup
+ */
+ public function moveup($seminaryUrl, $questgroupUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('move')))
+ {
// Set position
$this->Questgroups->moveQuestgroup($questgroup, true);
}
@@ -603,47 +603,47 @@
$this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
}
- // Media
- $picture = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
-
- // Set titile
- $this->addTitleLocalized('Move Questgroup');
-
- // Show confirmation
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('picture', $picture);
- }
+ // Media
+ $picture = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
- /**
- * Action: movedown
- *
- * Move a Questgroup down (increment position).
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $questgroupUrl URL-title of Questgroup
- */
- public function movedown($seminaryUrl, $questgroupUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('move')))
- {
+ // Set titile
+ $this->addTitleLocalized('Move Questgroup');
+
+ // Show confirmation
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('picture', $picture);
+ }
+
+
+ /**
+ * Action: movedown
+ *
+ * Move a Questgroup down (increment position).
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $questgroupUrl URL-title of Questgroup
+ */
+ public function movedown($seminaryUrl, $questgroupUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('move')))
+ {
// Set position
$this->Questgroups->moveQuestgroup($questgroup, false);
}
@@ -662,96 +662,96 @@
$this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
}
- // Media
- $picture = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
-
- // Set titile
- $this->addTitleLocalized('Move Questgroup');
-
- // Show confirmation
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('picture', $picture);
- }
+ // Media
+ $picture = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
- /**
- * Action: delete.
- *
- * Delete a Questgroup.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $questgroupUrl URL-Title of a Questgroup
- */
- public function delete($seminaryUrl, $questgroupUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
-
- // Get Questgrouphierarchy
- $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
+ // Set titile
+ $this->addTitleLocalized('Move Questgroup');
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete Questgroup
- $this->Questgroups->deleteQuestgroup($questgroup['id']);
-
- // Redirect
- if(!is_null($questgroup['hierarchy']))
- {
- // Parent Questgroup
- if(is_null($questgroup['hierarchy']['parent_questgroup_id'])) {
- $this->redirect($this->linker->link(array('simenaries', 'seminary', $seminary['url'])));
- }
- else
- {
- $parentQuestgroup = $this->Questgroups->getQuestgroupById($questgroup['hierarchy']['parent_questgroup_id']);
- $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $parentQuestgroup['url']), 1));
- }
- }
- else
- {
- // Related Questgroup
- $questtexts = $this->Questtexts->getRelatedQuesttextsForQuestgroup($questgroup['id']);
- $questtext = $this->Questtexts->pickQuesttextLastEnteredByCharacter(\hhu\z\controllers\SeminaryController::$character['id'], $questtexts);
- $quest = $this->Quests->getQuestById($questtext['quest_id']);
- $relatedQuestgroup = $this->Questgroups->getQuestgroupById($quest['questgroup_id']);
- $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $relatedQuestgroup['url']), 1));
- }
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
- }
+ // Show confirmation
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('picture', $picture);
+ }
- // Media
- $picture = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
-
- // Set titile
- $this->addTitleLocalized('Delete Questgroup');
-
- // Show confirmation
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('picture', $picture);
- }
-
- }
+
+ /**
+ * Action: delete.
+ *
+ * Delete a Questgroup.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $questgroupUrl URL-Title of a Questgroup
+ */
+ public function delete($seminaryUrl, $questgroupUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+
+ // Get Questgrouphierarchy
+ $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete Questgroup
+ $this->Questgroups->deleteQuestgroup($questgroup['id']);
+
+ // Redirect
+ if(!is_null($questgroup['hierarchy']))
+ {
+ // Parent Questgroup
+ if(is_null($questgroup['hierarchy']['parent_questgroup_id'])) {
+ $this->redirect($this->linker->link(array('simenaries', 'seminary', $seminary['url'])));
+ }
+ else
+ {
+ $parentQuestgroup = $this->Questgroups->getQuestgroupById($questgroup['hierarchy']['parent_questgroup_id']);
+ $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $parentQuestgroup['url']), 1));
+ }
+ }
+ else
+ {
+ // Related Questgroup
+ $questtexts = $this->Questtexts->getRelatedQuesttextsForQuestgroup($questgroup['id']);
+ $questtext = $this->Questtexts->pickQuesttextLastEnteredByCharacter(\hhu\z\controllers\SeminaryController::$character['id'], $questtexts);
+ $quest = $this->Quests->getQuestById($questtext['quest_id']);
+ $relatedQuestgroup = $this->Questgroups->getQuestgroupById($quest['questgroup_id']);
+ $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $relatedQuestgroup['url']), 1));
+ }
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('questgroup', $seminary['url'], $questgroup['url']), 1));
+ }
+
+ // Media
+ $picture = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $picture = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete Questgroup');
+
+ // Show confirmation
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('picture', $picture);
+ }
+
+ }
?>
diff --git a/controllers/QuestgroupshierarchyController.inc b/controllers/QuestgroupshierarchyController.inc
index b50cad5e..db3cb52c 100644
--- a/controllers/QuestgroupshierarchyController.inc
+++ b/controllers/QuestgroupshierarchyController.inc
@@ -1,346 +1,346 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the QuestgroupsAgent to display Questgroups.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupshierarchyController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'questgroupshierarchy', 'questgroups');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'create' => array('admin', 'moderator', 'user'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'moveup' => array('admin', 'moderator', 'user'),
- 'movedown' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'create' => array('admin'),
- 'edit' => array('admin'),
- 'moveup' => array('admin'),
- 'movedown' => array('admin'),
- 'delete' => array('admin')
- );
-
-
-
-
- /**
- * Action: create.
- *
- * Create a new Questgroupshierarchy.
- *
- * @param string $seminaryUrl URL-title of a Seminary
- */
- public function create($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get parent Questgroupshierarchy
- $parentQuestgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminary['id']);
-
- // Values
- $titleSingular = '';
- $titlePlural = '';
- $validation = array();
-
- // Create Questgroupshierarchy
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
- {
- // Get params and validate them
- $titleSingular = $this->request->getPostParam('title_singular');
- $validation = $this->Validation->addValidationResults(
- $validation,
- 'titleSingular',
- $this->Validation->validate($titleSingular, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
- );
- if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titleSingular, $seminary['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'titleSingular', 'exist', true);
- }
- $titlePlural = $this->request->getPostParam('title_plural');
- $validation = $this->Validation->addValidationResults(
- $validation,
- 'titlePlural',
- $this->Validation->validate($titlePlural, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
- );
- if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titlePlural, $seminary['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'titlePlural', 'exist', true);
- }
-
- // Validate parent Questgroupshierarchy
- $parentQuestgroupshierarchyIndex = null;
- foreach($parentQuestgroupshierarchy as $index => &$parentHierarchy)
- {
- $parentHierarchy['selected'] = ($parentHierarchy['url'] == $this->request->getPostParam('parent'));
- if($parentHierarchy['selected']) {
- $parentQuestgroupshierarchyIndex = $index;
- }
- }
-
- // Create new Questgroupshierarchy
- if($validation === true)
- {
- $questgroupshierarchyId = $this->Questgroupshierarchy->createQuestgroupshierarchy(
- $this->Auth->getUserId(),
- $seminary['id'],
- (!is_null($parentQuestgroupshierarchyIndex) ? $parentQuestgroupshierarchy[$parentQuestgroupshierarchyIndex]['id'] : null),
- $titleSingular,
- $titlePlural
- );
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyById($questgroupshierarchyId);
-
- // Redirect
- $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
- }
- }
-
- // Get validation settings
- $validationSettings = array(
- 'title' => \nre\configs\AppConfig::$validation['title']
- );
-
-
- // Set titile
- $this->addTitleLocalized('Create Questgroupshierarchy');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('titleSingular', $titleSingular);
- $this->set('titlePlural', $titlePlural);
- $this->set('parentQuestgroupshierarchy', $parentQuestgroupshierarchy);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: edit.
- *
- * Edit a Questgroupshierarchy.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
- */
- public function edit($seminaryUrl, $questgroupshierarchyUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroupshierarchy
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
-
- // Values
- $titleSingular = $questgroupshierarchy['title_singular'];
- $titlePlural = $questgroupshierarchy['title_plural'];
- $validation = array();
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $titleSingular = $this->request->getPostParam('title_singular');
- $validation = $this->Validation->addValidationResults(
- $validation,
- 'titleSingular',
- $this->Validation->validate($titleSingular, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
- );
- if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titleSingular, $seminary['id'], $questgroupshierarchy['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'titleSingular', 'exist', true);
- }
- $titlePlural = $this->request->getPostParam('title_plural');
- $validation = $this->Validation->addValidationResults(
- $validation,
- 'titlePlural',
- $this->Validation->validate($titlePlural, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
- );
- if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titlePlural, $seminary['id'], $questgroupshierarchy['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'titlePlural', 'exist', true);
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
-
- // Edit Questgroup
- if($validation === true)
- {
- $this->Questgroupshierarchy->editQuestgroupshierarchy(
- $questgroupshierarchy['id'],
- $titleSingular,
- $titlePlural
- );
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyById($questgroupshierarchy['id']);
-
- // Redirect to Seminary page
- $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
- }
- }
-
- // Get validation settings
- $validationSettings = array(
- 'title' => \nre\configs\AppConfig::$validation['title']
- );
-
-
- // Set titile
- $this->addTitleLocalized('Edit Questgroupshierarchy');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('titleSingular', $titleSingular);
- $this->set('titlePlural', $titlePlural);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: moveup.
- *
- * Move a Questgroupshierarchy up (decrement position).
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
- */
- public function moveup($seminaryUrl, $questgroupshierarchyUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroupshierarchy
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
-
- // Set position
- $this->Questgroupshierarchy->moveQuestgroupshierarchy($questgroupshierarchy, true);
-
-
- // Redirect
- $referer = $this->request->getGetParam('referer');
- if(!is_null($referer))
- {
- try {
- $questgroup = $this->Questgroups->getQuestgroupById($referer);
- $this->redirect($this->linker->link(array('questgroups', 'questgroup', $seminary['url'], $questgroup['url'])));
- }
- catch(IdNotFoundException $e) {
- }
- }
- $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
- }
-
-
- /**
- * Action: movedown.
- *
- * Move a Questgroupshierarchy down (increment position).
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
- */
- public function movedown($seminaryUrl, $questgroupshierarchyUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroupshierarchy
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
-
- // Set position
- $this->Questgroupshierarchy->moveQuestgroupshierarchy($questgroupshierarchy, false);
-
-
- // Redirect
- $referer = $this->request->getGetParam('referer');
- if(!is_null($referer))
- {
- try {
- $questgroup = $this->Questgroups->getQuestgroupById($referer);
- $this->redirect($this->linker->link(array('questgroups', 'questgroup', $seminary['url'], $questgroup['url'])));
- }
- catch(IdNotFoundException $e) {
- }
- }
- $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
- }
-
-
- /**
- * Action: delete.
- *
- * Delete a Questgroupshierarchy.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
- */
- public function delete($seminaryUrl, $questgroupshierarchyUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroupshierarchy
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete Questgroupshierarchy
- $this->Questgroupshierarchy->deleteQuestgroupshierarchy($questgroupshierarchy['id']);
- }
-
- // Redirect to Seminary page
- $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Delete Questgroupshierarchy');
-
- // Show confirmation
- $this->set('seminary', $seminary);
- $this->set('questgroupshierarchy', $questgroupshierarchy);
- }
-
- }
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the QuestgroupsAgent to display Questgroups.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupshierarchyController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'questgroupshierarchy', 'questgroups');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'create' => array('admin', 'moderator', 'user'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'moveup' => array('admin', 'moderator', 'user'),
+ 'movedown' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'create' => array('admin'),
+ 'edit' => array('admin'),
+ 'moveup' => array('admin'),
+ 'movedown' => array('admin'),
+ 'delete' => array('admin')
+ );
+
+
+
+
+ /**
+ * Action: create.
+ *
+ * Create a new Questgroupshierarchy.
+ *
+ * @param string $seminaryUrl URL-title of a Seminary
+ */
+ public function create($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get parent Questgroupshierarchy
+ $parentQuestgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminary['id']);
+
+ // Values
+ $titleSingular = '';
+ $titlePlural = '';
+ $validation = array();
+
+ // Create Questgroupshierarchy
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
+ {
+ // Get params and validate them
+ $titleSingular = $this->request->getPostParam('title_singular');
+ $validation = $this->Validation->addValidationResults(
+ $validation,
+ 'titleSingular',
+ $this->Validation->validate($titleSingular, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
+ );
+ if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titleSingular, $seminary['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'titleSingular', 'exist', true);
+ }
+ $titlePlural = $this->request->getPostParam('title_plural');
+ $validation = $this->Validation->addValidationResults(
+ $validation,
+ 'titlePlural',
+ $this->Validation->validate($titlePlural, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
+ );
+ if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titlePlural, $seminary['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'titlePlural', 'exist', true);
+ }
+
+ // Validate parent Questgroupshierarchy
+ $parentQuestgroupshierarchyIndex = null;
+ foreach($parentQuestgroupshierarchy as $index => &$parentHierarchy)
+ {
+ $parentHierarchy['selected'] = ($parentHierarchy['url'] == $this->request->getPostParam('parent'));
+ if($parentHierarchy['selected']) {
+ $parentQuestgroupshierarchyIndex = $index;
+ }
+ }
+
+ // Create new Questgroupshierarchy
+ if($validation === true)
+ {
+ $questgroupshierarchyId = $this->Questgroupshierarchy->createQuestgroupshierarchy(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ (!is_null($parentQuestgroupshierarchyIndex) ? $parentQuestgroupshierarchy[$parentQuestgroupshierarchyIndex]['id'] : null),
+ $titleSingular,
+ $titlePlural
+ );
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyById($questgroupshierarchyId);
+
+ // Redirect
+ $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array(
+ 'title' => \nre\configs\AppConfig::$validation['title']
+ );
+
+
+ // Set titile
+ $this->addTitleLocalized('Create Questgroupshierarchy');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('titleSingular', $titleSingular);
+ $this->set('titlePlural', $titlePlural);
+ $this->set('parentQuestgroupshierarchy', $parentQuestgroupshierarchy);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * Edit a Questgroupshierarchy.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
+ */
+ public function edit($seminaryUrl, $questgroupshierarchyUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroupshierarchy
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
+
+ // Values
+ $titleSingular = $questgroupshierarchy['title_singular'];
+ $titlePlural = $questgroupshierarchy['title_plural'];
+ $validation = array();
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $titleSingular = $this->request->getPostParam('title_singular');
+ $validation = $this->Validation->addValidationResults(
+ $validation,
+ 'titleSingular',
+ $this->Validation->validate($titleSingular, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
+ );
+ if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titleSingular, $seminary['id'], $questgroupshierarchy['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'titleSingular', 'exist', true);
+ }
+ $titlePlural = $this->request->getPostParam('title_plural');
+ $validation = $this->Validation->addValidationResults(
+ $validation,
+ 'titlePlural',
+ $this->Validation->validate($titlePlural, \nre\configs\AppConfig::$validation['questgroupshierarchytitle'])
+ );
+ if($this->Questgroupshierarchy->questgroupshierarchyTitleSingularExists($titlePlural, $seminary['id'], $questgroupshierarchy['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'titlePlural', 'exist', true);
+ }
+
+
+ // Edit Questgroup
+ if($validation === true)
+ {
+ $this->Questgroupshierarchy->editQuestgroupshierarchy(
+ $questgroupshierarchy['id'],
+ $titleSingular,
+ $titlePlural
+ );
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyById($questgroupshierarchy['id']);
+
+ // Redirect to Seminary page
+ $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array(
+ 'title' => \nre\configs\AppConfig::$validation['title']
+ );
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Questgroupshierarchy');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('titleSingular', $titleSingular);
+ $this->set('titlePlural', $titlePlural);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: moveup.
+ *
+ * Move a Questgroupshierarchy up (decrement position).
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
+ */
+ public function moveup($seminaryUrl, $questgroupshierarchyUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroupshierarchy
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
+
+ // Set position
+ $this->Questgroupshierarchy->moveQuestgroupshierarchy($questgroupshierarchy, true);
+
+
+ // Redirect
+ $referer = $this->request->getGetParam('referer');
+ if(!is_null($referer))
+ {
+ try {
+ $questgroup = $this->Questgroups->getQuestgroupById($referer);
+ $this->redirect($this->linker->link(array('questgroups', 'questgroup', $seminary['url'], $questgroup['url'])));
+ }
+ catch(IdNotFoundException $e) {
+ }
+ }
+ $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
+ }
+
+
+ /**
+ * Action: movedown.
+ *
+ * Move a Questgroupshierarchy down (increment position).
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
+ */
+ public function movedown($seminaryUrl, $questgroupshierarchyUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroupshierarchy
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
+
+ // Set position
+ $this->Questgroupshierarchy->moveQuestgroupshierarchy($questgroupshierarchy, false);
+
+
+ // Redirect
+ $referer = $this->request->getGetParam('referer');
+ if(!is_null($referer))
+ {
+ try {
+ $questgroup = $this->Questgroups->getQuestgroupById($referer);
+ $this->redirect($this->linker->link(array('questgroups', 'questgroup', $seminary['url'], $questgroup['url'])));
+ }
+ catch(IdNotFoundException $e) {
+ }
+ }
+ $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * Delete a Questgroupshierarchy.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $questgroupshierarchyUrl URL-title of Questgroupshierarchy
+ */
+ public function delete($seminaryUrl, $questgroupshierarchyUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroupshierarchy
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyByUrl($seminary['id'], $questgroupshierarchyUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete Questgroupshierarchy
+ $this->Questgroupshierarchy->deleteQuestgroupshierarchy($questgroupshierarchy['id']);
+ }
+
+ // Redirect to Seminary page
+ $this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete Questgroupshierarchy');
+
+ // Show confirmation
+ $this->set('seminary', $seminary);
+ $this->set('questgroupshierarchy', $questgroupshierarchy);
+ }
+
+ }
?>
diff --git a/controllers/QuestgroupshierarchypathController.inc b/controllers/QuestgroupshierarchypathController.inc
index 907017d5..3ced4e25 100644
--- a/controllers/QuestgroupshierarchypathController.inc
+++ b/controllers/QuestgroupshierarchypathController.inc
@@ -1,91 +1,91 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of QuestgroupshierarchypathAgent to display the
- * Questgroups hierarchy path.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupshierarchypathController extends \hhu\z\Controller
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'questgroups', 'questgroupshierarchy', 'quests', 'questtexts');
-
-
-
-
- /**
- * Action: index.
- *
- * Calculate and show the hierarchy path of a Questgroup.
- *
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $questgroupUrl URL-Title of a Questgroup
- * @param boolean $showGroup Show the current group itself
- */
- public function index($seminaryUrl, $questgroupUrl, $showGroup=false)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
-
- // Get parent Questgrouphierarchy
- $currentQuestgroup = $questgroup;
- $parentQuestgroupshierarchy = array();
- if($showGroup) {
- array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
- }
- if(is_null($questgroup['hierarchy']))
- {
- // Get related Questgroup
- $questtexts = $this->Questtexts->getRelatedQuesttextsForQuestgroup($currentQuestgroup['id']);
- $questtext = $this->Questtexts->pickQuesttextLastEnteredByCharacter(\hhu\z\controllers\SeminaryController::$character['id'], $questtexts);
- $quest = $this->Quests->getQuestById($questtext['quest_id']);
- $currentQuestgroup = $this->Questgroups->getQuestgroupById($quest['questgroup_id']);
- $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
- $quest['questgroup'] = $currentQuestgroup;
-
- // Use Hierarchy name for optional Questgroup
- if(!empty($parentQuestgroupshierarchy)) {
- $parentQuestgroupshierarchy[0]['hierarchy'] = $currentQuestgroup['hierarchy'];
- unset($parentQuestgroupshierarchy[0]['hierarchy']['questgroup_pos']);
- }
-
- array_unshift($parentQuestgroupshierarchy, $quest);
- array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
- }
- while(!empty($currentQuestgroup['hierarchy']) && !is_null($currentQuestgroup['hierarchy']['parent_questgroup_id']))
- {
- $currentQuestgroup = $this->Questgroups->GetQuestgroupById($currentQuestgroup['hierarchy']['parent_questgroup_id']);
- $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
- array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
- }
-
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('parentquestgroupshierarchy', $parentQuestgroupshierarchy);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of QuestgroupshierarchypathAgent to display the
+ * Questgroups hierarchy path.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupshierarchypathController extends \hhu\z\Controller
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'questgroups', 'questgroupshierarchy', 'quests', 'questtexts');
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * Calculate and show the hierarchy path of a Questgroup.
+ *
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $questgroupUrl URL-Title of a Questgroup
+ * @param boolean $showGroup Show the current group itself
+ */
+ public function index($seminaryUrl, $questgroupUrl, $showGroup=false)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
+
+ // Get parent Questgrouphierarchy
+ $currentQuestgroup = $questgroup;
+ $parentQuestgroupshierarchy = array();
+ if($showGroup) {
+ array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
+ }
+ if(is_null($questgroup['hierarchy']))
+ {
+ // Get related Questgroup
+ $questtexts = $this->Questtexts->getRelatedQuesttextsForQuestgroup($currentQuestgroup['id']);
+ $questtext = $this->Questtexts->pickQuesttextLastEnteredByCharacter(\hhu\z\controllers\SeminaryController::$character['id'], $questtexts);
+ $quest = $this->Quests->getQuestById($questtext['quest_id']);
+ $currentQuestgroup = $this->Questgroups->getQuestgroupById($quest['questgroup_id']);
+ $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
+ $quest['questgroup'] = $currentQuestgroup;
+
+ // Use Hierarchy name for optional Questgroup
+ if(!empty($parentQuestgroupshierarchy)) {
+ $parentQuestgroupshierarchy[0]['hierarchy'] = $currentQuestgroup['hierarchy'];
+ unset($parentQuestgroupshierarchy[0]['hierarchy']['questgroup_pos']);
+ }
+
+ array_unshift($parentQuestgroupshierarchy, $quest);
+ array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
+ }
+ while(!empty($currentQuestgroup['hierarchy']) && !is_null($currentQuestgroup['hierarchy']['parent_questgroup_id']))
+ {
+ $currentQuestgroup = $this->Questgroups->GetQuestgroupById($currentQuestgroup['hierarchy']['parent_questgroup_id']);
+ $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
+ array_unshift($parentQuestgroupshierarchy, $currentQuestgroup);
+ }
+
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('parentquestgroupshierarchy', $parentQuestgroupshierarchy);
+ }
+
+ }
?>
diff --git a/controllers/QuestsController.inc b/controllers/QuestsController.inc
index cc345b1f..813114e1 100644
--- a/controllers/QuestsController.inc
+++ b/controllers/QuestsController.inc
@@ -1,1506 +1,1506 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the QuestsAgent to display Quests.
- *
- * @author Oliver Hanraths
- */
- class QuestsController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('seminaries', 'questgroups', 'quests', 'questtexts', 'media', 'questtypes', 'questgroupshierarchy', 'xplevels');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'quest' => array('admin', 'moderator', 'user'),
- 'submissions' => array('admin', 'moderator', 'user'),
- 'submission' => array('admin', 'moderator', 'user'),
- 'create' => array('admin', 'moderator', 'user'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'edittexts' => array('admin', 'moderator', 'user'),
- 'edittask' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'index' => array('admin', 'moderator'),
- 'quest' => array('admin', 'moderator', 'user'),
- 'submissions' => array('admin', 'moderator'),
- 'submission' => array('admin', 'moderator'),
- 'create' => array('admin', 'moderator'),
- 'edit' => array('admin', 'moderator'),
- 'edittexts' => array('admin', 'moderator'),
- 'edittask' => array('admin', 'moderator'),
- 'delete' => array('admin')
- );
-
-
-
-
- /**
- * Prefilter that is executed before running the Controller.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- $this->checkAchievements($request, $response, array('character', 'quest'));
- $this->checkAchievements($request, $response, 'achievement');
- }
-
-
- /**
- * Action: index.
- *
- * List all Quests for a Seminary.
- *
- * @param string $seminaryUrl URL-Title of Seminary
- * @param string $all Show all Quests
- */
- public function index($seminaryUrl, $all=null)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Set filters
- $selectedQuestgroup = null;
- $selectedQuesttype = null;
- $selectedTitle = null;
- $page = 1;
- if($this->request->getRequestMethod() == 'GET')
- {
- $selectedQuestgroup = $this->request->getGetParam('questgroup');
- $selectedQuestgroup = !empty($selectedQuestgroup) ? $selectedQuestgroup : null;
- $selectedQuesttype = $this->request->getGetParam('questtype');
- $selectedQuesttype = !empty($selectedQuesttype) ? $selectedQuesttype : null;
- $selectedTitle = $this->request->getGetParam('title');
- $selectedTitle = !empty($selectedTitle) ? $selectedTitle : null;
- $page = $this->request->getGetParam('page');
- $page = !empty($page) ? intval($page) : 1;
- }
-
- // Get Quests
- $limit = ($all != 'all') ? \nre\configs\AppConfig::$misc['lists_limit'] : null;
- $offset = ($all != 'all') ? max((intval($page) - 1), 0) * $limit : 0;
- $questsCount = $this->Quests->getCountForQuestsForSeminaryByOpenSubmissions($seminary['id'], $selectedQuestgroup, $selectedQuesttype, $selectedTitle);
- $quests = $this->Quests->getQuestsForSeminaryByOpenSubmissions($seminary['id'], $selectedQuestgroup, $selectedQuesttype, $selectedTitle, $limit, $offset);
- foreach($quests as &$quest)
- {
- // Get Questtype
- $quest['questtype'] = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
- }
-
- // Get filter values
- $questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
- $questtypes = $this->Questtypes->getQuesttypes();
-
-
- // Set titile
- $this->addTitleLocalized('Quests');
- $this->addTitle($seminary['title']);
-
- // 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('selectedTitle', $selectedTitle);
- $this->set('quests', $quests);
- $this->set('questsCount', $questsCount);
- $this->set('all', $all);
- $this->set('page', $page);
- $this->set('limit', $limit);
- }
-
-
- /**
- * Action: quest.
- *
- * Show a quest and its task.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- * @param string $questgroupUrl URL-Title of Questgroup
- * @param string $questUrl URL-Title of Quest
- * @param string $questtexttypeUrl URL-Title of Questtexttype
- * @param int $questtextPos Position of Questtext
- */
- public function quest($seminaryUrl, $questgroupUrl, $questUrl, $questtexttypeUrl=null, $questtextPos=1)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- $questgroup['picture'] = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
- // Get Quest
- $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
-
- // Get Character
- $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
-
- // Check permissions
- if(count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
- {
- $previousQuests = $this->Quests->getPreviousQuests($quest['id']);
- if(count($previousQuests) == 0)
- {
- // Previous Questgroup
- $previousQuestgroup = $this->Questgroups->getPreviousQuestgroup($seminary['id'], $questgroup['id']);
- if(!is_null($previousQuestgroup) && !$this->Questgroups->hasCharacterSolvedQuestgroup($previousQuestgroup['id'], $character['id'])) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- }
- else
- {
- // Previous Quests
- // One previous Quest has to be solved and no other
- // following Quest of ones has to be tried
- // except it is also an previous Quest of the current Quest
- $solved = false;
- $tried = false;
- foreach($previousQuests as &$previousQuest)
- {
- // Check previous Quest
- if($this->Quests->hasCharacterSolvedQuest($previousQuest['id'], $character['id']))
- {
- $solved = true;
-
- // Check following Quests
- $followingQuests = $this->Quests->getNextQuests($previousQuest['id']);
- foreach($followingQuests as $followingQuest)
- {
- // Check following Quest
- if($followingQuest['id'] != $quest['id'] && $this->Quests->hasCharacterTriedQuest($followingQuest['id'], $character['id']))
- {
- $followingFollowingQuests = $this->Quests->getNextQuests($followingQuest['id']);
- if(!in_array($quest['id'], array_map(function($q) { return $q['id']; }, $followingFollowingQuests)))
- {
- $tried = true;
- break;
- }
- }
- }
-
- break;
- }
- }
- if(!$solved || $tried) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- }
- }
-
- // Set status “entered”
- $this->Quests->setQuestEntered($quest['id'], $character['id']);
-
- // Has Character solved quest?
- $solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
-
- // Get Questtexts
- $questtexts = array();
- $questtexts['Prolog'] = $this->Questtexts->getQuesttextsOfQuest($quest['id'], 'Prolog');
- if($solved || count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) > 0) {
- $questtexts['Epilog'] = $this->Questtexts->getQuesttextsOfQuest($quest['id'], 'Epilog');
- }
- foreach($questtexts as &$questtextList)
- {
- foreach($questtextList as &$questtext)
- {
- // Questtext media
- if(!is_null($questtext['questsmedia_id'])) {
- $questtext['media'] = $this->Media->getSeminaryMediaById($questtext['questsmedia_id']);
- }
-
- // Related Questgroups
- $questtext['relatedQuestsgroups'] = $this->Questgroups->getRelatedQuestsgroupsOfQuesttext($questtext['id']);
- }
- }
-
- // Quest status
- $questStatus = $this->request->getGetParam('status');
-
- // Quest media
- $questmedia = null;
- if(!is_null($quest['questsmedia_id'])) {
- $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
- }
-
- // Task
- $task = null;
- $questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
- if(!is_null($questtype['classname'])) {
- $task = $this->renderTask($questtype['classname'], $seminary, $questgroup, $quest, $character);
- }
- else
- {
- // Mark Quest as solved
- $this->Quests->setQuestSolved($quest['id'], $character['id']);
- $solved = true;
- }
-
- // Get (related) Questtexts
- $relatedQuesttexts = $this->Questtexts->getRelatedQuesttextsForQuestgroup($questgroup['id']);
- $relatedQuesttext = $this->Questtexts->pickQuesttextLastEnteredByCharacter($character['id'], $relatedQuesttexts);
- if(!is_null($relatedQuesttext)) {
- $relatedQuesttext['quest'] = $this->Quests->getQuestById($relatedQuesttext['quest_id']);
- if(!empty($relatedQuesttext['quest'])) {
- $relatedQuesttext['quest']['questgroup_url'] = $this->Questgroups->getQuestgroupById($relatedQuesttext['quest']['questgroup_id'])['url'];
- }
- }
-
- // Next Quest/Questgroup
- $nextQuests = null;
- $charactedHasChoosenNextQuest = false;
- $nextQuestgroup = null;
- if($solved || count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) > 0)
- {
- // Next Quest
- $nextQuests = $this->Quests->getNextQuests($quest['id']);
- foreach($nextQuests as &$nextQuest)
- {
- // Set entered status of Quest
- $nextQuest['entered'] = $this->Quests->hasCharacterEnteredQuest($nextQuest['id'], $character['id']);
- if($nextQuest['entered']) {
- $charactedHasChoosenNextQuest = true;
- }
- }
-
- // Next Questgroup
- if(empty($nextQuests))
- {
- if(is_null($relatedQuesttext))
- {
- $nextQuestgroup = $this->Questgroups->getNextQuestgroup($seminary['id'], $questgroup['id']);
- if(!is_null($nextQuestgroup)) {
- $nextQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($nextQuestgroup['id']);
- }
- }
- else
- {
- // Related (Main-) Quest
- $nextQuest = $relatedQuesttext['quest'];
- $nextQuest['entered'] = true;
- $nextQuests = array($nextQuest);
- }
- }
- }
-
-
- // Set titile
- $this->addTitle($quest['title']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('questtexts', $questtexts);
- $this->set('quest', $quest);
- $this->set('queststatus', $questStatus);
- $this->set('relatedquesttext', $relatedQuesttext);
- $this->set('nextquests', $nextQuests);
- $this->set('charactedHasChoosenNextQuest', $charactedHasChoosenNextQuest);
- $this->set('nextquestgroup', $nextQuestgroup);
- $this->set('task', $task);
- $this->set('media', $questmedia);
- $this->set('solved', $solved);
- }
-
-
- /**
- * List Character submissions for a Quest.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- * @param string $questgroupUrl URL-Title of Questgroup
- * @param string $questUrl URL-Title of Quest
- */
- public function submissions($seminaryUrl, $questgroupUrl, $questUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- $questgroup['picture'] = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
- // Get Quest
- $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
-
- // Media
- $questmedia = null;
- if(!is_null($quest['questsmedia_id'])) {
- $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
- }
-
- // Get submitted Character submissions waiting for approval
- $submittedSubmissionCharacters = $this->Characters->getCharactersSubmittedQuest($quest['id']);
-
- // Get unsolved Character submissions
- $unsolvedSubmissionCharacters = $this->Characters->getCharactersUnsolvedQuest($quest['id']);
-
- // Get solved Character submissions
- $solvedSubmissionCharacters = $this->Characters->getCharactersSolvedQuest($quest['id']);
-
-
- // Set titile
- $this->addTitleLocalized('Submissions');
- $this->addTitle($quest['title']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('quest', $quest);
- $this->set('media', $questmedia);
- $this->set('submittedSubmissionCharacters', $submittedSubmissionCharacters);
- $this->set('unsolvedSubmissionCharacters', $unsolvedSubmissionCharacters);
- $this->set('solvedSubmissionCharacters', $solvedSubmissionCharacters);
- }
-
-
- /**
- * Show and handle the submission of a Character for a Quest.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- * @param string $questgroupUrl URL-Title of Questgroup
- * @param string $questUrl URL-Title of Quest
- * @param string $characterUrl URL-Title of Character
- */
- public function submission($seminaryUrl, $questgroupUrl, $questUrl, $characterUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- $questgroup['picture'] = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
- // Get Quest
- $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
-
- // Character
- $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
-
- // Media
- $questmedia = null;
- if(!is_null($quest['questsmedia_id'])) {
- $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
- }
-
- // Questtype
- $questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
-
- // Render Questtype output
- $output = $this->renderTaskSubmission($questtype['classname'], $seminary, $questgroup, $quest, $character);
-
-
- // Set titile
- $this->addTitleLocalized('Submission of %s', $character['name']);
- $this->addTitle($quest['title']);
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('quest', $quest);
- $this->set('character', $character);
- $this->set('media', $questmedia);
- $this->set('output', $output);
- }
-
-
- /**
- * Action: create.
- *
- * Create a new Quest.
- *
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $questgroupUrl URL-Title of Questgroup
- */
- public function create($seminaryUrl, $questgroupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- // 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 types
- $questtypes = $this->Questtypes->getQuesttypes();
- foreach($questtypes as &$questtype) {
- $questtype['selected'] = false;
- }
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
-
- // Values
- $title = '';
- $xps = 0;
- $task = '';
- $entryText = '';
- $wrongText = '';
- $fields = array('title', 'xps');
- $validation = array();
-
- // Check request method
- 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->Quests->questTitleExists($title, $seminary['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $xps = $this->request->getPostParam('xps');
- $task = $this->request->getPostParam('task');
- $entryText = $this->request->getPostParam('entrytext');
- $wrongText = $this->request->getPostParam('wrongtext');
-
- // Validate Questtype
- $questtypeIndex = null;
- foreach($questtypes as $index => &$questtype)
- {
- $questtype['selected'] = ($questtype['url'] == $this->request->getPostParam('questtype'));
- if($questtype['selected']) {
- $questtypeIndex = $index;
- }
- }
- if(is_null($questtypeIndex)) {
- throw new \nre\exceptions\ParamsNotValidException($questtype);
- }
-
- // Validate media
- $media = null;
- if(!empty($_FILES) && array_key_exists('media', $_FILES) && $_FILES['media']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $media = $_FILES['media'];
-
- // Check error
- if($media['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $media['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $media['mimetype'] = \hhu\z\Utils::getMimetype($media['tmp_name'], $media['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $media['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $media['mimetype']);
- }
- elseif($media['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']);
- }
- }
-
- // Create new Quest
- if($validation === true)
- {
- $questId = $this->Quests->createQuest(
- $this->Auth->getUserId(),
- $questgroup['id'],
- $questtypes[$questtypeIndex]['id'],
- $title,
- $xps,
- $task,
- $entryText,
- $wrongText
- );
- $quest = $this->Quests->getQuestById($questId);
-
- // Update picture
- if(!is_null($media))
- {
- $questsmediaId = $this->Media->createQuestMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- $media['name'],
- $title,
- $media['type'],
- $media['tmp_name']
- );
- if($questsmediaId > 0) {
- $this->Quests->setQuestmedia($quest['id'], $questsmediaId);
- }
- }
-
- // Redirect
- $this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('Create Quest');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('mimetypes', $mimetypes);
- $this->set('questtypes', $questtypes);
- $this->set('title', $title);
- $this->set('task', $task);
- $this->set('entryText', $entryText);
- $this->set('wrongText', $wrongText);
- $this->set('xps', $xps);
- $this->set('questtype_id', $questtype);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
+ namespace hhu\z\controllers;
- /**
- * Action: edit.
- *
- * Edit a Quest of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- * @param string $questgroupUrl URL-Title of Questgroup
- * @param string $questUrl URL-Title of Quest
- */
- public function edit($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);
- $quest['type'] = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
-
- // Get Quest media
- $questmedia = null;
- if(!is_null($quest['questsmedia_id'])) {
- $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
- }
-
- // Get Quest types
- $questtypes = $this->Questtypes->getQuesttypes();
- foreach($questtypes as &$questtype) {
- $questtype['selected'] = ($questtype['id'] == $quest['questtype_id']);
- }
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
-
- // Values
- $title = $quest['title'];
- $xps = $quest['xps'];
- $task = $quest['task'];
- $entryText = $quest['entry_text'];
- $wrongText = $quest['wrong_text'];
- $fields = array('title', 'xps');
- $validation = array();
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST' && (!is_null($this->request->getPostParam('edit')) || !is_null($this->request->getPostParam('edit-task'))))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $title = $this->request->getPostParam('title');
- if($this->Quests->questTitleExists($title, $seminary['id'], $quest['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $xps = $this->request->getPostParam('xps');
- $task = $this->request->getPostParam('task');
- $entryText = $this->request->getPostParam('entrytext');
- $wrongText = $this->request->getPostParam('wrongtext');
-
- // Validate Questtype
- $questtypeIndex = null;
- foreach($questtypes as $index => &$questtype)
- {
- $questtype['selected'] = ($questtype['url'] == $this->request->getPostParam('questtype'));
- if($questtype['selected']) {
- $questtypeIndex = $index;
- }
- }
- if(is_null($questtypeIndex)) {
- throw new \nre\exceptions\ParamsNotValidException($questtype);
- }
-
- // Validate media
- $media = null;
- if(!empty($_FILES) && array_key_exists('media', $_FILES) && $_FILES['media']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $media = $_FILES['media'];
-
- // Check error
- if($media['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $media['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $media['mimetype'] = \hhu\z\Utils::getMimetype($media['tmp_name'], $media['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $media['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $media['mimetype']);
- }
- elseif($media['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']);
- }
- }
-
- // Edit Quest
- if($validation === true)
- {
- $this->Quests->editQuest(
- $quest['id'],
- $questtypes[$questtypeIndex]['id'],
- $title,
- $xps,
- $task,
- $entryText,
- $wrongText
- );
- $quest = $this->Quests->getQuestById($quest['id']);
-
- // Update picture
- if(!is_null($media))
- {
- $questsmediaId = $this->Media->createQuestMedia(
- $this->Auth->getUserId(),
- $seminary['id'],
- $media['name'],
- $title,
- $media['type'],
- $media['tmp_name']
- );
- if($questsmediaId > 0) {
- $this->Quests->setQuestmedia($quest['id'], $questsmediaId);
- }
- }
-
- // Redirect
- if(!is_null($this->request->getPostParam('edit-task'))) {
- // To task editing
- $this->redirect($this->linker->link(array('edittask', $seminary['url'], $questgroup['url'], $quest['url']), 1));
- }
- else {
- // To entry
- $this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1));
- }
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('Edit Quest');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('quest', $quest);
- $this->set('media', $questmedia);
- $this->set('mimetypes', $mimetypes);
- $this->set('questtypes', $questtypes);
- $this->set('title', $title);
- $this->set('task', $task);
- $this->set('entryText', $entryText);
- $this->set('wrongText', $wrongText);
- $this->set('xps', $xps);
- $this->set('questtype_id', $questtype);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: edittask.
- *
- * Edit the task of a Quest of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- * @param string $questgroupUrl URL-Title of Questgroup
- * @param string $questUrl URL-Title of Quest
- */
- public function edittask($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 Quest media
- $questmedia = null;
- if(!is_null($quest['questsmedia_id'])) {
- $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
- }
-
- // Render editing task
- $task = null;
- $questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
- if(!is_null($questtype['classname'])) {
- $task = $this->renderTaskEditing($questtype['classname'], $seminary, $questgroup, $quest);
- }
-
-
- // Set titile
- $this->addTitleLocalized('Edit Quest task');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('quest', $quest);
- $this->set('media', $questmedia);
- $this->set('task', $task);
- }
-
-
- /**
- * Action: edittexts.
- *
- * Edit the texts of a Quest of a Seminary.
- *
- * @throws \nre\exceptions\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);
- }
+ /**
+ * Controller of the QuestsAgent to display Quests.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestsController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('seminaries', 'questgroups', 'quests', 'questtexts', 'media', 'questtypes', 'questgroupshierarchy', 'xplevels');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'quest' => array('admin', 'moderator', 'user'),
+ 'submissions' => array('admin', 'moderator', 'user'),
+ 'submission' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin', 'moderator', 'user'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'edittexts' => array('admin', 'moderator', 'user'),
+ 'edittask' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'index' => array('admin', 'moderator'),
+ 'quest' => array('admin', 'moderator', 'user'),
+ 'submissions' => array('admin', 'moderator'),
+ 'submission' => array('admin', 'moderator'),
+ 'create' => array('admin', 'moderator'),
+ 'edit' => array('admin', 'moderator'),
+ 'edittexts' => array('admin', 'moderator'),
+ 'edittask' => array('admin', 'moderator'),
+ 'delete' => array('admin')
+ );
- /**
- * Action: delete.
- *
- * Delete a Quest of a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of Seminary
- * @param string $questgroupUrl URL-Title of Questgroup
- * @param string $questUrl URL-Title of Quest
- */
- public function delete($seminaryUrl, $questgroupUrl, $questUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
- // Get Questgroup
- $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
- $questgroup['picture'] = null;
- if(!is_null($questgroup['questgroupspicture_id'])) {
- $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
-
- // Get Quest
- $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
+ /**
+ * Prefilter that is executed before running the Controller.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete seminary
- $this->Quests->deleteQuest($quest['id']);
-
- // Redirect to Questgroup
- $this->redirect($this->linker->link(array('questgroups', 'questgroup', $seminary['url'], $questgroup['url'])));
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
- }
+ $this->checkAchievements($request, $response, array('character', 'quest'));
+ $this->checkAchievements($request, $response, 'achievement');
+ }
- // Set titile
- $this->addTitleLocalized('Delete Quest');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroup', $questgroup);
- $this->set('quest', $quest);
- }
-
-
-
-
- /**
- * Render and handle the task of a Quest.
- *
- * @param string $questtypeClassname Name of the class for the Questtype of a Quest
- * @param array $seminary Seminary data
- * @param array $questgroup Questgroup data
- * @param array $quest Quest data
- * @param array $character Character data
- * @return string Rendered output
- */
- private function renderTask($questtypeClassname, $seminary, $questgroup, $quest, $character)
- {
- $task = null;
- try {
- // Generate request and response
- $request = clone $this->request;
- $response = $this->createQuesttypeResponse('quest', $seminary, $questgroup, $quest, $character);
-
- // Load Questtype Agent
- $questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
-
- // Solve Quest
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')))
- {
- // Get user answers
- $answers = $this->request->getPostParam('answers');
-
- // Save answers in database
- try {
- if(!$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id'])) {
- $questtypeAgent->saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
- }
-
- // Match answers with correct ones
- $status = $questtypeAgent->matchAnswersofCharacter($seminary, $questgroup, $quest, $character, $answers);
- if($status === true)
- {
- // Mark Quest as solved
- $this->Quests->setQuestSolved($quest['id'], $character['id']);
-
- // Notify of XP-level change
- $newXPLevel = $this->Xplevels->getXPLevelById($character['xplevel_id']);
- if($newXPLevel['level'] > $character['xplevel']) {
- $this->Notification->addNotification(
- \hhu\z\controllers\components\NotificationComponent::TYPE_LEVELUP,
- $newXPLevel['level'],
- $this->linker->link(array('characters', 'character', $seminary['url'], $character['url']))
- );
- }
-
- // Redirect
- $this->redirect($this->linker->link(array(), 5, true, array('status'=>'solved'), false, 'task'));
- }
- elseif($status === false)
- {
- // Mark Quest as unsolved
- $this->Quests->setQuestUnsolved($quest['id'], $character['id']);
-
- // Redirect
- $this->redirect($this->linker->link(array(), 5, true, array('status'=>'unsolved'), false, 'task'));
- }
- else {
- // Mark Quest as submitted
- $this->Quests->setQuestSubmitted($quest['id'], $character['id']);
-
- // Send notification mail
- $this->sendSubmissionMail($seminary, $questgroup, $quest, $character);
-
- // Redirect
- $this->redirect($this->linker->link(array(), 5, true, null, false, 'task'));
- }
- }
- catch(\hhu\z\exceptions\SubmissionNotValidException $e) {
- $response->addParam($e);
- }
- }
-
- // Render Task
- $task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
- }
- catch(\nre\exceptions\ViewNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\nre\exceptions\ActionNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
- $task = $e->getMessage();
- }
-
-
- // Return rendered output
- return $task;
- }
-
-
- /**
- * Render and handle a Character submission for a Quest.
- *
- * @param string $questtypeClassname Name of the class for the Questtype of a Quest
- * @param array $seminary Seminary data
- * @param array $questgroup Questgroup data
- * @param array $quest Quest data
- * @param array $character Character data
- * @return string Rendered output
- */
- private function renderTaskSubmission($questtypeClassname, $seminary, $questgroup, $quest, $character)
- {
- $task = null;
- try {
- // Generate request and response
- $request = clone $this->request;
- $response = $this->createQuesttypeResponse('submission', $seminary, $questgroup, $quest, $character);
-
- // Load Questtype Agent
- $questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
-
- // Solve Quest
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')))
- {
- // Set status
- if($this->request->getPostParam('submit') == _('solved'))
- {
- // Mark Quest as solved
- $this->Quests->setQuestSolved($quest['id'], $character['id']);
- }
- else
- {
- // Mark Quest as unsolved
- $this->Quests->setQuestUnsolved($quest['id'], $character['id']);
- }
-
- // Save additional data for Character answers
- $questtypeAgent->controller->saveDataForCharacterAnswers($seminary, $questgroup, $quest, $character, $this->request->getPostParam('characterdata'));
-
- // Send notification
- $this->sendSubmissionApprovedMail($character, $seminary, $questgroup, $quest);
-
- // Redirect
- $this->redirect($this->linker->link(array('submissions', $seminary['url'], $questgroup['url'], $quest['url']), 1));
- }
-
- // Render task submissions
- $task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
- }
- catch(\nre\exceptions\ViewNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\nre\exceptions\ActionNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
- $task = $e->getMessage();
- }
-
-
- // Return rendered output
- return $task;
- }
+ /**
+ * Action: index.
+ *
+ * List all Quests for a Seminary.
+ *
+ * @param string $seminaryUrl URL-Title of Seminary
+ * @param string $all Show all Quests
+ */
+ public function index($seminaryUrl, $all=null)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Set filters
+ $selectedQuestgroup = null;
+ $selectedQuesttype = null;
+ $selectedTitle = null;
+ $page = 1;
+ if($this->request->getRequestMethod() == 'GET')
+ {
+ $selectedQuestgroup = $this->request->getGetParam('questgroup');
+ $selectedQuestgroup = !empty($selectedQuestgroup) ? $selectedQuestgroup : null;
+ $selectedQuesttype = $this->request->getGetParam('questtype');
+ $selectedQuesttype = !empty($selectedQuesttype) ? $selectedQuesttype : null;
+ $selectedTitle = $this->request->getGetParam('title');
+ $selectedTitle = !empty($selectedTitle) ? $selectedTitle : null;
+ $page = $this->request->getGetParam('page');
+ $page = !empty($page) ? intval($page) : 1;
+ }
+
+ // Get Quests
+ $limit = ($all != 'all') ? \nre\configs\AppConfig::$misc['lists_limit'] : null;
+ $offset = ($all != 'all') ? max((intval($page) - 1), 0) * $limit : 0;
+ $questsCount = $this->Quests->getCountForQuestsForSeminaryByOpenSubmissions($seminary['id'], $selectedQuestgroup, $selectedQuesttype, $selectedTitle);
+ $quests = $this->Quests->getQuestsForSeminaryByOpenSubmissions($seminary['id'], $selectedQuestgroup, $selectedQuesttype, $selectedTitle, $limit, $offset);
+ foreach($quests as &$quest)
+ {
+ // Get Questtype
+ $quest['questtype'] = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
+ }
+
+ // Get filter values
+ $questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
+ $questtypes = $this->Questtypes->getQuesttypes();
- /**
- * Render editing of a Quest.
- *
- * @param string $questtypeClassname Name of the class for the Questtype of a Quest
- * @param array $seminary Seminary data
- * @param array $questgroup Questgroup data
- * @param array $quest Quest data
- * @return string Rendered output
- */
- private function renderTaskEditing($questtypeClassname, $seminary, $questgroup, $quest)
- {
- $task = null;
- try {
- // Generate request and response
- $request = clone $this->request;
- $response = $this->createQuesttypeResponse('edittask', $seminary, $questgroup, $quest);
-
- // Load Questtype Agent
- $questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
+ // Set titile
+ $this->addTitleLocalized('Quests');
+ $this->addTitle($seminary['title']);
- // Render Task
- $task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
- }
- catch(\nre\exceptions\ViewNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\nre\exceptions\ActionNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
- $task = $e->getMessage();
- }
- catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
- $task = $e->getMessage();
- }
+ // 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('selectedTitle', $selectedTitle);
+ $this->set('quests', $quests);
+ $this->set('questsCount', $questsCount);
+ $this->set('all', $all);
+ $this->set('page', $page);
+ $this->set('limit', $limit);
+ }
- // Return rendered output
- return $task;
- }
-
-
- /**
- * Create a response for the Questtype rendering.
- *
- * @param string $action Action to run
- * @param mixed $param Additional parameters to add to the response
- * @return \nre\core\Response Generated response
- */
- private function createQuesttypeResponse($action, $param1)
- {
- // Clone current response
- $response = clone $this->response;
- // Clear parameters
- $response->clearParams(1);
-
- // Add Action
- $response->addParams(
- null,
- $action
- );
-
- // Add additional parameters
- foreach(array_slice(func_get_args(), 1) as $param) {
- $response->addParam($param);
- }
-
-
- // Return response
- return $response;
- }
-
-
- /**
- * Load and construct the QuesttypeAgent for a Questtype.
- *
- * @param string $questtypeClassname Name of the class for the Questtype of a Quest
- * @param \nre\core\Request $request Request
- * @param \nre\core\Response $response Response
- * @return \hhu\z\agents\QuesttypeAgent Questtype Agent
- */
- private function loadQuesttypeAgent($questtypeClassname, $request, $response)
- {
- // Load Agent
- \hhu\z\agents\QuesttypeAgent::load($questtypeClassname);
-
-
- // Construct and return Agent
- return \hhu\z\agents\QuesttypeAgent::factory($questtypeClassname, $request, $response);
- }
-
-
- /**
- * Run and render the Agent for a QuesttypeAgent and return ist output.
- *
- * @param \nre\core\Agent $questtypeAgent QuesttypeAgent to run and render
- * @param \nre\core\Request $request Request
- * @param \nre\core\Response $response Response
- * @return string Rendered output
- */
- private function runQuesttypeAgent($questtypeAgent, $request, $response)
- {
- // Run Agent
- $questtypeAgent->run($request, $response);
-
-
- // Render and return output
- return $questtypeAgent->render();
- }
-
-
- /**
- * Send mail for new Character submission.
- *
- * @param array $seminary Seminary which the Quest belongs to
- * @param array $questgroup Questgroup of Quest
- * @param array $quest Quest the answer has been submitted for
- * @param array $character Character that send the submission
- */
- private function sendSubmissionMail($seminary, $questgroup, $quest, $character)
- {
- // Get system moderators
- $moderators = $this->Characters->getCharactersWithCharacterRole($seminary['id'], 'moderator');
-
- // Send notification mail
- try {
- foreach($moderators as &$moderator)
- {
- $user = $this->Users->getUserById($moderator['user_id']);
- if($user['mailing']) {
- \hhu\z\Utils::sendMail(
- $user['email'],
- 'charactersubmission',
- true,
- array(
- $user,
- $seminary,
- $questgroup,
- $quest,
- $character
- ),
- $this->linker
- );
- }
- }
- }
- catch(\hhu\z\exceptions\MailingException $e) {
- $this->log($e->getMessage());
- }
- }
-
-
- /**
- * Send mail for approval of a Character submission.
- *
- * @param array $character Character of submission that has been approved
- * @param array $seminary Seminary which the Quest belongs to
- * @param array $questgroup Questgroup of Quest
- * @param array $quest Quest the submission has been approved for
- */
- private function sendSubmissionApprovedMail($character, $seminary, $questgroup, $quest)
- {
- // Get user
- $user = $this->Users->getUserById($character['user_id']);
- if(!$user['mailing']) {
- return;
- }
-
- // Send notification mail
- try {
- \hhu\z\Utils::sendMail(
- $user['email'],
- 'charactersubmissionapproved',
- true,
- array(
- $user,
- $seminary,
- $questgroup,
- $quest
- ),
- $this->linker
- );
- }
- catch(\hhu\z\exceptions\MailingException $e) {
- $this->log($e->getMessage());
- }
- }
-
- }
+ /**
+ * Action: quest.
+ *
+ * Show a quest and its task.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ * @param string $questgroupUrl URL-Title of Questgroup
+ * @param string $questUrl URL-Title of Quest
+ * @param string $questtexttypeUrl URL-Title of Questtexttype
+ * @param int $questtextPos Position of Questtext
+ */
+ public function quest($seminaryUrl, $questgroupUrl, $questUrl, $questtexttypeUrl=null, $questtextPos=1)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ $questgroup['picture'] = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+
+ // Get Quest
+ $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
+
+ // Get Character
+ $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
+
+ // Check permissions
+ if(count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
+ {
+ $previousQuests = $this->Quests->getPreviousQuests($quest['id']);
+ if(count($previousQuests) == 0)
+ {
+ // Previous Questgroup
+ $previousQuestgroup = $this->Questgroups->getPreviousQuestgroup($seminary['id'], $questgroup['id']);
+ if(!is_null($previousQuestgroup) && !$this->Questgroups->hasCharacterSolvedQuestgroup($previousQuestgroup['id'], $character['id'])) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ }
+ else
+ {
+ // Previous Quests
+ // One previous Quest has to be solved and no other
+ // following Quest of ones has to be tried
+ // except it is also an previous Quest of the current Quest
+ $solved = false;
+ $tried = false;
+ foreach($previousQuests as &$previousQuest)
+ {
+ // Check previous Quest
+ if($this->Quests->hasCharacterSolvedQuest($previousQuest['id'], $character['id']))
+ {
+ $solved = true;
+
+ // Check following Quests
+ $followingQuests = $this->Quests->getNextQuests($previousQuest['id']);
+ foreach($followingQuests as $followingQuest)
+ {
+ // Check following Quest
+ if($followingQuest['id'] != $quest['id'] && $this->Quests->hasCharacterTriedQuest($followingQuest['id'], $character['id']))
+ {
+ $followingFollowingQuests = $this->Quests->getNextQuests($followingQuest['id']);
+ if(!in_array($quest['id'], array_map(function($q) { return $q['id']; }, $followingFollowingQuests)))
+ {
+ $tried = true;
+ break;
+ }
+ }
+ }
+
+ break;
+ }
+ }
+ if(!$solved || $tried) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ }
+ }
+
+ // Set status “entered”
+ $this->Quests->setQuestEntered($quest['id'], $character['id']);
+
+ // Has Character solved quest?
+ $solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
+
+ // Get Questtexts
+ $questtexts = array();
+ $questtexts['Prolog'] = $this->Questtexts->getQuesttextsOfQuest($quest['id'], 'Prolog');
+ if($solved || count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) > 0) {
+ $questtexts['Epilog'] = $this->Questtexts->getQuesttextsOfQuest($quest['id'], 'Epilog');
+ }
+ foreach($questtexts as &$questtextList)
+ {
+ foreach($questtextList as &$questtext)
+ {
+ // Questtext media
+ if(!is_null($questtext['questsmedia_id'])) {
+ $questtext['media'] = $this->Media->getSeminaryMediaById($questtext['questsmedia_id']);
+ }
+
+ // Related Questgroups
+ $questtext['relatedQuestsgroups'] = $this->Questgroups->getRelatedQuestsgroupsOfQuesttext($questtext['id']);
+ }
+ }
+
+ // Quest status
+ $questStatus = $this->request->getGetParam('status');
+
+ // Quest media
+ $questmedia = null;
+ if(!is_null($quest['questsmedia_id'])) {
+ $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
+ }
+
+ // Task
+ $task = null;
+ $questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
+ if(!is_null($questtype['classname'])) {
+ $task = $this->renderTask($questtype['classname'], $seminary, $questgroup, $quest, $character);
+ }
+ else
+ {
+ // Mark Quest as solved
+ $this->Quests->setQuestSolved($quest['id'], $character['id']);
+ $solved = true;
+ }
+
+ // Get (related) Questtexts
+ $relatedQuesttexts = $this->Questtexts->getRelatedQuesttextsForQuestgroup($questgroup['id']);
+ $relatedQuesttext = $this->Questtexts->pickQuesttextLastEnteredByCharacter($character['id'], $relatedQuesttexts);
+ if(!is_null($relatedQuesttext)) {
+ $relatedQuesttext['quest'] = $this->Quests->getQuestById($relatedQuesttext['quest_id']);
+ if(!empty($relatedQuesttext['quest'])) {
+ $relatedQuesttext['quest']['questgroup_url'] = $this->Questgroups->getQuestgroupById($relatedQuesttext['quest']['questgroup_id'])['url'];
+ }
+ }
+
+ // Next Quest/Questgroup
+ $nextQuests = null;
+ $charactedHasChoosenNextQuest = false;
+ $nextQuestgroup = null;
+ if($solved || count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) > 0)
+ {
+ // Next Quest
+ $nextQuests = $this->Quests->getNextQuests($quest['id']);
+ foreach($nextQuests as &$nextQuest)
+ {
+ // Set entered status of Quest
+ $nextQuest['entered'] = $this->Quests->hasCharacterEnteredQuest($nextQuest['id'], $character['id']);
+ if($nextQuest['entered']) {
+ $charactedHasChoosenNextQuest = true;
+ }
+ }
+
+ // Next Questgroup
+ if(empty($nextQuests))
+ {
+ if(is_null($relatedQuesttext))
+ {
+ $nextQuestgroup = $this->Questgroups->getNextQuestgroup($seminary['id'], $questgroup['id']);
+ if(!is_null($nextQuestgroup)) {
+ $nextQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($nextQuestgroup['id']);
+ }
+ }
+ else
+ {
+ // Related (Main-) Quest
+ $nextQuest = $relatedQuesttext['quest'];
+ $nextQuest['entered'] = true;
+ $nextQuests = array($nextQuest);
+ }
+ }
+ }
+
+
+ // Set titile
+ $this->addTitle($quest['title']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('questtexts', $questtexts);
+ $this->set('quest', $quest);
+ $this->set('queststatus', $questStatus);
+ $this->set('relatedquesttext', $relatedQuesttext);
+ $this->set('nextquests', $nextQuests);
+ $this->set('charactedHasChoosenNextQuest', $charactedHasChoosenNextQuest);
+ $this->set('nextquestgroup', $nextQuestgroup);
+ $this->set('task', $task);
+ $this->set('media', $questmedia);
+ $this->set('solved', $solved);
+ }
+
+
+ /**
+ * List Character submissions for a Quest.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ * @param string $questgroupUrl URL-Title of Questgroup
+ * @param string $questUrl URL-Title of Quest
+ */
+ public function submissions($seminaryUrl, $questgroupUrl, $questUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ $questgroup['picture'] = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+
+ // Get Quest
+ $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
+
+ // Media
+ $questmedia = null;
+ if(!is_null($quest['questsmedia_id'])) {
+ $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
+ }
+
+ // Get submitted Character submissions waiting for approval
+ $submittedSubmissionCharacters = $this->Characters->getCharactersSubmittedQuest($quest['id']);
+
+ // Get unsolved Character submissions
+ $unsolvedSubmissionCharacters = $this->Characters->getCharactersUnsolvedQuest($quest['id']);
+
+ // Get solved Character submissions
+ $solvedSubmissionCharacters = $this->Characters->getCharactersSolvedQuest($quest['id']);
+
+
+ // Set titile
+ $this->addTitleLocalized('Submissions');
+ $this->addTitle($quest['title']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('quest', $quest);
+ $this->set('media', $questmedia);
+ $this->set('submittedSubmissionCharacters', $submittedSubmissionCharacters);
+ $this->set('unsolvedSubmissionCharacters', $unsolvedSubmissionCharacters);
+ $this->set('solvedSubmissionCharacters', $solvedSubmissionCharacters);
+ }
+
+
+ /**
+ * Show and handle the submission of a Character for a Quest.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ * @param string $questgroupUrl URL-Title of Questgroup
+ * @param string $questUrl URL-Title of Quest
+ * @param string $characterUrl URL-Title of Character
+ */
+ public function submission($seminaryUrl, $questgroupUrl, $questUrl, $characterUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ $questgroup['picture'] = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+
+ // Get Quest
+ $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
+
+ // Character
+ $character = $this->Characters->getCharacterByUrl($seminary['id'], $characterUrl);
+
+ // Media
+ $questmedia = null;
+ if(!is_null($quest['questsmedia_id'])) {
+ $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
+ }
+
+ // Questtype
+ $questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
+
+ // Render Questtype output
+ $output = $this->renderTaskSubmission($questtype['classname'], $seminary, $questgroup, $quest, $character);
+
+
+ // Set titile
+ $this->addTitleLocalized('Submission of %s', $character['name']);
+ $this->addTitle($quest['title']);
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('quest', $quest);
+ $this->set('character', $character);
+ $this->set('media', $questmedia);
+ $this->set('output', $output);
+ }
+
+
+ /**
+ * Action: create.
+ *
+ * Create a new Quest.
+ *
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $questgroupUrl URL-Title of Questgroup
+ */
+ public function create($seminaryUrl, $questgroupUrl)
+ {
+ // 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 types
+ $questtypes = $this->Questtypes->getQuesttypes();
+ foreach($questtypes as &$questtype) {
+ $questtype['selected'] = false;
+ }
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $title = '';
+ $xps = 0;
+ $task = '';
+ $entryText = '';
+ $wrongText = '';
+ $fields = array('title', 'xps');
+ $validation = array();
+
+ // Check request method
+ 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->Quests->questTitleExists($title, $seminary['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $xps = $this->request->getPostParam('xps');
+ $task = $this->request->getPostParam('task');
+ $entryText = $this->request->getPostParam('entrytext');
+ $wrongText = $this->request->getPostParam('wrongtext');
+
+ // Validate Questtype
+ $questtypeIndex = null;
+ foreach($questtypes as $index => &$questtype)
+ {
+ $questtype['selected'] = ($questtype['url'] == $this->request->getPostParam('questtype'));
+ if($questtype['selected']) {
+ $questtypeIndex = $index;
+ }
+ }
+ if(is_null($questtypeIndex)) {
+ throw new \nre\exceptions\ParamsNotValidException($questtype);
+ }
+
+ // Validate media
+ $media = null;
+ if(!empty($_FILES) && array_key_exists('media', $_FILES) && $_FILES['media']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $media = $_FILES['media'];
+
+ // Check error
+ if($media['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $media['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $media['mimetype'] = \hhu\z\Utils::getMimetype($media['tmp_name'], $media['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $media['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $media['mimetype']);
+ }
+ elseif($media['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Create new Quest
+ if($validation === true)
+ {
+ $questId = $this->Quests->createQuest(
+ $this->Auth->getUserId(),
+ $questgroup['id'],
+ $questtypes[$questtypeIndex]['id'],
+ $title,
+ $xps,
+ $task,
+ $entryText,
+ $wrongText
+ );
+ $quest = $this->Quests->getQuestById($questId);
+
+ // Update picture
+ if(!is_null($media))
+ {
+ $questsmediaId = $this->Media->createQuestMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $media['name'],
+ $title,
+ $media['type'],
+ $media['tmp_name']
+ );
+ if($questsmediaId > 0) {
+ $this->Quests->setQuestmedia($quest['id'], $questsmediaId);
+ }
+ }
+
+ // Redirect
+ $this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Create Quest');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('questtypes', $questtypes);
+ $this->set('title', $title);
+ $this->set('task', $task);
+ $this->set('entryText', $entryText);
+ $this->set('wrongText', $wrongText);
+ $this->set('xps', $xps);
+ $this->set('questtype_id', $questtype);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * Edit a Quest of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ * @param string $questgroupUrl URL-Title of Questgroup
+ * @param string $questUrl URL-Title of Quest
+ */
+ public function edit($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);
+ $quest['type'] = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
+
+ // Get Quest media
+ $questmedia = null;
+ if(!is_null($quest['questsmedia_id'])) {
+ $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
+ }
+
+ // Get Quest types
+ $questtypes = $this->Questtypes->getQuesttypes();
+ foreach($questtypes as &$questtype) {
+ $questtype['selected'] = ($questtype['id'] == $quest['questtype_id']);
+ }
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $title = $quest['title'];
+ $xps = $quest['xps'];
+ $task = $quest['task'];
+ $entryText = $quest['entry_text'];
+ $wrongText = $quest['wrong_text'];
+ $fields = array('title', 'xps');
+ $validation = array();
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST' && (!is_null($this->request->getPostParam('edit')) || !is_null($this->request->getPostParam('edit-task'))))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $title = $this->request->getPostParam('title');
+ if($this->Quests->questTitleExists($title, $seminary['id'], $quest['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $xps = $this->request->getPostParam('xps');
+ $task = $this->request->getPostParam('task');
+ $entryText = $this->request->getPostParam('entrytext');
+ $wrongText = $this->request->getPostParam('wrongtext');
+
+ // Validate Questtype
+ $questtypeIndex = null;
+ foreach($questtypes as $index => &$questtype)
+ {
+ $questtype['selected'] = ($questtype['url'] == $this->request->getPostParam('questtype'));
+ if($questtype['selected']) {
+ $questtypeIndex = $index;
+ }
+ }
+ if(is_null($questtypeIndex)) {
+ throw new \nre\exceptions\ParamsNotValidException($questtype);
+ }
+
+ // Validate media
+ $media = null;
+ if(!empty($_FILES) && array_key_exists('media', $_FILES) && $_FILES['media']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $media = $_FILES['media'];
+
+ // Check error
+ if($media['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'error', $media['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $media['mimetype'] = \hhu\z\Utils::getMimetype($media['tmp_name'], $media['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $media['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'mimetype', $media['mimetype']);
+ }
+ elseif($media['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'media', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Edit Quest
+ if($validation === true)
+ {
+ $this->Quests->editQuest(
+ $quest['id'],
+ $questtypes[$questtypeIndex]['id'],
+ $title,
+ $xps,
+ $task,
+ $entryText,
+ $wrongText
+ );
+ $quest = $this->Quests->getQuestById($quest['id']);
+
+ // Update picture
+ if(!is_null($media))
+ {
+ $questsmediaId = $this->Media->createQuestMedia(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $media['name'],
+ $title,
+ $media['type'],
+ $media['tmp_name']
+ );
+ if($questsmediaId > 0) {
+ $this->Quests->setQuestmedia($quest['id'], $questsmediaId);
+ }
+ }
+
+ // Redirect
+ if(!is_null($this->request->getPostParam('edit-task'))) {
+ // To task editing
+ $this->redirect($this->linker->link(array('edittask', $seminary['url'], $questgroup['url'], $quest['url']), 1));
+ }
+ else {
+ // To entry
+ $this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1));
+ }
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Quest');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('quest', $quest);
+ $this->set('media', $questmedia);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('questtypes', $questtypes);
+ $this->set('title', $title);
+ $this->set('task', $task);
+ $this->set('entryText', $entryText);
+ $this->set('wrongText', $wrongText);
+ $this->set('xps', $xps);
+ $this->set('questtype_id', $questtype);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edittask.
+ *
+ * Edit the task of a Quest of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ * @param string $questgroupUrl URL-Title of Questgroup
+ * @param string $questUrl URL-Title of Quest
+ */
+ public function edittask($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 Quest media
+ $questmedia = null;
+ if(!is_null($quest['questsmedia_id'])) {
+ $questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
+ }
+
+ // Render editing task
+ $task = null;
+ $questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
+ if(!is_null($questtype['classname'])) {
+ $task = $this->renderTaskEditing($questtype['classname'], $seminary, $questgroup, $quest);
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit Quest task');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('quest', $quest);
+ $this->set('media', $questmedia);
+ $this->set('task', $task);
+ }
+
+
+ /**
+ * Action: edittexts.
+ *
+ * Edit the texts of a Quest of a Seminary.
+ *
+ * @throws \nre\exceptions\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.
+ *
+ * Delete a Quest of a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of Seminary
+ * @param string $questgroupUrl URL-Title of Questgroup
+ * @param string $questUrl URL-Title of Quest
+ */
+ public function delete($seminaryUrl, $questgroupUrl, $questUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Questgroup
+ $questgroup = $this->Questgroups->getQuestgroupByUrl($seminary['id'], $questgroupUrl);
+ $questgroup['picture'] = null;
+ if(!is_null($questgroup['questgroupspicture_id'])) {
+ $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+
+ // Get Quest
+ $quest = $this->Quests->getQuestByUrl($seminary['id'], $questgroup['id'], $questUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete seminary
+ $this->Quests->deleteQuest($quest['id']);
+
+ // Redirect to Questgroup
+ $this->redirect($this->linker->link(array('questgroups', 'questgroup', $seminary['url'], $questgroup['url'])));
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete Quest');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroup', $questgroup);
+ $this->set('quest', $quest);
+ }
+
+
+
+
+ /**
+ * Render and handle the task of a Quest.
+ *
+ * @param string $questtypeClassname Name of the class for the Questtype of a Quest
+ * @param array $seminary Seminary data
+ * @param array $questgroup Questgroup data
+ * @param array $quest Quest data
+ * @param array $character Character data
+ * @return string Rendered output
+ */
+ private function renderTask($questtypeClassname, $seminary, $questgroup, $quest, $character)
+ {
+ $task = null;
+ try {
+ // Generate request and response
+ $request = clone $this->request;
+ $response = $this->createQuesttypeResponse('quest', $seminary, $questgroup, $quest, $character);
+
+ // Load Questtype Agent
+ $questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
+
+ // Solve Quest
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')))
+ {
+ // Get user answers
+ $answers = $this->request->getPostParam('answers');
+
+ // Save answers in database
+ try {
+ if(!$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id'])) {
+ $questtypeAgent->saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
+ }
+
+ // Match answers with correct ones
+ $status = $questtypeAgent->matchAnswersofCharacter($seminary, $questgroup, $quest, $character, $answers);
+ if($status === true)
+ {
+ // Mark Quest as solved
+ $this->Quests->setQuestSolved($quest['id'], $character['id']);
+
+ // Notify of XP-level change
+ $newXPLevel = $this->Xplevels->getXPLevelById($character['xplevel_id']);
+ if($newXPLevel['level'] > $character['xplevel']) {
+ $this->Notification->addNotification(
+ \hhu\z\controllers\components\NotificationComponent::TYPE_LEVELUP,
+ $newXPLevel['level'],
+ $this->linker->link(array('characters', 'character', $seminary['url'], $character['url']))
+ );
+ }
+
+ // Redirect
+ $this->redirect($this->linker->link(array(), 5, true, array('status'=>'solved'), false, 'task'));
+ }
+ elseif($status === false)
+ {
+ // Mark Quest as unsolved
+ $this->Quests->setQuestUnsolved($quest['id'], $character['id']);
+
+ // Redirect
+ $this->redirect($this->linker->link(array(), 5, true, array('status'=>'unsolved'), false, 'task'));
+ }
+ else {
+ // Mark Quest as submitted
+ $this->Quests->setQuestSubmitted($quest['id'], $character['id']);
+
+ // Send notification mail
+ $this->sendSubmissionMail($seminary, $questgroup, $quest, $character);
+
+ // Redirect
+ $this->redirect($this->linker->link(array(), 5, true, null, false, 'task'));
+ }
+ }
+ catch(\hhu\z\exceptions\SubmissionNotValidException $e) {
+ $response->addParam($e);
+ }
+ }
+
+ // Render Task
+ $task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
+ }
+ catch(\nre\exceptions\ViewNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\nre\exceptions\ActionNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+
+
+ // Return rendered output
+ return $task;
+ }
+
+
+ /**
+ * Render and handle a Character submission for a Quest.
+ *
+ * @param string $questtypeClassname Name of the class for the Questtype of a Quest
+ * @param array $seminary Seminary data
+ * @param array $questgroup Questgroup data
+ * @param array $quest Quest data
+ * @param array $character Character data
+ * @return string Rendered output
+ */
+ private function renderTaskSubmission($questtypeClassname, $seminary, $questgroup, $quest, $character)
+ {
+ $task = null;
+ try {
+ // Generate request and response
+ $request = clone $this->request;
+ $response = $this->createQuesttypeResponse('submission', $seminary, $questgroup, $quest, $character);
+
+ // Load Questtype Agent
+ $questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
+
+ // Solve Quest
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')))
+ {
+ // Set status
+ if($this->request->getPostParam('submit') == _('solved'))
+ {
+ // Mark Quest as solved
+ $this->Quests->setQuestSolved($quest['id'], $character['id']);
+ }
+ else
+ {
+ // Mark Quest as unsolved
+ $this->Quests->setQuestUnsolved($quest['id'], $character['id']);
+ }
+
+ // Save additional data for Character answers
+ $questtypeAgent->controller->saveDataForCharacterAnswers($seminary, $questgroup, $quest, $character, $this->request->getPostParam('characterdata'));
+
+ // Send notification
+ $this->sendSubmissionApprovedMail($character, $seminary, $questgroup, $quest);
+
+ // Redirect
+ $this->redirect($this->linker->link(array('submissions', $seminary['url'], $questgroup['url'], $quest['url']), 1));
+ }
+
+ // Render task submissions
+ $task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
+ }
+ catch(\nre\exceptions\ViewNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\nre\exceptions\ActionNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+
+
+ // Return rendered output
+ return $task;
+ }
+
+
+ /**
+ * Render editing of a Quest.
+ *
+ * @param string $questtypeClassname Name of the class for the Questtype of a Quest
+ * @param array $seminary Seminary data
+ * @param array $questgroup Questgroup data
+ * @param array $quest Quest data
+ * @return string Rendered output
+ */
+ private function renderTaskEditing($questtypeClassname, $seminary, $questgroup, $quest)
+ {
+ $task = null;
+ try {
+ // Generate request and response
+ $request = clone $this->request;
+ $response = $this->createQuesttypeResponse('edittask', $seminary, $questgroup, $quest);
+
+ // Load Questtype Agent
+ $questtypeAgent = $this->loadQuesttypeAgent($questtypeClassname, $request, $response);
+
+ // Render Task
+ $task = $this->runQuesttypeAgent($questtypeAgent, $request, $response);
+ }
+ catch(\nre\exceptions\ViewNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\nre\exceptions\ActionNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeModelNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeModelNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeControllerNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeControllerNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeAgentNotValidException $e) {
+ $task = $e->getMessage();
+ }
+ catch(\hhu\z\exceptions\QuesttypeAgentNotFoundException $e) {
+ $task = $e->getMessage();
+ }
+
+
+ // Return rendered output
+ return $task;
+ }
+
+
+ /**
+ * Create a response for the Questtype rendering.
+ *
+ * @param string $action Action to run
+ * @param mixed $param Additional parameters to add to the response
+ * @return \nre\core\Response Generated response
+ */
+ private function createQuesttypeResponse($action, $param1)
+ {
+ // Clone current response
+ $response = clone $this->response;
+ // Clear parameters
+ $response->clearParams(1);
+
+ // Add Action
+ $response->addParams(
+ null,
+ $action
+ );
+
+ // Add additional parameters
+ foreach(array_slice(func_get_args(), 1) as $param) {
+ $response->addParam($param);
+ }
+
+
+ // Return response
+ return $response;
+ }
+
+
+ /**
+ * Load and construct the QuesttypeAgent for a Questtype.
+ *
+ * @param string $questtypeClassname Name of the class for the Questtype of a Quest
+ * @param \nre\core\Request $request Request
+ * @param \nre\core\Response $response Response
+ * @return \hhu\z\agents\QuesttypeAgent Questtype Agent
+ */
+ private function loadQuesttypeAgent($questtypeClassname, $request, $response)
+ {
+ // Load Agent
+ \hhu\z\agents\QuesttypeAgent::load($questtypeClassname);
+
+
+ // Construct and return Agent
+ return \hhu\z\agents\QuesttypeAgent::factory($questtypeClassname, $request, $response);
+ }
+
+
+ /**
+ * Run and render the Agent for a QuesttypeAgent and return ist output.
+ *
+ * @param \nre\core\Agent $questtypeAgent QuesttypeAgent to run and render
+ * @param \nre\core\Request $request Request
+ * @param \nre\core\Response $response Response
+ * @return string Rendered output
+ */
+ private function runQuesttypeAgent($questtypeAgent, $request, $response)
+ {
+ // Run Agent
+ $questtypeAgent->run($request, $response);
+
+
+ // Render and return output
+ return $questtypeAgent->render();
+ }
+
+
+ /**
+ * Send mail for new Character submission.
+ *
+ * @param array $seminary Seminary which the Quest belongs to
+ * @param array $questgroup Questgroup of Quest
+ * @param array $quest Quest the answer has been submitted for
+ * @param array $character Character that send the submission
+ */
+ private function sendSubmissionMail($seminary, $questgroup, $quest, $character)
+ {
+ // Get system moderators
+ $moderators = $this->Characters->getCharactersWithCharacterRole($seminary['id'], 'moderator');
+
+ // Send notification mail
+ try {
+ foreach($moderators as &$moderator)
+ {
+ $user = $this->Users->getUserById($moderator['user_id']);
+ if($user['mailing']) {
+ \hhu\z\Utils::sendMail(
+ $user['email'],
+ 'charactersubmission',
+ true,
+ array(
+ $user,
+ $seminary,
+ $questgroup,
+ $quest,
+ $character
+ ),
+ $this->linker
+ );
+ }
+ }
+ }
+ catch(\hhu\z\exceptions\MailingException $e) {
+ $this->log($e->getMessage());
+ }
+ }
+
+
+ /**
+ * Send mail for approval of a Character submission.
+ *
+ * @param array $character Character of submission that has been approved
+ * @param array $seminary Seminary which the Quest belongs to
+ * @param array $questgroup Questgroup of Quest
+ * @param array $quest Quest the submission has been approved for
+ */
+ private function sendSubmissionApprovedMail($character, $seminary, $questgroup, $quest)
+ {
+ // Get user
+ $user = $this->Users->getUserById($character['user_id']);
+ if(!$user['mailing']) {
+ return;
+ }
+
+ // Send notification mail
+ try {
+ \hhu\z\Utils::sendMail(
+ $user['email'],
+ 'charactersubmissionapproved',
+ true,
+ array(
+ $user,
+ $seminary,
+ $questgroup,
+ $quest
+ ),
+ $this->linker
+ );
+ }
+ catch(\hhu\z\exceptions\MailingException $e) {
+ $this->log($e->getMessage());
+ }
+ }
+
+ }
?>
diff --git a/controllers/SeminariesController.inc b/controllers/SeminariesController.inc
index 3be361a5..19e6bea8 100644
--- a/controllers/SeminariesController.inc
+++ b/controllers/SeminariesController.inc
@@ -1,438 +1,438 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to list registered seminaries.
- *
- * @author Oliver Hanraths
- */
- class SeminariesController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('users', 'seminaries', 'characterroles', 'charactertypes', 'xplevels', 'questgroupshierarchy', 'questgroups', 'questgrouptexts', 'quests', 'questtexts', 'media');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator', 'user'),
- 'seminary' => array('admin', 'moderator', 'user'),
- 'create' => array('admin', 'moderator'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'copy' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin', 'moderator', 'user'),
- 'calculatexps' => array('admin', 'moderator', 'user')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'seminary' => array('admin', 'moderator', 'user', 'guest'),
- 'edit' => array('admin'),
- 'copy' => array('admin'),
- 'delete' => array('admin'),
- 'calculatexps' => array('admin', 'moderator')
- );
-
-
-
-
- /**
- * Action: index.
- *
- * List registered seminaries.
- */
- public function index()
- {
- // Get seminaries
- $seminaries = $this->Seminaries->getSeminaries();
-
- // Get additional data
- foreach($seminaries as &$seminary)
- {
- $description = \hhu\z\Utils::shortenString($seminary['description'], 100, 120);
- $seminary['description'] = $description.(strlen($description) < strlen($seminary['description']) ? ' …' : null);
- $seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
- $seminary['charactertypes'] = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
- $seminary['xplevels'] = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
-
- // Character of currently logged-in user
- try {
- $seminary['usercharacter'] = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
- $seminary['usercharacter']['characterroles'] = $this->Characterroles->getCharacterrolesForCharacterById($seminary['usercharacter']['id']);
- $seminary['xps'] = $this->Seminaries->getTotalXPs($seminary['id']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- }
-
- }
-
-
- // Set titile
- $this->addTitleLocalized('Seminaries');
-
- // Pass data to view
- $this->set('seminaries', $seminaries);
- }
-
-
- /**
- * Action: seminary.
- *
- * Show a seminary and its details.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a seminary
- */
- public function seminary($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Created user
- $seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
-
- // Get Character
- $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
-
- // Questgrouphierarchy and Questgroups
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminary['id']);
- foreach($questgroupshierarchy as &$hierarchy)
- {
- // Get Questgroups
- $hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
-
- // Get additional data
- foreach($hierarchy['questgroups'] as $i => &$questgroup)
- {
- // Check permission of Questgroups
- if($i >= 1 && count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
- {
- if(!$this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']))
- {
- $hierarchy['questgroups'] = array_slice($hierarchy['questgroups'], 0, $i);
- break;
- }
- }
-
- // Get first Questgroup text
- $text = $this->getFirstQuestgroupText($questgroup['id']);
- if(!is_null($text))
- {
- $questgroup['text'] = \hhu\z\Utils::shortenString($text, 100, 120).' …';
- }
-
- // Get Character XPs
- $questgroup['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($questgroup['id'], $character['id']);
-
- // Get Media
- $questgroup['picture'] = null;
- try {
- $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
- }
- catch(\nre\exceptions\IdNotFoundException $e) {
- }
- }
- }
-
-
- // Set titile
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('questgroupshierarchy', $questgroupshierarchy);
- }
-
-
- /**
- * Action: create.
- *
- * Create a new Seminary.
- */
- public function create()
- {
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
-
- // Values
- $title = '';
- $course = '';
- $description = '';
- $fields = array('title', 'course');
- $validation = array();
-
- // Create a new Seminary
- 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->Seminaries->seminaryTitleExists($title)) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $course = $this->request->getPostParam('course');
- $description = $this->request->getPostParam('description');
-
- // Validate moodpic
- $moodpic = null;
- if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $moodpic = $_FILES['moodpic'];
-
- // Check error
- if($moodpic['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $moodpic['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
- }
- elseif($moodpic['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
- }
- }
-
- // Create new Seminary
- if($validation === true)
- {
- $seminaryId = $this->Seminaries->createSeminary(
- $this->Auth->getUserId(),
- $title,
- $course,
- $description
- );
- $seminary = $this->Seminaries->getSeminaryById($seminaryId);
-
- // Upload moodpic
- if(!is_null($moodpic))
- {
- $mediaId = $this->Media->createMoodpic(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('seminarymoodpic-%s', $seminary['url']),
- '',
- $moodpic['mimetype'],
- $moodpic['tmp_name']
- );
- if($mediaId !== false) {
- $this->Seminaries->setMoodpicForSeminary($seminary['id'], $mediaId);
- }
- }
-
- // Redirect to Seminary overview
- $this->redirect($this->linker->link('index', 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('New seminary');
-
- // Pass data to view
- $this->set('title', $title);
- $this->set('course', $course);
- $this->set('description', $description);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: edit.
- *
- * Edit a seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a seminary
- */
- public function edit($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get allowed mimetypes
- $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
-
- // Values
- $title = $seminary['title'];
- $course = $seminary['course'];
- $description = $seminary['description'];
- $fields = array('title', 'course');
- $validation = array();
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $title = $this->request->getPostParam('title');
- if($this->Seminaries->seminaryTitleExists($title, $seminary['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $course = $this->request->getPostParam('course');
- $description = $this->request->getPostParam('description');
-
- // Validate moodpic
- $moodpic = null;
- if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
- {
- $moodpic = $_FILES['moodpic'];
-
- // Check error
- if($moodpic['error'] !== UPLOAD_ERR_OK) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
- }
-
- // Check mimetype
- $mediaMimetype = null;
- $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
- foreach($mimetypes as &$mimetype) {
- if($mimetype['mimetype'] == $moodpic['mimetype']) {
- $mediaMimetype = $mimetype;
- break;
- }
- }
- if(is_null($mediaMimetype)) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
- }
- elseif($moodpic['size'] > $mediaMimetype['size']) {
- $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
- }
- }
-
- // Edit Seminary
- if($validation === true)
- {
- $this->Seminaries->editSeminary(
- $seminary['id'],
- $title,
- $course,
- $description
- );
- $seminary = $this->Seminaries->getSeminaryById($seminary['id']);
-
- // Update moodpic
- if(!is_null($moodpic))
- {
- $mediaId = $this->Media->createMoodpic(
- $this->Auth->getUserId(),
- $seminary['id'],
- sprintf('seminarymoodpic-%s', $seminary['url']),
- '',
- $moodpic['mimetype'],
- $moodpic['tmp_name']
- );
- if($mediaId !== false) {
- $this->Seminaries->setMoodpicForSeminary($seminary['id'], $mediaId);
- }
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('Edit seminary');
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('title', $title);
- $this->set('course', $course);
- $this->set('description', $description);
- $this->set('mimetypes', $mimetypes);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to list registered seminaries.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminariesController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('users', 'seminaries', 'characterroles', 'charactertypes', 'xplevels', 'questgroupshierarchy', 'questgroups', 'questgrouptexts', 'quests', 'questtexts', 'media');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator', 'user'),
+ 'seminary' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin', 'moderator'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'copy' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin', 'moderator', 'user'),
+ 'calculatexps' => array('admin', 'moderator', 'user')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'seminary' => array('admin', 'moderator', 'user', 'guest'),
+ 'edit' => array('admin'),
+ 'copy' => array('admin'),
+ 'delete' => array('admin'),
+ 'calculatexps' => array('admin', 'moderator')
+ );
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * List registered seminaries.
+ */
+ public function index()
+ {
+ // Get seminaries
+ $seminaries = $this->Seminaries->getSeminaries();
+
+ // Get additional data
+ foreach($seminaries as &$seminary)
+ {
+ $description = \hhu\z\Utils::shortenString($seminary['description'], 100, 120);
+ $seminary['description'] = $description.(strlen($description) < strlen($seminary['description']) ? ' …' : null);
+ $seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
+ $seminary['charactertypes'] = $this->Charactertypes->getCharacterTypesForSeminary($seminary['id']);
+ $seminary['xplevels'] = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
+
+ // Character of currently logged-in user
+ try {
+ $seminary['usercharacter'] = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
+ $seminary['usercharacter']['characterroles'] = $this->Characterroles->getCharacterrolesForCharacterById($seminary['usercharacter']['id']);
+ $seminary['xps'] = $this->Seminaries->getTotalXPs($seminary['id']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ }
+
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Seminaries');
+
+ // Pass data to view
+ $this->set('seminaries', $seminaries);
+ }
+
+
+ /**
+ * Action: seminary.
+ *
+ * Show a seminary and its details.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a seminary
+ */
+ public function seminary($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Created user
+ $seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
+
+ // Get Character
+ $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
+
+ // Questgrouphierarchy and Questgroups
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminary['id']);
+ foreach($questgroupshierarchy as &$hierarchy)
+ {
+ // Get Questgroups
+ $hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
+
+ // Get additional data
+ foreach($hierarchy['questgroups'] as $i => &$questgroup)
+ {
+ // Check permission of Questgroups
+ if($i >= 1 && count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
+ {
+ if(!$this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']))
+ {
+ $hierarchy['questgroups'] = array_slice($hierarchy['questgroups'], 0, $i);
+ break;
+ }
+ }
+
+ // Get first Questgroup text
+ $text = $this->getFirstQuestgroupText($questgroup['id']);
+ if(!is_null($text))
+ {
+ $questgroup['text'] = \hhu\z\Utils::shortenString($text, 100, 120).' …';
+ }
+
+ // Get Character XPs
+ $questgroup['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($questgroup['id'], $character['id']);
+
+ // Get Media
+ $questgroup['picture'] = null;
+ try {
+ $questgroup['picture'] = $this->Media->getSeminaryMediaById($questgroup['questgroupspicture_id']);
+ }
+ catch(\nre\exceptions\IdNotFoundException $e) {
+ }
+ }
+ }
+
+
+ // Set titile
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('questgroupshierarchy', $questgroupshierarchy);
+ }
+
+
+ /**
+ * Action: create.
+ *
+ * Create a new Seminary.
+ */
+ public function create()
+ {
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $title = '';
+ $course = '';
+ $description = '';
+ $fields = array('title', 'course');
+ $validation = array();
+
+ // Create a new Seminary
+ 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->Seminaries->seminaryTitleExists($title)) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $course = $this->request->getPostParam('course');
+ $description = $this->request->getPostParam('description');
+
+ // Validate moodpic
+ $moodpic = null;
+ if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $moodpic = $_FILES['moodpic'];
+
+ // Check error
+ if($moodpic['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $moodpic['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
+ }
+ elseif($moodpic['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Create new Seminary
+ if($validation === true)
+ {
+ $seminaryId = $this->Seminaries->createSeminary(
+ $this->Auth->getUserId(),
+ $title,
+ $course,
+ $description
+ );
+ $seminary = $this->Seminaries->getSeminaryById($seminaryId);
+
+ // Upload moodpic
+ if(!is_null($moodpic))
+ {
+ $mediaId = $this->Media->createMoodpic(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('seminarymoodpic-%s', $seminary['url']),
+ '',
+ $moodpic['mimetype'],
+ $moodpic['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Seminaries->setMoodpicForSeminary($seminary['id'], $mediaId);
+ }
+ }
+
+ // Redirect to Seminary overview
+ $this->redirect($this->linker->link('index', 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('New seminary');
+
+ // Pass data to view
+ $this->set('title', $title);
+ $this->set('course', $course);
+ $this->set('description', $description);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * Edit a seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a seminary
+ */
+ public function edit($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get allowed mimetypes
+ $mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
+
+ // Values
+ $title = $seminary['title'];
+ $course = $seminary['course'];
+ $description = $seminary['description'];
+ $fields = array('title', 'course');
+ $validation = array();
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $title = $this->request->getPostParam('title');
+ if($this->Seminaries->seminaryTitleExists($title, $seminary['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $course = $this->request->getPostParam('course');
+ $description = $this->request->getPostParam('description');
+
+ // Validate moodpic
+ $moodpic = null;
+ if(!empty($_FILES) && array_key_exists('moodpic', $_FILES) && $_FILES['moodpic']['error'] != UPLOAD_ERR_NO_FILE)
+ {
+ $moodpic = $_FILES['moodpic'];
+
+ // Check error
+ if($moodpic['error'] !== UPLOAD_ERR_OK) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'error', $moodpic['error']);
+ }
+
+ // Check mimetype
+ $mediaMimetype = null;
+ $moodpic['mimetype'] = \hhu\z\Utils::getMimetype($moodpic['tmp_name'], $moodpic['type']);
+ foreach($mimetypes as &$mimetype) {
+ if($mimetype['mimetype'] == $moodpic['mimetype']) {
+ $mediaMimetype = $mimetype;
+ break;
+ }
+ }
+ if(is_null($mediaMimetype)) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'mimetype', $moodpic['mimetype']);
+ }
+ elseif($moodpic['size'] > $mediaMimetype['size']) {
+ $validation = $this->Validation->addValidationResult($validation, 'moodpic', 'size', $mediaMimetype['size']);
+ }
+ }
+
+ // Edit Seminary
+ if($validation === true)
+ {
+ $this->Seminaries->editSeminary(
+ $seminary['id'],
+ $title,
+ $course,
+ $description
+ );
+ $seminary = $this->Seminaries->getSeminaryById($seminary['id']);
+
+ // Update moodpic
+ if(!is_null($moodpic))
+ {
+ $mediaId = $this->Media->createMoodpic(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ sprintf('seminarymoodpic-%s', $seminary['url']),
+ '',
+ $moodpic['mimetype'],
+ $moodpic['tmp_name']
+ );
+ if($mediaId !== false) {
+ $this->Seminaries->setMoodpicForSeminary($seminary['id'], $mediaId);
+ }
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit seminary');
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('title', $title);
+ $this->set('course', $course);
+ $this->set('description', $description);
+ $this->set('mimetypes', $mimetypes);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
/**
* Copy a Seminary and selected content.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a seminary
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a seminary
*/
public function copy($seminaryUrl)
{
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
- // Values
- $title = sprintf('%s (%s)', $seminary['title'], _('Copy'));
- $course = $seminary['course'];
- $description = $seminary['description'];
+ // Values
+ $title = sprintf('%s (%s)', $seminary['title'], _('Copy'));
+ $course = $seminary['course'];
+ $description = $seminary['description'];
$elements = array();
- $fields = array('title', 'course');
- $validation = array();
+ $fields = array('title', 'course');
+ $validation = array();
$exception = null;
- // Check request method
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $title = $this->request->getPostParam('title');
- if($this->Seminaries->seminaryTitleExists($title)) {
- $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
- }
- $course = $this->request->getPostParam('course');
- $description = $this->request->getPostParam('description');
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $title = $this->request->getPostParam('title');
+ if($this->Seminaries->seminaryTitleExists($title)) {
+ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
+ }
+ $course = $this->request->getPostParam('course');
+ $description = $this->request->getPostParam('description');
$elements = $this->request->getPostParam('elements');
if(!is_array($elements)) {
$elements = array();
}
- // Copy Seminary
- if($validation === true)
- {
+ // Copy Seminary
+ if($validation === true)
+ {
try {
$seminaryId = $this->Seminaries->copySeminary(
$this->Auth->getUserId(),
@@ -470,132 +470,132 @@
}
}
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('title', $title);
- $this->set('course', $course);
- $this->set('description', $description);
- $this->set('elements', $elements);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('title', $title);
+ $this->set('course', $course);
+ $this->set('description', $description);
+ $this->set('elements', $elements);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
$this->set('exception', $exception);
}
-
-
- /**
- * Action: delete.
- *
- * Delete a seminary.
- *
- * @throws \nre\exceptions\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(!is_null($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));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Delete seminary');
-
- // Show confirmation
- $this->set('seminary', $seminary);
- }
-
-
- /**
- * Action: calculatexps.
- *
- * (Re-) Calculate the amount of achievable XPs for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function calculatexps($seminaryUrl)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // (Re-) Calculate XPs
+
+
+ /**
+ * Action: delete.
+ *
+ * Delete a seminary.
+ *
+ * @throws \nre\exceptions\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(!is_null($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));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete seminary');
+
+ // Show confirmation
+ $this->set('seminary', $seminary);
+ }
+
+
+ /**
+ * Action: calculatexps.
+ *
+ * (Re-) Calculate the amount of achievable XPs for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function calculatexps($seminaryUrl)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // (Re-) Calculate XPs
$this->Seminaries->calculateXPsForSeminary($seminary['id']);
-
- // Redirect to Questgroup
- $this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
- }
+
+ // Redirect to Questgroup
+ $this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
+ }
- /**
- * Get the first text of a Questgroup.
- *
- * @param int $questgroupId ID of a Questgroup
- * @return string First text of this Questgroup or NULL
- */
- private function getFirstQuestgroupText($questgroupId)
- {
- // Text of Questgroup itself
- $questgroupTexts = $this->Questgrouptexts->getQuestgroupTexts($questgroupId);
- if(!empty($questgroupTexts)) {
- return $questgroupTexts[0]['text'];
- }
-
- // Text of first Quest
- $quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
- if(!is_null($quest))
- {
- $questText = $this->Questtexts->getFirstQuestText($quest['id']);
- if(!is_null($questText)) {
- return $questText;
- }
- }
-
- // Text of ChildQuestgroups
- $questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
- $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
- foreach($childQuestgroupshierarchy as &$hierarchy)
- {
- // Get Questgroups
- $questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
- foreach($questgroups as &$group)
- {
- $childQuestgroupText = $this->getFirstQuestgroupText($group['id']);
- if(!is_null($childQuestgroupText)) {
- return $childQuestgroupText;
- }
- }
- }
-
-
- // No text found
- return null;
- }
-
- }
+ /**
+ * Get the first text of a Questgroup.
+ *
+ * @param int $questgroupId ID of a Questgroup
+ * @return string First text of this Questgroup or NULL
+ */
+ private function getFirstQuestgroupText($questgroupId)
+ {
+ // Text of Questgroup itself
+ $questgroupTexts = $this->Questgrouptexts->getQuestgroupTexts($questgroupId);
+ if(!empty($questgroupTexts)) {
+ return $questgroupTexts[0]['text'];
+ }
+
+ // Text of first Quest
+ $quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
+ if(!is_null($quest))
+ {
+ $questText = $this->Questtexts->getFirstQuestText($quest['id']);
+ if(!is_null($questText)) {
+ return $questText;
+ }
+ }
+
+ // Text of ChildQuestgroups
+ $questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
+ $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
+ foreach($childQuestgroupshierarchy as &$hierarchy)
+ {
+ // Get Questgroups
+ $questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
+ foreach($questgroups as &$group)
+ {
+ $childQuestgroupText = $this->getFirstQuestgroupText($group['id']);
+ if(!is_null($childQuestgroupText)) {
+ return $childQuestgroupText;
+ }
+ }
+ }
+
+
+ // No text found
+ return null;
+ }
+
+ }
?>
diff --git a/controllers/SeminarybarController.inc b/controllers/SeminarybarController.inc
index 00e7ee70..7a987c37 100644
--- a/controllers/SeminarybarController.inc
+++ b/controllers/SeminarybarController.inc
@@ -1,89 +1,89 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to display a sidebar with Seminary related
- * information.
- *
- * @author Oliver Hanraths
- */
- class SeminarybarController extends \hhu\z\Controller
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('characters', 'quests', 'questgroups', 'achievements', 'charactergroups', 'avatars', 'media', 'xplevels');
-
-
-
-
- /**
- * Action: index.
- */
- public function index()
- {
- // Do not render at first
- $this->set('render', false);
-
- // Get Seminary
- $seminary = SeminaryController::$seminary;
- if(is_null($seminary)) {
- return;
- }
-
- // Get Character
- $character = SeminaryController::$character;
- if(is_null($character)) {
- return;
- }
- $character['rank'] = $this->Characters->getXPRank($seminary['id'], $character['xps']);
-
- // Get “last” Quest
- $lastQuest = $this->Quests->getLastQuestForCharacter($character['id']);
- if(!is_null($lastQuest)) {
- $lastQuest['questgroup'] = $this->Questgroups->getQuestgroupById($lastQuest['questgroup_id']);
- }
-
- // Get last achieved Achievement
- $achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id'], false);
- $lastAchievement = array_shift($achievements);
-
- // Get Character group members
- $characterGroups = array();
- foreach($this->Charactergroups->getGroupsForCharacter($character['id']) as $group)
- {
- $groupsgroup = $this->Charactergroups->getGroupsgroupById($group['charactergroupsgroup_id']);
- if($groupsgroup['preferred'])
- {
- $group['members'] = $this->Characters->getCharactersForGroup($group['id']);
- $characterGroups[] = $group;
- }
- }
-
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('character', $character);
- $this->set('lastQuest', $lastQuest);
- $this->set('lastAchievement', $lastAchievement);
- $this->set('characterGroups', $characterGroups);
- // Render now
- $this->set('render', true);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to display a sidebar with Seminary related
+ * information.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminarybarController extends \hhu\z\Controller
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('characters', 'quests', 'questgroups', 'achievements', 'charactergroups', 'avatars', 'media', 'xplevels');
+
+
+
+
+ /**
+ * Action: index.
+ */
+ public function index()
+ {
+ // Do not render at first
+ $this->set('render', false);
+
+ // Get Seminary
+ $seminary = SeminaryController::$seminary;
+ if(is_null($seminary)) {
+ return;
+ }
+
+ // Get Character
+ $character = SeminaryController::$character;
+ if(is_null($character)) {
+ return;
+ }
+ $character['rank'] = $this->Characters->getXPRank($seminary['id'], $character['xps']);
+
+ // Get “last” Quest
+ $lastQuest = $this->Quests->getLastQuestForCharacter($character['id']);
+ if(!is_null($lastQuest)) {
+ $lastQuest['questgroup'] = $this->Questgroups->getQuestgroupById($lastQuest['questgroup_id']);
+ }
+
+ // Get last achieved Achievement
+ $achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id'], false);
+ $lastAchievement = array_shift($achievements);
+
+ // Get Character group members
+ $characterGroups = array();
+ foreach($this->Charactergroups->getGroupsForCharacter($character['id']) as $group)
+ {
+ $groupsgroup = $this->Charactergroups->getGroupsgroupById($group['charactergroupsgroup_id']);
+ if($groupsgroup['preferred'])
+ {
+ $group['members'] = $this->Characters->getCharactersForGroup($group['id']);
+ $characterGroups[] = $group;
+ }
+ }
+
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('character', $character);
+ $this->set('lastQuest', $lastQuest);
+ $this->set('lastAchievement', $lastAchievement);
+ $this->set('characterGroups', $characterGroups);
+ // Render now
+ $this->set('render', true);
+ }
+
+ }
?>
diff --git a/controllers/SeminarymenuController.inc b/controllers/SeminarymenuController.inc
index ff9d34d5..25a5f667 100644
--- a/controllers/SeminarymenuController.inc
+++ b/controllers/SeminarymenuController.inc
@@ -1,53 +1,53 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to display a menu with Seminary related
- * links.
- *
- * @author Oliver Hanraths
- */
- class SeminarymenuController extends \hhu\z\Controller
- {
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Set userdata
- $this->set('loggedUser', \hhu\z\controllers\IntermediateController::$user);
- $this->set('loggedSeminary', \hhu\z\controllers\SeminaryController::$seminary);
- $this->set('loggedCharacter', \hhu\z\controllers\SeminaryController::$character);
- }
-
-
- /**
- * Action: index.
- */
- public function index()
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to display a menu with Seminary related
+ * links.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminarymenuController extends \hhu\z\Controller
+ {
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Set userdata
+ $this->set('loggedUser', \hhu\z\controllers\IntermediateController::$user);
+ $this->set('loggedSeminary', \hhu\z\controllers\SeminaryController::$seminary);
+ $this->set('loggedCharacter', \hhu\z\controllers\SeminaryController::$character);
+ }
+
+
+ /**
+ * Action: index.
+ */
+ public function index()
+ {
+ }
+
+ }
?>
diff --git a/controllers/TextmailController.inc b/controllers/TextmailController.inc
index d6b28068..99a8fa1b 100644
--- a/controllers/TextmailController.inc
+++ b/controllers/TextmailController.inc
@@ -1,55 +1,55 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the TextmailAgent for generating a simple text-mail
- * message.
- *
- * @author Oliver Hanraths
- */
- class TextmailController extends \nre\core\Controller
- {
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
-
- // Set linker
- $this->set('linker', ($request instanceof \hhu\z\requests\MailRequest && !is_null($request->getLinker())) ? $request->getLinker() : null);
- }
-
-
- /**
- * Action: index.
- *
- * Create simple text-mail message.
- */
- public function index()
- {
- $this->set('appname', \nre\configs\AppConfig::$app['name']);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the TextmailAgent for generating a simple text-mail
+ * message.
+ *
+ * @author Oliver Hanraths
+ */
+ class TextmailController extends \nre\core\Controller
+ {
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+
+ // Set linker
+ $this->set('linker', ($request instanceof \hhu\z\requests\MailRequest && !is_null($request->getLinker())) ? $request->getLinker() : null);
+ }
+
+
+ /**
+ * Action: index.
+ *
+ * Create simple text-mail message.
+ */
+ public function index()
+ {
+ $this->set('appname', \nre\configs\AppConfig::$app['name']);
+ }
+
+ }
?>
diff --git a/controllers/UploadsController.inc b/controllers/UploadsController.inc
index eb208b4d..3468a6d5 100644
--- a/controllers/UploadsController.inc
+++ b/controllers/UploadsController.inc
@@ -1,318 +1,318 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the UploadsAgent to process and show user uploads.
- *
- * @author Oliver Hanraths
- */
- class UploadsController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('uploads', 'users', 'userroles', 'characterroles', 'seminaries', 'charactergroups');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'seminary' => array('admin', 'moderator', 'user', 'guest'),
- 'charactergroup' => array('admin', 'moderator', 'user', 'guest')
- );
- /**
- * User seminary permissions
- *
- * @var array
- */
- public $seminaryPermissions = array(
- 'seminary' => array('admin', 'moderator', 'user', 'guest'),
- 'charactergroup' => array('admin', 'moderator', 'user')
- );
-
-
-
-
- /**
- * Prefilter.
- *
- * @param \nre\core\Request $request Current request
- * @param \nre\core\Response $response Current response
- */
- public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
- {
- parent::preFilter($request, $response);
-
- // Set headers for caching control
- $response->addHeader("Pragma: public");
- $response->addHeader("Cache-control: public, max-age=".(60*60*24));
- $response->addHeader("Expires: ".gmdate('r', time()+(60*60*24)));
- $response->addHeader("Date: ".gmdate(\DateTime::RFC822));
- }
-
-
- /**
- * Action: seminary.
- *
- * Display a Seminary upload.
- *
- * @throws \nre\exceptions\AccessDeniedException
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-title of Seminary
- * @param string $uploadUrl URL-name of the upload
- * @param string $action Current action (optional)
- */
- public function seminary($seminaryUrl, $uploadUrl, $action=null)
- {
- // Get Seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Upload
- $upload = $this->Uploads->getSeminaryuploadByUrl($seminary['id'], $uploadUrl);
-
- // Check permissions
- if(!$upload['public'])
- {
- $user = $this->Users->getUserById($this->Auth->getUserId());
- $user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById($user['id']));
-
- // System roles
- if(count(array_intersect(array('admin', 'moderator'), $user['roles'])) == 0)
- {
- // Owner of file
- if($upload['created_user_id'] != $user['id'])
- {
- // Seminary permissions
- $characterRoles = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
- if(count(array_intersect(array('admin', 'moderator'), $characterRoles)) == 0) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- }
- }
- }
-
- // Get file
- switch($action)
- {
- case null:
- $file = $this->getUploadFile($upload);
- break;
- case 'thumbnail':
- $file = $this->createThumbnail($upload);
- break;
- default:
- throw new \nre\exceptions\ParamsNotValidException($action);
- break;
- }
- if(is_null($file)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('upload', $upload);
- $this->set('file', $file);
- }
-
-
- /**
- * Action: charactergroup.
- *
- * Display the icon of a Character group.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- * @param string $groupsgroupUrl URL-Title of a Character groups-group
- * @param string $groupUrl URL-Title of a Character group
- */
- public function charactergroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Get Character groups-group
- $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
-
- // Get Character group
- $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
-
- // Get Upload
- $upload = $this->Uploads->getSeminaryuploadById($group['seminaryupload_id']);
-
- // Get file
- $file = $this->getUploadFile($upload);
- if(is_null($file)) {
- return;
- }
-
-
- // Pass data to view
- $this->set('upload', $upload);
- $this->set('file', $file);
- }
-
-
-
-
- /**
- * Determine the file for an upload.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param array $upload Upload to get file for
- * @return object File for the upload (or null if upload is cached)
- */
- private function getUploadFile($upload)
- {
- // Set content-type
- $this->response->addHeader("Content-type: ".$upload['mimetype']."");
-
- // Set filename
- $upload['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$upload['url'];
- if(!file_exists($upload['filename'])) {
- throw new \nre\exceptions\IdNotFoundException($uploadUrl);
- }
-
- // Cache
- if($this->setCacheHeaders($upload['filename'])) {
- return null;
- }
-
-
- return file_get_contents($upload['filename']);
- }
-
-
- /**
- * Create a thumbnail from an upload.
- *
- * @param array $upload Upload to create thumbnail for
- * @return object Thumbnail for the upload (or null if thumbnail is cached)
- */
- private function createThumbnail($upload)
- {
- // Set filename
- $upload['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$upload['url'];
-
- // Set content-type
- $this->response->addHeader("Content-type: image/jpeg");
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- // Check file
- if(!file_exists($upload['filename'])) {
- throw new \nre\exceptions\IdNotFoundException($upload['url']);
- }
-
- // Cache
- if($this->setCacheHeaders($upload['filename'])) {
- return null;
- }
-
- // Set geometry
- $width = 100;
- $height = 100;
-
- switch($upload['mimetype'])
- {
- case 'image/jpeg':
- case 'image/png':
- // Read image from cache
- $tempFileName = ROOT.DS.\nre\configs\AppConfig::$dirs['temporary'].DS.$upload['url'].'-'.$width.'x'.$height;
- if(file_exists($tempFileName))
- {
- // Check age of file
- if(date('r', filemtime($tempFileName)+(60*60*24)) > date('r', time())) {
- // Too old, delete
- unlink($tempFileName);
- }
- else {
- // Valid, read and return
- return file_get_contents($tempFileName);
- }
- }
-
- // ImageMagick
- $im = new \Imagick($upload['filename']);
-
- // Calculate new size
- $geometry = $im->getImageGeometry();
- if($geometry['width'] < $width) {
- $width = $geometry['width'];
- }
- if($geometry['height'] < $height) {
- $height = $geometry['width'];
- }
-
- // Process
- $im->thumbnailImage($width, $height, true);
- $im->contrastImage(1);
- $im->setImageFormat('jpeg');
-
- // Save temporary file
- $im->writeImage($tempFileName);
-
-
- // Return resized image
- return $im;
- break;
- default:
- throw new \nre\exceptions\ParamsNotValidException('thumbnail');
- break;
- }
-
-
- return $this->getUploadFile($upload);
- }
-
-
- /**
- * Determine file information and set the HTTP-header for
- * caching accordingly.
- *
- * @param string $fileName Filename
- * @return boolean HTTP-status 304 was set (in cache)
- */
- private function setCacheHeaders($fileName)
- {
- // Determine last change of file
- $fileLastModified = gmdate('r', filemtime($fileName));
-
- // Generate E-Tag
- $fileEtag = hash('sha256', $fileLastModified.$fileName);
-
-
- // Set header
- $this->response->addHeader("Last-Modified: ".$fileLastModified);
- $this->response->addHeader("Etag: ".$fileEtag);
- // HTTP-status
- $headerModifiedSince = $this->request->getServerParam('HTTP_IF_MODIFIED_SINCE');
- $headerNoneMatch = $this->request->getServerParam('HTTP_IF_NONE_MATCH');
- if(
- !is_null($headerModifiedSince) && $fileLastModified < strtotime($headerModifiedSince) &&
- !is_null($headerNoneMatch) && $headerNoneMatch == $fileEtag
- ) {
- $this->response->setExit(true);
- $this->response->addHeader(\nre\core\WebUtils::getHttpHeader(304));
-
- return true;
- }
-
-
- return false;
- }
-
- }
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the UploadsAgent to process and show user uploads.
+ *
+ * @author Oliver Hanraths
+ */
+ class UploadsController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('uploads', 'users', 'userroles', 'characterroles', 'seminaries', 'charactergroups');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'seminary' => array('admin', 'moderator', 'user', 'guest'),
+ 'charactergroup' => array('admin', 'moderator', 'user', 'guest')
+ );
+ /**
+ * User seminary permissions
+ *
+ * @var array
+ */
+ public $seminaryPermissions = array(
+ 'seminary' => array('admin', 'moderator', 'user', 'guest'),
+ 'charactergroup' => array('admin', 'moderator', 'user')
+ );
+
+
+
+
+ /**
+ * Prefilter.
+ *
+ * @param \nre\core\Request $request Current request
+ * @param \nre\core\Response $response Current response
+ */
+ public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
+ {
+ parent::preFilter($request, $response);
+
+ // Set headers for caching control
+ $response->addHeader("Pragma: public");
+ $response->addHeader("Cache-control: public, max-age=".(60*60*24));
+ $response->addHeader("Expires: ".gmdate('r', time()+(60*60*24)));
+ $response->addHeader("Date: ".gmdate(\DateTime::RFC822));
+ }
+
+
+ /**
+ * Action: seminary.
+ *
+ * Display a Seminary upload.
+ *
+ * @throws \nre\exceptions\AccessDeniedException
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-title of Seminary
+ * @param string $uploadUrl URL-name of the upload
+ * @param string $action Current action (optional)
+ */
+ public function seminary($seminaryUrl, $uploadUrl, $action=null)
+ {
+ // Get Seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Upload
+ $upload = $this->Uploads->getSeminaryuploadByUrl($seminary['id'], $uploadUrl);
+
+ // Check permissions
+ if(!$upload['public'])
+ {
+ $user = $this->Users->getUserById($this->Auth->getUserId());
+ $user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById($user['id']));
+
+ // System roles
+ if(count(array_intersect(array('admin', 'moderator'), $user['roles'])) == 0)
+ {
+ // Owner of file
+ if($upload['created_user_id'] != $user['id'])
+ {
+ // Seminary permissions
+ $characterRoles = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
+ if(count(array_intersect(array('admin', 'moderator'), $characterRoles)) == 0) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ }
+ }
+ }
+
+ // Get file
+ switch($action)
+ {
+ case null:
+ $file = $this->getUploadFile($upload);
+ break;
+ case 'thumbnail':
+ $file = $this->createThumbnail($upload);
+ break;
+ default:
+ throw new \nre\exceptions\ParamsNotValidException($action);
+ break;
+ }
+ if(is_null($file)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('upload', $upload);
+ $this->set('file', $file);
+ }
+
+
+ /**
+ * Action: charactergroup.
+ *
+ * Display the icon of a Character group.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ * @param string $groupsgroupUrl URL-Title of a Character groups-group
+ * @param string $groupUrl URL-Title of a Character group
+ */
+ public function charactergroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Get Character groups-group
+ $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
+
+ // Get Character group
+ $group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
+
+ // Get Upload
+ $upload = $this->Uploads->getSeminaryuploadById($group['seminaryupload_id']);
+
+ // Get file
+ $file = $this->getUploadFile($upload);
+ if(is_null($file)) {
+ return;
+ }
+
+
+ // Pass data to view
+ $this->set('upload', $upload);
+ $this->set('file', $file);
+ }
+
+
+
+
+ /**
+ * Determine the file for an upload.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param array $upload Upload to get file for
+ * @return object File for the upload (or null if upload is cached)
+ */
+ private function getUploadFile($upload)
+ {
+ // Set content-type
+ $this->response->addHeader("Content-type: ".$upload['mimetype']."");
+
+ // Set filename
+ $upload['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$upload['url'];
+ if(!file_exists($upload['filename'])) {
+ throw new \nre\exceptions\IdNotFoundException($uploadUrl);
+ }
+
+ // Cache
+ if($this->setCacheHeaders($upload['filename'])) {
+ return null;
+ }
+
+
+ return file_get_contents($upload['filename']);
+ }
+
+
+ /**
+ * Create a thumbnail from an upload.
+ *
+ * @param array $upload Upload to create thumbnail for
+ * @return object Thumbnail for the upload (or null if thumbnail is cached)
+ */
+ private function createThumbnail($upload)
+ {
+ // Set filename
+ $upload['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$upload['url'];
+
+ // Set content-type
+ $this->response->addHeader("Content-type: image/jpeg");
+
+ // Check file
+ if(!file_exists($upload['filename'])) {
+ throw new \nre\exceptions\IdNotFoundException($upload['url']);
+ }
+
+ // Cache
+ if($this->setCacheHeaders($upload['filename'])) {
+ return null;
+ }
+
+ // Set geometry
+ $width = 100;
+ $height = 100;
+
+ switch($upload['mimetype'])
+ {
+ case 'image/jpeg':
+ case 'image/png':
+ // Read image from cache
+ $tempFileName = ROOT.DS.\nre\configs\AppConfig::$dirs['temporary'].DS.$upload['url'].'-'.$width.'x'.$height;
+ if(file_exists($tempFileName))
+ {
+ // Check age of file
+ if(date('r', filemtime($tempFileName)+(60*60*24)) > date('r', time())) {
+ // Too old, delete
+ unlink($tempFileName);
+ }
+ else {
+ // Valid, read and return
+ return file_get_contents($tempFileName);
+ }
+ }
+
+ // ImageMagick
+ $im = new \Imagick($upload['filename']);
+
+ // Calculate new size
+ $geometry = $im->getImageGeometry();
+ if($geometry['width'] < $width) {
+ $width = $geometry['width'];
+ }
+ if($geometry['height'] < $height) {
+ $height = $geometry['width'];
+ }
+
+ // Process
+ $im->thumbnailImage($width, $height, true);
+ $im->contrastImage(1);
+ $im->setImageFormat('jpeg');
+
+ // Save temporary file
+ $im->writeImage($tempFileName);
+
+
+ // Return resized image
+ return $im;
+ break;
+ default:
+ throw new \nre\exceptions\ParamsNotValidException('thumbnail');
+ break;
+ }
+
+
+ return $this->getUploadFile($upload);
+ }
+
+
+ /**
+ * Determine file information and set the HTTP-header for
+ * caching accordingly.
+ *
+ * @param string $fileName Filename
+ * @return boolean HTTP-status 304 was set (in cache)
+ */
+ private function setCacheHeaders($fileName)
+ {
+ // Determine last change of file
+ $fileLastModified = gmdate('r', filemtime($fileName));
+
+ // Generate E-Tag
+ $fileEtag = hash('sha256', $fileLastModified.$fileName);
+
+
+ // Set header
+ $this->response->addHeader("Last-Modified: ".$fileLastModified);
+ $this->response->addHeader("Etag: ".$fileEtag);
+ // HTTP-status
+ $headerModifiedSince = $this->request->getServerParam('HTTP_IF_MODIFIED_SINCE');
+ $headerNoneMatch = $this->request->getServerParam('HTTP_IF_NONE_MATCH');
+ if(
+ !is_null($headerModifiedSince) && $fileLastModified < strtotime($headerModifiedSince) &&
+ !is_null($headerNoneMatch) && $headerNoneMatch == $fileEtag
+ ) {
+ $this->response->setExit(true);
+ $this->response->addHeader(\nre\core\WebUtils::getHttpHeader(304));
+
+ return true;
+ }
+
+
+ return false;
+ }
+
+ }
?>
diff --git a/controllers/UserrolesController.inc b/controllers/UserrolesController.inc
index 238f189b..ee2f71a0 100644
--- a/controllers/UserrolesController.inc
+++ b/controllers/UserrolesController.inc
@@ -1,47 +1,47 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to display and manage userroles.
- *
- * @author Oliver Hanraths
- */
- class UserrolesController extends \hhu\z\Controller
- {
-
-
-
-
- /**
- * Action: user.
- *
- * Show a user and its details.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $userUrl URL-Username of an user
- */
- public function user($userUrl)
- {
- // Get userroles
- $roles = $this->Userroles->getUserrolesForUserByUrl($userUrl);
-
-
- // Pass data to view
- $this->set('roles', $roles);
- }
-
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to display and manage userroles.
+ *
+ * @author Oliver Hanraths
+ */
+ class UserrolesController extends \hhu\z\Controller
+ {
+
+
+
+
+ /**
+ * Action: user.
+ *
+ * Show a user and its details.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $userUrl URL-Username of an user
+ */
+ public function user($userUrl)
+ {
+ // Get userroles
+ $roles = $this->Userroles->getUserrolesForUserByUrl($userUrl);
+
+
+ // Pass data to view
+ $this->set('roles', $roles);
+ }
+
+
+ }
?>
diff --git a/controllers/UsersController.inc b/controllers/UsersController.inc
index f0e254fd..23f696c3 100644
--- a/controllers/UsersController.inc
+++ b/controllers/UsersController.inc
@@ -1,641 +1,641 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the Agent to list registered users and their data.
- *
- * @author Oliver Hanraths
- */
- class UsersController extends \hhu\z\controllers\IntermediateController
- {
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'index' => array('admin', 'moderator'),
- 'user' => array('admin', 'moderator', 'user'),
- 'create' => array('admin', 'moderator'),
- 'edit' => array('admin', 'moderator', 'user'),
- 'delete' => array('admin')
- );
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('users', 'userroles', 'characters', 'characterroles', 'avatars', 'media', 'xplevels');
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
-
-
-
-
- /**
- * Action: index.
- *
- * @param string $all Whether to list all users at once or not (optional)
- */
- public function index($all=null)
- {
- // Set filters
- $sortorder = 'username';
- $username = null;
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the Agent to list registered users and their data.
+ *
+ * @author Oliver Hanraths
+ */
+ class UsersController extends \hhu\z\controllers\IntermediateController
+ {
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'index' => array('admin', 'moderator'),
+ 'user' => array('admin', 'moderator', 'user'),
+ 'create' => array('admin', 'moderator'),
+ 'edit' => array('admin', 'moderator', 'user'),
+ 'delete' => array('admin')
+ );
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('users', 'userroles', 'characters', 'characterroles', 'avatars', 'media', 'xplevels');
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+
+
+
+
+ /**
+ * Action: index.
+ *
+ * @param string $all Whether to list all users at once or not (optional)
+ */
+ public function index($all=null)
+ {
+ // Set filters
+ $sortorder = 'username';
+ $username = null;
$name = null;
$email = null;
- $page = 1;
- if($this->request->getRequestMethod() == 'GET')
- {
- $sortorder = $this->request->getGetParam('sortorder');
- $sortorder = !empty($sortorder) ? $sortorder : 'username';
- $username = (!is_null($this->request->getGetParam('username'))) ? $this->request->getGetParam('username') : $username;
- $name = (!is_null($this->request->getGetParam('name'))) ? $this->request->getGetParam('name') : $name;
- $email = (!is_null($this->request->getGetParam('email'))) ? $this->request->getGetParam('email') : $email;
- $page = $this->request->getGetParam('page');
- $page = !empty($page) ? intval($page) : 1;
- }
-
- // Get registered users
- $limit = ($all != 'all') ? \nre\configs\AppConfig::$misc['lists_limit'] : null;
- $offset = ($all != 'all') ? max((intval($page) - 1), 0) * $limit : 0;
- $usersCount = $this->Users->getUsersCount($username, $name, $email);
- $users = $this->Users->getUsers($sortorder, $username, $name, $email, $limit, $offset);
- foreach($users as &$user) {
- $user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById($user['id']));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Users');
-
- // Pass data to view
- $this->set('users', $users);
- $this->set('usersCount', $usersCount);
- $this->set('sortorder', $sortorder);
- $this->set('username', $username);
- $this->set('name', $name);
- $this->set('email', $email);
- $this->set('all', $all);
- $this->set('page', $page);
- $this->set('limit', $limit);
- }
-
-
- /**
- * Action: user.
- *
- * Show a user and its details.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @throws \nre\exceptions\AccessDeniedException
- * @param string $userUrl URL-Username of an user
- */
- public function user($userUrl)
- {
- // Get user
- $user = $this->Users->getUserByUrl($userUrl);
-
- // Check permissions
- if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0 && $user['id'] != IntermediateController::$user['id']) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Get Characters
- $characters = $this->Characters->getCharactersForUser($user['id']);
-
- // Additional Character information
- foreach($characters as &$character)
- {
- // Seminary roles
- $character['characterroles'] = $this->Characterroles->getCharacterrolesForCharacterById($character['id']);
- $character['characterroles'] = array_map(function($a) { return $a['name']; }, $character['characterroles']);
-
- // Level
- try {
- $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
- }
- catch(\nre\Exceptions\IdNotFoundException $e) {
- // No XP-level
- }
-
- // Avatar
- $avatar = $this->Avatars->getAvatarById($character['avatar_id']);
- if(!is_null($avatar['small_avatarpicture_id']))
- {
- //$character['seminary'] =
- $character['small_avatar'] = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
- }
- }
-
-
- // Set titile
- $this->addTitleLocalized($user['username']);
- $this->addTitleLocalized('Users');
-
- // Pass data to view
- $this->set('user', $user);
- $this->set('characters', $characters);
- }
-
-
- /**
- * Action: login.
- *
- * Log in a user.
- */
- public function login()
- {
- $username = '';
- $referrer = null;
-
- // Log the user in
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('login')))
- {
- $username = $this->request->getPostParam('username');
- $referrer = $this->request->getPostParam('referrer');
- $userId = $this->Users->login(
- $username,
- $this->request->getPostParam('password')
- );
-
- if(!is_null($userId))
- {
- $this->Auth->setUserId($userId);
- $user = $this->Users->getUserById($userId);
-
- if(!empty($referrer)) {
- $this->redirect($referrer);
- }
- else {
- $this->redirect($this->linker->link(array($user['url']), 1));
- }
- }
- }
-
-
- // Set titile
- $this->addTitleLocalized('Login');
-
- // Pass data to view
- $this->set('username', $username);
- $this->set('referrer', $referrer);
- $this->set('failed', ($this->request->getRequestMethod() == 'POST'));
- }
-
-
- /**
- * Action: register.
- *
- * Register a new user.
- */
- public function register()
- {
- $username = '';
- $prename = '';
- $surname = '';
- $email = '';
-
- $fields = array('username', 'prename', 'surname', 'email', 'password');
- $validation = array();
+ $page = 1;
+ if($this->request->getRequestMethod() == 'GET')
+ {
+ $sortorder = $this->request->getGetParam('sortorder');
+ $sortorder = !empty($sortorder) ? $sortorder : 'username';
+ $username = (!is_null($this->request->getGetParam('username'))) ? $this->request->getGetParam('username') : $username;
+ $name = (!is_null($this->request->getGetParam('name'))) ? $this->request->getGetParam('name') : $name;
+ $email = (!is_null($this->request->getGetParam('email'))) ? $this->request->getGetParam('email') : $email;
+ $page = $this->request->getGetParam('page');
+ $page = !empty($page) ? intval($page) : 1;
+ }
+
+ // Get registered users
+ $limit = ($all != 'all') ? \nre\configs\AppConfig::$misc['lists_limit'] : null;
+ $offset = ($all != 'all') ? max((intval($page) - 1), 0) * $limit : 0;
+ $usersCount = $this->Users->getUsersCount($username, $name, $email);
+ $users = $this->Users->getUsers($sortorder, $username, $name, $email, $limit, $offset);
+ foreach($users as &$user) {
+ $user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById($user['id']));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Users');
+
+ // Pass data to view
+ $this->set('users', $users);
+ $this->set('usersCount', $usersCount);
+ $this->set('sortorder', $sortorder);
+ $this->set('username', $username);
+ $this->set('name', $name);
+ $this->set('email', $email);
+ $this->set('all', $all);
+ $this->set('page', $page);
+ $this->set('limit', $limit);
+ }
+
+
+ /**
+ * Action: user.
+ *
+ * Show a user and its details.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @throws \nre\exceptions\AccessDeniedException
+ * @param string $userUrl URL-Username of an user
+ */
+ public function user($userUrl)
+ {
+ // Get user
+ $user = $this->Users->getUserByUrl($userUrl);
+
+ // Check permissions
+ if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0 && $user['id'] != IntermediateController::$user['id']) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Get Characters
+ $characters = $this->Characters->getCharactersForUser($user['id']);
+
+ // Additional Character information
+ foreach($characters as &$character)
+ {
+ // Seminary roles
+ $character['characterroles'] = $this->Characterroles->getCharacterrolesForCharacterById($character['id']);
+ $character['characterroles'] = array_map(function($a) { return $a['name']; }, $character['characterroles']);
+
+ // Level
+ try {
+ $character['xplevel'] = $this->Xplevels->getXPLevelById($character['xplevel_id']);
+ }
+ catch(\nre\Exceptions\IdNotFoundException $e) {
+ // No XP-level
+ }
+
+ // Avatar
+ $avatar = $this->Avatars->getAvatarById($character['avatar_id']);
+ if(!is_null($avatar['small_avatarpicture_id']))
+ {
+ //$character['seminary'] =
+ $character['small_avatar'] = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
+ }
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized($user['username']);
+ $this->addTitleLocalized('Users');
+
+ // Pass data to view
+ $this->set('user', $user);
+ $this->set('characters', $characters);
+ }
+
+
+ /**
+ * Action: login.
+ *
+ * Log in a user.
+ */
+ public function login()
+ {
+ $username = '';
+ $referrer = null;
+
+ // Log the user in
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('login')))
+ {
+ $username = $this->request->getPostParam('username');
+ $referrer = $this->request->getPostParam('referrer');
+ $userId = $this->Users->login(
+ $username,
+ $this->request->getPostParam('password')
+ );
+
+ if(!is_null($userId))
+ {
+ $this->Auth->setUserId($userId);
+ $user = $this->Users->getUserById($userId);
+
+ if(!empty($referrer)) {
+ $this->redirect($referrer);
+ }
+ else {
+ $this->redirect($this->linker->link(array($user['url']), 1));
+ }
+ }
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Login');
+
+ // Pass data to view
+ $this->set('username', $username);
+ $this->set('referrer', $referrer);
+ $this->set('failed', ($this->request->getRequestMethod() == 'POST'));
+ }
+
+
+ /**
+ * Action: register.
+ *
+ * Register a new user.
+ */
+ public function register()
+ {
+ $username = '';
+ $prename = '';
+ $surname = '';
+ $email = '';
+
+ $fields = array('username', 'prename', 'surname', 'email', 'password');
+ $validation = array();
$emailhost = \nre\configs\AppConfig::$app['registration_host'];
-
- // Register a new user
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('register')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $username = $this->request->getPostParam('username');
- if($this->Users->usernameExists($username)) {
- $validation = $this->Validation->addValidationResult($validation, 'username', 'exist', true);
- }
- $prename = $this->request->getPostParam('prename');
- $surname = $this->request->getPostParam('surname');
- $email = $this->request->getPostParam('email');
+
+ // Register a new user
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('register')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $username = $this->request->getPostParam('username');
+ if($this->Users->usernameExists($username)) {
+ $validation = $this->Validation->addValidationResult($validation, 'username', 'exist', true);
+ }
+ $prename = $this->request->getPostParam('prename');
+ $surname = $this->request->getPostParam('surname');
+ $email = $this->request->getPostParam('email');
if(!empty($emailhost)) {
if(substr_compare($email, $emailhost, max(0, strlen($email)-strlen($emailhost)), strlen($emailhost)) !== 0) {
$validation = $this->Validation->addValidationResult($validation, 'email', 'host', 'invalid');
}
}
- if($this->Users->emailExists($email)) {
- $validation = $this->Validation->addValidationResult($validation, 'email', 'exist', true);
- }
+ if($this->Users->emailExists($email)) {
+ $validation = $this->Validation->addValidationResult($validation, 'email', 'exist', true);
+ }
$password = $this->request->getPostParam('password');
if($password != $this->request->getPostParam('passwordrepeat')) {
$validation = $this->Validation->addValidationResult($validation, 'password', 'repeat', false);
}
-
-
- // Register
- if($validation === true)
- {
- $userId = $this->Users->createUser(
- $username,
- $prename,
- $surname,
- $email,
- $password
- );
- $user = $this->Users->getUserById($userId);
-
- // Send mail
- $this->sendRegistrationMail($user);
-
- // Login
- $this->Auth->setUserId($userId);
-
-
- // Redirect to user page
- $this->redirect($this->linker->link(array($user['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('Registration');
-
- // Pass data to view
- $this->set('username', $username);
- $this->set('prename', $prename);
- $this->set('surname', $surname);
- $this->set('email', $email);
- $this->set('emailhost', $emailhost);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: logout.
- *
- * Log out a user.
- */
- public function logout()
- {
- // Unset the currently logged in user
- $this->Auth->setUserId(null);
-
- // Redirect
- $this->redirect($this->linker->link(array()));
- }
-
-
- /**
- * Action: manage.
- *
- * Manage users.
- */
- public function manage()
- {
- $selectedUsers = array();
- //global $sortorder;
- $sortorder = 'username';
-
- if($this->request->getRequestMethod() == 'POST')
- {
- // Set sortorder
- $sortorder = $this->request->getPostParam('sortorder');
-
- // Do action
- $selectedUsers = $this->request->getPostParam('users');
- if(!is_array($selectedUsers)) {
- $selectedUsers = array();
- }
- if(!is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0 && !is_null($this->request->getPostParam('users')) && count($this->request->getPostParam('users')) > 0)
- {
- $actions = $this->request->getPostParam('actions');
- $action = array_keys($actions)[0];
-
- switch($action)
- {
- // Add/remove role to/from Characters
- case 'addrole':
- case 'removerole':
- // Determine role and check permissions
- $role = null;
- switch($actions[$action])
- {
- case _('Admin'):
- if(!in_array('admin', \hhu\z\controllers\IntermediateController::$user['roles'])) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- $role = 'admin';
- break;
- case _('Moderator'):
- if(!in_array('admin', \hhu\z\controllers\IntermediateController::$user['roles'])) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- $role = 'moderator';
- break;
- case _('User'):
- if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0) {
- throw new \nre\exceptions\AccessDeniedException();
- }
- $role = 'user';
- break;
- }
-
- // Add role
- if($action == 'addrole') {
- foreach($selectedUsers as &$userId) {
- $this->Userroles->addUserroleToUser($userId, $role);
- }
- }
- // Remove role
- else {
- foreach($selectedUsers as &$userId) {
- $this->Userroles->removeUserroleFromUser($userId, $role);
- }
- }
- break;
- }
- }
- }
-
- // Get registered users
- $users = $this->Users->getUsers($sortorder);
- foreach($users as &$user) {
- $user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById($user['id']));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Manage users');
-
- // Pass data to view
- $this->set('users', $users);
- $this->set('selectedUsers', $selectedUsers);
- $this->set('sortorder', $sortorder);
- }
-
-
- /**
- * Action: create.
- *
- * Create a new user.
- */
- public function create()
- {
- // Values
- $username = '';
- $prename = '';
- $surname = '';
- $email = '';
- $fields = array('username', 'prename', 'surname', 'email', 'password');
- $validation = array();
-
- // Create new user
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $username = $this->request->getPostParam('username');
- if($this->Users->usernameExists($username)) {
- $validation = $this->Validation->addValidationResult($validation, 'username', 'exist', true);
- }
- $prename = $this->request->getPostParam('prename');
- $surname = $this->request->getPostParam('surname');
- $email = $this->request->getPostParam('email');
- if($this->Users->emailExists($email)) {
- $validation = $this->Validation->addValidationResult($validation, 'email', 'exist', true);
- }
- $password = $this->request->getPostParam('password');
- if($password != $this->request->getPostParam('passwordrepeat')) {
- $validation = $this->Validation->addValidationResult($validation, 'password', 'repeat', false);
- }
-
- // Create
- if($validation === true)
- {
- $userId = $this->Users->createUser(
- $this->request->getPostParam('username'),
- $this->request->getPostParam('prename'),
- $this->request->getPostParam('surname'),
- $this->request->getPostParam('email'),
- $this->request->getPostParam('password')
- );
-
- // Redirect to user
- $user = $this->Users->getUserById($userId);
- $this->redirect($this->linker->link(array($user['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
-
-
- // Set titile
- $this->addTitleLocalized('New user');
-
- // Pass data to view
- $this->set('username', $username);
- $this->set('prename', $prename);
- $this->set('surname', $surname);
- $this->set('email', $email);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: edit.
- *
- * Edit a user.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $userUrl URL-Username of an user
- */
- public function edit($userUrl)
- {
- // User
- $user = $this->Users->getUserByUrl($userUrl);
-
- // Check permissions
- if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0 && $user['id'] != \hhu\z\controllers\IntermediateController::$user['id']) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Values
- $username = $user['username'];
- $prename = $user['prename'];
- $surname = $user['surname'];
- $email = $user['email'];
- $mailing = $user['mailing'];
- $fields = array('username', 'prename', 'surname', 'email');
- $validation = array();
-
- // Edit user
- if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save')))
- {
- // Get params and validate them
- $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
- $username = $this->request->getPostParam('username');
- if($this->Users->usernameExists($username, $user['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'username', 'exist', true);
- }
- $password = $this->request->getPostParam('password');
- if(!empty($password))
+
+
+ // Register
+ if($validation === true)
{
- $validation = $this->Validation->addValidationResults($validation,
- 'password',
- $this->Validation->validateParam(
- $this->request->getPostParams(),
- 'password'
- )
- );
+ $userId = $this->Users->createUser(
+ $username,
+ $prename,
+ $surname,
+ $email,
+ $password
+ );
+ $user = $this->Users->getUserById($userId);
+
+ // Send mail
+ $this->sendRegistrationMail($user);
+
+ // Login
+ $this->Auth->setUserId($userId);
+
+
+ // Redirect to user page
+ $this->redirect($this->linker->link(array($user['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Registration');
+
+ // Pass data to view
+ $this->set('username', $username);
+ $this->set('prename', $prename);
+ $this->set('surname', $surname);
+ $this->set('email', $email);
+ $this->set('emailhost', $emailhost);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: logout.
+ *
+ * Log out a user.
+ */
+ public function logout()
+ {
+ // Unset the currently logged in user
+ $this->Auth->setUserId(null);
+
+ // Redirect
+ $this->redirect($this->linker->link(array()));
+ }
+
+
+ /**
+ * Action: manage.
+ *
+ * Manage users.
+ */
+ public function manage()
+ {
+ $selectedUsers = array();
+ //global $sortorder;
+ $sortorder = 'username';
+
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Set sortorder
+ $sortorder = $this->request->getPostParam('sortorder');
+
+ // Do action
+ $selectedUsers = $this->request->getPostParam('users');
+ if(!is_array($selectedUsers)) {
+ $selectedUsers = array();
+ }
+ if(!is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0 && !is_null($this->request->getPostParam('users')) && count($this->request->getPostParam('users')) > 0)
+ {
+ $actions = $this->request->getPostParam('actions');
+ $action = array_keys($actions)[0];
+
+ switch($action)
+ {
+ // Add/remove role to/from Characters
+ case 'addrole':
+ case 'removerole':
+ // Determine role and check permissions
+ $role = null;
+ switch($actions[$action])
+ {
+ case _('Admin'):
+ if(!in_array('admin', \hhu\z\controllers\IntermediateController::$user['roles'])) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ $role = 'admin';
+ break;
+ case _('Moderator'):
+ if(!in_array('admin', \hhu\z\controllers\IntermediateController::$user['roles'])) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ $role = 'moderator';
+ break;
+ case _('User'):
+ if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+ $role = 'user';
+ break;
+ }
+
+ // Add role
+ if($action == 'addrole') {
+ foreach($selectedUsers as &$userId) {
+ $this->Userroles->addUserroleToUser($userId, $role);
+ }
+ }
+ // Remove role
+ else {
+ foreach($selectedUsers as &$userId) {
+ $this->Userroles->removeUserroleFromUser($userId, $role);
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ // Get registered users
+ $users = $this->Users->getUsers($sortorder);
+ foreach($users as &$user) {
+ $user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById($user['id']));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Manage users');
+
+ // Pass data to view
+ $this->set('users', $users);
+ $this->set('selectedUsers', $selectedUsers);
+ $this->set('sortorder', $sortorder);
+ }
+
+
+ /**
+ * Action: create.
+ *
+ * Create a new user.
+ */
+ public function create()
+ {
+ // Values
+ $username = '';
+ $prename = '';
+ $surname = '';
+ $email = '';
+ $fields = array('username', 'prename', 'surname', 'email', 'password');
+ $validation = array();
+
+ // Create new user
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $username = $this->request->getPostParam('username');
+ if($this->Users->usernameExists($username)) {
+ $validation = $this->Validation->addValidationResult($validation, 'username', 'exist', true);
+ }
+ $prename = $this->request->getPostParam('prename');
+ $surname = $this->request->getPostParam('surname');
+ $email = $this->request->getPostParam('email');
+ if($this->Users->emailExists($email)) {
+ $validation = $this->Validation->addValidationResult($validation, 'email', 'exist', true);
+ }
+ $password = $this->request->getPostParam('password');
+ if($password != $this->request->getPostParam('passwordrepeat')) {
+ $validation = $this->Validation->addValidationResult($validation, 'password', 'repeat', false);
+ }
+
+ // Create
+ if($validation === true)
+ {
+ $userId = $this->Users->createUser(
+ $this->request->getPostParam('username'),
+ $this->request->getPostParam('prename'),
+ $this->request->getPostParam('surname'),
+ $this->request->getPostParam('email'),
+ $this->request->getPostParam('password')
+ );
+
+ // Redirect to user
+ $user = $this->Users->getUserById($userId);
+ $this->redirect($this->linker->link(array($user['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('New user');
+
+ // Pass data to view
+ $this->set('username', $username);
+ $this->set('prename', $prename);
+ $this->set('surname', $surname);
+ $this->set('email', $email);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: edit.
+ *
+ * Edit a user.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $userUrl URL-Username of an user
+ */
+ public function edit($userUrl)
+ {
+ // User
+ $user = $this->Users->getUserByUrl($userUrl);
+
+ // Check permissions
+ if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0 && $user['id'] != \hhu\z\controllers\IntermediateController::$user['id']) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Values
+ $username = $user['username'];
+ $prename = $user['prename'];
+ $surname = $user['surname'];
+ $email = $user['email'];
+ $mailing = $user['mailing'];
+ $fields = array('username', 'prename', 'surname', 'email');
+ $validation = array();
+
+ // Edit user
+ if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save')))
+ {
+ // Get params and validate them
+ $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
+ $username = $this->request->getPostParam('username');
+ if($this->Users->usernameExists($username, $user['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'username', 'exist', true);
+ }
+ $password = $this->request->getPostParam('password');
+ if(!empty($password))
+ {
+ $validation = $this->Validation->addValidationResults($validation,
+ 'password',
+ $this->Validation->validateParam(
+ $this->request->getPostParams(),
+ 'password'
+ )
+ );
if($password != $this->request->getPostParam('passwordrepeat')) {
$validation = $this->Validation->addValidationResult($validation, 'password', 'repeat', false);
}
- }
- $prename = $this->request->getPostParam('prename');
- $surname = $this->request->getPostParam('surname');
- $email = $this->request->getPostParam('email');
- if($this->Users->emailExists($email, $user['id'])) {
- $validation = $this->Validation->addValidationResult($validation, 'email', 'exist', true);
- }
- $mailing = !is_null($this->request->getPostParam('mailing'));
-
- // Save changes
- if($validation === true)
- {
- // Edit user
- $this->Users->editUser(
- $user['id'],
- (count(array_intersect(array('admin','moderator'),\hhu\z\controllers\IntermediateController::$user['roles'])) > 0) ? $this->request->getPostParam('username') : $user['username'],
- $prename,
- $surname,
- $email,
- $password,
- $mailing
- );
-
- // Redirect to entry
- $user = $this->Users->getUserById($user['id']);
- $this->redirect($this->linker->link(array('user', $user['url']), 1));
- }
- }
-
- // Get validation settings
- $validationSettings = array();
- foreach($fields as &$field) {
- $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
- }
- $validationSettings['password'] = \nre\configs\AppConfig::$validation['password'];
-
-
- // Set titile
- $this->addTitleLocalized('Edit user');
-
- // Pass data to view
- $this->set('username', $username);
- $this->set('prename', $prename);
- $this->set('surname', $surname);
- $this->set('email', $email);
- $this->set('mailing', $mailing);
- $this->set('validation', $validation);
- $this->set('validationSettings', $validationSettings);
- }
-
-
- /**
- * Action: delete.
- *
- * Delete a user.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $userUrl URL-Username of an user
- */
- public function delete($userUrl)
- {
- // User
- $user = $this->Users->getUserByUrl($userUrl);
-
- // Check request method
- if($this->request->getRequestMethod() == 'POST')
- {
- // Check confirmation
- if(!is_null($this->request->getPostParam('delete')))
- {
- // Delete user
- $this->Users->deleteUser($user['id']);
-
- // Redirect to overview
- $this->redirect($this->linker->link(null, 1));
- }
-
- // Redirect to entry
- $this->redirect($this->linker->link(array('user', $user['url']), 1));
- }
-
-
- // Set titile
- $this->addTitleLocalized('Delete user');
-
- // Show confirmation
- $this->set('user', $user);
- }
-
-
-
-
- /**
- * Send mail for new user registration.
- *
- * @param array $user Newly registered user
- */
- private function sendRegistrationMail($user)
- {
- // Get system moderators
- $moderators = $this->Users->getUsersWithRole('moderator');
-
- // Send notification mail
- try {
- foreach($moderators as &$moderator)
- {
- if($moderator['mailing']) {
- \hhu\z\Utils::sendMail(
- $moderator['email'],
- 'userregistration',
- true,
- array(
- $moderator,
- $user
- ),
- $this->linker
- );
- }
- }
- }
- catch(\hhu\z\exceptions\MailingException $e) {
- $this->log($e->getMessage());
- }
- }
-
- }
+ }
+ $prename = $this->request->getPostParam('prename');
+ $surname = $this->request->getPostParam('surname');
+ $email = $this->request->getPostParam('email');
+ if($this->Users->emailExists($email, $user['id'])) {
+ $validation = $this->Validation->addValidationResult($validation, 'email', 'exist', true);
+ }
+ $mailing = !is_null($this->request->getPostParam('mailing'));
+
+ // Save changes
+ if($validation === true)
+ {
+ // Edit user
+ $this->Users->editUser(
+ $user['id'],
+ (count(array_intersect(array('admin','moderator'),\hhu\z\controllers\IntermediateController::$user['roles'])) > 0) ? $this->request->getPostParam('username') : $user['username'],
+ $prename,
+ $surname,
+ $email,
+ $password,
+ $mailing
+ );
+
+ // Redirect to entry
+ $user = $this->Users->getUserById($user['id']);
+ $this->redirect($this->linker->link(array('user', $user['url']), 1));
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array();
+ foreach($fields as &$field) {
+ $validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
+ }
+ $validationSettings['password'] = \nre\configs\AppConfig::$validation['password'];
+
+
+ // Set titile
+ $this->addTitleLocalized('Edit user');
+
+ // Pass data to view
+ $this->set('username', $username);
+ $this->set('prename', $prename);
+ $this->set('surname', $surname);
+ $this->set('email', $email);
+ $this->set('mailing', $mailing);
+ $this->set('validation', $validation);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+
+ /**
+ * Action: delete.
+ *
+ * Delete a user.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $userUrl URL-Username of an user
+ */
+ public function delete($userUrl)
+ {
+ // User
+ $user = $this->Users->getUserByUrl($userUrl);
+
+ // Check request method
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Check confirmation
+ if(!is_null($this->request->getPostParam('delete')))
+ {
+ // Delete user
+ $this->Users->deleteUser($user['id']);
+
+ // Redirect to overview
+ $this->redirect($this->linker->link(null, 1));
+ }
+
+ // Redirect to entry
+ $this->redirect($this->linker->link(array('user', $user['url']), 1));
+ }
+
+
+ // Set titile
+ $this->addTitleLocalized('Delete user');
+
+ // Show confirmation
+ $this->set('user', $user);
+ }
+
+
+
+
+ /**
+ * Send mail for new user registration.
+ *
+ * @param array $user Newly registered user
+ */
+ private function sendRegistrationMail($user)
+ {
+ // Get system moderators
+ $moderators = $this->Users->getUsersWithRole('moderator');
+
+ // Send notification mail
+ try {
+ foreach($moderators as &$moderator)
+ {
+ if($moderator['mailing']) {
+ \hhu\z\Utils::sendMail(
+ $moderator['email'],
+ 'userregistration',
+ true,
+ array(
+ $moderator,
+ $user
+ ),
+ $this->linker
+ );
+ }
+ }
+ }
+ catch(\hhu\z\exceptions\MailingException $e) {
+ $this->log($e->getMessage());
+ }
+ }
+
+ }
?>
diff --git a/controllers/XplevelsController.inc b/controllers/XplevelsController.inc
index 91bb32f5..e147d93f 100644
--- a/controllers/XplevelsController.inc
+++ b/controllers/XplevelsController.inc
@@ -1,188 +1,188 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers;
-
-
- /**
- * Controller of the XplevelsAgent to handle XP-levels of a
- * Seminary.
- *
- * @author Oliver Hanraths
- */
- class XplevelsController extends \hhu\z\controllers\SeminaryController
- {
- /**
- * Required components
- *
- * @var array
- */
- public $components = array('validation');
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('xplevels');
- /**
- * User permissions
- *
- * @var array
- */
- public $permissions = array(
- 'manage' => array('admin', 'moderator', 'user')
- );
-
-
-
-
- /**
- * Action: manage.
- *
- * Manage XP-levels.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a Seminary
- */
- public function manage($seminaryUrl)
- {
- // Get seminary
- $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
-
- // Check permissions
- if(
- (is_null(self::$character) && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0) &&
- $seminary['created_user_id'] != self::$user['id']
- ) {
- throw new \nre\exceptions\AccessDeniedException();
- }
-
- // Get XP-levels
- $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
-
- // Values
- $xplevelsValues = array();
- foreach($xplevels as &$xplevel) {
- $xplevelsValues[$xplevel['id']] = $xplevel;
- }
- $deletes = array();
- $validations = array(
- 'edit' => true,
- 'create' => true
- );
-
- // Edit
- $action = null;
- if($this->request->getRequestMethod() == 'POST')
- {
- // Edit and delete XP-levels
- if(!is_null($this->request->getPostParam('edit')))
- {
- $action = 'edit';
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers;
+
+
+ /**
+ * Controller of the XplevelsAgent to handle XP-levels of a
+ * Seminary.
+ *
+ * @author Oliver Hanraths
+ */
+ class XplevelsController extends \hhu\z\controllers\SeminaryController
+ {
+ /**
+ * Required components
+ *
+ * @var array
+ */
+ public $components = array('validation');
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('xplevels');
+ /**
+ * User permissions
+ *
+ * @var array
+ */
+ public $permissions = array(
+ 'manage' => array('admin', 'moderator', 'user')
+ );
+
+
+
+
+ /**
+ * Action: manage.
+ *
+ * Manage XP-levels.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a Seminary
+ */
+ public function manage($seminaryUrl)
+ {
+ // Get seminary
+ $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
+
+ // Check permissions
+ if(
+ (is_null(self::$character) && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) == 0) &&
+ $seminary['created_user_id'] != self::$user['id']
+ ) {
+ throw new \nre\exceptions\AccessDeniedException();
+ }
+
+ // Get XP-levels
+ $xplevels = $this->Xplevels->getXPLevelsForSeminary($seminary['id']);
+
+ // Values
+ $xplevelsValues = array();
+ foreach($xplevels as &$xplevel) {
+ $xplevelsValues[$xplevel['id']] = $xplevel;
+ }
+ $deletes = array();
+ $validations = array(
+ 'edit' => true,
+ 'create' => true
+ );
+
+ // Edit
+ $action = null;
+ if($this->request->getRequestMethod() == 'POST')
+ {
+ // Edit and delete XP-levels
+ if(!is_null($this->request->getPostParam('edit')))
+ {
+ $action = 'edit';
// Get params
$xplevelsValues = $this->request->getPostParam('xplevels');
$deletes = $this->request->getPostParam('deletes');
-
- // Validate params
- if(!is_array($deletes)) {
- $deletes = array();
- }
- foreach($xplevels as &$xplevel)
- {
- if(array_key_exists($xplevel['id'], $deletes)) {
- continue;
- }
-
- $xplevelValidation = $this->Validation->validateParams($xplevelsValues[$xplevel['id']], array('xps'));
- if($xplevelValidation !== true)
- {
- if(!is_array($validations['edit'])) {
- $validations['edit'] = array();
- }
- if(!array_key_exists($xplevel['id'], $validations['edit']) || !is_array($validations['edit'][$xplevel['id']])) {
- $validations['edit'][$xplevel['id']] = array();
- }
- $validations['edit'][$xplevel['id']] = $this->Validation->addValidationResults($validations['edit'][$xplevel['id']], 'xps', $xplevelValidation);
- }
- }
-
- // Edit and delete
- if($validations['edit'] === true)
- {
- foreach($xplevels as &$xplevel)
- {
- // Delete
- if(array_key_exists($xplevel['id'], $deletes)) {
- $this->Xplevels->deleteXPLevel($xplevel);
- }
- // Edit
- elseif(array_key_exists($xplevel['id'], $xplevelsValues))
- {
- $this->Xplevels->editXPLevel(
- $xplevel['id'],
- $xplevelsValues[$xplevel['id']]['xps']
- );
- }
- }
-
- // Redirect
- $this->redirect($this->linker->link(null, 3));
- }
- }
-
- // Create XP-level
- if(!is_null($this->request->getPostParam('create')))
- {
- $action = 'create';
-
- // Get params and validate them
- $xplevelnew = $this->request->getPostParam('xplevelnew');
- $validations[$action] = $this->Validation->validateParams($xplevelnew, array('xps'));
- // Create
- if($validations[$action] === true)
- {
- $this->Xplevels->createXPLevel(
- $this->Auth->getUserId(),
- $seminary['id'],
- $xplevelnew['xps']
- );
-
- // Redirect
- $this->redirect($this->linker->link(null, 3));
- }
- }
- }
-
- // Get validation settings
- $validationSettings = array(
- 'xps' => \nre\configs\AppConfig::$validation['xps']
- );
-
-
- // Set titile
- $this->addTitleLocalized('Manage XP-levels');
- $this->addTitle($seminary['title']);
-
- // Pass data to view
- $this->set('seminary', $seminary);
- $this->set('xplevels', $xplevels);
- $this->set('xplevelsValues', $xplevelsValues);
- $this->set('deletes', $deletes);
- $this->set('action', $action);
- $this->set('validations', $validations);
- $this->set('validationSettings', $validationSettings);
- }
-
- }
+ // Validate params
+ if(!is_array($deletes)) {
+ $deletes = array();
+ }
+ foreach($xplevels as &$xplevel)
+ {
+ if(array_key_exists($xplevel['id'], $deletes)) {
+ continue;
+ }
+
+ $xplevelValidation = $this->Validation->validateParams($xplevelsValues[$xplevel['id']], array('xps'));
+ if($xplevelValidation !== true)
+ {
+ if(!is_array($validations['edit'])) {
+ $validations['edit'] = array();
+ }
+ if(!array_key_exists($xplevel['id'], $validations['edit']) || !is_array($validations['edit'][$xplevel['id']])) {
+ $validations['edit'][$xplevel['id']] = array();
+ }
+ $validations['edit'][$xplevel['id']] = $this->Validation->addValidationResults($validations['edit'][$xplevel['id']], 'xps', $xplevelValidation);
+ }
+ }
+
+ // Edit and delete
+ if($validations['edit'] === true)
+ {
+ foreach($xplevels as &$xplevel)
+ {
+ // Delete
+ if(array_key_exists($xplevel['id'], $deletes)) {
+ $this->Xplevels->deleteXPLevel($xplevel);
+ }
+ // Edit
+ elseif(array_key_exists($xplevel['id'], $xplevelsValues))
+ {
+ $this->Xplevels->editXPLevel(
+ $xplevel['id'],
+ $xplevelsValues[$xplevel['id']]['xps']
+ );
+ }
+ }
+
+ // Redirect
+ $this->redirect($this->linker->link(null, 3));
+ }
+ }
+
+ // Create XP-level
+ if(!is_null($this->request->getPostParam('create')))
+ {
+ $action = 'create';
+
+ // Get params and validate them
+ $xplevelnew = $this->request->getPostParam('xplevelnew');
+ $validations[$action] = $this->Validation->validateParams($xplevelnew, array('xps'));
+
+ // Create
+ if($validations[$action] === true)
+ {
+ $this->Xplevels->createXPLevel(
+ $this->Auth->getUserId(),
+ $seminary['id'],
+ $xplevelnew['xps']
+ );
+
+ // Redirect
+ $this->redirect($this->linker->link(null, 3));
+ }
+ }
+ }
+
+ // Get validation settings
+ $validationSettings = array(
+ 'xps' => \nre\configs\AppConfig::$validation['xps']
+ );
+
+
+ // Set titile
+ $this->addTitleLocalized('Manage XP-levels');
+ $this->addTitle($seminary['title']);
+
+ // Pass data to view
+ $this->set('seminary', $seminary);
+ $this->set('xplevels', $xplevels);
+ $this->set('xplevelsValues', $xplevelsValues);
+ $this->set('deletes', $deletes);
+ $this->set('action', $action);
+ $this->set('validations', $validations);
+ $this->set('validationSettings', $validationSettings);
+ }
+
+ }
?>
diff --git a/controllers/components/AchievementComponent.inc b/controllers/components/AchievementComponent.inc
index 70601543..1c0e7385 100644
--- a/controllers/components/AchievementComponent.inc
+++ b/controllers/components/AchievementComponent.inc
@@ -1,41 +1,41 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers\components;
-
-
- /**
- * Component to handle achievements.
- *
- * @author Oliver Hanraths
- */
- class AchievementComponent extends \nre\core\Component
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('achievements');
-
-
-
-
- /**
- * Construct a new Achievements-component.
- */
- public function __construct()
- {
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers\components;
+
+
+ /**
+ * Component to handle achievements.
+ *
+ * @author Oliver Hanraths
+ */
+ class AchievementComponent extends \nre\core\Component
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('achievements');
+
+
+
+
+ /**
+ * Construct a new Achievements-component.
+ */
+ public function __construct()
+ {
+ }
+
+ }
?>
diff --git a/controllers/components/AuthComponent.inc b/controllers/components/AuthComponent.inc
index 0db6c69d..eab74914 100644
--- a/controllers/components/AuthComponent.inc
+++ b/controllers/components/AuthComponent.inc
@@ -1,79 +1,79 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers\components;
-
-
- /**
- * Component to handle authentication and authorization.
- *
- * @author Oliver Hanraths
- */
- class AuthComponent extends \nre\core\Component
- {
- /**
- * Key to save a user-ID as
- *
- * @var string
- */
- const KEY_USER_ID = 'user_id';
-
-
-
-
- /**
- * Construct a new Auth-component.
- */
- public function __construct()
- {
- // Start session
- if(session_id() === '') {
- session_start();
- }
- }
-
-
-
-
- /**
- * Set the ID of the user that is currently logged in.
- *
- * @param int $userId ID of the currently logged in user
- */
- public function setUserId($userId)
- {
- if(is_null($userId)) {
- unset($_SESSION[self::KEY_USER_ID]);
- }
- else {
- $_SESSION[self::KEY_USER_ID] = $userId;
- }
- }
-
-
- /**
- * Get the ID of the user that is currently logged in.
- *
- * @return int ID of the currently logged in user
- */
- public function getUserId()
- {
- if(array_key_exists(self::KEY_USER_ID, $_SESSION)) {
- return $_SESSION[self::KEY_USER_ID];
- }
-
-
- return null;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers\components;
+
+
+ /**
+ * Component to handle authentication and authorization.
+ *
+ * @author Oliver Hanraths
+ */
+ class AuthComponent extends \nre\core\Component
+ {
+ /**
+ * Key to save a user-ID as
+ *
+ * @var string
+ */
+ const KEY_USER_ID = 'user_id';
+
+
+
+
+ /**
+ * Construct a new Auth-component.
+ */
+ public function __construct()
+ {
+ // Start session
+ if(session_id() === '') {
+ session_start();
+ }
+ }
+
+
+
+
+ /**
+ * Set the ID of the user that is currently logged in.
+ *
+ * @param int $userId ID of the currently logged in user
+ */
+ public function setUserId($userId)
+ {
+ if(is_null($userId)) {
+ unset($_SESSION[self::KEY_USER_ID]);
+ }
+ else {
+ $_SESSION[self::KEY_USER_ID] = $userId;
+ }
+ }
+
+
+ /**
+ * Get the ID of the user that is currently logged in.
+ *
+ * @return int ID of the currently logged in user
+ */
+ public function getUserId()
+ {
+ if(array_key_exists(self::KEY_USER_ID, $_SESSION)) {
+ return $_SESSION[self::KEY_USER_ID];
+ }
+
+
+ return null;
+ }
+
+ }
?>
diff --git a/controllers/components/NotificationComponent.inc b/controllers/components/NotificationComponent.inc
index bddffc80..ecf17ac1 100644
--- a/controllers/components/NotificationComponent.inc
+++ b/controllers/components/NotificationComponent.inc
@@ -1,108 +1,108 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers\components;
-
-
- /**
- * Component to handle user notifications
- *
- * @author Oliver Hanraths
- */
- class NotificationComponent extends \nre\core\Component
- {
- /**
- * Type: Achievement
- *
- * @var string
- */
- const TYPE_ACHIEVEMENT = 'achievement';
- /**
- * Type: Level-up
- *
- * @var string
- */
- const TYPE_LEVELUP = 'levelup';
- /**
- * Key for Session-Array to store notifications in
- *
- * @var string
- */
- const SESSION_KEY = 'notifications';
-
-
-
-
- /**
- * Construct a new Notification-component.
- */
- public function __construct()
- {
- // Start session
- if(session_id() === '') {
- session_start();
- }
-
- // Prepare array
- if(!array_key_exists(self::SESSION_KEY, $_SESSION)) {
- $_SESSION[self::SESSION_KEY] = array();
- }
- }
-
-
-
-
- /**
- * Add a notification.
- *
- * @param string $type Type of notification
- * @param string $message Message to display
- * @param string $link Optional URL to link to
- * @param string $image Optional URL of image to display
- */
- public function addNotification($type, $message, $link=null, $image=null)
- {
- $_SESSION[self::SESSION_KEY][] = array(
- 'type' => $type,
- 'message' => $message,
- 'link' => $link,
- 'image' => $image
- );
- }
-
-
- /**
- * Get all registered notifiactions and clear them.
- *
- * @return array List of existing notifications
- */
- public function getNotifications()
- {
- $notifications = $_SESSION[self::SESSION_KEY];
- $this->clearNotifications();
-
-
- return $notifications;
- }
-
-
- /**
- * Clear all notifications currently registered
- */
- public function clearNotifications()
- {
- unset($_SESSION[self::SESSION_KEY]);
- $_SESSION[self::SESSION_KEY] = array();
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers\components;
+
+
+ /**
+ * Component to handle user notifications
+ *
+ * @author Oliver Hanraths
+ */
+ class NotificationComponent extends \nre\core\Component
+ {
+ /**
+ * Type: Achievement
+ *
+ * @var string
+ */
+ const TYPE_ACHIEVEMENT = 'achievement';
+ /**
+ * Type: Level-up
+ *
+ * @var string
+ */
+ const TYPE_LEVELUP = 'levelup';
+ /**
+ * Key for Session-Array to store notifications in
+ *
+ * @var string
+ */
+ const SESSION_KEY = 'notifications';
+
+
+
+
+ /**
+ * Construct a new Notification-component.
+ */
+ public function __construct()
+ {
+ // Start session
+ if(session_id() === '') {
+ session_start();
+ }
+
+ // Prepare array
+ if(!array_key_exists(self::SESSION_KEY, $_SESSION)) {
+ $_SESSION[self::SESSION_KEY] = array();
+ }
+ }
+
+
+
+
+ /**
+ * Add a notification.
+ *
+ * @param string $type Type of notification
+ * @param string $message Message to display
+ * @param string $link Optional URL to link to
+ * @param string $image Optional URL of image to display
+ */
+ public function addNotification($type, $message, $link=null, $image=null)
+ {
+ $_SESSION[self::SESSION_KEY][] = array(
+ 'type' => $type,
+ 'message' => $message,
+ 'link' => $link,
+ 'image' => $image
+ );
+ }
+
+
+ /**
+ * Get all registered notifiactions and clear them.
+ *
+ * @return array List of existing notifications
+ */
+ public function getNotifications()
+ {
+ $notifications = $_SESSION[self::SESSION_KEY];
+ $this->clearNotifications();
+
+
+ return $notifications;
+ }
+
+
+ /**
+ * Clear all notifications currently registered
+ */
+ public function clearNotifications()
+ {
+ unset($_SESSION[self::SESSION_KEY]);
+ $_SESSION[self::SESSION_KEY] = array();
+ }
+
+ }
?>
diff --git a/controllers/components/QuesttypedataComponent.inc b/controllers/components/QuesttypedataComponent.inc
index 6c23e4f6..1a55805f 100644
--- a/controllers/components/QuesttypedataComponent.inc
+++ b/controllers/components/QuesttypedataComponent.inc
@@ -3,25 +3,25 @@
/**
* The Legend of Z
*
- * @author Oliver Hanraths
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
*/
-
+
namespace hhu\z\controllers\components;
-
-
+
+
/**
* Component to handle data for Questtypes between different Quest states.
- *
- * @author Oliver Hanraths
+ *
+ * @author Oliver Hanraths
*/
class QuesttypedataComponent extends \nre\core\Component
{
/**
* Session key
- *
+ *
* @var string
*/
const SESSION_KEY = 'questtypes';
@@ -45,7 +45,7 @@
/**
* Set data with a key-value pair.
- *
+ *
* @param int $questId ID of Quest to set data for
* @param mixed $key Key
* @param mixed $value Value
@@ -64,7 +64,7 @@
/**
* Get data by a key.
- *
+ *
* @param int $questId ID of Quest to set data for
* @param mixed $key Key
* @return mixed Value
@@ -86,4 +86,4 @@
}
-?>
+?>
diff --git a/controllers/components/ValidationComponent.inc b/controllers/components/ValidationComponent.inc
index 33f7963d..0a639bf0 100644
--- a/controllers/components/ValidationComponent.inc
+++ b/controllers/components/ValidationComponent.inc
@@ -1,183 +1,183 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\controllers\components;
-
-
- /**
- * Component to validate user input.
- *
- * @author Oliver Hanraths
- */
- class ValidationComponent extends \nre\core\Component
- {
- /**
- * Validation settings
- *
- * @var array
- */
- private $config;
-
-
-
-
- /**
- * Construct a new Validation-component.
- */
- public function __construct()
- {
- // Get validation settings from configuration
- $this->config = \nre\configs\AppConfig::$validation;
- }
-
-
-
-
- /**
- * Validate an user input.
- *
- * @param mixed $input User input to validate
- * @param array $settings Validation setting
- * @return mixed True or the settings the validation fails on
- */
- public function validate($input, $settings)
- {
- $validation = array();
-
- // Min string length
- if(array_key_exists('minlength', $settings) && strlen($input) < $settings['minlength']) {
- $validation['minlength'] = $settings['minlength'];
- }
- // Max string length
- if(array_key_exists('maxlength', $settings) && strlen($input) > $settings['maxlength']) {
- $validation['maxlength'] = $settings['maxlength'];
- }
-
- // Regex
- if(array_key_exists('regex', $settings) && !preg_match($settings['regex'], $input)) {
- $validation['regex'] = $settings['regex'];
- }
-
-
- // Return true or the failed fields
- if(empty($validation)) {
- return true;
- }
- return $validation;
- }
-
-
- /**
- * Validate an user input parameter.
- *
- * @param array $params User input parameters
- * @param array $index Names of parameter to validate and to validate against
- * @return mixed True or the parameter with settings the validation failed on
- */
- public function validateParam($params, $index)
- {
- // Check parameter
- if(!array_key_exists($index, $params)) {
- throw new \nre\exceptions\ParamsNotValidException($index);
- }
- // Check settings
- if(!array_key_exists($index, $this->config)) {
- return true;
- }
-
-
- // Validate parameter and return result
- return $this->validate($params[$index], $this->config[$index]);
- }
-
-
- /**
- * Validate user input parameters.
- *
- * @param array $params User input parameters
- * @param array $indices Names of parameters to validate and to validate against
- * @return mixed True or the parameters with settings the validation failed on
- */
- public function validateParams($params, $indices)
- {
- // Validate parameters
- $validation = true;
- foreach($indices as $index) {
- $validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index));
- }
-
-
- // Return validation results
- return $validation;
- }
-
-
- /**
- * Add a custom determined validation result to a validation
- * array.
- *
- * @param mixed $validation Validation array to add result to
- * @param string $index Name of parameter of the custom validation result
- * @param string $setting Name of setting of the custom validation result
- * @param mixed $result Validation result
- * @return mixed The altered validation array
- */
- public function addValidationResult($validation, $index, $setting, $result)
- {
- // Create validation array
- if(!is_array($validation)) {
- $validation = array();
- }
-
- // Add validation results
- if(!array_key_exists($index, $validation)) {
- $validation[$index] = array();
- }
- $validation[$index][$setting] = $result;
-
-
- // Return new validation result
- return $validation;
- }
-
-
- /**
- * Add custom determined validation results to a validation
- * arary.
- *
- * @param mixed $validation Validation array to add result to
- * @param string $index Name of parameter of the custom validation result
- * @param mixed $result Validation result
- * @return mixed The altered validation array
- */
- public function addValidationResults($validation, $index, $results)
- {
- // Create validation array
- if(!is_array($validation)) {
- $validation = array();
- }
-
- // Add validation results
- if($results !== true) {
- $validation[$index] = $results;
- }
-
-
- // Return new validation result
- if(empty($validation)) {
- return true;
- }
- return $validation;
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\controllers\components;
+
+
+ /**
+ * Component to validate user input.
+ *
+ * @author Oliver Hanraths
+ */
+ class ValidationComponent extends \nre\core\Component
+ {
+ /**
+ * Validation settings
+ *
+ * @var array
+ */
+ private $config;
+
+
+
+
+ /**
+ * Construct a new Validation-component.
+ */
+ public function __construct()
+ {
+ // Get validation settings from configuration
+ $this->config = \nre\configs\AppConfig::$validation;
+ }
+
+
+
+
+ /**
+ * Validate an user input.
+ *
+ * @param mixed $input User input to validate
+ * @param array $settings Validation setting
+ * @return mixed True or the settings the validation fails on
+ */
+ public function validate($input, $settings)
+ {
+ $validation = array();
+
+ // Min string length
+ if(array_key_exists('minlength', $settings) && strlen($input) < $settings['minlength']) {
+ $validation['minlength'] = $settings['minlength'];
+ }
+ // Max string length
+ if(array_key_exists('maxlength', $settings) && strlen($input) > $settings['maxlength']) {
+ $validation['maxlength'] = $settings['maxlength'];
+ }
+
+ // Regex
+ if(array_key_exists('regex', $settings) && !preg_match($settings['regex'], $input)) {
+ $validation['regex'] = $settings['regex'];
+ }
+
+
+ // Return true or the failed fields
+ if(empty($validation)) {
+ return true;
+ }
+ return $validation;
+ }
+
+
+ /**
+ * Validate an user input parameter.
+ *
+ * @param array $params User input parameters
+ * @param array $index Names of parameter to validate and to validate against
+ * @return mixed True or the parameter with settings the validation failed on
+ */
+ public function validateParam($params, $index)
+ {
+ // Check parameter
+ if(!array_key_exists($index, $params)) {
+ throw new \nre\exceptions\ParamsNotValidException($index);
+ }
+ // Check settings
+ if(!array_key_exists($index, $this->config)) {
+ return true;
+ }
+
+
+ // Validate parameter and return result
+ return $this->validate($params[$index], $this->config[$index]);
+ }
+
+
+ /**
+ * Validate user input parameters.
+ *
+ * @param array $params User input parameters
+ * @param array $indices Names of parameters to validate and to validate against
+ * @return mixed True or the parameters with settings the validation failed on
+ */
+ public function validateParams($params, $indices)
+ {
+ // Validate parameters
+ $validation = true;
+ foreach($indices as $index) {
+ $validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index));
+ }
+
+
+ // Return validation results
+ return $validation;
+ }
+
+
+ /**
+ * Add a custom determined validation result to a validation
+ * array.
+ *
+ * @param mixed $validation Validation array to add result to
+ * @param string $index Name of parameter of the custom validation result
+ * @param string $setting Name of setting of the custom validation result
+ * @param mixed $result Validation result
+ * @return mixed The altered validation array
+ */
+ public function addValidationResult($validation, $index, $setting, $result)
+ {
+ // Create validation array
+ if(!is_array($validation)) {
+ $validation = array();
+ }
+
+ // Add validation results
+ if(!array_key_exists($index, $validation)) {
+ $validation[$index] = array();
+ }
+ $validation[$index][$setting] = $result;
+
+
+ // Return new validation result
+ return $validation;
+ }
+
+
+ /**
+ * Add custom determined validation results to a validation
+ * arary.
+ *
+ * @param mixed $validation Validation array to add result to
+ * @param string $index Name of parameter of the custom validation result
+ * @param mixed $result Validation result
+ * @return mixed The altered validation array
+ */
+ public function addValidationResults($validation, $index, $results)
+ {
+ // Create validation array
+ if(!is_array($validation)) {
+ $validation = array();
+ }
+
+ // Add validation results
+ if($results !== true) {
+ $validation[$index] = $results;
+ }
+
+
+ // Return new validation result
+ if(empty($validation)) {
+ return true;
+ }
+ return $validation;
+ }
+
+ }
?>
diff --git a/models/AchievementsModel.inc b/models/AchievementsModel.inc
index f138f6e5..aafae4b7 100644
--- a/models/AchievementsModel.inc
+++ b/models/AchievementsModel.inc
@@ -1,386 +1,386 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Achievements-tables.
- *
- * @author Oliver Hanraths
- */
- class AchievementsModel extends \hhu\z\Model
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('media');
-
-
-
-
- /**
- * Construct a new AchievementsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get an Achievement by its URL.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $achievementUrl URL-title of Achievement
- * @return array Achievement data
- */
- public function getAchievementByUrl($seminaryId, $achievementUrl)
- {
- $data = $this->db->query(
- 'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
- 'FROM achievements '.
- 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
- $seminaryId, $achievementUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($achievementUrl);
- }
-
-
- return $data[0];
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
- /**
- * Get an Achievement by its ID.
- *
- * @param int $achievementId ID of Achievement
- * @return array Achievement data
- */
- public function getAchievementById($achievementId)
- {
- $data = $this->db->query(
- 'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
- 'FROM achievements '.
- 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
- 'WHERE achievements.id = ?',
- 'i',
- $achievementId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($achievementId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get all not yet achieved Achievements for a Seminary that can
- * only be achieved once (only by one Character).
- *
- * @param int $seminaryId ID of Seminary
- * @return array Achievements data
- */
- public function getUnachievedOnlyOnceAchievementsForSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT achievements.id, achievements.pos, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
- 'FROM achievements '.
- 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
- 'WHERE achievements.seminary_id = ? AND only_once = 1 AND NOT EXISTS ('.
- 'SELECT character_id '.
- 'FROM achievements_characters '.
- 'WHERE achievements_characters.achievement_id = achievements.id'.
- ')',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get all Achievements that have a deadline.
- *
- * @param int $seminaryId ID of Seminary
- * @return array Achievements data
- */
- public function getDeadlineAchievements($seminaryId)
- {
- return $this->db->query(
- 'SELECT achievements.id, achievements.pos, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
- 'FROM achievements '.
- 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
- 'WHERE achievements.seminary_id = ? AND deadline IS NOT NULL '.
- 'ORDER BY deadline ASC',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get seldom Achievements.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $count Number of Achievements to retrieve
- * @param bool $alsoWithDeadline Include Achievements with deadline (optional)
- * @return array List of seldom Achievements
- */
- public function getSeldomAchievements($seminaryId, $count, $alsoWithDeadline=true)
- {
- return $this->db->query(
- 'SELECT achievements.id, achievements.pos, achievements.title, achievements.url, achievements.description, achievements.progress, achievements.hidden, achievements.unachieved_achievementsmedia_id, achievements.achieved_achievementsmedia_id, count(DISTINCT achievements_characters.character_id) AS c '.
- 'FROM achievements_characters '.
- 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = achievements_characters.character_id '.
- 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
- 'LEFT JOIN achievements ON achievements.id = achievements_characters.achievement_id '.
- 'WHERE achievements.seminary_id = ? AND achievements.only_once = 0 '.
- (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
- 'GROUP BY achievements_characters.achievement_id '.
- 'ORDER BY count(DISTINCT achievements_characters.character_id) ASC '.
- 'LIMIT ?',
- 'sii',
- 'user',
- $seminaryId,
- $count
- );
- }
-
-
- /**
- * Get all achieved Achievements for a Character.
- *
- * @param int $characterId ID of Character
- * @param bool $alsoWithDeadline Include Achievements with deadline (optional)
- * @return array Achievements data
- */
- public function getAchievedAchievementsForCharacter($characterId, $alsoWithDeadline=true)
- {
- return $this->db->query(
- 'SELECT achievements.id, achievements.pos, achievements_characters.created, achievements.title, achievements.url, achievements.description, achievements.progress, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
- 'FROM achievements '.
- 'INNER JOIN achievements_characters ON achievements_characters.achievement_id = achievements.id '.
- 'WHERE achievements_characters.character_id = ? '.
- (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
- 'ORDER BY achievements_characters.created DESC',
- 'i',
- $characterId
- );
- }
-
-
- /**
- * Get all not yet achieved Achievements for a Character.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $characterId ID of Character
- * @param boolean $includeOnlyOnce Include Achievements that can only be achieved by one Character
- * @param boolean $alsoWithDeadline Include milestone Achievements
- * @return array Achievements data
- */
- public function getUnachhievedAchievementsForCharacter($seminaryId, $characterId, $includeOnlyOnce=false, $alsoWithDeadline=true)
- {
- return $this->db->query(
- 'SELECT achievements.id, achievements.pos, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
- 'FROM achievements '.
- 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
- 'WHERE achievements.seminary_id = ? AND only_once <= ? AND NOT EXISTS ('.
- 'SELECT character_id '.
- 'FROM achievements_characters '.
- 'WHERE '.
- 'achievements_characters.achievement_id = achievements.id AND '.
- 'achievements_characters.character_id = ?'.
- ') '.
- (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
- 'ORDER BY achievements.pos ASC',
- 'iii',
- $seminaryId,
- $includeOnlyOnce,
- $characterId
- );
- }
-
-
- /**
- * Get the amount of Achievement for a Seminary.
- *
- * @param int $seminaryId ID of Seminary
- * @param boolean $includeOnlyOnce Include Achievements that can only be achieved by one Character
- * @param boolean $alsoWithDeadline Include milestone Achievements
- * @return int Count of Achievements
- */
- public function getAchievementsCountForSeminary($seminaryId, $includeOnlyOnce=false, $alsoWithDeadline=true)
- {
- $data = $this->db->query(
- 'SELECT count(id) AS c '.
- 'FROM achievements '.
- 'WHERE seminary_id = ? AND only_once <= ?'.
- (!$alsoWithDeadline ? ' AND achievements.deadline IS NULL ' : null),
- 'ii',
- $seminaryId,
- $includeOnlyOnce
- );
- if(!empty($data)) {
- return $data[0]['c'];
- }
-
-
- return 0;
- }
+ /**
+ * Model to interact with Achievements-tables.
+ *
+ * @author Oliver Hanraths
+ */
+ class AchievementsModel extends \hhu\z\Model
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('media');
- /**
- * Get all Achievements for a Seminary.
- *
- * @param int $seminaryId ID of Seminary
- * @return array List of Achievements
- */
- public function getAchievementsForSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
- 'FROM achievements '.
- 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
- 'WHERE seminary_id = ? '.
- 'ORDER BY pos ASC',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get the rank for the number of achieved Achievements.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $xps Amount of achieved Achievements
- * @return int Rank of Achievements count
- */
- public function getCountRank($seminaryId, $count)
- {
- $data = $this->db->query(
- 'SELECT count(*) AS c '.
- 'FROM ('.
- 'SELECT count(DISTINCT achievement_id) '.
- 'FROM achievements_characters '.
- 'LEFT JOIN achievements ON achievements.id = achievements_characters.achievement_id '.
- 'WHERE achievements.seminary_id = ? '.
- 'GROUP BY character_id '.
- 'HAVING count(DISTINCT achievement_id) > ?'.
- ') AS ranking',
- 'ii',
- $seminaryId,
- $count
- );
- if(!empty($data)) {
- return $data[0]['c'] + 1;
- }
-
-
- return 1;
- }
-
-
- /**
- * Get all date conditions for an Achievement.
- *
- * @param int $achievementId ID of Achievement
- * @return array Date conditions
- */
- public function getAchievementConditionsDate($achievementId)
- {
- return $this->db->query(
- 'SELECT id, `select` '.
- 'FROM achievementconditions_date '.
- 'WHERE achievement_id = ?',
- 'i',
- $achievementId
- );
- }
-
-
- /**
- * Check a date condition.
- *
- * @param string $select SELECT-string with date-functions
- * @return boolean Result
- */
- public function checkAchievementConditionDate($select)
- {
- $data = $this->db->query(
- 'SELECT ('.$select.') AS got '
- );
- if(!empty($data)) {
- return ($data[0]['got'] == 1);
- }
-
-
- return false;
- }
- /**
- * Add a new date condition.
- *
- * @param int $userId ID of creating user
- * @param int $achievementId ID of Achievement to add condition to
- * @param string $select SELECT-string for condition
- */
- public function addAchievementConditionDate($userId, $achievementId, $select)
- {
- $this->db->query(
- 'INSERT INTO achievementconditions_date '.
- '(created_user_id, achievement_id, `select`) '.
- 'VALUES '.
- '(?, ?, ?)',
- 'iis',
- $userId,
- $achievementId,
- $select
- );
-
- }
+ /**
+ * Construct a new AchievementsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
- /**
- * Edit a date condition.
- *
- * @param int $conditionId ID of condition to edit
- * @param string $select New SELECT-string for condition
- */
- public function editAchievementConditionDate($conditionId, $select)
- {
- $this->db->query(
- 'UPDATE achievementconditions_date '.
- 'SET `select` = ? '.
- 'WHERE id = ?',
- 'si',
- $select,
- $conditionId
- );
- }
+
+
+ /**
+ * Get an Achievement by its URL.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $achievementUrl URL-title of Achievement
+ * @return array Achievement data
+ */
+ public function getAchievementByUrl($seminaryId, $achievementUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
+ 'FROM achievements '.
+ 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
+ $seminaryId, $achievementUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($achievementUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get an Achievement by its ID.
+ *
+ * @param int $achievementId ID of Achievement
+ * @return array Achievement data
+ */
+ public function getAchievementById($achievementId)
+ {
+ $data = $this->db->query(
+ 'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
+ 'FROM achievements '.
+ 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
+ 'WHERE achievements.id = ?',
+ 'i',
+ $achievementId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($achievementId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get all not yet achieved Achievements for a Seminary that can
+ * only be achieved once (only by one Character).
+ *
+ * @param int $seminaryId ID of Seminary
+ * @return array Achievements data
+ */
+ public function getUnachievedOnlyOnceAchievementsForSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT achievements.id, achievements.pos, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
+ 'FROM achievements '.
+ 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
+ 'WHERE achievements.seminary_id = ? AND only_once = 1 AND NOT EXISTS ('.
+ 'SELECT character_id '.
+ 'FROM achievements_characters '.
+ 'WHERE achievements_characters.achievement_id = achievements.id'.
+ ')',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get all Achievements that have a deadline.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @return array Achievements data
+ */
+ public function getDeadlineAchievements($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT achievements.id, achievements.pos, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
+ 'FROM achievements '.
+ 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
+ 'WHERE achievements.seminary_id = ? AND deadline IS NOT NULL '.
+ 'ORDER BY deadline ASC',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get seldom Achievements.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $count Number of Achievements to retrieve
+ * @param bool $alsoWithDeadline Include Achievements with deadline (optional)
+ * @return array List of seldom Achievements
+ */
+ public function getSeldomAchievements($seminaryId, $count, $alsoWithDeadline=true)
+ {
+ return $this->db->query(
+ 'SELECT achievements.id, achievements.pos, achievements.title, achievements.url, achievements.description, achievements.progress, achievements.hidden, achievements.unachieved_achievementsmedia_id, achievements.achieved_achievementsmedia_id, count(DISTINCT achievements_characters.character_id) AS c '.
+ 'FROM achievements_characters '.
+ 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = achievements_characters.character_id '.
+ 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
+ 'LEFT JOIN achievements ON achievements.id = achievements_characters.achievement_id '.
+ 'WHERE achievements.seminary_id = ? AND achievements.only_once = 0 '.
+ (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
+ 'GROUP BY achievements_characters.achievement_id '.
+ 'ORDER BY count(DISTINCT achievements_characters.character_id) ASC '.
+ 'LIMIT ?',
+ 'sii',
+ 'user',
+ $seminaryId,
+ $count
+ );
+ }
+
+
+ /**
+ * Get all achieved Achievements for a Character.
+ *
+ * @param int $characterId ID of Character
+ * @param bool $alsoWithDeadline Include Achievements with deadline (optional)
+ * @return array Achievements data
+ */
+ public function getAchievedAchievementsForCharacter($characterId, $alsoWithDeadline=true)
+ {
+ return $this->db->query(
+ 'SELECT achievements.id, achievements.pos, achievements_characters.created, achievements.title, achievements.url, achievements.description, achievements.progress, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
+ 'FROM achievements '.
+ 'INNER JOIN achievements_characters ON achievements_characters.achievement_id = achievements.id '.
+ 'WHERE achievements_characters.character_id = ? '.
+ (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
+ 'ORDER BY achievements_characters.created DESC',
+ 'i',
+ $characterId
+ );
+ }
+
+
+ /**
+ * Get all not yet achieved Achievements for a Character.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $characterId ID of Character
+ * @param boolean $includeOnlyOnce Include Achievements that can only be achieved by one Character
+ * @param boolean $alsoWithDeadline Include milestone Achievements
+ * @return array Achievements data
+ */
+ public function getUnachhievedAchievementsForCharacter($seminaryId, $characterId, $includeOnlyOnce=false, $alsoWithDeadline=true)
+ {
+ return $this->db->query(
+ 'SELECT achievements.id, achievements.pos, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
+ 'FROM achievements '.
+ 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
+ 'WHERE achievements.seminary_id = ? AND only_once <= ? AND NOT EXISTS ('.
+ 'SELECT character_id '.
+ 'FROM achievements_characters '.
+ 'WHERE '.
+ 'achievements_characters.achievement_id = achievements.id AND '.
+ 'achievements_characters.character_id = ?'.
+ ') '.
+ (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
+ 'ORDER BY achievements.pos ASC',
+ 'iii',
+ $seminaryId,
+ $includeOnlyOnce,
+ $characterId
+ );
+ }
+
+
+ /**
+ * Get the amount of Achievement for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param boolean $includeOnlyOnce Include Achievements that can only be achieved by one Character
+ * @param boolean $alsoWithDeadline Include milestone Achievements
+ * @return int Count of Achievements
+ */
+ public function getAchievementsCountForSeminary($seminaryId, $includeOnlyOnce=false, $alsoWithDeadline=true)
+ {
+ $data = $this->db->query(
+ 'SELECT count(id) AS c '.
+ 'FROM achievements '.
+ 'WHERE seminary_id = ? AND only_once <= ?'.
+ (!$alsoWithDeadline ? ' AND achievements.deadline IS NULL ' : null),
+ 'ii',
+ $seminaryId,
+ $includeOnlyOnce
+ );
+ if(!empty($data)) {
+ return $data[0]['c'];
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Get all Achievements for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @return array List of Achievements
+ */
+ public function getAchievementsForSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
+ 'FROM achievements '.
+ 'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
+ 'WHERE seminary_id = ? '.
+ 'ORDER BY pos ASC',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get the rank for the number of achieved Achievements.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $xps Amount of achieved Achievements
+ * @return int Rank of Achievements count
+ */
+ public function getCountRank($seminaryId, $count)
+ {
+ $data = $this->db->query(
+ 'SELECT count(*) AS c '.
+ 'FROM ('.
+ 'SELECT count(DISTINCT achievement_id) '.
+ 'FROM achievements_characters '.
+ 'LEFT JOIN achievements ON achievements.id = achievements_characters.achievement_id '.
+ 'WHERE achievements.seminary_id = ? '.
+ 'GROUP BY character_id '.
+ 'HAVING count(DISTINCT achievement_id) > ?'.
+ ') AS ranking',
+ 'ii',
+ $seminaryId,
+ $count
+ );
+ if(!empty($data)) {
+ return $data[0]['c'] + 1;
+ }
+
+
+ return 1;
+ }
+
+
+ /**
+ * Get all date conditions for an Achievement.
+ *
+ * @param int $achievementId ID of Achievement
+ * @return array Date conditions
+ */
+ public function getAchievementConditionsDate($achievementId)
+ {
+ return $this->db->query(
+ 'SELECT id, `select` '.
+ 'FROM achievementconditions_date '.
+ 'WHERE achievement_id = ?',
+ 'i',
+ $achievementId
+ );
+ }
+
+
+ /**
+ * Check a date condition.
+ *
+ * @param string $select SELECT-string with date-functions
+ * @return boolean Result
+ */
+ public function checkAchievementConditionDate($select)
+ {
+ $data = $this->db->query(
+ 'SELECT ('.$select.') AS got '
+ );
+ if(!empty($data)) {
+ return ($data[0]['got'] == 1);
+ }
+
+
+ return false;
+ }
+
+
+ /**
+ * Add a new date condition.
+ *
+ * @param int $userId ID of creating user
+ * @param int $achievementId ID of Achievement to add condition to
+ * @param string $select SELECT-string for condition
+ */
+ public function addAchievementConditionDate($userId, $achievementId, $select)
+ {
+ $this->db->query(
+ 'INSERT INTO achievementconditions_date '.
+ '(created_user_id, achievement_id, `select`) '.
+ 'VALUES '.
+ '(?, ?, ?)',
+ 'iis',
+ $userId,
+ $achievementId,
+ $select
+ );
+
+ }
+
+
+ /**
+ * Edit a date condition.
+ *
+ * @param int $conditionId ID of condition to edit
+ * @param string $select New SELECT-string for condition
+ */
+ public function editAchievementConditionDate($conditionId, $select)
+ {
+ $this->db->query(
+ 'UPDATE achievementconditions_date '.
+ 'SET `select` = ? '.
+ 'WHERE id = ?',
+ 'si',
+ $select,
+ $conditionId
+ );
+ }
/**
* Copy all date conditions of an Achievement.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceAchievementId ID of Achievement to copy conditions from
* @param int $targetAchievementId ID of Achievement to copy conditions to
@@ -400,157 +400,157 @@
}
- /**
- * Delete a date condition.
- *
- * @param int $conditionId ID of condition to delete
- */
- public function deleteAchievementConditionDate($conditionId)
- {
- $this->db->query('DELETE FROM achievementconditions_date WHERE id = ?', 'i', $conditionId);
- }
-
-
- /**
- * Get all Character conditions for an Achievement.
- *
- * @param int $achievementId ID of Achievement
- * @return array Character conditions
- */
- public function getAchievementConditionsCharacter($achievementId)
- {
- return $this->db->query(
- 'SELECT id, field, value '.
- 'FROM achievementconditions_character '.
- 'WHERE achievement_id = ?',
- 'i',
- $achievementId
- );
- }
-
-
- /**
- * Check a Character condition.
- *
- * @param string $field Field to check
- * @param int $value The value the field has to match
- * @param int $characterId ID of Character
- * @return boolean Result
- */
- public function checkAchievementConditionCharacter($field, $value, $characterId)
- {
- $data = $this->db->query(
- "SELECT ($field >= $value) AS got ".
- 'FROM ('.
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- ') AS c '.
- 'WHERE c.id = ?',
- 'i',
- $characterId
- );
- if(!empty($data)) {
- return ($data[0]['got'] == 1);
- }
-
-
-
-
-
- return false;
- }
-
-
- /**
- * Get the progress for a Character condition.
- *
- * @param string $field Field to check
- * @param int $value The value the field has to match
- * @param int $characterId ID of Character
- * @return float Percentage progress
- */
- public function getAchievementConditionCharacterProgress($field, $value, $characterId)
- {
- $data = $this->db->query(
- "SELECT $field AS field ".
- 'FROM ('.
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- ') AS c '.
- 'WHERE c.id = ?',
- 'i',
- $characterId
- );
- if(!empty($data)) {
- return $data[0]['field'] / $value;
- }
-
-
- return 0;
- }
+ /**
+ * Delete a date condition.
+ *
+ * @param int $conditionId ID of condition to delete
+ */
+ public function deleteAchievementConditionDate($conditionId)
+ {
+ $this->db->query('DELETE FROM achievementconditions_date WHERE id = ?', 'i', $conditionId);
+ }
- /**
- * Add a new Character condition.
- *
- * @param int $userId ID of creating user
- * @param int $achievementId ID of Achievement to add condition to
- * @param string $field Field to match
- * @param string $value Value to match
- */
- public function addAchievementConditionCharacter($userId, $achievementId, $field, $value)
- {
- $this->db->query(
- 'INSERT INTO achievementconditions_character '.
- '(created_user_id, achievement_id, field, value) '.
- 'VALUES '.
- '(?, ?, ?, ?)',
- 'iiss',
- $userId,
- $achievementId,
- $field,
- $value
- );
-
- }
+ /**
+ * Get all Character conditions for an Achievement.
+ *
+ * @param int $achievementId ID of Achievement
+ * @return array Character conditions
+ */
+ public function getAchievementConditionsCharacter($achievementId)
+ {
+ return $this->db->query(
+ 'SELECT id, field, value '.
+ 'FROM achievementconditions_character '.
+ 'WHERE achievement_id = ?',
+ 'i',
+ $achievementId
+ );
+ }
- /**
- * Edit a Character condition.
- *
- * @param int $conditionId ID of condition to edit
- * @param string $field Field to match
- * @param string $value Value to match
- */
- public function editAchievementConditionCharacter($conditionId, $field, $value)
- {
- $this->db->query(
- 'UPDATE achievementconditions_character '.
- 'SET field = ?, value = ? '.
- 'WHERE id = ?',
- 'ssi',
- $field,
- $value,
- $conditionId
- );
- }
+ /**
+ * Check a Character condition.
+ *
+ * @param string $field Field to check
+ * @param int $value The value the field has to match
+ * @param int $characterId ID of Character
+ * @return boolean Result
+ */
+ public function checkAchievementConditionCharacter($field, $value, $characterId)
+ {
+ $data = $this->db->query(
+ "SELECT ($field >= $value) AS got ".
+ 'FROM ('.
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ ') AS c '.
+ 'WHERE c.id = ?',
+ 'i',
+ $characterId
+ );
+ if(!empty($data)) {
+ return ($data[0]['got'] == 1);
+ }
+
+
+
+
+
+ return false;
+ }
+
+
+ /**
+ * Get the progress for a Character condition.
+ *
+ * @param string $field Field to check
+ * @param int $value The value the field has to match
+ * @param int $characterId ID of Character
+ * @return float Percentage progress
+ */
+ public function getAchievementConditionCharacterProgress($field, $value, $characterId)
+ {
+ $data = $this->db->query(
+ "SELECT $field AS field ".
+ 'FROM ('.
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ ') AS c '.
+ 'WHERE c.id = ?',
+ 'i',
+ $characterId
+ );
+ if(!empty($data)) {
+ return $data[0]['field'] / $value;
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Add a new Character condition.
+ *
+ * @param int $userId ID of creating user
+ * @param int $achievementId ID of Achievement to add condition to
+ * @param string $field Field to match
+ * @param string $value Value to match
+ */
+ public function addAchievementConditionCharacter($userId, $achievementId, $field, $value)
+ {
+ $this->db->query(
+ 'INSERT INTO achievementconditions_character '.
+ '(created_user_id, achievement_id, field, value) '.
+ 'VALUES '.
+ '(?, ?, ?, ?)',
+ 'iiss',
+ $userId,
+ $achievementId,
+ $field,
+ $value
+ );
+
+ }
+
+
+ /**
+ * Edit a Character condition.
+ *
+ * @param int $conditionId ID of condition to edit
+ * @param string $field Field to match
+ * @param string $value Value to match
+ */
+ public function editAchievementConditionCharacter($conditionId, $field, $value)
+ {
+ $this->db->query(
+ 'UPDATE achievementconditions_character '.
+ 'SET field = ?, value = ? '.
+ 'WHERE id = ?',
+ 'ssi',
+ $field,
+ $value,
+ $conditionId
+ );
+ }
/**
* Copy all Character conditions of an Achievement.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceAchievementId ID of Achievement to copy conditions from
* @param int $targetAchievementId ID of Achievement to copy conditions to
@@ -570,186 +570,186 @@
}
- /**
- * Delete a Character condition.
- *
- * @param int $conditionId ID of condition to delete
- */
- public function deleteAchievementConditionCharacter($conditionId)
- {
- $this->db->query('DELETE FROM achievementconditions_character WHERE id = ?', 'i', $conditionId);
- }
-
-
- /**
- * Get all Quest conditions for an Achievement.
- *
- * @param int $achievementId ID of Achievement
- * @return array Quest conditions
- */
- public function getAchievementConditionsQuest($achievementId)
- {
- return $this->db->query(
- 'SELECT id, field, `count`, value, quest_id, status, groupby '.
- 'FROM achievementconditions_quest '.
- 'WHERE achievement_id = ?',
- 'i',
- $achievementId
- );
- }
-
-
- /**
- * Check a Quest condition.
- *
- * @param string $field Field to check
- * @param boolean $count Conut field-value
- * @param int $value The value the field has to match
- * @param int $status Status of Quest or NULL
- * @param string $groupby Field to group or NULL
- * @param int $questId ID of related Quest or NULL
- * @param int $characterId ID of Character
- * @return boolean Result
- */
- public function checkAchievementConditionQuest($field, $count, $value, $status, $groupby, $questId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT ('.(
- $count
- ? "count($field) = $value"
- : "$field = $value"
- ). ') AS got '.
- 'FROM quests_characters '.
- 'WHERE '.
- 'character_id = ?'.
- (!is_null($questId) ? " AND quest_id = $questId" : '').
- (!is_null($status) ? " AND status = $status" : '').
- (!is_null($groupby) ? " GROUP BY $groupby" : ''),
- 'i',
- $characterId
- );
- if(!empty($data)) {
- foreach($data as &$datum) {
- if($datum['got'] == 1) {
- return true;
- }
- }
- }
-
-
- return false;
- }
-
-
- /**
- * Get the progress for a Quest condition.
- *
- * @param string $field Field to check
- * @param boolean $count Conut field-value
- * @param int $value The value the field has to match
- * @param int $status Status of Quest or NULL
- * @param string $groupby Field to group or NULL
- * @param int $questId ID of related Quest or NULL
- * @param int $characterId ID of Character
- * @return float Percentage progress
- */
- public function getAchievementConditionQuestProgress($field, $count, $value, $status, $groupby, $questId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT '.(
- $count
- ? "count($field)"
- : "$field"
- ). ' AS field '.
- 'FROM quests_characters '.
- 'WHERE '.
- 'character_id = ?'.
- (!is_null($questId) ? " AND quest_id = $questId" : '').
- (!is_null($status) ? " AND status = $status" : '').
- (!is_null($groupby) ? " GROUP BY $groupby" : ''),
- 'i',
- $characterId
- );
- if(!empty($data))
- {
- $maxField = 0;
- foreach($data as &$datum) {
- $maxField = max($maxField, intval($datum['field']));
- }
-
- return $maxField / $value;
- }
-
-
- return 0;
- }
+ /**
+ * Delete a Character condition.
+ *
+ * @param int $conditionId ID of condition to delete
+ */
+ public function deleteAchievementConditionCharacter($conditionId)
+ {
+ $this->db->query('DELETE FROM achievementconditions_character WHERE id = ?', 'i', $conditionId);
+ }
- /**
- * Add a new Quest condition.
- *
- * @param int $userId ID of creating user
- * @param int $achievementId ID of Achievement to add condition to
- * @param string $field Field to match
- * @param boolean $count Count the value
- * @param string $value Value to match
- * @param int $questId ID of Quest (optional)
- * @param int $status Quest status (optional)
- * @param string $groupby Field to group by (optional)
- */
- public function addAchievementConditionQuest($userId, $achievementId, $field, $count, $value, $questId=null, $status=null, $groupby=null)
- {
- $this->db->query(
- 'INSERT INTO achievementconditions_quest '.
- '(created_user_id, achievement_id, field, count, value, quest_id, status, groupby) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?, ?, ?, ?)',
- 'iisisiis',
- $userId,
- $achievementId,
- $field,
- $count,
- $value,
- $questId,
- $status,
- $groupby
- );
-
- }
+ /**
+ * Get all Quest conditions for an Achievement.
+ *
+ * @param int $achievementId ID of Achievement
+ * @return array Quest conditions
+ */
+ public function getAchievementConditionsQuest($achievementId)
+ {
+ return $this->db->query(
+ 'SELECT id, field, `count`, value, quest_id, status, groupby '.
+ 'FROM achievementconditions_quest '.
+ 'WHERE achievement_id = ?',
+ 'i',
+ $achievementId
+ );
+ }
- /**
- * Edit a Quest condition.
- *
- * @param int $conditionId ID of condition to edit
- * @param string $field Field to match
- * @param boolean $count Count the value
- * @param string $value Value to match
- * @param int $questId ID of Quest (optional)
- * @param int $status Quest status (optional)
- * @param string $groupby Field to group by (optional)
- */
- public function editAchievementConditionQuest($conditionId, $field, $count, $value, $questId=null, $status=null, $groupby=null)
- {
- $this->db->query(
- 'UPDATE achievementconditions_quest '.
- 'SET field = ?, count = ?, value = ?, quest_id = ?, status = ?, groupby = ? '.
- 'WHERE id = ?',
- 'sisiisi',
- $field,
- $count,
- $value,
- $questId,
- $status,
- $groupby,
- $conditionId
- );
- }
+ /**
+ * Check a Quest condition.
+ *
+ * @param string $field Field to check
+ * @param boolean $count Conut field-value
+ * @param int $value The value the field has to match
+ * @param int $status Status of Quest or NULL
+ * @param string $groupby Field to group or NULL
+ * @param int $questId ID of related Quest or NULL
+ * @param int $characterId ID of Character
+ * @return boolean Result
+ */
+ public function checkAchievementConditionQuest($field, $count, $value, $status, $groupby, $questId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT ('.(
+ $count
+ ? "count($field) = $value"
+ : "$field = $value"
+ ). ') AS got '.
+ 'FROM quests_characters '.
+ 'WHERE '.
+ 'character_id = ?'.
+ (!is_null($questId) ? " AND quest_id = $questId" : '').
+ (!is_null($status) ? " AND status = $status" : '').
+ (!is_null($groupby) ? " GROUP BY $groupby" : ''),
+ 'i',
+ $characterId
+ );
+ if(!empty($data)) {
+ foreach($data as &$datum) {
+ if($datum['got'] == 1) {
+ return true;
+ }
+ }
+ }
+
+
+ return false;
+ }
+
+
+ /**
+ * Get the progress for a Quest condition.
+ *
+ * @param string $field Field to check
+ * @param boolean $count Conut field-value
+ * @param int $value The value the field has to match
+ * @param int $status Status of Quest or NULL
+ * @param string $groupby Field to group or NULL
+ * @param int $questId ID of related Quest or NULL
+ * @param int $characterId ID of Character
+ * @return float Percentage progress
+ */
+ public function getAchievementConditionQuestProgress($field, $count, $value, $status, $groupby, $questId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT '.(
+ $count
+ ? "count($field)"
+ : "$field"
+ ). ' AS field '.
+ 'FROM quests_characters '.
+ 'WHERE '.
+ 'character_id = ?'.
+ (!is_null($questId) ? " AND quest_id = $questId" : '').
+ (!is_null($status) ? " AND status = $status" : '').
+ (!is_null($groupby) ? " GROUP BY $groupby" : ''),
+ 'i',
+ $characterId
+ );
+ if(!empty($data))
+ {
+ $maxField = 0;
+ foreach($data as &$datum) {
+ $maxField = max($maxField, intval($datum['field']));
+ }
+
+ return $maxField / $value;
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Add a new Quest condition.
+ *
+ * @param int $userId ID of creating user
+ * @param int $achievementId ID of Achievement to add condition to
+ * @param string $field Field to match
+ * @param boolean $count Count the value
+ * @param string $value Value to match
+ * @param int $questId ID of Quest (optional)
+ * @param int $status Quest status (optional)
+ * @param string $groupby Field to group by (optional)
+ */
+ public function addAchievementConditionQuest($userId, $achievementId, $field, $count, $value, $questId=null, $status=null, $groupby=null)
+ {
+ $this->db->query(
+ 'INSERT INTO achievementconditions_quest '.
+ '(created_user_id, achievement_id, field, count, value, quest_id, status, groupby) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?, ?, ?, ?)',
+ 'iisisiis',
+ $userId,
+ $achievementId,
+ $field,
+ $count,
+ $value,
+ $questId,
+ $status,
+ $groupby
+ );
+
+ }
+
+
+ /**
+ * Edit a Quest condition.
+ *
+ * @param int $conditionId ID of condition to edit
+ * @param string $field Field to match
+ * @param boolean $count Count the value
+ * @param string $value Value to match
+ * @param int $questId ID of Quest (optional)
+ * @param int $status Quest status (optional)
+ * @param string $groupby Field to group by (optional)
+ */
+ public function editAchievementConditionQuest($conditionId, $field, $count, $value, $questId=null, $status=null, $groupby=null)
+ {
+ $this->db->query(
+ 'UPDATE achievementconditions_quest '.
+ 'SET field = ?, count = ?, value = ?, quest_id = ?, status = ?, groupby = ? '.
+ 'WHERE id = ?',
+ 'sisiisi',
+ $field,
+ $count,
+ $value,
+ $questId,
+ $status,
+ $groupby,
+ $conditionId
+ );
+ }
/**
* Copy all Quest conditions of an Achievement.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceAchievementId ID of Achievement to copy conditions from
* @param int $targetAchievementId ID of Achievement to copy conditions to
@@ -793,178 +793,178 @@
}
- /**
- * Delete a Quest condition.
- *
- * @param int $conditionId ID of condition to delete
- */
- public function deleteAchievementConditionQuest($conditionId)
- {
- $this->db->query('DELETE FROM achievementconditions_quest WHERE id = ?', 'i', $conditionId);
- }
-
-
- /**
- * Get all Metaachievement conditions for an Achievement.
- *
- * @param int $achievementId ID of Achievement
- * @return array Metaachievement conditions
- */
- public function getAchievementConditionsAchievement($achievementId)
- {
- return $this->db->query(
- 'SELECT id, field, `count`, value, meta_achievement_id, groupby '.
- 'FROM achievementconditions_achievement '.
- 'WHERE achievement_id = ?',
- 'i',
- $achievementId
- );
- }
-
-
- /**
- * Check a Metaachievement condition.
- *
- * @param string $field Field to check
- * @param boolean $count Conut field-value
- * @param int $value The value the field has to match
- * @param string $groupby Field to group or NULL
- * @param int $metaAchievementId ID of related Achievement or NULL
- * @param int $characterId ID of Character
- * @return boolean Result
- */
- public function checkAchievementConditionAchievement($field, $count, $value, $groupby, $metaAchievementId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT ('.(
- $count
- ? "count($field) >= $value"
- : "$field = $value"
- ). ') AS got '.
- 'FROM achievements_characters '.
- 'WHERE '.
- 'character_id = ?'.
- (!is_null($metaAchievementId) ? " AND achievement_id = $metaAchievementId" : '').
- (!is_null($groupby) ? " GROUP BY $groupby" : ''),
- 'i',
- $characterId
- );
- if(!empty($data)) {
- foreach($data as &$datum) {
- if($datum['got'] == 1) {
- return true;
- }
- }
- }
-
-
- return false;
- }
-
-
- /**
- * Get the progress for a Metaachievement condition.
- *
- * @param string $field Field to check
- * @param boolean $count Conut field-value
- * @param int $value The value the field has to match
- * @param string $groupby Field to group or NULL
- * @param int $metaAchievementId ID of related Achievement or NULL
- * @param int $characterId ID of Character
- * @return float Percentage progress
- */
- public function getAchievementConditionAchievementProgress($field, $count, $value, $groupby, $metaAchievementId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT '.(
- $count
- ? "count($field)"
- : "$field"
- ). ' AS field '.
- 'FROM achievements_characters '.
- 'WHERE '.
- 'character_id = ?'.
- (!is_null($metaAchievementId) ? " AND achievement_id = $metaAchievementId" : '').
- (!is_null($groupby) ? " GROUP BY $groupby" : ''),
- 'i',
- $characterId
- );
- if(!empty($data))
- {
- $maxField = 0;
- foreach($data as &$datum) {
- $maxField = max($maxField, intval($datum['field']));
- }
-
- return $maxField / $value;
- }
-
-
- return 0;
- }
+ /**
+ * Delete a Quest condition.
+ *
+ * @param int $conditionId ID of condition to delete
+ */
+ public function deleteAchievementConditionQuest($conditionId)
+ {
+ $this->db->query('DELETE FROM achievementconditions_quest WHERE id = ?', 'i', $conditionId);
+ }
- /**
- * Add a new Achievement condition.
- *
- * @param int $userId ID of creating user
- * @param int $achievementId ID of Achievement to add condition to
- * @param string $field Field to match
- * @param boolean $count Count the value
- * @param string $value Value to match
- * @param int $metaAchievementId ID of Meta-Achievement (optional)
- * @param string $groupby Field to group by (optional)
- */
- public function addAchievementConditionAchievement($userId, $achievementId, $field, $count, $value, $metaAchievementId=null, $groupby=null)
- {
- $this->db->query(
- 'INSERT INTO achievementconditions_achievement '.
- '(created_user_id, achievement_id, field, count, value, meta_achievement_id, groupby) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?, ?, ?)',
- 'iisisis',
- $userId,
- $achievementId,
- $field,
- $count,
- $value,
- $metaAchievementId,
- $groupby
- );
-
- }
+ /**
+ * Get all Metaachievement conditions for an Achievement.
+ *
+ * @param int $achievementId ID of Achievement
+ * @return array Metaachievement conditions
+ */
+ public function getAchievementConditionsAchievement($achievementId)
+ {
+ return $this->db->query(
+ 'SELECT id, field, `count`, value, meta_achievement_id, groupby '.
+ 'FROM achievementconditions_achievement '.
+ 'WHERE achievement_id = ?',
+ 'i',
+ $achievementId
+ );
+ }
- /**
- * Edit a Achievement condition.
- *
- * @param int $conditionId ID of condition to edit
- * @param string $field Field to match
- * @param boolean $count Count the value
- * @param string $value Value to match
- * @param int $metaAchievementId ID of Achievement (optional)
- * @param string $groupby Field to group by (optional)
- */
- public function editAchievementConditionAchievement($conditionId, $field, $count, $value, $metaAchievementId=null, $groupby=null)
- {
- $this->db->query(
- 'UPDATE achievementconditions_achievement '.
- 'SET field = ?, count = ?, value = ?, meta_achievement_id = ?, groupby = ? '.
- 'WHERE id = ?',
- 'sisisi',
- $field,
- $count,
- $value,
- $metaAchievementId,
- $groupby,
- $conditionId
- );
- }
+ /**
+ * Check a Metaachievement condition.
+ *
+ * @param string $field Field to check
+ * @param boolean $count Conut field-value
+ * @param int $value The value the field has to match
+ * @param string $groupby Field to group or NULL
+ * @param int $metaAchievementId ID of related Achievement or NULL
+ * @param int $characterId ID of Character
+ * @return boolean Result
+ */
+ public function checkAchievementConditionAchievement($field, $count, $value, $groupby, $metaAchievementId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT ('.(
+ $count
+ ? "count($field) >= $value"
+ : "$field = $value"
+ ). ') AS got '.
+ 'FROM achievements_characters '.
+ 'WHERE '.
+ 'character_id = ?'.
+ (!is_null($metaAchievementId) ? " AND achievement_id = $metaAchievementId" : '').
+ (!is_null($groupby) ? " GROUP BY $groupby" : ''),
+ 'i',
+ $characterId
+ );
+ if(!empty($data)) {
+ foreach($data as &$datum) {
+ if($datum['got'] == 1) {
+ return true;
+ }
+ }
+ }
+
+
+ return false;
+ }
+
+
+ /**
+ * Get the progress for a Metaachievement condition.
+ *
+ * @param string $field Field to check
+ * @param boolean $count Conut field-value
+ * @param int $value The value the field has to match
+ * @param string $groupby Field to group or NULL
+ * @param int $metaAchievementId ID of related Achievement or NULL
+ * @param int $characterId ID of Character
+ * @return float Percentage progress
+ */
+ public function getAchievementConditionAchievementProgress($field, $count, $value, $groupby, $metaAchievementId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT '.(
+ $count
+ ? "count($field)"
+ : "$field"
+ ). ' AS field '.
+ 'FROM achievements_characters '.
+ 'WHERE '.
+ 'character_id = ?'.
+ (!is_null($metaAchievementId) ? " AND achievement_id = $metaAchievementId" : '').
+ (!is_null($groupby) ? " GROUP BY $groupby" : ''),
+ 'i',
+ $characterId
+ );
+ if(!empty($data))
+ {
+ $maxField = 0;
+ foreach($data as &$datum) {
+ $maxField = max($maxField, intval($datum['field']));
+ }
+
+ return $maxField / $value;
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Add a new Achievement condition.
+ *
+ * @param int $userId ID of creating user
+ * @param int $achievementId ID of Achievement to add condition to
+ * @param string $field Field to match
+ * @param boolean $count Count the value
+ * @param string $value Value to match
+ * @param int $metaAchievementId ID of Meta-Achievement (optional)
+ * @param string $groupby Field to group by (optional)
+ */
+ public function addAchievementConditionAchievement($userId, $achievementId, $field, $count, $value, $metaAchievementId=null, $groupby=null)
+ {
+ $this->db->query(
+ 'INSERT INTO achievementconditions_achievement '.
+ '(created_user_id, achievement_id, field, count, value, meta_achievement_id, groupby) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?, ?, ?)',
+ 'iisisis',
+ $userId,
+ $achievementId,
+ $field,
+ $count,
+ $value,
+ $metaAchievementId,
+ $groupby
+ );
+
+ }
+
+
+ /**
+ * Edit a Achievement condition.
+ *
+ * @param int $conditionId ID of condition to edit
+ * @param string $field Field to match
+ * @param boolean $count Count the value
+ * @param string $value Value to match
+ * @param int $metaAchievementId ID of Achievement (optional)
+ * @param string $groupby Field to group by (optional)
+ */
+ public function editAchievementConditionAchievement($conditionId, $field, $count, $value, $metaAchievementId=null, $groupby=null)
+ {
+ $this->db->query(
+ 'UPDATE achievementconditions_achievement '.
+ 'SET field = ?, count = ?, value = ?, meta_achievement_id = ?, groupby = ? '.
+ 'WHERE id = ?',
+ 'sisisi',
+ $field,
+ $count,
+ $value,
+ $metaAchievementId,
+ $groupby,
+ $conditionId
+ );
+ }
/**
* Copy all Achievement conditions of an Achievement.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceAchievementId ID of Achievement to copy conditions from
* @param int $targetAchievementId ID of Achievement to copy conditions to
@@ -1008,279 +1008,279 @@
}
- /**
- * Delete a Achievement condition.
- *
- * @param int $conditionId ID of condition to delete
- */
- public function deleteAchievementConditionAchievement($conditionId)
- {
- $this->db->query('DELETE FROM achievementconditions_achievement WHERE id = ?', 'i', $conditionId);
- }
-
-
- /**
- * Set an Achievement as achieved for a Character.
- *
- * @param int $achievementId ID of Achievement
- * @param int $characterId ID of Character
- */
- public function setAchievementAchieved($achievementId, $characterId)
- {
- $this->db->query(
- 'INSERT INTO achievements_characters '.
- '(achievement_id, character_id) '.
- 'VALUES '.
- '(?, ?)',
- 'ii',
- $achievementId, $characterId
- );
- }
-
-
- /**
- * Check if a Character has achieved an Achievement.
- *
- * @param int $achievementId ID of Achievement
- * @param int $characterId ID of Character
- * @return boolean Whether Character has achieved the Achievement or not
- */
- public function hasCharacterAchievedAchievement($achievementId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT achievement_id, character_id, created '.
- 'FROM achievements_characters '.
- 'WHERE achievement_id = ? AND character_id = ?',
- 'ii',
- $achievementId, $characterId
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return false;
- }
+ /**
+ * Delete a Achievement condition.
+ *
+ * @param int $conditionId ID of condition to delete
+ */
+ public function deleteAchievementConditionAchievement($conditionId)
+ {
+ $this->db->query('DELETE FROM achievementconditions_achievement WHERE id = ?', 'i', $conditionId);
+ }
- /**
- * Get all existing Achievements conditions.
- *
- * @return array List of Achievements conditions
- */
- public function getAchievementsConditions()
- {
- return $this->db->query(
- 'SELECT id, created, `condition` '.
- 'FROM achievementconditions'
- );
- }
+ /**
+ * Set an Achievement as achieved for a Character.
+ *
+ * @param int $achievementId ID of Achievement
+ * @param int $characterId ID of Character
+ */
+ public function setAchievementAchieved($achievementId, $characterId)
+ {
+ $this->db->query(
+ 'INSERT INTO achievements_characters '.
+ '(achievement_id, character_id) '.
+ 'VALUES '.
+ '(?, ?)',
+ 'ii',
+ $achievementId, $characterId
+ );
+ }
- /**
- * Check if an Achievement title already exists.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $title Achievement title to check
- * @param int $characterId Do not check this ID (for editing)
- * @return boolean Whether Achievement title exists or not
- */
- public function achievementTitleExists($seminaryId, $title, $achievementId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM achievements '.
- 'WHERE seminary_id = ? AND (title = ? OR url = ?)',
- 'iss',
- $seminaryId,
- $title,
- \nre\core\Linker::createLinkParam($title)
- );
-
-
- return (!empty($data) && (is_null($achievementId) || $achievementId != $data[0]['id']));
- }
+ /**
+ * Check if a Character has achieved an Achievement.
+ *
+ * @param int $achievementId ID of Achievement
+ * @param int $characterId ID of Character
+ * @return boolean Whether Character has achieved the Achievement or not
+ */
+ public function hasCharacterAchievedAchievement($achievementId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT achievement_id, character_id, created '.
+ 'FROM achievements_characters '.
+ 'WHERE achievement_id = ? AND character_id = ?',
+ 'ii',
+ $achievementId, $characterId
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
- /**
- * Create a new Achievement for a Seminary.
- *
- * @param int $userId ID of creating user
- * @param int $seminaryId ID of Seminary
- * @param int $conditionId ID of Achievement condition
- * @param string $title Title of new Achievement
- * @param string $description Description of new Achievement
- * @param boolean $progress Show progress
- * @param boolean $hidden Secret Achievement
- * @param boolean $onlyOnce Only achieveable by one user
- * @param boolean $allConditions Achievement must match all conditions
- * @param string $deadline Deadline for Achievement
- * @return int ID of newly created Achievement
- */
- public function createAchievement($userId, $seminaryId, $conditionId, $title, $description, $progress, $hidden, $onlyOnce, $allConditions, $deadline)
- {
- // Get position
- $pos = $this->db->query(
- 'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
- 'FROM achievements '.
- 'WHERE seminary_id = ?',
- 'i',
- $seminaryId
- );
- $pos = $pos[0]['pos'];
-
- // Create Achievement
- $this->db->query(
- 'INSERT INTO achievements '.
- '(created_user_id, seminary_id, achievementcondition_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
- 'iiiisssiiiis',
- $userId,
- $seminaryId,
- $conditionId,
- $pos,
- $title,
- \nre\core\Linker::createLinkParam($title),
- $description,
- $progress,
- $hidden,
- $onlyOnce,
- $allConditions,
- $deadline
- );
-
-
- // Return ID
- return $this->db->getInsertId();
- }
-
-
- /**
- * Move an Achievement up (decrement position) or down
- * (increment position).
- *
- * @param array $achievement Achievement to move
- * @param boolean $up True for moving up, false for down
- */
- public function moveAchievement($achievement, $up)
- {
- $this->db->setAutocommit(false);
- try {
- // Set temporary position
- $this->db->query(
- 'UPDATE achievements '.
- 'SET pos = 0 '.
- 'WHERE id = ?',
- 'i',
- $achievement['id']
- );
- // Switch entry
- $this->db->query(
- 'UPDATE achievements '.
- 'SET pos = ? '.
- 'WHERE seminary_id = ? AND pos = ?',
- 'iii',
- $achievement['pos'],
- $achievement['seminary_id'],
- $achievement['pos'] + ($up ? -1 : 1)
- );
- // Set new position
- $this->db->query(
- 'UPDATE achievements '.
- 'SET pos = ? '.
- 'WHERE id = ?',
- 'ii',
- $achievement['pos'] + ($up ? -1 : 1),
- $achievement['id']
- );
-
- $this->db->commit();
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
- $this->db->setAutocommit(true);
- }
+ return false;
+ }
- /**
- * Edit an Achievement of a Seminary.
- *
- * @param int $achievementId ID of Achievement to edit
- * @param int $conditionId ID of Achievement condition
- * @param string $title New title of Achievement
- * @param string $description New description of Achievement
- * @param boolean $progress Show progress
- * @param boolean $hidden Secret Achievement
- * @param boolean $onlyOnce Only achieveable by one user
- * @param boolean $allConditions Achievement must match all conditions
- * @param string $deadline Deadline for Achievement
- */
- public function editAchievement($achievementId, $conditionId, $title, $description, $progress, $hidden, $onlyOnce, $allConditions, $deadline)
- {
- $this->db->query(
- 'UPDATE achievements '.
- 'SET achievementcondition_id = ?, title = ?, url = ?, description = ?, progress = ?, hidden = ?, only_once = ?, all_conditions = ?, deadline = ? '.
- 'WHERE id = ?',
- 'isssiiiisi',
- $conditionId,
- $title,
- \nre\core\Linker::createLinkParam($title),
- $description,
- $progress,
- $hidden,
- $onlyOnce,
- $allConditions,
- $deadline,
- $achievementId
- );
- }
+ /**
+ * Get all existing Achievements conditions.
+ *
+ * @return array List of Achievements conditions
+ */
+ public function getAchievementsConditions()
+ {
+ return $this->db->query(
+ 'SELECT id, created, `condition` '.
+ 'FROM achievementconditions'
+ );
+ }
- /**
- * Set unachieved media for an Achievement.
- *
- * @param int $achievementId ID of Achievement to set media for
- * @param int $achievementsmediaId ID of achievementsmedia to set
- */
- public function setUnachievedMediaForAchievement($achievementId, $achievementsmediaId)
- {
- $this->db->query(
- 'UPDATE achievements '.
- 'SET unachieved_achievementsmedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $achievementsmediaId,
- $achievementId
- );
- }
+ /**
+ * Check if an Achievement title already exists.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $title Achievement title to check
+ * @param int $characterId Do not check this ID (for editing)
+ * @return boolean Whether Achievement title exists or not
+ */
+ public function achievementTitleExists($seminaryId, $title, $achievementId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM achievements '.
+ 'WHERE seminary_id = ? AND (title = ? OR url = ?)',
+ 'iss',
+ $seminaryId,
+ $title,
+ \nre\core\Linker::createLinkParam($title)
+ );
- /**
- * Set achieved media for an Achievement.
- *
- * @param int $achievementId ID of Achievement to set media for
- * @param int $achievementsmediaId ID of achievementsmedia to set
- */
- public function setAchievedMediaForAchievement($achievementId, $achievementsmediaId)
- {
- $this->db->query(
- 'UPDATE achievements '.
- 'SET achieved_achievementsmedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $achievementsmediaId,
- $achievementId
- );
- }
+ return (!empty($data) && (is_null($achievementId) || $achievementId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Achievement for a Seminary.
+ *
+ * @param int $userId ID of creating user
+ * @param int $seminaryId ID of Seminary
+ * @param int $conditionId ID of Achievement condition
+ * @param string $title Title of new Achievement
+ * @param string $description Description of new Achievement
+ * @param boolean $progress Show progress
+ * @param boolean $hidden Secret Achievement
+ * @param boolean $onlyOnce Only achieveable by one user
+ * @param boolean $allConditions Achievement must match all conditions
+ * @param string $deadline Deadline for Achievement
+ * @return int ID of newly created Achievement
+ */
+ public function createAchievement($userId, $seminaryId, $conditionId, $title, $description, $progress, $hidden, $onlyOnce, $allConditions, $deadline)
+ {
+ // Get position
+ $pos = $this->db->query(
+ 'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
+ 'FROM achievements '.
+ 'WHERE seminary_id = ?',
+ 'i',
+ $seminaryId
+ );
+ $pos = $pos[0]['pos'];
+
+ // Create Achievement
+ $this->db->query(
+ 'INSERT INTO achievements '.
+ '(created_user_id, seminary_id, achievementcondition_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
+ 'iiiisssiiiis',
+ $userId,
+ $seminaryId,
+ $conditionId,
+ $pos,
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $description,
+ $progress,
+ $hidden,
+ $onlyOnce,
+ $allConditions,
+ $deadline
+ );
+
+
+ // Return ID
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Move an Achievement up (decrement position) or down
+ * (increment position).
+ *
+ * @param array $achievement Achievement to move
+ * @param boolean $up True for moving up, false for down
+ */
+ public function moveAchievement($achievement, $up)
+ {
+ $this->db->setAutocommit(false);
+ try {
+ // Set temporary position
+ $this->db->query(
+ 'UPDATE achievements '.
+ 'SET pos = 0 '.
+ 'WHERE id = ?',
+ 'i',
+ $achievement['id']
+ );
+ // Switch entry
+ $this->db->query(
+ 'UPDATE achievements '.
+ 'SET pos = ? '.
+ 'WHERE seminary_id = ? AND pos = ?',
+ 'iii',
+ $achievement['pos'],
+ $achievement['seminary_id'],
+ $achievement['pos'] + ($up ? -1 : 1)
+ );
+ // Set new position
+ $this->db->query(
+ 'UPDATE achievements '.
+ 'SET pos = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $achievement['pos'] + ($up ? -1 : 1),
+ $achievement['id']
+ );
+
+ $this->db->commit();
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+ $this->db->setAutocommit(true);
+ }
+
+
+ /**
+ * Edit an Achievement of a Seminary.
+ *
+ * @param int $achievementId ID of Achievement to edit
+ * @param int $conditionId ID of Achievement condition
+ * @param string $title New title of Achievement
+ * @param string $description New description of Achievement
+ * @param boolean $progress Show progress
+ * @param boolean $hidden Secret Achievement
+ * @param boolean $onlyOnce Only achieveable by one user
+ * @param boolean $allConditions Achievement must match all conditions
+ * @param string $deadline Deadline for Achievement
+ */
+ public function editAchievement($achievementId, $conditionId, $title, $description, $progress, $hidden, $onlyOnce, $allConditions, $deadline)
+ {
+ $this->db->query(
+ 'UPDATE achievements '.
+ 'SET achievementcondition_id = ?, title = ?, url = ?, description = ?, progress = ?, hidden = ?, only_once = ?, all_conditions = ?, deadline = ? '.
+ 'WHERE id = ?',
+ 'isssiiiisi',
+ $conditionId,
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $description,
+ $progress,
+ $hidden,
+ $onlyOnce,
+ $allConditions,
+ $deadline,
+ $achievementId
+ );
+ }
+
+
+ /**
+ * Set unachieved media for an Achievement.
+ *
+ * @param int $achievementId ID of Achievement to set media for
+ * @param int $achievementsmediaId ID of achievementsmedia to set
+ */
+ public function setUnachievedMediaForAchievement($achievementId, $achievementsmediaId)
+ {
+ $this->db->query(
+ 'UPDATE achievements '.
+ 'SET unachieved_achievementsmedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $achievementsmediaId,
+ $achievementId
+ );
+ }
+
+
+ /**
+ * Set achieved media for an Achievement.
+ *
+ * @param int $achievementId ID of Achievement to set media for
+ * @param int $achievementsmediaId ID of achievementsmedia to set
+ */
+ public function setAchievedMediaForAchievement($achievementId, $achievementsmediaId)
+ {
+ $this->db->query(
+ 'UPDATE achievements '.
+ 'SET achieved_achievementsmedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $achievementsmediaId,
+ $achievementId
+ );
+ }
/**
* Copy all Achievements of a Seminary.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceSeminaryId Seminary to copy from
* @param int $targetSeminaryId Seminary to copy to
@@ -1368,40 +1368,40 @@
}
}
-
- /**
- * Delete an Achievement.
- *
- * @param int $achievement Achievement to delete
- */
- public function deleteAchievement($achievement)
- {
- $this->db->setAutocommit(false);
- try {
- // Delete Achievement
- $this->db->query('DELETE FROM achievements WHERE id = ?', 'i', $achievementId);
- // Adjust positions
- $this->db->query(
- 'UPDATE achievements '.
- 'SET pos = pos - 1 '.
- 'WHERE seminary_id = ? AND pos > ?',
- 'ii',
- $achievement['seminary_id'],
- $achievement['pos']
- );
+ /**
+ * Delete an Achievement.
+ *
+ * @param int $achievement Achievement to delete
+ */
+ public function deleteAchievement($achievement)
+ {
+ $this->db->setAutocommit(false);
+ try {
+ // Delete Achievement
+ $this->db->query('DELETE FROM achievements WHERE id = ?', 'i', $achievementId);
- $this->db->commit();
- }
- catch(\Exception $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
+ // Adjust positions
+ $this->db->query(
+ 'UPDATE achievements '.
+ 'SET pos = pos - 1 '.
+ 'WHERE seminary_id = ? AND pos > ?',
+ 'ii',
+ $achievement['seminary_id'],
+ $achievement['pos']
+ );
- $this->db->setAutocommit(true);
- }
-
- }
+ $this->db->commit();
+ }
+ catch(\Exception $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+
+ $this->db->setAutocommit(true);
+ }
+
+ }
?>
diff --git a/models/AvatarsModel.inc b/models/AvatarsModel.inc
index 6bcf757f..9abd09b3 100644
--- a/models/AvatarsModel.inc
+++ b/models/AvatarsModel.inc
@@ -1,182 +1,182 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Avatars-tables.
- *
- * @author Oliver Hanraths
- */
- class AvatarsModel extends \hhu\z\Model
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('media');
-
-
-
-
- /**
- * Construct a new AvatarsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get an Avatar by its ID
- *
- * @param int $avatarId ID of Avatar
- * @return array Avatar data
- */
- public function getAvatarById($avatarId)
- {
- $data = $this->db->query(
- 'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
- 'FROM avatars '.
- 'WHERE id = ?',
- 'i',
- $avatarId
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return null;
- }
-
-
- /**
- * Get an Avatar by its Character type and XP-level.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $charactertypeUrl URL-title of Character type
- * @param int $xplevel XP-level
- * @return array Avatar data
- */
- public function getAvatarByTypeAndLevel($seminaryId, $charactertypeUrl, $xplevel)
- {
- $data = $this->db->query(
- 'SELECT avatars.id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
- 'FROM avatars '.
- 'INNER JOIN charactertypes ON charactertypes.id = avatars.charactertype_id '.
- 'INNER JOIN xplevels ON xplevels.id = avatars.xplevel_id AND xplevels.seminary_id = charactertypes.seminary_id '.
- 'WHERE charactertypes.seminary_id = ? AND charactertypes.url = ? AND xplevels.level = ?',
- 'isi',
- $seminaryId,
- $charactertypeUrl,
- $xplevel
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
- }
-
-
- return $data[0];
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
- /**
- * Get an Avatar by its Character type and XP-level.
- *
- * @param int $charactertypeId ID of Character type
- * @param int $xplevelId ID of XP-level
- * @return array Avatar data
- */
- public function getAvatarByTypeAndLevelId($charactertypeId, $xplevelId)
- {
- $data = $this->db->query(
- 'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
- 'FROM avatars '.
- 'WHERE charactertype_id = ? AND xplevel_id = ?',
- 'ii',
- $charactertypeId,
- $xplevelId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($charactertypeId.'-'.$xplevelId);
- }
-
-
- return $data[0];
- }
+ /**
+ * Model to interact with Avatars-tables.
+ *
+ * @author Oliver Hanraths
+ */
+ class AvatarsModel extends \hhu\z\Model
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('media');
- /**
- * Set the picture for an Avatar.
- *
- * @param int $userId ID of creating user
- * @param int $charactertypeId ID of Charactertype of Avatar
- * @param int $xplevelId ID of XP-level of Avatar
- * @param int $avatarpictureId ID of Avatar picture to set
- */
- public function setAvatarForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
- {
- $this->db->query(
- 'INSERT INTO avatars '.
- '(created_user_id, charactertype_id, xplevel_id, avatarpicture_id) '.
- 'VALUES '.
- '(?, ?, ?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'avatarpicture_id = ?',
- 'iiiii',
- $userId,
- $charactertypeId,
- $xplevelId,
- $avatarpictureId,
- $avatarpictureId
- );
- }
- /**
- * Set the portrait picture for an Avatar.
- *
- * @param int $userId ID of creating user
- * @param int $charactertypeId ID of Charactertype of Avatar
- * @param int $xplevelId ID of XP-level of Avatar
- * @param int $avatarpictureId ID of Avatar portrait picture to set
- */
- public function setAvatarPortraitForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
- {
- $this->db->query(
- 'INSERT INTO avatars '.
- '(created_user_id, charactertype_id, xplevel_id, small_avatarpicture_id) '.
- 'VALUES '.
- '(?, ?, ?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'small_avatarpicture_id = ?',
- 'iiiii',
- $userId,
- $charactertypeId,
- $xplevelId,
- $avatarpictureId,
- $avatarpictureId
- );
- }
+ /**
+ * Construct a new AvatarsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get an Avatar by its ID
+ *
+ * @param int $avatarId ID of Avatar
+ * @return array Avatar data
+ */
+ public function getAvatarById($avatarId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
+ 'FROM avatars '.
+ 'WHERE id = ?',
+ 'i',
+ $avatarId
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Get an Avatar by its Character type and XP-level.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $charactertypeUrl URL-title of Character type
+ * @param int $xplevel XP-level
+ * @return array Avatar data
+ */
+ public function getAvatarByTypeAndLevel($seminaryId, $charactertypeUrl, $xplevel)
+ {
+ $data = $this->db->query(
+ 'SELECT avatars.id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
+ 'FROM avatars '.
+ 'INNER JOIN charactertypes ON charactertypes.id = avatars.charactertype_id '.
+ 'INNER JOIN xplevels ON xplevels.id = avatars.xplevel_id AND xplevels.seminary_id = charactertypes.seminary_id '.
+ 'WHERE charactertypes.seminary_id = ? AND charactertypes.url = ? AND xplevels.level = ?',
+ 'isi',
+ $seminaryId,
+ $charactertypeUrl,
+ $xplevel
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get an Avatar by its Character type and XP-level.
+ *
+ * @param int $charactertypeId ID of Character type
+ * @param int $xplevelId ID of XP-level
+ * @return array Avatar data
+ */
+ public function getAvatarByTypeAndLevelId($charactertypeId, $xplevelId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
+ 'FROM avatars '.
+ 'WHERE charactertype_id = ? AND xplevel_id = ?',
+ 'ii',
+ $charactertypeId,
+ $xplevelId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($charactertypeId.'-'.$xplevelId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Set the picture for an Avatar.
+ *
+ * @param int $userId ID of creating user
+ * @param int $charactertypeId ID of Charactertype of Avatar
+ * @param int $xplevelId ID of XP-level of Avatar
+ * @param int $avatarpictureId ID of Avatar picture to set
+ */
+ public function setAvatarForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
+ {
+ $this->db->query(
+ 'INSERT INTO avatars '.
+ '(created_user_id, charactertype_id, xplevel_id, avatarpicture_id) '.
+ 'VALUES '.
+ '(?, ?, ?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'avatarpicture_id = ?',
+ 'iiiii',
+ $userId,
+ $charactertypeId,
+ $xplevelId,
+ $avatarpictureId,
+ $avatarpictureId
+ );
+ }
+
+
+ /**
+ * Set the portrait picture for an Avatar.
+ *
+ * @param int $userId ID of creating user
+ * @param int $charactertypeId ID of Charactertype of Avatar
+ * @param int $xplevelId ID of XP-level of Avatar
+ * @param int $avatarpictureId ID of Avatar portrait picture to set
+ */
+ public function setAvatarPortraitForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
+ {
+ $this->db->query(
+ 'INSERT INTO avatars '.
+ '(created_user_id, charactertype_id, xplevel_id, small_avatarpicture_id) '.
+ 'VALUES '.
+ '(?, ?, ?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'small_avatarpicture_id = ?',
+ 'iiiii',
+ $userId,
+ $charactertypeId,
+ $xplevelId,
+ $avatarpictureId,
+ $avatarpictureId
+ );
+ }
/**
* Copy all Avatars from a Seminary.
- *
+ *
* @param int $userId ID of copying user
* @param array $charactertypeIds Mapping of Charactertype-IDs from source Seminary to target Seminary
* @param array $xplevelIds Mapping of XP-level-IDs from source Seminary to targetSeminary
@@ -217,7 +217,7 @@
}
}
}
-
- }
+
+ }
?>
diff --git a/models/CharactergroupsModel.inc b/models/CharactergroupsModel.inc
index 73978c04..5ff81e81 100644
--- a/models/CharactergroupsModel.inc
+++ b/models/CharactergroupsModel.inc
@@ -1,186 +1,186 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model of the CharactergroupsAgent to interact with
- * Charactergroups-table.
- *
- * @author Oliver Hanraths
- */
- class CharactergroupsModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new CharactergroupsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get Character groups-groups of a Seminary.
- *
- * @param int $seminaryId ID of the corresponding Seminary
- * @return array Character groups-groups data
- */
- public function getGroupsroupsForSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT id, name, url, preferred '.
- 'FROM charactergroupsgroups '.
- 'WHERE seminary_id = ?',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get a Character groups-group by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryId ID of the corresponding Seminary
- * @param string $groupsgroupUrl URL-name of the Character groups-group
- * @return array Character groups-group data
- */
- public function getGroupsgroupByUrl($seminaryId, $groupsgroupUrl)
- {
- $data = $this->db->query(
- 'SELECT id, name, url, preferred '.
- 'FROM charactergroupsgroups '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
- $seminaryId, $groupsgroupUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($groupsgroupUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Character groups-group by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $groupsgroupId ID of the Character groups-group
- * @return array Character groups-group data
- */
- public function getGroupsgroupById($groupsgroupId)
- {
- $data = $this->db->query(
- 'SELECT id, name, url, preferred '.
- 'FROM charactergroupsgroups '.
- 'WHERE id = ?',
- 'i',
- $groupsgroupId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($groupsgroupId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Check if a Character groups-group name already exists.
- *
- * @param string $name Name to check
- * @param int $groupsgroupId Do not check this ID (for editing)
- * @return boolean Whether name exists or not
- */
- public function characterGroupsgroupNameExists($name, $groupsgroupId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM charactergroupsgroups '.
- 'WHERE name = ? OR url = ?',
- 'ss',
- $name,
- \nre\core\Linker::createLinkParam($name)
- );
-
-
- return (!empty($data) && (is_null($groupsgroupId) || $groupsgroupId != $data[0]['id']));
- }
-
-
- /**
- * Create a new Character groups-group.
- *
- * @param int $userId ID of user
- * @param int $seminaryId ID of Seminary
- * @param string $name Name of new groups-group
- * @param boolean $preferred Whether groups-group is preferred or not
- * @return int ID of newly created groups-group
- */
- public function createGroupsgroup($userId, $seminaryId, $name, $preferred)
- {
- $this->db->query(
- 'INSERT INTO charactergroupsgroups '.
- '(created_user_id, seminary_id, name, url, preferred) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?)',
- 'iissd',
- $userId,
- $seminaryId,
- $name,
- \nre\core\Linker::createLinkParam($name),
- $preferred
- );
-
-
- return $this->db->getInsertId();
- }
-
-
- /**
- * Edit a Character groups-group.
- *
- * @param int $groupsgroupId ID of groups-group to edit
- * @param string $name New name of groups-group
- * @param boolean $preferred Whether groups-group is preferred or not
- */
- public function editGroupsgroup($groupsgroupId, $name, $preferred)
- {
- $this->db->query(
- 'UPDATE charactergroupsgroups '.
- 'SET name = ?, url = ?, preferred = ? '.
- 'WHERE id = ?',
- 'ssdi',
- $name,
- \nre\core\Linker::createLinkParam($name),
- $preferred,
- $groupsgroupId
- );
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model of the CharactergroupsAgent to interact with
+ * Charactergroups-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactergroupsModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new CharactergroupsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get Character groups-groups of a Seminary.
+ *
+ * @param int $seminaryId ID of the corresponding Seminary
+ * @return array Character groups-groups data
+ */
+ public function getGroupsroupsForSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT id, name, url, preferred '.
+ 'FROM charactergroupsgroups '.
+ 'WHERE seminary_id = ?',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get a Character groups-group by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryId ID of the corresponding Seminary
+ * @param string $groupsgroupUrl URL-name of the Character groups-group
+ * @return array Character groups-group data
+ */
+ public function getGroupsgroupByUrl($seminaryId, $groupsgroupUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, name, url, preferred '.
+ 'FROM charactergroupsgroups '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
+ $seminaryId, $groupsgroupUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($groupsgroupUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Character groups-group by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $groupsgroupId ID of the Character groups-group
+ * @return array Character groups-group data
+ */
+ public function getGroupsgroupById($groupsgroupId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, name, url, preferred '.
+ 'FROM charactergroupsgroups '.
+ 'WHERE id = ?',
+ 'i',
+ $groupsgroupId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($groupsgroupId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Check if a Character groups-group name already exists.
+ *
+ * @param string $name Name to check
+ * @param int $groupsgroupId Do not check this ID (for editing)
+ * @return boolean Whether name exists or not
+ */
+ public function characterGroupsgroupNameExists($name, $groupsgroupId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM charactergroupsgroups '.
+ 'WHERE name = ? OR url = ?',
+ 'ss',
+ $name,
+ \nre\core\Linker::createLinkParam($name)
+ );
+
+
+ return (!empty($data) && (is_null($groupsgroupId) || $groupsgroupId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Character groups-group.
+ *
+ * @param int $userId ID of user
+ * @param int $seminaryId ID of Seminary
+ * @param string $name Name of new groups-group
+ * @param boolean $preferred Whether groups-group is preferred or not
+ * @return int ID of newly created groups-group
+ */
+ public function createGroupsgroup($userId, $seminaryId, $name, $preferred)
+ {
+ $this->db->query(
+ 'INSERT INTO charactergroupsgroups '.
+ '(created_user_id, seminary_id, name, url, preferred) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?)',
+ 'iissd',
+ $userId,
+ $seminaryId,
+ $name,
+ \nre\core\Linker::createLinkParam($name),
+ $preferred
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Edit a Character groups-group.
+ *
+ * @param int $groupsgroupId ID of groups-group to edit
+ * @param string $name New name of groups-group
+ * @param boolean $preferred Whether groups-group is preferred or not
+ */
+ public function editGroupsgroup($groupsgroupId, $name, $preferred)
+ {
+ $this->db->query(
+ 'UPDATE charactergroupsgroups '.
+ 'SET name = ?, url = ?, preferred = ? '.
+ 'WHERE id = ?',
+ 'ssdi',
+ $name,
+ \nre\core\Linker::createLinkParam($name),
+ $preferred,
+ $groupsgroupId
+ );
+ }
/**
* Copy all Character groups-groups of a Seminary.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceSeminaryId ID of Seminary to copy from
* @param int $targetSeminaryId ID of Seminary to copy to
@@ -212,330 +212,330 @@
return $groupsgroupIds;
}
-
-
- /**
- * Delete a Character groups-group.
- *
- * @param int $groupsgroupId ID of groups-group to delete
- */
- public function deleteGroupsgroup($groupsgroupId)
- {
- $this->db->query('DELETE FROM charactergroupsgroups WHERE id = ?', 'i', $groupsgroupId);
- }
-
-
- /**
- * Get Character groups for a Character groups-group.
- *
- * @param int $groupsgroupId ID of the Character groups-group
- * @param string $sortorder Field to sort by (optional)
- * @return array Character groups
- */
- public function getGroupsForGroupsgroup($groupsgroupId, $sortorder='name')
- {
- // Set sort order
- switch($sortorder)
- {
- case 'xps':
- $sortorder = 'xps DESC';
- break;
- case 'name':
- default:
- $sortorder = 'name ASC';
- break;
- }
-
- // Get and return Character groups
- return $this->db->query(
- 'SELECT '.
- 'charactergroups.id, charactergroups.name, charactergroups.url, charactergroups.motto, charactergroups.charactergroupsmedia_id, '.
- 'cache_charactergroups.xps '.
- 'FROM charactergroups '.
- 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
- 'WHERE charactergroups.charactergroupsgroup_id = ? '.
- "ORDER BY $sortorder",
- 'i',
- $groupsgroupId
- );
- }
-
-
- /**
- * Get Character groups for a Character.
- *
- * @param int $characterId ID of the Character
- * @return array Character groups
- */
- public function getGroupsForCharacter($characterId)
- {
- return $this->db->query(
- 'SELECT '.
- 'charactergroups.id, charactergroups.charactergroupsgroup_id, charactergroups.name, charactergroups.url, charactergroups.charactergroupsmedia_id, '.
- 'cache_charactergroups.xps, '.
- 'charactergroupsgroups.id AS charactergroupsgroup_id, charactergroupsgroups.name AS charactergroupsgroup_name, charactergroupsgroups.url AS charactergroupsgroup_url '.
- 'FROM characters_charactergroups '.
- 'LEFT JOIN charactergroups ON charactergroups.id = characters_charactergroups.charactergroup_id '.
- 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
- 'LEFT JOIN charactergroupsgroups ON charactergroupsgroups.id = charactergroups.charactergroupsgroup_id '.
- 'WHERE characters_charactergroups.character_id = ?',
- 'i',
- $characterId
- );
- }
-
-
- /**
- * Get a Character group by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $groupsgroupId ID of the Character groups-group
- * @param string $groupUrl URL-name of the Character group
- * @return array Character group data
- */
- public function getGroupByUrl($groupsgroupId, $groupUrl)
- {
- $data = $this->db->query(
- 'SELECT '.
- 'charactergroups.id, charactergroups.name, charactergroups.url, charactergroups.motto, charactergroups.charactergroupsmedia_id, '.
- 'cache_charactergroups.xps '.
- 'FROM charactergroups '.
- 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
- 'WHERE charactergroups.charactergroupsgroup_id = ? AND url = ?',
- 'is',
- $groupsgroupId, $groupUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($groupUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Character group by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $groupsgroupId ID of the Character group
- * @return array Character group data
- */
- public function getGroupById($groupId)
- {
- $data = $this->db->query(
- 'SELECT '.
- 'charactergroups.id, charactergroups.name, charactergroups.url, charactergroups.motto, charactergroups.charactergroupsmedia_id, '.
- 'cache_charactergroups.xps '.
- 'FROM charactergroups '.
- 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
- 'WHERE charactergroups.id = ?',
- 'i',
- $groupId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($groupId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get the Character groups for a Quest.
- *
- * @param int $questId ID of the Character groups Quest
- * @return array Character groups
- */
- public function getGroupsForQuest($questId)
- {
- $groups = $this->db->query(
- 'SELECT charactergroups.id, charactergroups.name, charactergroups.url, charactergroupsquests_groups.created, charactergroupsquests_groups.xps_factor, charactergroupsquests.xps '.
- 'FROM charactergroupsquests_groups '.
- 'LEFT JOIN charactergroups ON charactergroups.id = charactergroupsquests_groups.charactergroup_id '.
- 'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
- 'WHERE charactergroupsquests_groups.charactergroupsquest_id = ? '.
- 'ORDER BY xps_factor DESC',
- 'i',
- $questId
- );
- foreach($groups as &$group) {
- $group['xps'] = round($group['xps'] * $group['xps_factor'], 1);
- }
-
-
- return $groups;
- }
-
-
- /**
- * Check if a Character group name already exists.
- *
- * @param string $name Name to check
- * @param int $groupsgroupId Do not check this ID (for editing)
- * @return boolean Whether name exists or not
- */
- public function characterGroupNameExists($name, $groupId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM charactergroups '.
- 'WHERE name = ? OR url = ?',
- 'ss',
- $name,
- \nre\core\Linker::createLinkParam($name)
- );
-
-
- return (!empty($data) && (is_null($groupId) || $groupId != $data[0]['id']));
- }
-
-
- /**
- * Create a new Character group.
- *
- * @param int $userId ID of user
- * @param int $groupsgroupId ID of Character groups-group
- * @param string $name Name of new group
- * @param string $motto Motto of new group
- * @return int ID of newly created group
- */
- public function createGroup($userId, $groupsgroupId, $name, $motto)
- {
- $this->db->query(
- 'INSERT INTO charactergroups '.
- '(created_user_id, charactergroupsgroup_id, name, url, motto) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?)',
- 'iisss',
- $userId,
- $groupsgroupId,
- $name,
- \nre\core\Linker::createLinkParam($name),
- $motto
- );
-
-
- return $this->db->getInsertId();
- }
-
-
- /**
- * Set the media for a Character group.
- *
- * @param int $groupId ID of Character group to set media for
- * @param int $mediaId ID of Character groups media
- */
- public function setMediaForGroup($groupId, $mediaId)
- {
- $this->db->query(
- 'UPDATE charactergroups '.
- 'SET charactergroupsmedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $mediaId,
- $groupId
- );
- }
-
-
- /**
- * Edit a Character group.
- *
- * @param int $groupId ID of Character group to edit
- * @param string $name New name of group
- * @param string $motto New motto of group
- */
- public function editGroup($groupId, $name, $motto)
- {
- $this->db->query(
- 'UPDATE charactergroups '.
- 'SET name = ?, url = ?, motto = ? '.
- 'WHERE id = ?',
- 'sssi',
- $name,
- \nre\core\Linker::createLinkParam($name),
- $motto,
- $groupId
- );
- }
-
-
- /**
- * Delete a Character group.
- *
- * @param int $groupId ID of Character group to delete
- */
- public function deleteGroup($groupId)
- {
- $this->db->query('DELETE FROM charactergroups WHERE id = ?', 'i', $groupId);
- }
-
-
- /**
- * Get the rank of a XP-value of a Character.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $xps XP-value to get rank for
- * @return int Rank of XP-value
- */
- public function getXPRank($groupsgroupId, $xps)
- {
- $data = $this->db->query(
- 'SELECT count(charactergroups.id) AS c '.
- 'FROM charactergroups '.
- 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
- 'WHERE charactergroups.charactergroupsgroup_id = ? AND cache_charactergroups.xps > ?',
- 'id',
- $groupsgroupId, $xps
- );
- if(!empty($data)) {
- return $data[0]['c'] + 1;
- }
-
-
- return 1;
- }
-
-
- /**
- * Add a Character to a Character group.
- *
- * @param int $groupId ID of Character group
- * @param int $characterId ID of Character to add
- */
- public function addCharacterToCharactergroup($groupId, $characterId)
- {
- $this->db->query(
- 'INSERT INTO characters_charactergroups '.
- '(character_id, charactergroup_id) '.
- 'VALUES '.
- '(?, ?)',
- 'ii',
- $characterId,
- $groupId
- );
- }
-
-
- /**
- * Remove a Character from a Character group.
- *
- * @param int $groupId ID of Character group
- * @param int $characterId ID of Character to remove
- */
- public function removeCharacterFromCharactergroup($groupId, $characterId)
- {
- $this->db->query(
- 'DELETE FROM characters_charactergroups '.
- 'WHERE charactergroup_id = ? AND character_id = ?',
- 'ii',
- $groupId,
- $characterId
- );
- }
-
- }
+
+
+ /**
+ * Delete a Character groups-group.
+ *
+ * @param int $groupsgroupId ID of groups-group to delete
+ */
+ public function deleteGroupsgroup($groupsgroupId)
+ {
+ $this->db->query('DELETE FROM charactergroupsgroups WHERE id = ?', 'i', $groupsgroupId);
+ }
+
+
+ /**
+ * Get Character groups for a Character groups-group.
+ *
+ * @param int $groupsgroupId ID of the Character groups-group
+ * @param string $sortorder Field to sort by (optional)
+ * @return array Character groups
+ */
+ public function getGroupsForGroupsgroup($groupsgroupId, $sortorder='name')
+ {
+ // Set sort order
+ switch($sortorder)
+ {
+ case 'xps':
+ $sortorder = 'xps DESC';
+ break;
+ case 'name':
+ default:
+ $sortorder = 'name ASC';
+ break;
+ }
+
+ // Get and return Character groups
+ return $this->db->query(
+ 'SELECT '.
+ 'charactergroups.id, charactergroups.name, charactergroups.url, charactergroups.motto, charactergroups.charactergroupsmedia_id, '.
+ 'cache_charactergroups.xps '.
+ 'FROM charactergroups '.
+ 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
+ 'WHERE charactergroups.charactergroupsgroup_id = ? '.
+ "ORDER BY $sortorder",
+ 'i',
+ $groupsgroupId
+ );
+ }
+
+
+ /**
+ * Get Character groups for a Character.
+ *
+ * @param int $characterId ID of the Character
+ * @return array Character groups
+ */
+ public function getGroupsForCharacter($characterId)
+ {
+ return $this->db->query(
+ 'SELECT '.
+ 'charactergroups.id, charactergroups.charactergroupsgroup_id, charactergroups.name, charactergroups.url, charactergroups.charactergroupsmedia_id, '.
+ 'cache_charactergroups.xps, '.
+ 'charactergroupsgroups.id AS charactergroupsgroup_id, charactergroupsgroups.name AS charactergroupsgroup_name, charactergroupsgroups.url AS charactergroupsgroup_url '.
+ 'FROM characters_charactergroups '.
+ 'LEFT JOIN charactergroups ON charactergroups.id = characters_charactergroups.charactergroup_id '.
+ 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
+ 'LEFT JOIN charactergroupsgroups ON charactergroupsgroups.id = charactergroups.charactergroupsgroup_id '.
+ 'WHERE characters_charactergroups.character_id = ?',
+ 'i',
+ $characterId
+ );
+ }
+
+
+ /**
+ * Get a Character group by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $groupsgroupId ID of the Character groups-group
+ * @param string $groupUrl URL-name of the Character group
+ * @return array Character group data
+ */
+ public function getGroupByUrl($groupsgroupId, $groupUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT '.
+ 'charactergroups.id, charactergroups.name, charactergroups.url, charactergroups.motto, charactergroups.charactergroupsmedia_id, '.
+ 'cache_charactergroups.xps '.
+ 'FROM charactergroups '.
+ 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
+ 'WHERE charactergroups.charactergroupsgroup_id = ? AND url = ?',
+ 'is',
+ $groupsgroupId, $groupUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($groupUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Character group by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $groupsgroupId ID of the Character group
+ * @return array Character group data
+ */
+ public function getGroupById($groupId)
+ {
+ $data = $this->db->query(
+ 'SELECT '.
+ 'charactergroups.id, charactergroups.name, charactergroups.url, charactergroups.motto, charactergroups.charactergroupsmedia_id, '.
+ 'cache_charactergroups.xps '.
+ 'FROM charactergroups '.
+ 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
+ 'WHERE charactergroups.id = ?',
+ 'i',
+ $groupId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($groupId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get the Character groups for a Quest.
+ *
+ * @param int $questId ID of the Character groups Quest
+ * @return array Character groups
+ */
+ public function getGroupsForQuest($questId)
+ {
+ $groups = $this->db->query(
+ 'SELECT charactergroups.id, charactergroups.name, charactergroups.url, charactergroupsquests_groups.created, charactergroupsquests_groups.xps_factor, charactergroupsquests.xps '.
+ 'FROM charactergroupsquests_groups '.
+ 'LEFT JOIN charactergroups ON charactergroups.id = charactergroupsquests_groups.charactergroup_id '.
+ 'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
+ 'WHERE charactergroupsquests_groups.charactergroupsquest_id = ? '.
+ 'ORDER BY xps_factor DESC',
+ 'i',
+ $questId
+ );
+ foreach($groups as &$group) {
+ $group['xps'] = round($group['xps'] * $group['xps_factor'], 1);
+ }
+
+
+ return $groups;
+ }
+
+
+ /**
+ * Check if a Character group name already exists.
+ *
+ * @param string $name Name to check
+ * @param int $groupsgroupId Do not check this ID (for editing)
+ * @return boolean Whether name exists or not
+ */
+ public function characterGroupNameExists($name, $groupId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM charactergroups '.
+ 'WHERE name = ? OR url = ?',
+ 'ss',
+ $name,
+ \nre\core\Linker::createLinkParam($name)
+ );
+
+
+ return (!empty($data) && (is_null($groupId) || $groupId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Character group.
+ *
+ * @param int $userId ID of user
+ * @param int $groupsgroupId ID of Character groups-group
+ * @param string $name Name of new group
+ * @param string $motto Motto of new group
+ * @return int ID of newly created group
+ */
+ public function createGroup($userId, $groupsgroupId, $name, $motto)
+ {
+ $this->db->query(
+ 'INSERT INTO charactergroups '.
+ '(created_user_id, charactergroupsgroup_id, name, url, motto) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?)',
+ 'iisss',
+ $userId,
+ $groupsgroupId,
+ $name,
+ \nre\core\Linker::createLinkParam($name),
+ $motto
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Set the media for a Character group.
+ *
+ * @param int $groupId ID of Character group to set media for
+ * @param int $mediaId ID of Character groups media
+ */
+ public function setMediaForGroup($groupId, $mediaId)
+ {
+ $this->db->query(
+ 'UPDATE charactergroups '.
+ 'SET charactergroupsmedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $mediaId,
+ $groupId
+ );
+ }
+
+
+ /**
+ * Edit a Character group.
+ *
+ * @param int $groupId ID of Character group to edit
+ * @param string $name New name of group
+ * @param string $motto New motto of group
+ */
+ public function editGroup($groupId, $name, $motto)
+ {
+ $this->db->query(
+ 'UPDATE charactergroups '.
+ 'SET name = ?, url = ?, motto = ? '.
+ 'WHERE id = ?',
+ 'sssi',
+ $name,
+ \nre\core\Linker::createLinkParam($name),
+ $motto,
+ $groupId
+ );
+ }
+
+
+ /**
+ * Delete a Character group.
+ *
+ * @param int $groupId ID of Character group to delete
+ */
+ public function deleteGroup($groupId)
+ {
+ $this->db->query('DELETE FROM charactergroups WHERE id = ?', 'i', $groupId);
+ }
+
+
+ /**
+ * Get the rank of a XP-value of a Character.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $xps XP-value to get rank for
+ * @return int Rank of XP-value
+ */
+ public function getXPRank($groupsgroupId, $xps)
+ {
+ $data = $this->db->query(
+ 'SELECT count(charactergroups.id) AS c '.
+ 'FROM charactergroups '.
+ 'LEFT JOIN cache_charactergroups ON cache_charactergroups.charactergroup_id = charactergroups.id '.
+ 'WHERE charactergroups.charactergroupsgroup_id = ? AND cache_charactergroups.xps > ?',
+ 'id',
+ $groupsgroupId, $xps
+ );
+ if(!empty($data)) {
+ return $data[0]['c'] + 1;
+ }
+
+
+ return 1;
+ }
+
+
+ /**
+ * Add a Character to a Character group.
+ *
+ * @param int $groupId ID of Character group
+ * @param int $characterId ID of Character to add
+ */
+ public function addCharacterToCharactergroup($groupId, $characterId)
+ {
+ $this->db->query(
+ 'INSERT INTO characters_charactergroups '.
+ '(character_id, charactergroup_id) '.
+ 'VALUES '.
+ '(?, ?)',
+ 'ii',
+ $characterId,
+ $groupId
+ );
+ }
+
+
+ /**
+ * Remove a Character from a Character group.
+ *
+ * @param int $groupId ID of Character group
+ * @param int $characterId ID of Character to remove
+ */
+ public function removeCharacterFromCharactergroup($groupId, $characterId)
+ {
+ $this->db->query(
+ 'DELETE FROM characters_charactergroups '.
+ 'WHERE charactergroup_id = ? AND character_id = ?',
+ 'ii',
+ $groupId,
+ $characterId
+ );
+ }
+
+ }
?>
diff --git a/models/CharactergroupsquestsModel.inc b/models/CharactergroupsquestsModel.inc
index 52b7382b..88d749dd 100644
--- a/models/CharactergroupsquestsModel.inc
+++ b/models/CharactergroupsquestsModel.inc
@@ -1,383 +1,383 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model of the CharactergroupsquestsAgent to interact with
- * Charactergroupsquests-table.
- *
- * @author Oliver Hanraths
- */
- class CharactergroupsquestsModel extends \hhu\z\Model
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('uploads', 'media');
-
-
-
-
- /**
- * Construct a new CharactergroupsquestsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get Character groups Quests of a Character groups-groups.
- *
- * @param int $groupsgroupId ID of the Character groups-group
- * @return array Character groups Quest data
- */
- public function getQuestsForCharactergroupsgroup($groupsgroupId)
- {
- return $this->db->query(
- 'SELECT id, questgroups_id, title, url, xps, questsmedia_id '.
- 'FROM charactergroupsquests '.
- 'WHERE charactergroupsgroup_id = ? '.
- 'ORDER BY created ASC',
- 'i',
- $groupsgroupId
- );
- }
-
-
- /**
- * Get a Character groups Quest by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $groupsgroupId ID of the Character groups-group
- * @param string $questUrl URL-title of the Character groups Quest
- * @return array Character groups Quest data
- */
- public function getQuestByUrl($groupsgroupId, $questUrl)
- {
- $data = $this->db->query(
- 'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '.
- 'FROM charactergroupsquests '.
- 'WHERE charactergroupsgroup_id = ? AND url = ?',
- 'is',
- $groupsgroupId,
- $questUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Character groups Quest by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $questId ID of the Character groups Quest
- * @return array Character groups Quest data
- */
- public function getQuestById($questId)
- {
- $data = $this->db->query(
- 'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '.
- 'FROM charactergroupsquests '.
- 'WHERE id = ?',
- 'i',
- $questId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get Character groups Quests for a Character group.
- *
- * @param int $groupId ID of the Character group
- * @return array Character groups Quests
- */
- public function getQuestsForGroup($groupId)
- {
- $quests = $this->db->query(
- 'SELECT charactergroupsquests.id, charactergroupsquests_groups.created, charactergroupsquests.title, charactergroupsquests.url, charactergroupsquests.xps, charactergroupsquests_groups.xps_factor '.
- 'FROM charactergroupsquests_groups '.
- 'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
- 'WHERE charactergroupsquests_groups.charactergroup_id = ? '.
- 'ORDER BY charactergroupsquests.created ASC',
- 'i',
- $groupId
- );
- foreach($quests as &$quest) {
- $quest['group_xps'] = round($quest['xps'] * $quest['xps_factor'], 1);
- }
-
-
- return $quests;
- }
-
-
- /**
- * Get XPs of a Character group for a Character groups Quest.
- *
- * @param int $questId ID of Character groups Quest
- * @param int $groupId ID of Character group to get XPs of
- * @return array XP-record
- */
- public function getXPsOfGroupForQuest($questId, $groupId)
- {
- $data = $this->db->query(
- 'SELECT charactergroupsquests_groups.created, charactergroupsquests_groups.xps_factor, charactergroupsquests.xps '.
- 'FROM charactergroupsquests_groups '.
- 'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
- 'WHERE charactergroupsquests_groups.charactergroupsquest_id = ? AND charactergroupsquests_groups.charactergroup_id = ?',
- 'ii',
- $questId,
- $groupId
- );
- if(empty($data)) {
- return null;
- }
-
- $data = $data[0];
- $data['xps'] = round($data['xps'] * $data['xps_factor'], 1);
-
-
- return $data;
- }
-
-
- /**
- * Set XPs of a Character group for a Character groups Quest.
- *
- * @param int $questId ID of Character groups Quest
- * @param int $groupId ID of Character group to set XPs of
- * @param float $xpsFactor XPs-factor
- */
- public function setXPsOfGroupForQuest($questId, $groupId, $xpsFactor)
- {
- $this->db->query(
- 'INSERT INTO charactergroupsquests_groups '.
- '(charactergroupsquest_id, charactergroup_id, xps_factor) '.
- 'VALUES '.
- '(?, ?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'xps_factor = ?',
- 'iidd',
- $questId,
- $groupId,
- $xpsFactor,
- $xpsFactor
- );
- }
-
-
- /**
- * Remove a Character group from a Character groups Quest.
- *
- * @param int $questId ID of Character groups Quest
- * @param int $groupId ID of Character group to remove
- */
- public function deleteGroupForQuest($questId, $groupId)
- {
- $this->db->query(
- 'DELETE FROM charactergroupsquests_groups '.
- 'WHERE charactergroupsquest_id = ? AND charactergroup_id = ?',
- 'ii',
- $questId, $groupId
- );
- }
-
-
- /**
- * Check if a Character groups Quest title already exists.
- *
- * @param string $name Character groups Quest title to check
- * @param int $questId Do not check this ID (for editing)
- * @return boolean Whether Character groups Quest title exists or not
- */
- public function characterGroupsQuestTitleExists($title, $questId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM charactergroupsquests '.
- 'WHERE title = ? OR url = ?',
- 'ss',
- $title,
- \nre\core\Linker::createLinkParam($title)
- );
-
- return (!empty($data) && (is_null($questId) || $questId != $data[0]['id']));
- }
-
-
- /**
- * Set the media for a Character groups Quest.
- *
- * @param int $questId ID of Quest to upload media for
- * @param int $mediaId ID of Quests media
- */
- public function setMediaForQuest($questId, $mediaId)
- {
- $this->db->query(
- 'UPDATE charactergroupsquests '.
- 'SET questsmedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $mediaId,
- $questId
- );
- }
-
-
- /**
- * Upload a media for a Character groups Quest.
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param int $questId ID of Quest to upload media for
- * @param array $file File-array of file to upload
- * @param string $filename Filename for media
- * @return boolean Whether upload succeeded or not
- */
- public function uploadMediaForQuest($userId, $seminaryId, $questId, $file, $filename)
- {
- // Save file on harddrive
- $uploadId = $this->Uploads->uploadSeminaryFile($userId, $seminaryId, $file['name'], $filename, $file['tmp_name'], $file['type']);
- if($uploadId === false) {
- return false;
- }
-
- // Create database record
- $this->db->query(
- 'INSERT INTO charactergroupsquests_seminaryuploads '.
- '(seminaryupload_id, charactergroupsquest_id, created_user_id) '.
- 'VALUES '.
- '(?, ?, ?) ',
- 'iii',
- $uploadId, $questId, $userId
- );
-
-
- return true;
- }
-
-
- /**
- * Get uploaded Medai for a Character groups Quest.
- *
- * @param int $questId ID of Quest to get media for
- * @return array Seminary uploads
- */
- public function getMediaForQuest($questId)
- {
- return $this->db->query(
- 'SELECT seminaryupload_id, created, created_user_id '.
- 'FROM charactergroupsquests_seminaryuploads '.
- 'WHERE charactergroupsquest_id = ?',
- 'i',
- $questId
- );
- }
-
-
- /**
- * Create a new Character groups Quest.
- *
- * @param int $userId ID of user
- * @param int $groupsgroupId ID of Character groups-group
- * @param int $questgroupId ID of Quest group
- * @param string $title Title of new Quest
- * @param string $description Description of new Quset
- * @param int $xps Amount of XPs for new Quest
- * @param string $rules Rules of new Quest
- * @param string $wonText Won-text of new Quset
- * @param string $lostText Lost-text of new Quest
- * @return int ID of newly created Quest
- */
- public function createQuest($userId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
- {
- $this->db->query(
- 'INSERT INTO charactergroupsquests '.
- '(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
- 'iiisssdsss',
- $userId,
- $groupsgroupId,
- $questgroupId,
- $title,
- \nre\core\Linker::createLinkParam($title),
- $description,
- $xps,
- $rules,
- $wonText,
- $lostText
- );
-
-
- return $this->db->getInsertId();
- }
-
-
- /**
- * Edit a Character groups Quest.
- *
- * @param int $questId ID of Character groups Quest to edit
- * @param int $groupsgroupId ID of Character groups-group
- * @param int $questgroupId ID of Quest group
- * @param string $title Title of new Quest
- * @param string $description Description of new Quset
- * @param int $xps Amount of XPs for new Quest
- * @param string $rules Rules of new Quest
- * @param string $wonText Won-text of new Quset
- * @param string $lostText Lost-text of new Quest
- */
- public function editQuest($questId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
- {
- $this->db->query(
- 'UPDATE charactergroupsquests '.
- 'SET charactergroupsgroup_id = ?, questgroups_id = ?, title = ?, url = ?, description = ?, xps = ?, rules = ?, won_text = ?, lost_text= ? '.
- 'WHERE id = ?',
- 'iisssdsssi',
- $groupsgroupId,
- $questgroupId,
- $title,
- \nre\core\Linker::createLinkParam($title),
- $description,
- $xps,
- $rules,
- $wonText,
- $lostText,
- $questId
- );
- }
-
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model of the CharactergroupsquestsAgent to interact with
+ * Charactergroupsquests-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactergroupsquestsModel extends \hhu\z\Model
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('uploads', 'media');
+
+
+
+
+ /**
+ * Construct a new CharactergroupsquestsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get Character groups Quests of a Character groups-groups.
+ *
+ * @param int $groupsgroupId ID of the Character groups-group
+ * @return array Character groups Quest data
+ */
+ public function getQuestsForCharactergroupsgroup($groupsgroupId)
+ {
+ return $this->db->query(
+ 'SELECT id, questgroups_id, title, url, xps, questsmedia_id '.
+ 'FROM charactergroupsquests '.
+ 'WHERE charactergroupsgroup_id = ? '.
+ 'ORDER BY created ASC',
+ 'i',
+ $groupsgroupId
+ );
+ }
+
+
+ /**
+ * Get a Character groups Quest by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $groupsgroupId ID of the Character groups-group
+ * @param string $questUrl URL-title of the Character groups Quest
+ * @return array Character groups Quest data
+ */
+ public function getQuestByUrl($groupsgroupId, $questUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '.
+ 'FROM charactergroupsquests '.
+ 'WHERE charactergroupsgroup_id = ? AND url = ?',
+ 'is',
+ $groupsgroupId,
+ $questUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Character groups Quest by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $questId ID of the Character groups Quest
+ * @return array Character groups Quest data
+ */
+ public function getQuestById($questId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '.
+ 'FROM charactergroupsquests '.
+ 'WHERE id = ?',
+ 'i',
+ $questId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get Character groups Quests for a Character group.
+ *
+ * @param int $groupId ID of the Character group
+ * @return array Character groups Quests
+ */
+ public function getQuestsForGroup($groupId)
+ {
+ $quests = $this->db->query(
+ 'SELECT charactergroupsquests.id, charactergroupsquests_groups.created, charactergroupsquests.title, charactergroupsquests.url, charactergroupsquests.xps, charactergroupsquests_groups.xps_factor '.
+ 'FROM charactergroupsquests_groups '.
+ 'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
+ 'WHERE charactergroupsquests_groups.charactergroup_id = ? '.
+ 'ORDER BY charactergroupsquests.created ASC',
+ 'i',
+ $groupId
+ );
+ foreach($quests as &$quest) {
+ $quest['group_xps'] = round($quest['xps'] * $quest['xps_factor'], 1);
+ }
+
+
+ return $quests;
+ }
+
+
+ /**
+ * Get XPs of a Character group for a Character groups Quest.
+ *
+ * @param int $questId ID of Character groups Quest
+ * @param int $groupId ID of Character group to get XPs of
+ * @return array XP-record
+ */
+ public function getXPsOfGroupForQuest($questId, $groupId)
+ {
+ $data = $this->db->query(
+ 'SELECT charactergroupsquests_groups.created, charactergroupsquests_groups.xps_factor, charactergroupsquests.xps '.
+ 'FROM charactergroupsquests_groups '.
+ 'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
+ 'WHERE charactergroupsquests_groups.charactergroupsquest_id = ? AND charactergroupsquests_groups.charactergroup_id = ?',
+ 'ii',
+ $questId,
+ $groupId
+ );
+ if(empty($data)) {
+ return null;
+ }
+
+ $data = $data[0];
+ $data['xps'] = round($data['xps'] * $data['xps_factor'], 1);
+
+
+ return $data;
+ }
+
+
+ /**
+ * Set XPs of a Character group for a Character groups Quest.
+ *
+ * @param int $questId ID of Character groups Quest
+ * @param int $groupId ID of Character group to set XPs of
+ * @param float $xpsFactor XPs-factor
+ */
+ public function setXPsOfGroupForQuest($questId, $groupId, $xpsFactor)
+ {
+ $this->db->query(
+ 'INSERT INTO charactergroupsquests_groups '.
+ '(charactergroupsquest_id, charactergroup_id, xps_factor) '.
+ 'VALUES '.
+ '(?, ?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'xps_factor = ?',
+ 'iidd',
+ $questId,
+ $groupId,
+ $xpsFactor,
+ $xpsFactor
+ );
+ }
+
+
+ /**
+ * Remove a Character group from a Character groups Quest.
+ *
+ * @param int $questId ID of Character groups Quest
+ * @param int $groupId ID of Character group to remove
+ */
+ public function deleteGroupForQuest($questId, $groupId)
+ {
+ $this->db->query(
+ 'DELETE FROM charactergroupsquests_groups '.
+ 'WHERE charactergroupsquest_id = ? AND charactergroup_id = ?',
+ 'ii',
+ $questId, $groupId
+ );
+ }
+
+
+ /**
+ * Check if a Character groups Quest title already exists.
+ *
+ * @param string $name Character groups Quest title to check
+ * @param int $questId Do not check this ID (for editing)
+ * @return boolean Whether Character groups Quest title exists or not
+ */
+ public function characterGroupsQuestTitleExists($title, $questId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM charactergroupsquests '.
+ 'WHERE title = ? OR url = ?',
+ 'ss',
+ $title,
+ \nre\core\Linker::createLinkParam($title)
+ );
+
+ return (!empty($data) && (is_null($questId) || $questId != $data[0]['id']));
+ }
+
+
+ /**
+ * Set the media for a Character groups Quest.
+ *
+ * @param int $questId ID of Quest to upload media for
+ * @param int $mediaId ID of Quests media
+ */
+ public function setMediaForQuest($questId, $mediaId)
+ {
+ $this->db->query(
+ 'UPDATE charactergroupsquests '.
+ 'SET questsmedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $mediaId,
+ $questId
+ );
+ }
+
+
+ /**
+ * Upload a media for a Character groups Quest.
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param int $questId ID of Quest to upload media for
+ * @param array $file File-array of file to upload
+ * @param string $filename Filename for media
+ * @return boolean Whether upload succeeded or not
+ */
+ public function uploadMediaForQuest($userId, $seminaryId, $questId, $file, $filename)
+ {
+ // Save file on harddrive
+ $uploadId = $this->Uploads->uploadSeminaryFile($userId, $seminaryId, $file['name'], $filename, $file['tmp_name'], $file['type']);
+ if($uploadId === false) {
+ return false;
+ }
+
+ // Create database record
+ $this->db->query(
+ 'INSERT INTO charactergroupsquests_seminaryuploads '.
+ '(seminaryupload_id, charactergroupsquest_id, created_user_id) '.
+ 'VALUES '.
+ '(?, ?, ?) ',
+ 'iii',
+ $uploadId, $questId, $userId
+ );
+
+
+ return true;
+ }
+
+
+ /**
+ * Get uploaded Medai for a Character groups Quest.
+ *
+ * @param int $questId ID of Quest to get media for
+ * @return array Seminary uploads
+ */
+ public function getMediaForQuest($questId)
+ {
+ return $this->db->query(
+ 'SELECT seminaryupload_id, created, created_user_id '.
+ 'FROM charactergroupsquests_seminaryuploads '.
+ 'WHERE charactergroupsquest_id = ?',
+ 'i',
+ $questId
+ );
+ }
+
+
+ /**
+ * Create a new Character groups Quest.
+ *
+ * @param int $userId ID of user
+ * @param int $groupsgroupId ID of Character groups-group
+ * @param int $questgroupId ID of Quest group
+ * @param string $title Title of new Quest
+ * @param string $description Description of new Quset
+ * @param int $xps Amount of XPs for new Quest
+ * @param string $rules Rules of new Quest
+ * @param string $wonText Won-text of new Quset
+ * @param string $lostText Lost-text of new Quest
+ * @return int ID of newly created Quest
+ */
+ public function createQuest($userId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
+ {
+ $this->db->query(
+ 'INSERT INTO charactergroupsquests '.
+ '(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
+ 'iiisssdsss',
+ $userId,
+ $groupsgroupId,
+ $questgroupId,
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $description,
+ $xps,
+ $rules,
+ $wonText,
+ $lostText
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Edit a Character groups Quest.
+ *
+ * @param int $questId ID of Character groups Quest to edit
+ * @param int $groupsgroupId ID of Character groups-group
+ * @param int $questgroupId ID of Quest group
+ * @param string $title Title of new Quest
+ * @param string $description Description of new Quset
+ * @param int $xps Amount of XPs for new Quest
+ * @param string $rules Rules of new Quest
+ * @param string $wonText Won-text of new Quset
+ * @param string $lostText Lost-text of new Quest
+ */
+ public function editQuest($questId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
+ {
+ $this->db->query(
+ 'UPDATE charactergroupsquests '.
+ 'SET charactergroupsgroup_id = ?, questgroups_id = ?, title = ?, url = ?, description = ?, xps = ?, rules = ?, won_text = ?, lost_text= ? '.
+ 'WHERE id = ?',
+ 'iisssdsssi',
+ $groupsgroupId,
+ $questgroupId,
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $description,
+ $xps,
+ $rules,
+ $wonText,
+ $lostText,
+ $questId
+ );
+ }
+
+
/**
* Copy all Character groups Quests from a Seminary.
- *
+ *
* @param int $userId ID of copying user
* @param array $groupsgroupIds Mapping of Character groups-group-IDs from source Seminary to target Seminary
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
@@ -424,17 +424,17 @@
}
- /**
- * Delete a Character groups Quest.
- *
- * @param int $questId ID of Character groups Quest to delete
- */
- public function deleteQuest($questId)
- {
- $this->db->query('DELETE FROM charactergroupsquests WHERE id = ?', 'i', $questId);
- }
-
-
- }
+ /**
+ * Delete a Character groups Quest.
+ *
+ * @param int $questId ID of Character groups Quest to delete
+ */
+ public function deleteQuest($questId)
+ {
+ $this->db->query('DELETE FROM charactergroupsquests WHERE id = ?', 'i', $questId);
+ }
+
+
+ }
?>
diff --git a/models/CharacterrolesModel.inc b/models/CharacterrolesModel.inc
index 752d4a0a..92ef3342 100644
--- a/models/CharacterrolesModel.inc
+++ b/models/CharacterrolesModel.inc
@@ -1,100 +1,100 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with characterroles-table.
- *
- * @author Oliver Hanraths
- */
- class CharacterrolesModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new CharacterrolesModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get all characterroles for a Character referenced by its ID.
- *
- * @param int $userId ID of an user
- * @return array Characterroles for a Character
- */
- public function getCharacterrolesForCharacterById($characterId)
- {
- return $this->db->query(
- 'SELECT characterroles.id, characterroles.created, characterroles.name '.
- 'FROM characters_characterroles '.
- 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
- 'WHERE characters_characterroles.character_id = ?',
- 'i',
- $characterId
- );
- }
-
-
- /**
- * Add a role to a Character.
- *
- * @param int $characterId ID of Character to add role to
- * @param string $characterrole Role to add
- */
- public function addCharacterroleToCharacter($characterId, $characterrole)
- {
- $this->db->query(
- 'INSERT IGNORE INTO characters_characterroles '.
- '(character_id, characterrole_id) '.
- 'SELECT ?, id '.
- 'FROM characterroles '.
- 'WHERE name = ?',
- 'is',
- $characterId,
- $characterrole
- );
- }
-
-
- /**
- * Remove a role from a Character.
- *
- * @param int $characterId ID of Character to remove role from
- * @param string $characterrole Role to remove
- */
- public function removeCharacterroleFromCharacter($characterId, $characterrole)
- {
- $this->db->query(
- 'DELETE FROM characters_characterroles '.
- 'WHERE character_id = ? AND characterrole_id = ('.
- 'SELECT id '.
- 'FROM characterroles '.
- 'WHERE name = ?'.
- ')',
- 'is',
- $characterId,
- $characterrole
- );
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with characterroles-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharacterrolesModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new CharacterrolesModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get all characterroles for a Character referenced by its ID.
+ *
+ * @param int $userId ID of an user
+ * @return array Characterroles for a Character
+ */
+ public function getCharacterrolesForCharacterById($characterId)
+ {
+ return $this->db->query(
+ 'SELECT characterroles.id, characterroles.created, characterroles.name '.
+ 'FROM characters_characterroles '.
+ 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
+ 'WHERE characters_characterroles.character_id = ?',
+ 'i',
+ $characterId
+ );
+ }
+
+
+ /**
+ * Add a role to a Character.
+ *
+ * @param int $characterId ID of Character to add role to
+ * @param string $characterrole Role to add
+ */
+ public function addCharacterroleToCharacter($characterId, $characterrole)
+ {
+ $this->db->query(
+ 'INSERT IGNORE INTO characters_characterroles '.
+ '(character_id, characterrole_id) '.
+ 'SELECT ?, id '.
+ 'FROM characterroles '.
+ 'WHERE name = ?',
+ 'is',
+ $characterId,
+ $characterrole
+ );
+ }
+
+
+ /**
+ * Remove a role from a Character.
+ *
+ * @param int $characterId ID of Character to remove role from
+ * @param string $characterrole Role to remove
+ */
+ public function removeCharacterroleFromCharacter($characterId, $characterrole)
+ {
+ $this->db->query(
+ 'DELETE FROM characters_characterroles '.
+ 'WHERE character_id = ? AND characterrole_id = ('.
+ 'SELECT id '.
+ 'FROM characterroles '.
+ 'WHERE name = ?'.
+ ')',
+ 'is',
+ $characterId,
+ $characterrole
+ );
+ }
+
+ }
?>
diff --git a/models/CharactersModel.inc b/models/CharactersModel.inc
index 0582b553..1334f24e 100644
--- a/models/CharactersModel.inc
+++ b/models/CharactersModel.inc
@@ -1,697 +1,697 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Characters-table.
- *
- * @author Oliver Hanraths
- */
- class CharactersModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new CharactersModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get all characters for an user.
- *
- * @param int $userId ID of the user
- * @return array Characters
- */
- public function getCharactersForUser($userId)
- {
- return $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
- 'WHERE characters.user_id = ?',
- 'i',
- $userId
- );
- }
-
-
- /**
- * Get count of Characters for a Seminary.
- *
- * @param int $seminaryId ID of the Seminary
- * @param string $charactername Only get Characters with the given name (optional)
- * @return int Count of Characters
- */
- public function getCharactersForSeminaryCount($seminaryId, $charactername=null)
- {
- $data = $this->db->query(
- 'SELECT count(DISTINCT characters.id) AS c '.
- 'FROM characters '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
- 'WHERE seminaries.id = ? '.
- (!is_null($charactername) ? sprintf('AND characters.name LIKE \'%%%s%%\'', $charactername) : null),
- 'i',
- $seminaryId
- );
- if(!empty($data)) {
- return $data[0]['c'];
- }
-
-
- return 0;
- }
-
-
- /**
- * Get Characters for a Seminary.
- *
- * @param int $seminaryId ID of the Seminary
- * @param bool $onlyWithRole Only Characters that have at least one role assigned (optional)
- * @return array Characters
- */
- public function getCharactersForSeminary($seminaryId, $onlyWithRole=false)
- {
- return $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
- 'WHERE seminaries.id = ?'.
- ($onlyWithRole ? ' AND EXISTS (SELECT character_id FROM characters_characterroles WHERE character_id = characters.id)' : null),
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get Characters for a Seminary sorted and optionally limited.
- *
- * @param int $seminaryId ID of the Seminary
- * @param string $sort Field to sort by
- * @param string $charactername Only get Characters with the given name (optional)
- * @param int $limit Limit amount of Characters (optional)
- * @param int $offset Offset (optional)
- * @return array Characters
- */
- public function getCharactersForSeminarySorted($seminaryId, $sort, $charactername='', $limit=null, $offset=0)
- {
- switch($sort)
- {
- case 'name':
- case 'created':
- case 'xps':
- $orders = array(
- 'name' => 'ASC',
- 'created' => 'DESC',
- 'xps' => 'DESC'
- );
-
- return $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
- 'WHERE seminaries.id = ? '.
- (!is_null($charactername) ? sprintf(' AND characters.name LIKE \'%%%s%%\' ', $charactername) : null).
- sprintf(
- 'ORDER BY %s.%s %s ',
- ($sort == 'xps' ? 'cache_characters' : 'characters'),
- $sort,
- $orders[$sort]
- ).
- (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
- 'i',
- $seminaryId
- );
- break;
- case 'role':
- return $this->db->query(
- 'SELECT DISTINCT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
- 'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
- 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
- 'WHERE seminaries.id = ? '.
- (!is_null($charactername) ? sprintf(' AND characters.name LIKE \'%%%s%%\' ', $charactername) : null).
- 'ORDER BY characterroles.id IS NULL, characterroles.id ASC '.
- (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
- 'i',
- $seminaryId
- );
- break;
- default:
- return $this->db->query(
- 'SELECT DISTINCT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
- 'LEFT JOIN characters_seminarycharacterfields ON characters_seminarycharacterfields.character_id = characters.id '.
- 'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id AND seminarycharacterfields.url = ? '.
- 'WHERE seminaries.id = ? '.
- (!is_null($charactername) ? sprintf(' AND characters.name LIKE \'%%%s%%\' ', $charactername) : null).
- 'ORDER BY characters_seminarycharacterfields.value ASC '.
- (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
- 'si',
- $sort,
- $seminaryId
- );
- break;
- }
- }
-
-
- /**
- * Get Characters for a Character group.
- *
- * @param int $groupId ID of the Character group
- * @return array Characters
- */
- public function getCharactersForGroup($groupId)
- {
- return $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'LEFT JOIN characters_charactergroups ON characters_charactergroups.character_id = characters.id '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE characters_charactergroups.charactergroup_id = ? '.
- 'ORDER BY cache_characters.xps DESC',
- 'i',
- $groupId
- );
- }
-
-
- /**
- * Get the character of a user for a Seminary.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $userId ID of the user
- * @param int $seminaryId ID of the Seminary
- * @return array Character data
- */
- public function getCharacterForUserAndSeminary($userId, $seminaryId)
- {
- $data = $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE characters.user_id = ? AND charactertypes.seminary_id = ?',
- 'ii',
- $userId, $seminaryId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($userId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Character by its Url.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryId ID of the Seminary
- * @param string $characterUrl URL-name of the Character
- * @return array Character data
- */
- public function getCharacterByUrl($seminaryId, $characterUrl)
- {
- $data = $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE charactertypes.seminary_id = ? AND characters.url = ?',
- 'is',
- $seminaryId, $characterUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($characterUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Character by its Id.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $characterId ID of the Character
- * @return array Character data
- */
- public function getCharacterById($characterId)
- {
- $data = $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE characters.id = ?',
- 'i',
- $characterId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($characterUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get Characters with the given Character role.
- *
- * @param string $characterrole Character role
- * @return array List of Characters
- */
- public function getCharactersWithRole($characterrole)
- {
- return $this->db->query(
- 'SELECT characters.id, characters.created, characters.user_id, characters.name, characters.url '.
- 'FROM characters '.
- 'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
- 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
- 'WHERE characterroles.name = ? '.
- 'ORDER BY name ASC',
- 's',
- $characterrole
- );
- }
-
-
- /**
- * Get Characters with the most amount of Achievements.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $conut Amount of Characters to retrieve
- * @param bool $alsoWithDeadline Include Achievements with deadline (optional)
- * @return array List of Characters
- */
- public function getCharactersWithMostAchievements($seminaryId, $count, $alsoWithDeadline=true)
- {
- return $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'count(DISTINCT achievement_id) AS c '.
- 'FROM achievements_characters '.
- 'INNER JOIN achievements ON achievements.id = achievements_characters.achievement_id '.
- 'INNER JOIN characters ON characters.id = achievements_characters.character_id '.
- 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
- 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
- 'WHERE achievements.seminary_id = ? AND deadline IS NULL '.
- (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
- 'GROUP BY achievements_characters.character_id '.
- 'ORDER BY count(DISTINCT achievements_characters.achievement_id) DESC '.
- 'LIMIT ?',
- 'sii',
- 'user',
- $seminaryId,
- $count
- );
- }
-
-
- /**
- * Get the rank of a XP-value of a Character.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $xps XP-value to get rank for
- * @return int Rank of XP-value
- */
- public function getXPRank($seminaryId, $xps)
- {
- $data = $this->db->query(
- 'SELECT count(characters.id) AS c '.
- 'FROM charactertypes '.
- 'INNER JOIN characters ON characters.charactertype_id = charactertypes.id '.
- 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
- 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
- 'WHERE seminary_id = ? AND cache_characters.xps > ?',
- 'sid',
- 'user',
- $seminaryId, $xps
- );
- if(!empty($data)) {
- return $data[0]['c'] + 1;
- }
-
-
- return 1;
- }
-
-
- /**
- * Get the superior $count Characters in the ranking.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $xps XP-value of Character
- * @param int $count Count of Characters to determine
- * @return array List of superior Characters
- */
- public function getSuperiorCharacters($seminaryId, $xps, $count)
- {
- $data = $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
- 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
- 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE charactertypes.seminary_id = ? AND cache_characters.xps > ? '.
- 'ORDER BY cache_characters.xps ASC, RAND() '.
- 'LIMIT ?',
- 'sidd',
- 'user',
- $seminaryId, $xps, $count
- );
- $data = array_reverse($data);
-
-
- return $data;
- }
-
-
- /**
- * Get the inferior $count Characters in the ranking.
- *
- * @param int $seminaryId ID of Seminary
- * @param int characterId ID of Character
- * @param int $xps XP-value of Character
- * @param int $count Count of Characters to determine
- * @return array List of inferior Characters
- */
- public function getInferiorCharacters($seminaryId, $characterId, $xps, $count)
- {
- return $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
- 'FROM characters '.
- 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
- 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
- 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE charactertypes.seminary_id = ? AND cache_characters.xps <= ? AND characters.id <> ? '.
- 'ORDER BY cache_characters.xps DESC, RAND() '.
- 'LIMIT ?',
- 'sidid',
- 'user',
- $seminaryId, $xps, $characterId, $count
- );
- }
-
-
- /**
- * Get Characters that solved a Quest.
- *
- * @param int $questId ID of Quest to get Characters for
- * @return array Characters data
- */
- public function getCharactersSolvedQuest($questId)
- {
- return $data = $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'quests_characters.created AS submission_created '.
- 'FROM quests_characters '.
- 'INNER JOIN characters ON characters.id = quests_characters.character_id '.
- 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE quests_characters.quest_id = ? AND quests_characters.status = ? AND NOT EXISTS ('.
- 'SELECT id '.
- 'FROM quests_characters AS qc '.
- 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
- ') '.
- 'ORDER BY quests_characters.created ASC',
- 'ii',
- $questId, QuestsModel::QUEST_STATUS_SOLVED
- );
- }
-
-
- /**
- * Get Characters that did not solv a Quest.
- *
- * @param int $questId ID of Quest to get Characters for
- * @return array Characters data
- */
- public function getCharactersUnsolvedQuest($questId)
- {
- return $data = $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'quests_characters.created AS submission_created '.
- 'FROM quests_characters '.
- 'INNER JOIN characters ON characters.id = quests_characters.character_id '.
- 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE quests_characters.quest_id = ? AND quests_characters.status = ? AND NOT EXISTS ('.
- 'SELECT id '.
- 'FROM quests_characters AS qc '.
- 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
- ') '.
- 'ORDER BY quests_characters.created ASC',
- 'ii',
- $questId, QuestsModel::QUEST_STATUS_UNSOLVED
- );
- }
-
-
- /**
- * Get Characters that sent a submission for a Quest.
- *
- * @param int $questId ID of Quest to get Characters for
- * @return array Characters data
- */
- public function getCharactersSubmittedQuest($questId)
- {
- return $data = $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'quests_characters.created AS submission_created '.
- 'FROM quests_characters '.
- 'INNER JOIN characters ON characters.id = quests_characters.character_id '.
- 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'WHERE quests_characters.quest_id = ? AND quests_characters.status = ? AND NOT EXISTS ('.
- 'SELECT id '.
- 'FROM quests_characters AS qc '.
- 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
- ') '.
- 'ORDER BY quests_characters.created ASC',
- 'ii',
- $questId, QuestsModel::QUEST_STATUS_SUBMITTED
- );
- }
-
-
- /**
- * Get Characters with the given Character role.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $characterrole Character role
- * @return array List of users
- */
- public function getCharactersWithCharacterRole($seminaryId, $characterrole)
- {
- return $this->db->query(
- 'SELECT '.
- 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
- 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
- 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
- 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
- 'FROM characters '.
- 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
- 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
- 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
- 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
- 'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
- 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
- 'WHERE seminaries.id = ? AND characterroles.name = ?',
- 'is',
- $seminaryId, $characterrole
- );
- }
-
-
- /**
- * Check if a Character name already exists.
- *
- * @param string $name Character name to check
- * @param int $characterId Do not check this ID (for editing)
- * @return boolean Whether Character name exists or not
- */
- public function characterNameExists($name, $characterId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM characters '.
- 'WHERE name = ? OR url = ?',
- 'ss',
- $name,
- \nre\core\Linker::createLinkParam($name)
- );
-
-
- return (!empty($data) && (is_null($characterId) || $characterId != $data[0]['id']));
- }
-
-
- /**
- * Create a new Character.
- *
- * @param int $userId User-ID that creates the new character
- * @param int $charactertypeId ID of type of new Character
- * @param string $characterName Name for the new Character
- * @return int ID of Character
- */
- public function createCharacter($userId, $charactertypeId, $characterName)
- {
- $this->db->query(
- 'INSERT INTO characters '.
- '(user_id, charactertype_id, name, url) '.
- 'VALUES '.
- '(?, ?, ?, ?)',
- 'iiss',
- $userId,
- $charactertypeId,
- $characterName,
- \nre\core\Linker::createLinkParam($characterName)
- );
-
-
- return $this->db->getInsertId();
- }
-
-
- /**
- * Edit a new Character.
- *
- * @param int $characterId ID of the Character to edit
- * @param int $charactertypeId ID of new type of Character
- * @param string $characterName New name for Character
- */
- public function editCharacter($characterId, $charactertypeId, $characterName)
- {
- $this->db->query(
- 'UPDATE characters '.
- 'SET charactertype_id = ?, name = ?, url = ? '.
- 'WHERE id = ?',
- 'issi',
- $charactertypeId,
- $characterName,
- \nre\core\Linker::createLinkParam($characterName),
- $characterId
- );
- }
-
-
- /**
- * Delete a Character.
- *
- * @param int $characterId ID of the Character to delete
- */
- public function deleteCharacter($characterId)
- {
- $this->db->query('DELETE FROM characters WHERE id = ?', 'i', $characterId);
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with Characters-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactersModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new CharactersModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get all characters for an user.
+ *
+ * @param int $userId ID of the user
+ * @return array Characters
+ */
+ public function getCharactersForUser($userId)
+ {
+ return $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
+ 'WHERE characters.user_id = ?',
+ 'i',
+ $userId
+ );
+ }
+
+
+ /**
+ * Get count of Characters for a Seminary.
+ *
+ * @param int $seminaryId ID of the Seminary
+ * @param string $charactername Only get Characters with the given name (optional)
+ * @return int Count of Characters
+ */
+ public function getCharactersForSeminaryCount($seminaryId, $charactername=null)
+ {
+ $data = $this->db->query(
+ 'SELECT count(DISTINCT characters.id) AS c '.
+ 'FROM characters '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
+ 'WHERE seminaries.id = ? '.
+ (!is_null($charactername) ? sprintf('AND characters.name LIKE \'%%%s%%\'', $charactername) : null),
+ 'i',
+ $seminaryId
+ );
+ if(!empty($data)) {
+ return $data[0]['c'];
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Get Characters for a Seminary.
+ *
+ * @param int $seminaryId ID of the Seminary
+ * @param bool $onlyWithRole Only Characters that have at least one role assigned (optional)
+ * @return array Characters
+ */
+ public function getCharactersForSeminary($seminaryId, $onlyWithRole=false)
+ {
+ return $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
+ 'WHERE seminaries.id = ?'.
+ ($onlyWithRole ? ' AND EXISTS (SELECT character_id FROM characters_characterroles WHERE character_id = characters.id)' : null),
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get Characters for a Seminary sorted and optionally limited.
+ *
+ * @param int $seminaryId ID of the Seminary
+ * @param string $sort Field to sort by
+ * @param string $charactername Only get Characters with the given name (optional)
+ * @param int $limit Limit amount of Characters (optional)
+ * @param int $offset Offset (optional)
+ * @return array Characters
+ */
+ public function getCharactersForSeminarySorted($seminaryId, $sort, $charactername='', $limit=null, $offset=0)
+ {
+ switch($sort)
+ {
+ case 'name':
+ case 'created':
+ case 'xps':
+ $orders = array(
+ 'name' => 'ASC',
+ 'created' => 'DESC',
+ 'xps' => 'DESC'
+ );
+
+ return $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
+ 'WHERE seminaries.id = ? '.
+ (!is_null($charactername) ? sprintf(' AND characters.name LIKE \'%%%s%%\' ', $charactername) : null).
+ sprintf(
+ 'ORDER BY %s.%s %s ',
+ ($sort == 'xps' ? 'cache_characters' : 'characters'),
+ $sort,
+ $orders[$sort]
+ ).
+ (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
+ 'i',
+ $seminaryId
+ );
+ break;
+ case 'role':
+ return $this->db->query(
+ 'SELECT DISTINCT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
+ 'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
+ 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
+ 'WHERE seminaries.id = ? '.
+ (!is_null($charactername) ? sprintf(' AND characters.name LIKE \'%%%s%%\' ', $charactername) : null).
+ 'ORDER BY characterroles.id IS NULL, characterroles.id ASC '.
+ (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
+ 'i',
+ $seminaryId
+ );
+ break;
+ default:
+ return $this->db->query(
+ 'SELECT DISTINCT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
+ 'LEFT JOIN characters_seminarycharacterfields ON characters_seminarycharacterfields.character_id = characters.id '.
+ 'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id AND seminarycharacterfields.url = ? '.
+ 'WHERE seminaries.id = ? '.
+ (!is_null($charactername) ? sprintf(' AND characters.name LIKE \'%%%s%%\' ', $charactername) : null).
+ 'ORDER BY characters_seminarycharacterfields.value ASC '.
+ (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
+ 'si',
+ $sort,
+ $seminaryId
+ );
+ break;
+ }
+ }
+
+
+ /**
+ * Get Characters for a Character group.
+ *
+ * @param int $groupId ID of the Character group
+ * @return array Characters
+ */
+ public function getCharactersForGroup($groupId)
+ {
+ return $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'LEFT JOIN characters_charactergroups ON characters_charactergroups.character_id = characters.id '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE characters_charactergroups.charactergroup_id = ? '.
+ 'ORDER BY cache_characters.xps DESC',
+ 'i',
+ $groupId
+ );
+ }
+
+
+ /**
+ * Get the character of a user for a Seminary.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $userId ID of the user
+ * @param int $seminaryId ID of the Seminary
+ * @return array Character data
+ */
+ public function getCharacterForUserAndSeminary($userId, $seminaryId)
+ {
+ $data = $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE characters.user_id = ? AND charactertypes.seminary_id = ?',
+ 'ii',
+ $userId, $seminaryId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($userId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Character by its Url.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryId ID of the Seminary
+ * @param string $characterUrl URL-name of the Character
+ * @return array Character data
+ */
+ public function getCharacterByUrl($seminaryId, $characterUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE charactertypes.seminary_id = ? AND characters.url = ?',
+ 'is',
+ $seminaryId, $characterUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($characterUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Character by its Id.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $characterId ID of the Character
+ * @return array Character data
+ */
+ public function getCharacterById($characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE characters.id = ?',
+ 'i',
+ $characterId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($characterUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get Characters with the given Character role.
+ *
+ * @param string $characterrole Character role
+ * @return array List of Characters
+ */
+ public function getCharactersWithRole($characterrole)
+ {
+ return $this->db->query(
+ 'SELECT characters.id, characters.created, characters.user_id, characters.name, characters.url '.
+ 'FROM characters '.
+ 'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
+ 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
+ 'WHERE characterroles.name = ? '.
+ 'ORDER BY name ASC',
+ 's',
+ $characterrole
+ );
+ }
+
+
+ /**
+ * Get Characters with the most amount of Achievements.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $conut Amount of Characters to retrieve
+ * @param bool $alsoWithDeadline Include Achievements with deadline (optional)
+ * @return array List of Characters
+ */
+ public function getCharactersWithMostAchievements($seminaryId, $count, $alsoWithDeadline=true)
+ {
+ return $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'count(DISTINCT achievement_id) AS c '.
+ 'FROM achievements_characters '.
+ 'INNER JOIN achievements ON achievements.id = achievements_characters.achievement_id '.
+ 'INNER JOIN characters ON characters.id = achievements_characters.character_id '.
+ 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
+ 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
+ 'WHERE achievements.seminary_id = ? AND deadline IS NULL '.
+ (!$alsoWithDeadline ? 'AND achievements.deadline IS NULL ' : null).
+ 'GROUP BY achievements_characters.character_id '.
+ 'ORDER BY count(DISTINCT achievements_characters.achievement_id) DESC '.
+ 'LIMIT ?',
+ 'sii',
+ 'user',
+ $seminaryId,
+ $count
+ );
+ }
+
+
+ /**
+ * Get the rank of a XP-value of a Character.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $xps XP-value to get rank for
+ * @return int Rank of XP-value
+ */
+ public function getXPRank($seminaryId, $xps)
+ {
+ $data = $this->db->query(
+ 'SELECT count(characters.id) AS c '.
+ 'FROM charactertypes '.
+ 'INNER JOIN characters ON characters.charactertype_id = charactertypes.id '.
+ 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
+ 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
+ 'WHERE seminary_id = ? AND cache_characters.xps > ?',
+ 'sid',
+ 'user',
+ $seminaryId, $xps
+ );
+ if(!empty($data)) {
+ return $data[0]['c'] + 1;
+ }
+
+
+ return 1;
+ }
+
+
+ /**
+ * Get the superior $count Characters in the ranking.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $xps XP-value of Character
+ * @param int $count Count of Characters to determine
+ * @return array List of superior Characters
+ */
+ public function getSuperiorCharacters($seminaryId, $xps, $count)
+ {
+ $data = $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
+ 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
+ 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE charactertypes.seminary_id = ? AND cache_characters.xps > ? '.
+ 'ORDER BY cache_characters.xps ASC, RAND() '.
+ 'LIMIT ?',
+ 'sidd',
+ 'user',
+ $seminaryId, $xps, $count
+ );
+ $data = array_reverse($data);
+
+
+ return $data;
+ }
+
+
+ /**
+ * Get the inferior $count Characters in the ranking.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int characterId ID of Character
+ * @param int $xps XP-value of Character
+ * @param int $count Count of Characters to determine
+ * @return array List of inferior Characters
+ */
+ public function getInferiorCharacters($seminaryId, $characterId, $xps, $count)
+ {
+ return $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
+ 'FROM characters '.
+ 'INNER JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
+ 'INNER JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id AND characterroles.name = ? '.
+ 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE charactertypes.seminary_id = ? AND cache_characters.xps <= ? AND characters.id <> ? '.
+ 'ORDER BY cache_characters.xps DESC, RAND() '.
+ 'LIMIT ?',
+ 'sidid',
+ 'user',
+ $seminaryId, $xps, $characterId, $count
+ );
+ }
+
+
+ /**
+ * Get Characters that solved a Quest.
+ *
+ * @param int $questId ID of Quest to get Characters for
+ * @return array Characters data
+ */
+ public function getCharactersSolvedQuest($questId)
+ {
+ return $data = $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'quests_characters.created AS submission_created '.
+ 'FROM quests_characters '.
+ 'INNER JOIN characters ON characters.id = quests_characters.character_id '.
+ 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE quests_characters.quest_id = ? AND quests_characters.status = ? AND NOT EXISTS ('.
+ 'SELECT id '.
+ 'FROM quests_characters AS qc '.
+ 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
+ ') '.
+ 'ORDER BY quests_characters.created ASC',
+ 'ii',
+ $questId, QuestsModel::QUEST_STATUS_SOLVED
+ );
+ }
+
+
+ /**
+ * Get Characters that did not solv a Quest.
+ *
+ * @param int $questId ID of Quest to get Characters for
+ * @return array Characters data
+ */
+ public function getCharactersUnsolvedQuest($questId)
+ {
+ return $data = $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'quests_characters.created AS submission_created '.
+ 'FROM quests_characters '.
+ 'INNER JOIN characters ON characters.id = quests_characters.character_id '.
+ 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE quests_characters.quest_id = ? AND quests_characters.status = ? AND NOT EXISTS ('.
+ 'SELECT id '.
+ 'FROM quests_characters AS qc '.
+ 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
+ ') '.
+ 'ORDER BY quests_characters.created ASC',
+ 'ii',
+ $questId, QuestsModel::QUEST_STATUS_UNSOLVED
+ );
+ }
+
+
+ /**
+ * Get Characters that sent a submission for a Quest.
+ *
+ * @param int $questId ID of Quest to get Characters for
+ * @return array Characters data
+ */
+ public function getCharactersSubmittedQuest($questId)
+ {
+ return $data = $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'quests_characters.created AS submission_created '.
+ 'FROM quests_characters '.
+ 'INNER JOIN characters ON characters.id = quests_characters.character_id '.
+ 'INNER JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'INNER JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'INNER JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'WHERE quests_characters.quest_id = ? AND quests_characters.status = ? AND NOT EXISTS ('.
+ 'SELECT id '.
+ 'FROM quests_characters AS qc '.
+ 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
+ ') '.
+ 'ORDER BY quests_characters.created ASC',
+ 'ii',
+ $questId, QuestsModel::QUEST_STATUS_SUBMITTED
+ );
+ }
+
+
+ /**
+ * Get Characters with the given Character role.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $characterrole Character role
+ * @return array List of users
+ */
+ public function getCharactersWithCharacterRole($seminaryId, $characterrole)
+ {
+ return $this->db->query(
+ 'SELECT '.
+ 'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
+ 'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
+ 'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
+ 'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
+ 'FROM characters '.
+ 'LEFT JOIN cache_characters ON cache_characters.character_id = characters.id '.
+ 'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
+ 'LEFT JOIN xplevels ON xplevels.id = cache_characters.xplevel_id '.
+ 'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
+ 'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
+ 'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
+ 'WHERE seminaries.id = ? AND characterroles.name = ?',
+ 'is',
+ $seminaryId, $characterrole
+ );
+ }
+
+
+ /**
+ * Check if a Character name already exists.
+ *
+ * @param string $name Character name to check
+ * @param int $characterId Do not check this ID (for editing)
+ * @return boolean Whether Character name exists or not
+ */
+ public function characterNameExists($name, $characterId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM characters '.
+ 'WHERE name = ? OR url = ?',
+ 'ss',
+ $name,
+ \nre\core\Linker::createLinkParam($name)
+ );
+
+
+ return (!empty($data) && (is_null($characterId) || $characterId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Character.
+ *
+ * @param int $userId User-ID that creates the new character
+ * @param int $charactertypeId ID of type of new Character
+ * @param string $characterName Name for the new Character
+ * @return int ID of Character
+ */
+ public function createCharacter($userId, $charactertypeId, $characterName)
+ {
+ $this->db->query(
+ 'INSERT INTO characters '.
+ '(user_id, charactertype_id, name, url) '.
+ 'VALUES '.
+ '(?, ?, ?, ?)',
+ 'iiss',
+ $userId,
+ $charactertypeId,
+ $characterName,
+ \nre\core\Linker::createLinkParam($characterName)
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Edit a new Character.
+ *
+ * @param int $characterId ID of the Character to edit
+ * @param int $charactertypeId ID of new type of Character
+ * @param string $characterName New name for Character
+ */
+ public function editCharacter($characterId, $charactertypeId, $characterName)
+ {
+ $this->db->query(
+ 'UPDATE characters '.
+ 'SET charactertype_id = ?, name = ?, url = ? '.
+ 'WHERE id = ?',
+ 'issi',
+ $charactertypeId,
+ $characterName,
+ \nre\core\Linker::createLinkParam($characterName),
+ $characterId
+ );
+ }
+
+
+ /**
+ * Delete a Character.
+ *
+ * @param int $characterId ID of the Character to delete
+ */
+ public function deleteCharacter($characterId)
+ {
+ $this->db->query('DELETE FROM characters WHERE id = ?', 'i', $characterId);
+ }
+
+ }
?>
diff --git a/models/CharactertypesModel.inc b/models/CharactertypesModel.inc
index 38a207eb..eb812864 100644
--- a/models/CharactertypesModel.inc
+++ b/models/CharactertypesModel.inc
@@ -1,209 +1,209 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Charactertypes-table.
- *
- * @author Oliver Hanraths
- */
- class CharactertypesModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new CharactertypesModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get all Character types of a Seminary.
- *
- * @param int $seminaryId ID of Seminary to get types of
- * @return array Character types
- */
- public function getCharacterTypesForSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT id, seminary_id, name, url '.
- 'FROM charactertypes '.
- 'WHERE seminary_id = ? '.
- 'ORDER BY name ASC',
- 'i',
- $seminaryId
- );
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
- /**
- * Get Character type by its URL.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $charactretypeUrl URL-title of Character type
- * @return array Character type data
- */
- public function getCharactertypeByUrl($seminaryId, $charactertypeUrl)
- {
- $data = $this->db->query(
- 'SELECT id, seminary_id, name, url '.
- 'FROM charactertypes '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
- $seminaryId,
- $charactertypeUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
- }
-
-
- return $data[0];
- }
+ /**
+ * Model to interact with Charactertypes-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class CharactertypesModel extends \hhu\z\Model
+ {
- /**
- * Get Character type by its ID.
- *
- * @param string $charactertypeId ID of Character type
- * @return array Character type data
- */
- public function getCharactertypeById($charactertypeId)
- {
- $data = $this->db->query(
- 'SELECT id, seminary_id, name, url '.
- 'FROM charactertypes '.
- 'WHERE id = ?',
- 'i',
- $charactertypeId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($charactertypeId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Check if a Charactertype name already exists.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $name Charactertype name to check
- * @param int $charactertypeId Do not check this ID (for editing)
- * @return boolean Whether Charactertype name exists or not
- */
- public function charactertypeNameExists($seminaryId, $name, $charactertypeId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM charactertypes '.
- 'WHERE seminary_id = ? AND (name = ? OR url = ?)',
- 'iss',
- $seminaryId,
- $name,
- \nre\core\Linker::createLinkParam($name)
- );
-
- return (!empty($data) && (is_null($charactertypeId) || $charactertypeId != $data[0]['id']));
- }
- /**
- * Create a new Charactertype for a Seminary.
- *
- * @param int $userId ID of creating user
- * @param int $seminaryId ID of Seminary
- * @param string $name Name for new Charactertype
- * @return int ID of newly created Charactertype
- */
- public function createCharactertype($userId, $seminaryId, $name)
- {
- $charactertypeId = null;
- $this->db->setAutocommit(false);
- try {
- // Create Charactertype
- $this->db->query(
- 'INSERT INTO charactertypes '.
- '(created_user_id, seminary_id, name, url) '.
- 'VALUES '.
- '(?, ?, ?, ?) ',
- 'iiss',
- $userId,
- $seminaryId,
- $name,
- \nre\core\Linker::createLinkParam($name)
- );
- $charactertypeId = $this->db->getInsertId();
-
- // Create avatars
- $this->db->query(
- 'INSERT INTO avatars '.
- '(created_user_id, charactertype_id, xplevel_id) '.
- 'SELECT ?, ?, xplevels.id '.
- 'FROM xplevels '.
- 'WHERE seminary_id = ?',
- 'iii',
- $userId,
- $charactertypeId,
- $seminaryId
- );
-
- $this->db->commit();
- }
- catch(\Exception $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
- $this->db->setAutocommit(true);
+ /**
+ * Construct a new CharactertypesModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get all Character types of a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary to get types of
+ * @return array Character types
+ */
+ public function getCharacterTypesForSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT id, seminary_id, name, url '.
+ 'FROM charactertypes '.
+ 'WHERE seminary_id = ? '.
+ 'ORDER BY name ASC',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get Character type by its URL.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $charactretypeUrl URL-title of Character type
+ * @return array Character type data
+ */
+ public function getCharactertypeByUrl($seminaryId, $charactertypeUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, seminary_id, name, url '.
+ 'FROM charactertypes '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
+ $seminaryId,
+ $charactertypeUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get Character type by its ID.
+ *
+ * @param string $charactertypeId ID of Character type
+ * @return array Character type data
+ */
+ public function getCharactertypeById($charactertypeId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, seminary_id, name, url '.
+ 'FROM charactertypes '.
+ 'WHERE id = ?',
+ 'i',
+ $charactertypeId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($charactertypeId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Check if a Charactertype name already exists.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $name Charactertype name to check
+ * @param int $charactertypeId Do not check this ID (for editing)
+ * @return boolean Whether Charactertype name exists or not
+ */
+ public function charactertypeNameExists($seminaryId, $name, $charactertypeId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM charactertypes '.
+ 'WHERE seminary_id = ? AND (name = ? OR url = ?)',
+ 'iss',
+ $seminaryId,
+ $name,
+ \nre\core\Linker::createLinkParam($name)
+ );
+
+ return (!empty($data) && (is_null($charactertypeId) || $charactertypeId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Charactertype for a Seminary.
+ *
+ * @param int $userId ID of creating user
+ * @param int $seminaryId ID of Seminary
+ * @param string $name Name for new Charactertype
+ * @return int ID of newly created Charactertype
+ */
+ public function createCharactertype($userId, $seminaryId, $name)
+ {
+ $charactertypeId = null;
+ $this->db->setAutocommit(false);
+ try {
+ // Create Charactertype
+ $this->db->query(
+ 'INSERT INTO charactertypes '.
+ '(created_user_id, seminary_id, name, url) '.
+ 'VALUES '.
+ '(?, ?, ?, ?) ',
+ 'iiss',
+ $userId,
+ $seminaryId,
+ $name,
+ \nre\core\Linker::createLinkParam($name)
+ );
+ $charactertypeId = $this->db->getInsertId();
+
+ // Create avatars
+ $this->db->query(
+ 'INSERT INTO avatars '.
+ '(created_user_id, charactertype_id, xplevel_id) '.
+ 'SELECT ?, ?, xplevels.id '.
+ 'FROM xplevels '.
+ 'WHERE seminary_id = ?',
+ 'iii',
+ $userId,
+ $charactertypeId,
+ $seminaryId
+ );
+
+ $this->db->commit();
+ }
+ catch(\Exception $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+ $this->db->setAutocommit(true);
+
+
+ return $charactertypeId;
+ }
+
+
+ /**
+ * Edit a Charactertype.
+ *
+ * @param int $charactertypeId ID of Charactertype to edit
+ * @param string $name New name of Charactertype
+ */
+ public function editCharactertype($charactertypeId, $name)
+ {
+ $this->db->query(
+ 'UPDATE charactertypes '.
+ 'SET name = ?, url = ? '.
+ 'WHERE id = ?',
+ 'ssi',
+ $name,
+ \nre\core\Linker::createLinkParam($name),
+ $charactertypeId
+ );
+ }
- return $charactertypeId;
- }
-
-
- /**
- * Edit a Charactertype.
- *
- * @param int $charactertypeId ID of Charactertype to edit
- * @param string $name New name of Charactertype
- */
- public function editCharactertype($charactertypeId, $name)
- {
- $this->db->query(
- 'UPDATE charactertypes '.
- 'SET name = ?, url = ? '.
- 'WHERE id = ?',
- 'ssi',
- $name,
- \nre\core\Linker::createLinkParam($name),
- $charactertypeId
- );
- }
-
-
/**
* Copy all Charactertypes of a Seminary.
- *
+ *
* @param int $userId ID of copying user
* @param int $sourceSeminaryId ID of Seminary to copy from
* @param int $targetSeminaryId ID of Seminary to copy to
@@ -237,16 +237,16 @@
}
- /**
- * Delete a Charactertype.
- *
- * @param int $charactertypeId ID of Charactertype to delete
- */
- public function deleteCharactertype($charactertypeId)
- {
- $this->db->query('DELETE FROM charactertypes WHERE id = ?', 'i', $charactertypeId);
- }
-
- }
+ /**
+ * Delete a Charactertype.
+ *
+ * @param int $charactertypeId ID of Charactertype to delete
+ */
+ public function deleteCharactertype($charactertypeId)
+ {
+ $this->db->query('DELETE FROM charactertypes WHERE id = ?', 'i', $charactertypeId);
+ }
+
+ }
?>
diff --git a/models/MapModel.inc b/models/MapModel.inc
index d758bbfd..02ea0842 100644
--- a/models/MapModel.inc
+++ b/models/MapModel.inc
@@ -1,42 +1,42 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with the maps-table.
- *
- * @author Oliver Hanraths
- */
- class MapModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new MapModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with the maps-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class MapModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new MapModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
/**
* Get the map of a Seminary.
- *
+ *
* @param int $seminaryId ID of Seminary to get map of
* @return array Map data
*/
@@ -56,7 +56,7 @@
return null;
}
-
- }
+
+ }
?>
diff --git a/models/MediaModel.inc b/models/MediaModel.inc
index cb0e4004..a1cfc775 100644
--- a/models/MediaModel.inc
+++ b/models/MediaModel.inc
@@ -1,144 +1,144 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with the Media-tables.
- *
- * @author Oliver Hanraths
- */
- class MediaModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new MediaModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get a medium by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $mediaURL URL-name of the Medium
- * @return array Medium data
- */
- public function getMediaByUrl($mediaUrl)
- {
- $data = $this->db->query(
- 'SELECT id, name, url, description, mimetype '.
- 'FROM media '.
- 'WHERE url = ?',
- 's',
- $mediaUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($mediaUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a medium by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $mediaId ID of the Medium
- * @return array Medium data
- */
- public function getMediaById($mediaId)
- {
- $data = $this->db->query(
- 'SELECT id, name, url, description, mimetype '.
- 'FROM media '.
- 'WHERE id = ?',
- 'i',
- $mediaId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($mediaId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Seminary medium by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryId ID of the seminary
- * @param string $seminaryMediaUrl URL-name of the Seminary medium
- * @return array Seminary medium data
- */
- public function getSeminaryMediaByUrl($seminaryId, $seminaryMediaUrl)
- {
- $data = $this->db->query(
- 'SELECT id, name, url, description, mimetype '.
- 'FROM seminarymedia '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with the Media-tables.
+ *
+ * @author Oliver Hanraths
+ */
+ class MediaModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new MediaModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get a medium by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $mediaURL URL-name of the Medium
+ * @return array Medium data
+ */
+ public function getMediaByUrl($mediaUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, name, url, description, mimetype '.
+ 'FROM media '.
+ 'WHERE url = ?',
+ 's',
+ $mediaUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($mediaUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a medium by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $mediaId ID of the Medium
+ * @return array Medium data
+ */
+ public function getMediaById($mediaId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, name, url, description, mimetype '.
+ 'FROM media '.
+ 'WHERE id = ?',
+ 'i',
+ $mediaId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($mediaId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Seminary medium by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryId ID of the seminary
+ * @param string $seminaryMediaUrl URL-name of the Seminary medium
+ * @return array Seminary medium data
+ */
+ public function getSeminaryMediaByUrl($seminaryId, $seminaryMediaUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, name, url, description, mimetype '.
+ 'FROM seminarymedia '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
$seminaryId,
- $seminaryMediaUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($seminaryId.': '.$seminaryMediaUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Seminary medium by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryMediaId ID of the Seminary medium
- * @return array Seminary medium data
- */
- public function getSeminaryMediaById($mediaId)
- {
- $data = $this->db->query(
- 'SELECT id, name, url, description, mimetype '.
- 'FROM seminarymedia '.
- 'WHERE id = ?',
- 'i',
- $mediaId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($mediaId);
- }
-
-
- return $data[0];
- }
+ $seminaryMediaUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($seminaryId.': '.$seminaryMediaUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Seminary medium by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryMediaId ID of the Seminary medium
+ * @return array Seminary medium data
+ */
+ public function getSeminaryMediaById($mediaId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, name, url, description, mimetype '.
+ 'FROM seminarymedia '.
+ 'WHERE id = ?',
+ 'i',
+ $mediaId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($mediaId);
+ }
+
+
+ return $data[0];
+ }
/**
* Copy all media from a Seminary.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceSeminaryId ID of Seminary to copy from
* @param int $targetSeminaryId ID of Seminary to copy to
@@ -196,104 +196,104 @@
// Return new media IDs
return $seminaryMediaIds;
}
-
-
- /**
- * Create a new moodpic.
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param string $filename Filename of uploading media
- * @param string $description Description for media
- * @param string $mimetype Mimetype of media
- * @param string $tmpFilename Name of temporary uploaded file
- * @return mixed ID of media record or false if upload failed
- */
- public function createMoodpic($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
- {
- $mediaId = false;
- $this->db->setAutocommit(false);
-
- try {
- // Create Seminary media record
- $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
-
- // Upload file
- $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
- if(!move_uploaded_file($tmpFilename, $filename))
- {
- $this->db->rollback();
- $mediaId = false;
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
-
- $this->db->setAutocommit(true);
- return $mediaId;
- }
- /**
- * Create a new Avatar picture for a Charactertype by creating a new Seminarymedia and
- * adding it to the list of Avatar pictures.
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param string $filename Filename of uploading media
- * @param string $description Description for media
- * @param string $mimetype Mimetype of media
- * @param string $tmpFilename Name of temporary uploaded file
- * @return mixed ID of media record or false if upload failed
- */
- public function createAvatarpicture($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
- {
- $mediaId = false;
- $this->db->setAutocommit(false);
-
- try {
- // Create Seminary media record
- $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
-
- // Add media to Achievements media
- $this->db->query(
- 'INSERT INTO avatarpictures '.
- '(seminarymedia_id, created_user_id) '.
- 'VALUES '.
- '(?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'created_user_id = ?',
- 'iii',
- $mediaId,
- $userId,
- $userId
- );
-
- // Create filename
- $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
- if(!move_uploaded_file($tmpFilename, $filename))
- {
- $this->db->rollback();
- $mediaId = false;
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
-
- $this->db->setAutocommit(true);
- return $mediaId;
- }
+ /**
+ * Create a new moodpic.
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param string $filename Filename of uploading media
+ * @param string $description Description for media
+ * @param string $mimetype Mimetype of media
+ * @param string $tmpFilename Name of temporary uploaded file
+ * @return mixed ID of media record or false if upload failed
+ */
+ public function createMoodpic($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
+ {
+ $mediaId = false;
+ $this->db->setAutocommit(false);
+
+ try {
+ // Create Seminary media record
+ $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
+
+ // Upload file
+ $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
+ if(!move_uploaded_file($tmpFilename, $filename))
+ {
+ $this->db->rollback();
+ $mediaId = false;
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+
+ $this->db->setAutocommit(true);
+ return $mediaId;
+ }
+
+
+ /**
+ * Create a new Avatar picture for a Charactertype by creating a new Seminarymedia and
+ * adding it to the list of Avatar pictures.
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param string $filename Filename of uploading media
+ * @param string $description Description for media
+ * @param string $mimetype Mimetype of media
+ * @param string $tmpFilename Name of temporary uploaded file
+ * @return mixed ID of media record or false if upload failed
+ */
+ public function createAvatarpicture($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
+ {
+ $mediaId = false;
+ $this->db->setAutocommit(false);
+
+ try {
+ // Create Seminary media record
+ $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
+
+ // Add media to Achievements media
+ $this->db->query(
+ 'INSERT INTO avatarpictures '.
+ '(seminarymedia_id, created_user_id) '.
+ 'VALUES '.
+ '(?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'created_user_id = ?',
+ 'iii',
+ $mediaId,
+ $userId,
+ $userId
+ );
+
+ // Create filename
+ $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
+ if(!move_uploaded_file($tmpFilename, $filename))
+ {
+ $this->db->rollback();
+ $mediaId = false;
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+
+ $this->db->setAutocommit(true);
+ return $mediaId;
+ }
/**
* Copy an Avatar picture.
- *
+ *
* @param int $userId ID of creating user
* @param int $seminaryMediaId ID of Seminary media to copy
*/
@@ -313,64 +313,64 @@
);
}
-
- /**
- * Create a new Questgroup picture (Moodpic).
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param int $questgroupId ID of Questgroup to create picture for
- * @param string $filename Filename of uploading media
- * @param string $description Description for media
- * @param string $mimetype Mimetype of media
- * @param string $tmpFilename Name of temporary uploaded file
- * @return mixed ID of media record or false if upload failed
- */
- public function createQuestgrouppicture($userId, $seminaryId, $questgroupId, $filename, $description, $mimetype, $tmpFilename)
- {
- $mediaId = false;
- $this->db->setAutocommit(false);
-
- try {
- // Create Seminary media record
- $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
- // Add media to Questgroups pictures
- $this->db->query(
- 'INSERT INTO questgroupspictures '.
- '(media_id, created_user_id) '.
- 'VALUES '.
- '(?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'created_user_id = ?',
- 'iii',
- $mediaId,
- $userId,
- $userId
- );
-
- // Upload file
- $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
- if(!move_uploaded_file($tmpFilename, $filename))
- {
- $this->db->rollback();
- $mediaId = false;
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
-
- $this->db->setAutocommit(true);
- return $mediaId;
- }
+ /**
+ * Create a new Questgroup picture (Moodpic).
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param int $questgroupId ID of Questgroup to create picture for
+ * @param string $filename Filename of uploading media
+ * @param string $description Description for media
+ * @param string $mimetype Mimetype of media
+ * @param string $tmpFilename Name of temporary uploaded file
+ * @return mixed ID of media record or false if upload failed
+ */
+ public function createQuestgrouppicture($userId, $seminaryId, $questgroupId, $filename, $description, $mimetype, $tmpFilename)
+ {
+ $mediaId = false;
+ $this->db->setAutocommit(false);
+
+ try {
+ // Create Seminary media record
+ $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
+
+ // Add media to Questgroups pictures
+ $this->db->query(
+ 'INSERT INTO questgroupspictures '.
+ '(media_id, created_user_id) '.
+ 'VALUES '.
+ '(?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'created_user_id = ?',
+ 'iii',
+ $mediaId,
+ $userId,
+ $userId
+ );
+
+ // Upload file
+ $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
+ if(!move_uploaded_file($tmpFilename, $filename))
+ {
+ $this->db->rollback();
+ $mediaId = false;
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+
+ $this->db->setAutocommit(true);
+ return $mediaId;
+ }
/**
* Copy a Questgroup picture.
- *
+ *
* @param int $userId ID of creating user
* @param int $seminaryMediaId ID of Seminary media to copy
*/
@@ -389,69 +389,69 @@
$userId
);
}
-
-
- /**
- * Create a new Quests media by creating a new Seminarymedia and
- * adding it to the list of Quests media.
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param string $filename Filename of uploading media
- * @param string $description Description for media
- * @param string $mimetype Mimetype of media
- * @param string $tmpFilename Name of temporary uploaded file
- * @return mixed ID of media record or false if upload failed
- */
- public function createQuestMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
- {
- $mediaId = false;
- $this->db->setAutocommit(false);
-
- try {
- // Create Seminary media record
- $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
-
- // Add media to Quests media
- $this->db->query(
- 'INSERT INTO questsmedia '.
- '(media_id, created_user_id) '.
- 'VALUES '.
- '(?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'created_user_id = ?',
- 'iii',
- $mediaId,
- $userId,
- $userId
- );
-
- // Create filename
- $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
- if(!move_uploaded_file($tmpFilename, $filename))
- {
- $this->db->rollback();
- $mediaId = false;
- }
- else {
- $this->db->commit();
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
-
- $this->db->setAutocommit(true);
- return $mediaId;
- }
+
+
+ /**
+ * Create a new Quests media by creating a new Seminarymedia and
+ * adding it to the list of Quests media.
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param string $filename Filename of uploading media
+ * @param string $description Description for media
+ * @param string $mimetype Mimetype of media
+ * @param string $tmpFilename Name of temporary uploaded file
+ * @return mixed ID of media record or false if upload failed
+ */
+ public function createQuestMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
+ {
+ $mediaId = false;
+ $this->db->setAutocommit(false);
+
+ try {
+ // Create Seminary media record
+ $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
+
+ // Add media to Quests media
+ $this->db->query(
+ 'INSERT INTO questsmedia '.
+ '(media_id, created_user_id) '.
+ 'VALUES '.
+ '(?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'created_user_id = ?',
+ 'iii',
+ $mediaId,
+ $userId,
+ $userId
+ );
+
+ // Create filename
+ $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
+ if(!move_uploaded_file($tmpFilename, $filename))
+ {
+ $this->db->rollback();
+ $mediaId = false;
+ }
+ else {
+ $this->db->commit();
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+
+ $this->db->setAutocommit(true);
+ return $mediaId;
+ }
/**
* Copy media of a Quest.
- *
+ *
* @param int $userId ID of creating user
* @param int $seminaryMediaId ID of Quest media to copy
*/
@@ -470,119 +470,119 @@
$userId
);
}
-
-
- /**
- * Create a new Character groups media by creating a new Seminarymedia and
- * adding it to the list of media for Character groups.
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param string $filename Filename of uploading media
- * @param string $description Description for media
- * @param string $mimetype Mimetype of media
- * @param string $tmpFilename Name of temporary uploaded file
- * @return mixed ID of media record or false if upload failed
- */
- public function createCharactergroupMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
- {
- $mediaId = false;
- $this->db->setAutocommit(false);
-
- try {
- // Create Seminary media record
- $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
-
- // Add media to Character groups media
- $this->db->query(
- 'INSERT INTO charactergroupsmedia '.
- '(seminarymedia_id, created_user_id) '.
- 'VALUES '.
- '(?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'created_user_id = ?',
- 'iii',
- $mediaId,
- $userId,
- $userId
- );
-
- // Create filename
- $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
- if(!move_uploaded_file($tmpFilename, $filename))
- {
- $this->db->rollback();
- $mediaId = false;
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
-
- $this->db->setAutocommit(true);
- return $mediaId;
- }
- /**
- * Create a new Achievement media by creating a new Seminarymedia and
- * adding it to the list of media for Achievements.
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param string $filename Filename of uploading media
- * @param string $description Description for media
- * @param string $mimetype Mimetype of media
- * @param string $tmpFilename Name of temporary uploaded file
- * @return mixed ID of media record or false if upload failed
- */
- public function createAchievementMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
- {
- $mediaId = false;
- $this->db->setAutocommit(false);
-
- try {
- // Create Seminary media record
- $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
-
- // Add media to Achievements media
- $this->db->query(
- 'INSERT INTO achievementsmedia '.
- '(seminarymedia_id, created_user_id) '.
- 'VALUES '.
- '(?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'created_user_id = ?',
- 'iii',
- $mediaId,
- $userId,
- $userId
- );
-
- // Create filename
- $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
- if(!move_uploaded_file($tmpFilename, $filename))
- {
- $this->db->rollback();
- $mediaId = false;
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
-
- $this->db->setAutocommit(true);
- return $mediaId;
- }
+ /**
+ * Create a new Character groups media by creating a new Seminarymedia and
+ * adding it to the list of media for Character groups.
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param string $filename Filename of uploading media
+ * @param string $description Description for media
+ * @param string $mimetype Mimetype of media
+ * @param string $tmpFilename Name of temporary uploaded file
+ * @return mixed ID of media record or false if upload failed
+ */
+ public function createCharactergroupMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
+ {
+ $mediaId = false;
+ $this->db->setAutocommit(false);
+
+ try {
+ // Create Seminary media record
+ $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
+
+ // Add media to Character groups media
+ $this->db->query(
+ 'INSERT INTO charactergroupsmedia '.
+ '(seminarymedia_id, created_user_id) '.
+ 'VALUES '.
+ '(?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'created_user_id = ?',
+ 'iii',
+ $mediaId,
+ $userId,
+ $userId
+ );
+
+ // Create filename
+ $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
+ if(!move_uploaded_file($tmpFilename, $filename))
+ {
+ $this->db->rollback();
+ $mediaId = false;
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+
+ $this->db->setAutocommit(true);
+ return $mediaId;
+ }
+
+
+ /**
+ * Create a new Achievement media by creating a new Seminarymedia and
+ * adding it to the list of media for Achievements.
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param string $filename Filename of uploading media
+ * @param string $description Description for media
+ * @param string $mimetype Mimetype of media
+ * @param string $tmpFilename Name of temporary uploaded file
+ * @return mixed ID of media record or false if upload failed
+ */
+ public function createAchievementMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
+ {
+ $mediaId = false;
+ $this->db->setAutocommit(false);
+
+ try {
+ // Create Seminary media record
+ $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
+
+ // Add media to Achievements media
+ $this->db->query(
+ 'INSERT INTO achievementsmedia '.
+ '(seminarymedia_id, created_user_id) '.
+ 'VALUES '.
+ '(?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'created_user_id = ?',
+ 'iii',
+ $mediaId,
+ $userId,
+ $userId
+ );
+
+ // Create filename
+ $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
+ if(!move_uploaded_file($tmpFilename, $filename))
+ {
+ $this->db->rollback();
+ $mediaId = false;
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+
+ $this->db->setAutocommit(true);
+ return $mediaId;
+ }
/**
* Copy Achievement media.
- *
+ *
* @param int $userId ID of creating user
* @param int $seminaryMediaId ID of Seminary media to copy
*/
@@ -605,10 +605,10 @@
/**
* Gather some information about a Seminary medium.
- *
+ *
* The infos are organized in an associative array and contain the
* following keys: width and height
- *
+ *
* @param int $seminarymediaId ID of Seminary media to get infos for
* @return array List of infos for Seminary medium
*/
@@ -627,54 +627,54 @@
// Return infos
return $infos;
}
-
-
-
-
- /**
- * Create a new Seminary media.
- *
- * @param int $userId ID of user that does the upload
- * @param int $seminaryId ID of Seminary
- * @param string $filename Filename of uploading media
- * @param string $description Description for media
- * @param string $mimetype Mimetype of media
- * @return mixed ID of media record or false if upload failed
- */
- private function createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype)
- {
- // Check for existing database record
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM seminarymedia '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
+
+
+
+
+ /**
+ * Create a new Seminary media.
+ *
+ * @param int $userId ID of user that does the upload
+ * @param int $seminaryId ID of Seminary
+ * @param string $filename Filename of uploading media
+ * @param string $description Description for media
+ * @param string $mimetype Mimetype of media
+ * @return mixed ID of media record or false if upload failed
+ */
+ private function createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype)
+ {
+ // Check for existing database record
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM seminarymedia '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
$seminaryId,
- \nre\core\Linker::createLinkParam($filename)
- );
- if(!empty($data)) {
- return $data[0]['id'];
- }
-
- // Create database record
- $this->db->query(
- 'INSERT INTO seminarymedia '.
- '(created_user_id, seminary_id, name, url, description, mimetype) '.
- 'VALUES '.
- '(?, ? ,? ,?, ?, ?)',
- 'iissss',
- $userId,
- $seminaryId,
- $filename,
- \nre\core\Linker::createLinkParam($filename),
- $description,
- $mimetype
- );
-
-
- return $this->db->getInsertId();
- }
-
- }
+ \nre\core\Linker::createLinkParam($filename)
+ );
+ if(!empty($data)) {
+ return $data[0]['id'];
+ }
+
+ // Create database record
+ $this->db->query(
+ 'INSERT INTO seminarymedia '.
+ '(created_user_id, seminary_id, name, url, description, mimetype) '.
+ 'VALUES '.
+ '(?, ? ,? ,?, ?, ?)',
+ 'iissss',
+ $userId,
+ $seminaryId,
+ $filename,
+ \nre\core\Linker::createLinkParam($filename),
+ $description,
+ $mimetype
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+ }
?>
diff --git a/models/QuestgroupsModel.inc b/models/QuestgroupsModel.inc
index 946cb4cd..f79e2031 100644
--- a/models/QuestgroupsModel.inc
+++ b/models/QuestgroupsModel.inc
@@ -1,529 +1,529 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Questgroups-table.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupsModel extends \hhu\z\Model
- {
- /**
- * Questgroup-status: Entered
- *
- * @var int;
- */
- const QUESTGROUP_STATUS_ENTERED = 0;
-
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('questgroupshierarchy', 'questgrouptexts', 'quests', 'questtexts', 'media');
-
-
-
-
- /**
- * Construct a new QuestgroupsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get all Questgroups for a Questgroup hierarchy.
- *
- * @param int $hierarchyId ID of the Questgroup hierarchy to get Questgroups for
- * @param int $parentQuestgroupId ID of the parent Questgroup hierarchy
- * @return array Questgroups for the given hierarchy
- */
- public function getQuestgroupsForHierarchy($hierarchyId, $parentQuestgroupId=null)
- {
- // Get Questgroups
- $questgroups = array();
- if(is_null($parentQuestgroupId))
- {
- $questgroups = $this->db->query(
- 'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id, questgroups.achievable_xps '.
- 'FROM questgroups_questgroupshierarchy '.
- 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
- 'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id IS NULL '.
- 'ORDER BY questgroups_questgroupshierarchy.pos ASC',
- 'i',
- $hierarchyId
- );
- }
- else
- {
- $questgroups = $this->db->query(
- 'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id, questgroups.achievable_xps '.
- 'FROM questgroups_questgroupshierarchy '.
- 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
- 'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id = ? '.
- 'ORDER BY questgroups_questgroupshierarchy.pos ASC',
- 'ii',
- $hierarchyId, $parentQuestgroupId
- );
- }
-
-
- // Return Questgroups
- return $questgroups;
- }
-
-
- /**
- * Get all Questgroups for a Seminary.
- *
- * @param int $seminaryId ID of Seminary
- * @return array List of Questgroups
- */
- public function getQuestgroupsForSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
- 'FROM questgroups '.
- 'WHERE seminary_id = ? '.
- 'ORDER BY title ASC',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get a Questgroup by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $questgroupId ID of a Questgroup
- * @return array Questgroup data
- */
- public function getQuestgroupById($questgroupId)
- {
- $data = $this->db->query(
- 'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
- 'FROM questgroups '.
- 'WHERE questgroups.id = ?',
- 'i',
- $questgroupId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questgroupId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Questgroup by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryId ID of the corresponding seminary
- * @param string $questgroupURL URL-title of a Questgroup
- * @return array Questgroup data
- */
- public function getQuestgroupByUrl($seminaryId, $questgroupUrl)
- {
- $data = $this->db->query(
- 'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
- 'FROM questgroups '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
- $seminaryId, $questgroupUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questgroupUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get the next Questgroup.
- *
- * Determine the next Questgroup. If there is no next Questgroup
- * on the same level as the given Quest then the followed-up
- * Questgroup from a higher hierarchy level is returned.
- *
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with Questgroups-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupsModel extends \hhu\z\Model
+ {
+ /**
+ * Questgroup-status: Entered
+ *
+ * @var int;
+ */
+ const QUESTGROUP_STATUS_ENTERED = 0;
+
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('questgroupshierarchy', 'questgrouptexts', 'quests', 'questtexts', 'media');
+
+
+
+
+ /**
+ * Construct a new QuestgroupsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get all Questgroups for a Questgroup hierarchy.
+ *
+ * @param int $hierarchyId ID of the Questgroup hierarchy to get Questgroups for
+ * @param int $parentQuestgroupId ID of the parent Questgroup hierarchy
+ * @return array Questgroups for the given hierarchy
+ */
+ public function getQuestgroupsForHierarchy($hierarchyId, $parentQuestgroupId=null)
+ {
+ // Get Questgroups
+ $questgroups = array();
+ if(is_null($parentQuestgroupId))
+ {
+ $questgroups = $this->db->query(
+ 'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id, questgroups.achievable_xps '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
+ 'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id IS NULL '.
+ 'ORDER BY questgroups_questgroupshierarchy.pos ASC',
+ 'i',
+ $hierarchyId
+ );
+ }
+ else
+ {
+ $questgroups = $this->db->query(
+ 'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id, questgroups.achievable_xps '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
+ 'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id = ? '.
+ 'ORDER BY questgroups_questgroupshierarchy.pos ASC',
+ 'ii',
+ $hierarchyId, $parentQuestgroupId
+ );
+ }
+
+
+ // Return Questgroups
+ return $questgroups;
+ }
+
+
+ /**
+ * Get all Questgroups for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @return array List of Questgroups
+ */
+ public function getQuestgroupsForSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
+ 'FROM questgroups '.
+ 'WHERE seminary_id = ? '.
+ 'ORDER BY title ASC',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get a Questgroup by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $questgroupId ID of a Questgroup
+ * @return array Questgroup data
+ */
+ public function getQuestgroupById($questgroupId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
+ 'FROM questgroups '.
+ 'WHERE questgroups.id = ?',
+ 'i',
+ $questgroupId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questgroupId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Questgroup by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryId ID of the corresponding seminary
+ * @param string $questgroupURL URL-title of a Questgroup
+ * @return array Questgroup data
+ */
+ public function getQuestgroupByUrl($seminaryId, $questgroupUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
+ 'FROM questgroups '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
+ $seminaryId, $questgroupUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questgroupUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get the next Questgroup.
+ *
+ * Determine the next Questgroup. If there is no next Questgroup
+ * on the same level as the given Quest then the followed-up
+ * Questgroup from a higher hierarchy level is returned.
+ *
* @param int $seminaryId ID of Seminary
- * @param int $questgroupId ID of Questgroup to get next Questgroup of
- * @return array Questgroup data
- */
- public function getNextQuestgroup($seminaryId, $questgroupId)
- {
- $currentQuestgroup = $this->getQuestgroupById($questgroupId);
- $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
- if(empty($currentQuestgroup['hierarchy'])) {
- return null;
- }
-
- $nextQuestgroup = $this->_getNextQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id'], $currentQuestgroup['hierarchy']['questgroup_pos']);
- if(is_null($nextQuestgroup) && !is_null($currentQuestgroup['hierarchy']['parent_questgroup_id'])) {
- $nextQuestgroup = $this->getNextQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id']);
- }
-
-
- return $nextQuestgroup;
- }
-
-
- /**
- * Get the previous Questgroup.
- *
- * Determine the previous Questgroup. If there is no previous
- * Questgroup on the same level as the given Quest then the
- * followed-up Questgroup from a higher hierarchy level is
- * returned.
- *
+ * @param int $questgroupId ID of Questgroup to get next Questgroup of
+ * @return array Questgroup data
+ */
+ public function getNextQuestgroup($seminaryId, $questgroupId)
+ {
+ $currentQuestgroup = $this->getQuestgroupById($questgroupId);
+ $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
+ if(empty($currentQuestgroup['hierarchy'])) {
+ return null;
+ }
+
+ $nextQuestgroup = $this->_getNextQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id'], $currentQuestgroup['hierarchy']['questgroup_pos']);
+ if(is_null($nextQuestgroup) && !is_null($currentQuestgroup['hierarchy']['parent_questgroup_id'])) {
+ $nextQuestgroup = $this->getNextQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id']);
+ }
+
+
+ return $nextQuestgroup;
+ }
+
+
+ /**
+ * Get the previous Questgroup.
+ *
+ * Determine the previous Questgroup. If there is no previous
+ * Questgroup on the same level as the given Quest then the
+ * followed-up Questgroup from a higher hierarchy level is
+ * returned.
+ *
* @param int $seminaryId ID of Seminary
- * @param int $questgroupId ID of Questgroup to get previous Questgroup of
- * @return array Questgroup data
- */
- public function getPreviousQuestgroup($seminaryId, $questgroupId)
- {
- $currentQuestgroup = $this->getQuestgroupById($questgroupId);
- $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
- if(empty($currentQuestgroup['hierarchy'])) {
- return null;
- }
-
- $previousQuestgroup = $this->_getPreviousQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id'], $currentQuestgroup['hierarchy']['questgroup_pos']);
- if(is_null($previousQuestgroup) && !is_null($currentQuestgroup['hierarchy']['parent_questgroup_id'])) {
- $previousQuestgroup = $this->getPreviousQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id']);
- }
-
-
- return $previousQuestgroup;
- }
-
-
- /**
- * Mark a Questgroup as entered for a Character.
- *
- * @param int $questId ID of Quest to mark as entered
- * @param int $characterId ID of Character that entered the Quest
- */
- public function setQuestgroupEntered($questgroupId, $characterId)
- {
- $this->setQuestgroupStatus($questgroupId, $characterId, self::QUESTGROUP_STATUS_ENTERED, false);
- }
-
-
- /**
- * Determine if the given Character has entered a Questgroup.
- *
- * @param int $questgroupId ID of Questgroup to check
- * @param int $characterId ID of Character to check
- * @result boolean Whether Character has entered the Questgroup or not
- */
- public function hasCharacterEnteredQuestgroup($questgroupId, $characterId)
- {
- $count = $this->db->query(
- 'SELECT count(id) AS c '.
- 'FROM questgroups_characters '.
- 'WHERE questgroup_id = ? AND character_id = ? AND status IN (?)',
- 'iii',
- $questgroupId,
- $characterId,
- self::QUESTGROUP_STATUS_ENTERED
- );
-
-
- return (!empty($count) && intval($count[0]['c']) > 0);
- }
-
-
- /**
- * Determine if the given Character has solved a Questgroup.
- *
- * @param int $questgroupId ID of Questgroup to check
- * @param int $characterId ID of Character to check
- * @result boolean Whether Character has solved the Questgroup or not
- */
- public function hasCharacterSolvedQuestgroup($questgroupId, $characterId)
- {
- // Get data of Questgroup
- $questgroup = $this->getQuestgroupById($questgroupId);
- $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
-
- // Check last Quest(s) of this Questgroup
- $solvedLastQuest = false;
- $lastQuests = $this->Quests->getLastQuestsOfQuestgroup($questgroup['id']);
- // Check last Quest(s) of last child Questgroup
- if(empty($lastQuests) && !empty($questgroup['hierarchy']))
- {
- $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['hierarchy']['id']);
- if(!empty($childQuestgroupshierarchy))
- {
- $childQuestgroupshierarchy = array_pop($childQuestgroupshierarchy);
- $childQuestgroups = $this->getQuestgroupsForHierarchy($childQuestgroupshierarchy['id'], $questgroupId);
- if(!empty($childQuestgroups))
- {
- $childQuestgroup = array_pop($childQuestgroups);
- $lastQuests = $this->Quests->getLastQuestsOfQuestgroup($childQuestgroup['id']);
- }
- }
- }
- foreach($lastQuests as &$lastQuest)
- {
- if($this->Quests->hasCharacterSolvedQuest($lastQuest['id'], $characterId))
- {
- $solvedLastQuest = true;
- break;
- }
- }
- if(!$solvedLastQuest) {
- return false;
- }
-
- // Check all child Questgroups
- if(!empty($questgroup['hierarchy']))
- {
- $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['hierarchy']['id']);
- foreach($childQuestgroupshierarchy as &$hierarchy)
- {
- // Get Questgroups
- $questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
- foreach($questgroups as &$group) {
- if(!$this->hasCharacterSolvedQuestgroup($group['id'], $characterId)) {
- return false;
- }
- }
- }
- }
-
-
- return true;
- }
-
-
- /**
- * Get all related Questgroups of a Questtext.
- *
- * @param int $questtextId ID of the Questtext
- * @return array Related Questgroups for the Questtext
- */
- public function getRelatedQuestsgroupsOfQuesttext($questtextId)
- {
- return $this->db->query(
- 'SELECT questgroups.id, questgroups_questtexts.questtext_id, questgroups.title, questgroups.url, questgroups_questtexts.entry_text '.
- 'FROM questgroups_questtexts '.
- 'INNER JOIN questgroups ON questgroups.id = questgroups_questtexts.questgroup_id '.
- 'WHERE questgroups_questtexts.questtext_id = ?',
- 'i',
- $questtextId
- );
- }
-
-
- /**
- * Get all related Questgroups of a Quest.
- *
- * @param int $questId ID of the Quest
- * @return array Related Quests for the Quest
- */
- public function getRelatedQuestsgroupsOfQuest($questId)
- {
- return $this->db->query(
- 'SELECT questgroups_questtexts.questgroup_id AS id '.
- 'FROM quests '.
- 'INNER JOIN questtexts ON questtexts.quest_id = quests.id '.
- 'INNER JOIN questgroups_questtexts ON questgroups_questtexts.questtext_id = questtexts.id '.
- 'WHERE quests.id = ?',
- 'i',
- $questId
- );
-
- }
-
-
- /**
- * Get all related Questgroups of a Questgroup.
- *
- * @param int $questgroupId ID of the Questgroup
- * @return array Related Questgroups for the Questgroup
- */
- public function getRelatedQuestsgroupsOfQuestgroup($questgroupId)
- {
- return $this->db->query(
- 'SELECT DISTINCT questgroups_questtexts.questgroup_id AS id '.
- 'FROM questgroups '.
- 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
- 'INNER JOIN questtexts ON questtexts.quest_id = quests.id '.
- 'INNER JOIN questgroups_questtexts ON questgroups_questtexts.questtext_id = questtexts.id '.
- 'WHERE questgroups.id = ?',
- 'i',
- $questgroupId
- );
- }
-
-
- /**
- * Summarize XPs of all Quests for a Questgroup and its
- * sub-Questgroups solved by a Character.
- *
- * @param int $questgroupId ID of Questgroup
- * @param int $characterId ID of Character
- * @return int Sum of XPs
- */
- public function getAchievedXPsForQuestgroup($questgroupId, $characterId)
- {
- // Questgroup
- $xps = $this->_getAchievedXPsForQuestgroup($questgroupId, $characterId);
-
- // Related Questgroups
- foreach($this->getRelatedQuestsgroupsOfQuestgroup($questgroupId) as $relatedQuestgroup) {
- $xps += $this->getAchievedXPsForQuestgroup($relatedQuestgroup['id'], $characterId);
- }
-
- // XPs of child Questgroups
- $questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
- if(!empty($questgroupHierarchy))
- {
- $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
- foreach($childQuestgroupshierarchy as &$hierarchy)
- {
- $childQuestgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
- foreach($childQuestgroups as &$childQuestgroup) {
- $xps += $this->getAchievedXPsForQuestgroup($childQuestgroup['id'], $characterId);
- }
- }
- }
-
-
- return $xps;
- }
-
-
- /**
- * Check if a Questgroups title already exists for a Seminary.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $title Questgroup title to check
- * @param int $questgroupId Do not check this ID (for editing)
- * @return boolean Whether Questgroup title exists or not
- */
- public function questgroupTitleExists($seminaryId, $title, $questgroupId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM questgroups '.
- 'WHERE seminary_id = ? AND (title = ? OR url = ?)',
- 'iss',
- $seminaryId,
- $title,
- \nre\core\Linker::createLinkParam($title)
- );
-
- return (!empty($data) && (is_null($questgroupId) || $questgroupId != $data[0]['id']));
- }
-
-
- /**
- * Create a new Questgroup.
- *
- * @param int $userId User-ID that creates the new character
- * @param int $seminaryId ID of Seminary
- * @param string $title Title for new Questgroup
- * @return int ID of new Questgroup
- */
- public function createQuestgroup($userId, $seminaryId, $title)
- {
- $this->db->query(
- 'INSERT INTO questgroups '.
- '(created_user_id, seminary_id, title, url) '.
- 'VALUES '.
- '(?, ?, ?, ?)',
- 'iiss',
- $userId,
- $seminaryId,
- $title,
- \nre\core\Linker::createLinkParam($title)
- );
-
-
- return $this->db->getInsertId();
- }
+ * @param int $questgroupId ID of Questgroup to get previous Questgroup of
+ * @return array Questgroup data
+ */
+ public function getPreviousQuestgroup($seminaryId, $questgroupId)
+ {
+ $currentQuestgroup = $this->getQuestgroupById($questgroupId);
+ $currentQuestgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($currentQuestgroup['id']);
+ if(empty($currentQuestgroup['hierarchy'])) {
+ return null;
+ }
+
+ $previousQuestgroup = $this->_getPreviousQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id'], $currentQuestgroup['hierarchy']['questgroup_pos']);
+ if(is_null($previousQuestgroup) && !is_null($currentQuestgroup['hierarchy']['parent_questgroup_id'])) {
+ $previousQuestgroup = $this->getPreviousQuestgroup($seminaryId, $currentQuestgroup['hierarchy']['parent_questgroup_id']);
+ }
- /**
- * Set the moodpic for a Questgroup.
- *
- * @param int $questgroupId ID of Questgroup to set moodpic for
- * @param int $mediaId ID of moodpic media
- */
- public function setMoodpicForQuestgroup($questgroupId, $mediaId)
- {
- $this->db->query(
- 'UPDATE questgroups '.
- 'SET questgroupspicture_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $mediaId,
- $questgroupId
- );
- }
+ return $previousQuestgroup;
+ }
- /**
- * Add a Questgroup to a Questgroupshierarchy.
- *
- * @param int $questgroupId Id of Questgroup to add
- * @param int $hierarchyId Id of Hierarchy to add Questgroup to
- * @param int $parentQuestgroupId Id of parent Questgroup
- */
- public function addQuestgroupToHierarchy($questgroupId, $hierarchyId, $parentQuestgroupId)
- {
- // Get last position
- $pos = $this->db->query(
- 'SELECT COALESCE(MAX(pos),0) AS pos '.
- 'FROM questgroups_questgroupshierarchy '.
- 'WHERE questgroupshierarchy_id = ? AND '.
- 'parent_questgroup_id '.(!is_null($parentQuestgroupId) ? sprintf('= %d', $parentQuestgroupId) : 'IS NULL'),
- 'i',
- $hierarchyId
- );
- $pos = intval($pos[0]['pos']);
-
- // Add Questgroup to Hierarchy
- $this->db->query(
- 'INSERT INTO questgroups_questgroupshierarchy '.
- '(questgroup_id, questgroupshierarchy_id, parent_questgroup_id, pos) '.
- 'VALUES '.
- '(?, ?, ?, ?)',
- 'iiii',
- $questgroupId,
- $hierarchyId,
- $parentQuestgroupId,
- $pos + 1
- );
- }
+ /**
+ * Mark a Questgroup as entered for a Character.
+ *
+ * @param int $questId ID of Quest to mark as entered
+ * @param int $characterId ID of Character that entered the Quest
+ */
+ public function setQuestgroupEntered($questgroupId, $characterId)
+ {
+ $this->setQuestgroupStatus($questgroupId, $characterId, self::QUESTGROUP_STATUS_ENTERED, false);
+ }
+
+
+ /**
+ * Determine if the given Character has entered a Questgroup.
+ *
+ * @param int $questgroupId ID of Questgroup to check
+ * @param int $characterId ID of Character to check
+ * @result boolean Whether Character has entered the Questgroup or not
+ */
+ public function hasCharacterEnteredQuestgroup($questgroupId, $characterId)
+ {
+ $count = $this->db->query(
+ 'SELECT count(id) AS c '.
+ 'FROM questgroups_characters '.
+ 'WHERE questgroup_id = ? AND character_id = ? AND status IN (?)',
+ 'iii',
+ $questgroupId,
+ $characterId,
+ self::QUESTGROUP_STATUS_ENTERED
+ );
+
+
+ return (!empty($count) && intval($count[0]['c']) > 0);
+ }
+
+
+ /**
+ * Determine if the given Character has solved a Questgroup.
+ *
+ * @param int $questgroupId ID of Questgroup to check
+ * @param int $characterId ID of Character to check
+ * @result boolean Whether Character has solved the Questgroup or not
+ */
+ public function hasCharacterSolvedQuestgroup($questgroupId, $characterId)
+ {
+ // Get data of Questgroup
+ $questgroup = $this->getQuestgroupById($questgroupId);
+ $questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
+
+ // Check last Quest(s) of this Questgroup
+ $solvedLastQuest = false;
+ $lastQuests = $this->Quests->getLastQuestsOfQuestgroup($questgroup['id']);
+ // Check last Quest(s) of last child Questgroup
+ if(empty($lastQuests) && !empty($questgroup['hierarchy']))
+ {
+ $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['hierarchy']['id']);
+ if(!empty($childQuestgroupshierarchy))
+ {
+ $childQuestgroupshierarchy = array_pop($childQuestgroupshierarchy);
+ $childQuestgroups = $this->getQuestgroupsForHierarchy($childQuestgroupshierarchy['id'], $questgroupId);
+ if(!empty($childQuestgroups))
+ {
+ $childQuestgroup = array_pop($childQuestgroups);
+ $lastQuests = $this->Quests->getLastQuestsOfQuestgroup($childQuestgroup['id']);
+ }
+ }
+ }
+ foreach($lastQuests as &$lastQuest)
+ {
+ if($this->Quests->hasCharacterSolvedQuest($lastQuest['id'], $characterId))
+ {
+ $solvedLastQuest = true;
+ break;
+ }
+ }
+ if(!$solvedLastQuest) {
+ return false;
+ }
+
+ // Check all child Questgroups
+ if(!empty($questgroup['hierarchy']))
+ {
+ $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['hierarchy']['id']);
+ foreach($childQuestgroupshierarchy as &$hierarchy)
+ {
+ // Get Questgroups
+ $questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
+ foreach($questgroups as &$group) {
+ if(!$this->hasCharacterSolvedQuestgroup($group['id'], $characterId)) {
+ return false;
+ }
+ }
+ }
+ }
+
+
+ return true;
+ }
+
+
+ /**
+ * Get all related Questgroups of a Questtext.
+ *
+ * @param int $questtextId ID of the Questtext
+ * @return array Related Questgroups for the Questtext
+ */
+ public function getRelatedQuestsgroupsOfQuesttext($questtextId)
+ {
+ return $this->db->query(
+ 'SELECT questgroups.id, questgroups_questtexts.questtext_id, questgroups.title, questgroups.url, questgroups_questtexts.entry_text '.
+ 'FROM questgroups_questtexts '.
+ 'INNER JOIN questgroups ON questgroups.id = questgroups_questtexts.questgroup_id '.
+ 'WHERE questgroups_questtexts.questtext_id = ?',
+ 'i',
+ $questtextId
+ );
+ }
+
+
+ /**
+ * Get all related Questgroups of a Quest.
+ *
+ * @param int $questId ID of the Quest
+ * @return array Related Quests for the Quest
+ */
+ public function getRelatedQuestsgroupsOfQuest($questId)
+ {
+ return $this->db->query(
+ 'SELECT questgroups_questtexts.questgroup_id AS id '.
+ 'FROM quests '.
+ 'INNER JOIN questtexts ON questtexts.quest_id = quests.id '.
+ 'INNER JOIN questgroups_questtexts ON questgroups_questtexts.questtext_id = questtexts.id '.
+ 'WHERE quests.id = ?',
+ 'i',
+ $questId
+ );
+
+ }
+
+
+ /**
+ * Get all related Questgroups of a Questgroup.
+ *
+ * @param int $questgroupId ID of the Questgroup
+ * @return array Related Questgroups for the Questgroup
+ */
+ public function getRelatedQuestsgroupsOfQuestgroup($questgroupId)
+ {
+ return $this->db->query(
+ 'SELECT DISTINCT questgroups_questtexts.questgroup_id AS id '.
+ 'FROM questgroups '.
+ 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
+ 'INNER JOIN questtexts ON questtexts.quest_id = quests.id '.
+ 'INNER JOIN questgroups_questtexts ON questgroups_questtexts.questtext_id = questtexts.id '.
+ 'WHERE questgroups.id = ?',
+ 'i',
+ $questgroupId
+ );
+ }
+
+
+ /**
+ * Summarize XPs of all Quests for a Questgroup and its
+ * sub-Questgroups solved by a Character.
+ *
+ * @param int $questgroupId ID of Questgroup
+ * @param int $characterId ID of Character
+ * @return int Sum of XPs
+ */
+ public function getAchievedXPsForQuestgroup($questgroupId, $characterId)
+ {
+ // Questgroup
+ $xps = $this->_getAchievedXPsForQuestgroup($questgroupId, $characterId);
+
+ // Related Questgroups
+ foreach($this->getRelatedQuestsgroupsOfQuestgroup($questgroupId) as $relatedQuestgroup) {
+ $xps += $this->getAchievedXPsForQuestgroup($relatedQuestgroup['id'], $characterId);
+ }
+
+ // XPs of child Questgroups
+ $questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
+ if(!empty($questgroupHierarchy))
+ {
+ $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
+ foreach($childQuestgroupshierarchy as &$hierarchy)
+ {
+ $childQuestgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
+ foreach($childQuestgroups as &$childQuestgroup) {
+ $xps += $this->getAchievedXPsForQuestgroup($childQuestgroup['id'], $characterId);
+ }
+ }
+ }
+
+
+ return $xps;
+ }
+
+
+ /**
+ * Check if a Questgroups title already exists for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $title Questgroup title to check
+ * @param int $questgroupId Do not check this ID (for editing)
+ * @return boolean Whether Questgroup title exists or not
+ */
+ public function questgroupTitleExists($seminaryId, $title, $questgroupId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM questgroups '.
+ 'WHERE seminary_id = ? AND (title = ? OR url = ?)',
+ 'iss',
+ $seminaryId,
+ $title,
+ \nre\core\Linker::createLinkParam($title)
+ );
+
+ return (!empty($data) && (is_null($questgroupId) || $questgroupId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Questgroup.
+ *
+ * @param int $userId User-ID that creates the new character
+ * @param int $seminaryId ID of Seminary
+ * @param string $title Title for new Questgroup
+ * @return int ID of new Questgroup
+ */
+ public function createQuestgroup($userId, $seminaryId, $title)
+ {
+ $this->db->query(
+ 'INSERT INTO questgroups '.
+ '(created_user_id, seminary_id, title, url) '.
+ 'VALUES '.
+ '(?, ?, ?, ?)',
+ 'iiss',
+ $userId,
+ $seminaryId,
+ $title,
+ \nre\core\Linker::createLinkParam($title)
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Set the moodpic for a Questgroup.
+ *
+ * @param int $questgroupId ID of Questgroup to set moodpic for
+ * @param int $mediaId ID of moodpic media
+ */
+ public function setMoodpicForQuestgroup($questgroupId, $mediaId)
+ {
+ $this->db->query(
+ 'UPDATE questgroups '.
+ 'SET questgroupspicture_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $mediaId,
+ $questgroupId
+ );
+ }
+
+
+ /**
+ * Add a Questgroup to a Questgroupshierarchy.
+ *
+ * @param int $questgroupId Id of Questgroup to add
+ * @param int $hierarchyId Id of Hierarchy to add Questgroup to
+ * @param int $parentQuestgroupId Id of parent Questgroup
+ */
+ public function addQuestgroupToHierarchy($questgroupId, $hierarchyId, $parentQuestgroupId)
+ {
+ // Get last position
+ $pos = $this->db->query(
+ 'SELECT COALESCE(MAX(pos),0) AS pos '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'WHERE questgroupshierarchy_id = ? AND '.
+ 'parent_questgroup_id '.(!is_null($parentQuestgroupId) ? sprintf('= %d', $parentQuestgroupId) : 'IS NULL'),
+ 'i',
+ $hierarchyId
+ );
+ $pos = intval($pos[0]['pos']);
+
+ // Add Questgroup to Hierarchy
+ $this->db->query(
+ 'INSERT INTO questgroups_questgroupshierarchy '.
+ '(questgroup_id, questgroupshierarchy_id, parent_questgroup_id, pos) '.
+ 'VALUES '.
+ '(?, ?, ?, ?)',
+ 'iiii',
+ $questgroupId,
+ $hierarchyId,
+ $parentQuestgroupId,
+ $pos + 1
+ );
+ }
/**
* Copy Questgroupshierarchy of Questgroups from a Seminary.
- *
+ *
* @param array $questgroupshierarchyIds Mapping of hierarchy-IDs from source Seminary to target Seminary
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
*/
@@ -568,7 +568,7 @@
/**
* Copy all related Questgroups of Questtexts of a Seminary.
- *
+ *
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
* @param array $questtextIds Mapping of Questtext-IDs from source Seminary to target Seminary
*/
@@ -594,104 +594,104 @@
}
- /**
- * Move a Questgroup up (decrement position) or down (increment
- * position).
- *
- * @param array $questgroup Questgroup to move
- * @param boolean $up True for moving up, false for down
- */
- public function moveQuestgroup($questgroup, $up)
- {
- $this->db->setAutocommit(false);
- try {
- // Set temporary position
- $this->db->query(
- 'UPDATE questgroups_questgroupshierarchy '.
- 'SET pos = 0 '.
- 'WHERE questgroup_id = ?',
- 'i',
- $questgroup['id']
- );
- // Switch entry
- if(is_null($questgroup['hierarchy']['parent_questgroup_id'])) {
- $this->db->query(
- 'UPDATE questgroups_questgroupshierarchy '.
- 'SET pos = ? '.
- 'WHERE questgroupshierarchy_id = ? AND parent_questgroup_id IS NULL AND pos = ?',
- 'iii',
- $questgroup['hierarchy']['questgroup_pos'],
- $questgroup['hierarchy']['id'],
- $questgroup['hierarchy']['questgroup_pos'] + ($up ? -1 : 1)
- );
- }
- else {
- $this->db->query(
- 'UPDATE questgroups_questgroupshierarchy '.
- 'SET pos = ? '.
- 'WHERE questgroupshierarchy_id = ? AND parent_questgroup_id = ? AND pos = ?',
- 'iiii',
- $questgroup['hierarchy']['questgroup_pos'],
- $questgroup['hierarchy']['id'],
- $questgroup['hierarchy']['parent_questgroup_id'],
- $questgroup['hierarchy']['questgroup_pos'] + ($up ? -1 : 1)
- );
- }
- // Set new position
- $this->db->query(
- 'UPDATE questgroups_questgroupshierarchy '.
- 'SET pos = ? '.
- 'WHERE questgroup_id = ?',
- 'ii',
- $questgroup['hierarchy']['questgroup_pos'] + ($up ? -1 : 1),
- $questgroup['id']
- );
-
- $this->db->commit();
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
- $this->db->setAutocommit(true);
- }
+ /**
+ * Move a Questgroup up (decrement position) or down (increment
+ * position).
+ *
+ * @param array $questgroup Questgroup to move
+ * @param boolean $up True for moving up, false for down
+ */
+ public function moveQuestgroup($questgroup, $up)
+ {
+ $this->db->setAutocommit(false);
+ try {
+ // Set temporary position
+ $this->db->query(
+ 'UPDATE questgroups_questgroupshierarchy '.
+ 'SET pos = 0 '.
+ 'WHERE questgroup_id = ?',
+ 'i',
+ $questgroup['id']
+ );
+ // Switch entry
+ if(is_null($questgroup['hierarchy']['parent_questgroup_id'])) {
+ $this->db->query(
+ 'UPDATE questgroups_questgroupshierarchy '.
+ 'SET pos = ? '.
+ 'WHERE questgroupshierarchy_id = ? AND parent_questgroup_id IS NULL AND pos = ?',
+ 'iii',
+ $questgroup['hierarchy']['questgroup_pos'],
+ $questgroup['hierarchy']['id'],
+ $questgroup['hierarchy']['questgroup_pos'] + ($up ? -1 : 1)
+ );
+ }
+ else {
+ $this->db->query(
+ 'UPDATE questgroups_questgroupshierarchy '.
+ 'SET pos = ? '.
+ 'WHERE questgroupshierarchy_id = ? AND parent_questgroup_id = ? AND pos = ?',
+ 'iiii',
+ $questgroup['hierarchy']['questgroup_pos'],
+ $questgroup['hierarchy']['id'],
+ $questgroup['hierarchy']['parent_questgroup_id'],
+ $questgroup['hierarchy']['questgroup_pos'] + ($up ? -1 : 1)
+ );
+ }
+ // Set new position
+ $this->db->query(
+ 'UPDATE questgroups_questgroupshierarchy '.
+ 'SET pos = ? '.
+ 'WHERE questgroup_id = ?',
+ 'ii',
+ $questgroup['hierarchy']['questgroup_pos'] + ($up ? -1 : 1),
+ $questgroup['id']
+ );
+
+ $this->db->commit();
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+ $this->db->setAutocommit(true);
+ }
- /**
- * Edit a Questgroup.
- *
- * @throws \nre\exceptions\DatamodelException
- * @param int $questgroupId ID of Questgroup to edit
- * @param string $title New title of Questgroup
- */
- public function editQuestgroup($questgroupId, $title)
- {
- $this->db->query(
- 'UPDATE questgroups '.
- 'SET title = ?, url = ? '.
- 'WHERE id = ?',
- 'ssi',
- $title,
- \nre\core\Linker::createLinkParam($title),
- $questgroupId
- );
- }
+ /**
+ * Edit a Questgroup.
+ *
+ * @throws \nre\exceptions\DatamodelException
+ * @param int $questgroupId ID of Questgroup to edit
+ * @param string $title New title of Questgroup
+ */
+ public function editQuestgroup($questgroupId, $title)
+ {
+ $this->db->query(
+ 'UPDATE questgroups '.
+ 'SET title = ?, url = ? '.
+ 'WHERE id = ?',
+ 'ssi',
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $questgroupId
+ );
+ }
- /**
- * Copy Questgroups of Seminary.
- *
- * @throws \nre\exceptions\DatamodelException
+ /**
+ * Copy Questgroups of Seminary.
+ *
+ * @throws \nre\exceptions\DatamodelException
* @param int $userId ID of creating user
- * @param int $sourceSeminaryId ID of Seminary to copy Questgroups from
+ * @param int $sourceSeminaryId ID of Seminary to copy Questgroups from
* @param int $targetSeminaryId ID of Seminary to copy Questgroups to
* @param array $questgroupshierarchyIds Mapping of hierarchy-IDs from source Seminary to target Seminary
* @param array $seminaryMediaIds Mapping of Seminary-media-IDs from source Seminary to target Seminary (optional)
* @return array Mapping of Questgroup-IDs from source Seminary to target Seminary
- */
- public function copyQuestgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $questgroupshierarchyIds, $seminaryMediaIds=null)
- {
+ */
+ public function copyQuestgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $questgroupshierarchyIds, $seminaryMediaIds=null)
+ {
// Get Questgroups of source Seminary
$questgroupIds = array();
$questgroups = $this->getQuestgroupsForSeminary($sourceSeminaryId);
@@ -731,272 +731,272 @@
return $questgroupIds;
- }
+ }
- /**
- * Delete a Questgroup.
- *
- * @param int $questgroupId ID of Questgroup to delete
- */
- public function deleteQuestgroup($questgroupId)
- {
- $this->db->query(
- 'DELETE FROM questgroups WHERE id = ?',
- 'i',
- $questgroupId
- );
- }
-
-
-
-
- /**
- * Get the next (direct) Questgroup.
- *
+ /**
+ * Delete a Questgroup.
+ *
+ * @param int $questgroupId ID of Questgroup to delete
+ */
+ public function deleteQuestgroup($questgroupId)
+ {
+ $this->db->query(
+ 'DELETE FROM questgroups WHERE id = ?',
+ 'i',
+ $questgroupId
+ );
+ }
+
+
+
+
+ /**
+ * Get the next (direct) Questgroup.
+ *
* @param int $seminaryId ID of Seminary
- * @param int $parentQuestgroupId ID of parent Questgroup to get next Questgroup of
- * @param int $questgroupPos Position of Questgroup to get next Questgroup of
- * @return array Data of next Questgroup or NULL
- */
- private function _getNextQuestgroup($seminaryId, $parentQuestgroupId, $questgroupPos)
- {
- if(!is_null($parentQuestgroupId))
- {
- $data = $this->db->query(
- 'SELECT * '.
- 'FROM questgroups_questgroupshierarchy '.
- 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
- 'WHERE seminary_id = ? AND parent_questgroup_id = ? AND pos = ? + 1',
- 'iii',
- $seminaryId, $parentQuestgroupId, $questgroupPos
- );
- }
- else
- {
- $data = $this->db->query(
- 'SELECT * '.
- 'FROM questgroups_questgroupshierarchy '.
- 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
- 'WHERE seminary_id = ? AND parent_questgroup_id IS NULL AND pos = ? + 1',
- 'ii',
- $seminaryId, $questgroupPos
- );
- }
- if(empty($data)) {
- return null;
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get the previous (direct) Questgroup.
- *
+ * @param int $parentQuestgroupId ID of parent Questgroup to get next Questgroup of
+ * @param int $questgroupPos Position of Questgroup to get next Questgroup of
+ * @return array Data of next Questgroup or NULL
+ */
+ private function _getNextQuestgroup($seminaryId, $parentQuestgroupId, $questgroupPos)
+ {
+ if(!is_null($parentQuestgroupId))
+ {
+ $data = $this->db->query(
+ 'SELECT * '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
+ 'WHERE seminary_id = ? AND parent_questgroup_id = ? AND pos = ? + 1',
+ 'iii',
+ $seminaryId, $parentQuestgroupId, $questgroupPos
+ );
+ }
+ else
+ {
+ $data = $this->db->query(
+ 'SELECT * '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
+ 'WHERE seminary_id = ? AND parent_questgroup_id IS NULL AND pos = ? + 1',
+ 'ii',
+ $seminaryId, $questgroupPos
+ );
+ }
+ if(empty($data)) {
+ return null;
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get the previous (direct) Questgroup.
+ *
* @param int $seminaryId ID of Seminary
- * @param int $parentQuestgroupId ID of parent Questgroup to get previous Questgroup of
- * @param int $questgroupPos Position of Questgroup to get previous Questgroup of
- * @return array Data of previous Questgroup or NULL
- */
- private function _getPreviousQuestgroup($seminaryId, $parentQuestgroupId, $questgroupPos)
- {
- if(!is_null($parentQuestgroupId))
- {
- $data = $this->db->query(
- 'SELECT * '.
- 'FROM questgroups_questgroupshierarchy '.
- 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
- 'WHERE seminary_id = ? AND parent_questgroup_id = ? AND pos = ? - 1',
- 'iii',
- $seminaryId, $parentQuestgroupId, $questgroupPos
- );
- }
- else
- {
- $data = $this->db->query(
- 'SELECT * '.
- 'FROM questgroups_questgroupshierarchy '.
- 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
- 'WHERE seminary_id = ? AND parent_questgroup_id IS NULL AND pos = ? - 1',
- 'ii',
- $seminaryId, $questgroupPos
- );
- }
- if(empty($data)) {
- return null;
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Mark a Questgroup for a Character.
- *
- * @param int $questgroupId ID of Questgroup to mark
- * @param int $characterId ID of Character to mark the Questgroup for
- * @param int $status Questgroup status to mark
- * @param boolean $repeated Insert although status is already set for this Questgroup and Character
- */
- private function setQuestgroupStatus($questgroupId, $characterId, $status, $repeated=true)
- {
- // Check if status is already set
- if(!$repeated)
- {
- $count = $this->db->query(
- 'SELECT count(*) AS c '.
- 'FROM questgroups_characters '.
- 'WHERE questgroup_id = ? AND character_id = ? AND status = ?',
- 'iii',
- $questgroupId,
- $characterId,
- $status
- );
- if(!empty($count) && intval($count[0]['c']) > 0) {
- return;
- }
- }
-
- // Set status
- $this->db->query(
- 'INSERT INTO questgroups_characters '.
- '(questgroup_id, character_id, status) '.
- 'VALUES '.
- '(?, ?, ?) ',
- 'iii',
- $questgroupId,
- $characterId,
- $status
- );
- }
-
-
- /**
- * Calculate the total amount of achievable XPs for a
- * Questgroup, its sub-Questgroups, related Questgroups etc. and
- * store this value in the database.
- *
- * @param int $questgroupId ID of Questgroup
- * @param array $calculatedQuests Already calculated Quests
- * @return int Sum of calculated XPs
- */
- public function calculateXPsForQuestgroup($questgroupId, &$calculatedQuests=array())
- {
- $xps = 0;
-
- // Quests
- $quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
- if(!is_null($quest)) {
- $xps = $this->_calculateXPsForQuestgroup($quest);
- }
-
- // Child Questgroups
- $questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
- if(!empty($questgroupHierarchy))
- {
- $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
- foreach($childQuestgroupshierarchy as &$hierarchy)
- {
- $questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
- foreach($questgroups as &$questgroup) {
- $xps += $this->calculateXPsForQuestgroup($questgroup['id'], $calculatedQuests);
- }
- }
- }
-
- // Save XPs
- $this->setXPsForQuestgroup($questgroupId, $xps);
-
-
- return $xps;
- }
-
-
-
-
- /**
- * Get the sum of XPs of Quests for a Questgroup solved by a
- * Character.
- *
- * @param int $questgroupId ID of Questgroup
- * @param int $characterId ID of Character
- * @return int Sum of XPs of Quests
- */
- private function _getAchievedXPsForQuestgroup($questgroupId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT COALESCE(SUM(quests.xps),0) AS xps '.
- 'FROM quests '.
- 'INNER JOIN quests_characters ON quests_characters.quest_id = quests.id AND quests_characters.character_id = ? AND quests_characters.status = ? '.
- 'WHERE quests.questgroup_id = ?',
- 'iii',
- $characterId,
- \hhu\z\models\QuestsModel::QUEST_STATUS_SOLVED,
- $questgroupId
- );
- if(!empty($data)) {
- return $data[0]['xps'];
- }
- }
-
-
- /**
- * Calculate the total amount of achievable XPs for a Quest and
- * its following Quests by choosing the path with the highest
- * amount of XPs.
- *
- * @param int $quest Quest data
- * @param array $calculatedQuests Already calculated Quests
- * @return int Sum of calculated XPs
- */
- private function _calculateXPsForQuestgroup($quest, &$calculatedQuests=array())
- {
- $xps = $quest['xps'];
-
- // Related Questgroups
- $relatedQuestgroups = $this->getRelatedQuestsgroupsOfQuest($quest['id']);
- foreach($relatedQuestgroups as &$relatedQuestgroup) {
- $xps += $this->calculateXPsForQuestgroup($relatedQuestgroup['id'], $calculatedQuests);
- }
-
- // Next Quests
- $nextQuests = $this->Quests->getNextQuests($quest['id']);
- $allNextXPs = array(0);
- foreach($nextQuests as &$nextQuest)
- {
- if(!array_key_exists($nextQuest['id'], $calculatedQuests)) {
- $calculatedQuests[$nextQuest['id']] = $this->_calculateXPsForQuestgroup($nextQuest, $calculatedQuests);
- }
- $allNextXPs[] = $calculatedQuests[$nextQuest['id']];
- }
- $xps += max($allNextXPs);
-
-
- return $xps;
- }
-
-
- /**
- * Set achievable XPs for a Questgroup.
- *
- * @param int $questgroupId ID of Questgroup
- * @param int $xps XPs to set
- */
- private function setXPsForQuestgroup($questgroupId, $xps)
- {
- $this->db->query(
- 'UPDATE questgroups '.
- 'SET achievable_xps = ? '.
- 'WHERE id = ?',
- 'ii',
- $xps,
- $questgroupId
- );
- }
-
- }
+ * @param int $parentQuestgroupId ID of parent Questgroup to get previous Questgroup of
+ * @param int $questgroupPos Position of Questgroup to get previous Questgroup of
+ * @return array Data of previous Questgroup or NULL
+ */
+ private function _getPreviousQuestgroup($seminaryId, $parentQuestgroupId, $questgroupPos)
+ {
+ if(!is_null($parentQuestgroupId))
+ {
+ $data = $this->db->query(
+ 'SELECT * '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
+ 'WHERE seminary_id = ? AND parent_questgroup_id = ? AND pos = ? - 1',
+ 'iii',
+ $seminaryId, $parentQuestgroupId, $questgroupPos
+ );
+ }
+ else
+ {
+ $data = $this->db->query(
+ 'SELECT * '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
+ 'WHERE seminary_id = ? AND parent_questgroup_id IS NULL AND pos = ? - 1',
+ 'ii',
+ $seminaryId, $questgroupPos
+ );
+ }
+ if(empty($data)) {
+ return null;
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Mark a Questgroup for a Character.
+ *
+ * @param int $questgroupId ID of Questgroup to mark
+ * @param int $characterId ID of Character to mark the Questgroup for
+ * @param int $status Questgroup status to mark
+ * @param boolean $repeated Insert although status is already set for this Questgroup and Character
+ */
+ private function setQuestgroupStatus($questgroupId, $characterId, $status, $repeated=true)
+ {
+ // Check if status is already set
+ if(!$repeated)
+ {
+ $count = $this->db->query(
+ 'SELECT count(*) AS c '.
+ 'FROM questgroups_characters '.
+ 'WHERE questgroup_id = ? AND character_id = ? AND status = ?',
+ 'iii',
+ $questgroupId,
+ $characterId,
+ $status
+ );
+ if(!empty($count) && intval($count[0]['c']) > 0) {
+ return;
+ }
+ }
+
+ // Set status
+ $this->db->query(
+ 'INSERT INTO questgroups_characters '.
+ '(questgroup_id, character_id, status) '.
+ 'VALUES '.
+ '(?, ?, ?) ',
+ 'iii',
+ $questgroupId,
+ $characterId,
+ $status
+ );
+ }
+
+
+ /**
+ * Calculate the total amount of achievable XPs for a
+ * Questgroup, its sub-Questgroups, related Questgroups etc. and
+ * store this value in the database.
+ *
+ * @param int $questgroupId ID of Questgroup
+ * @param array $calculatedQuests Already calculated Quests
+ * @return int Sum of calculated XPs
+ */
+ public function calculateXPsForQuestgroup($questgroupId, &$calculatedQuests=array())
+ {
+ $xps = 0;
+
+ // Quests
+ $quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
+ if(!is_null($quest)) {
+ $xps = $this->_calculateXPsForQuestgroup($quest);
+ }
+
+ // Child Questgroups
+ $questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
+ if(!empty($questgroupHierarchy))
+ {
+ $childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
+ foreach($childQuestgroupshierarchy as &$hierarchy)
+ {
+ $questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
+ foreach($questgroups as &$questgroup) {
+ $xps += $this->calculateXPsForQuestgroup($questgroup['id'], $calculatedQuests);
+ }
+ }
+ }
+
+ // Save XPs
+ $this->setXPsForQuestgroup($questgroupId, $xps);
+
+
+ return $xps;
+ }
+
+
+
+
+ /**
+ * Get the sum of XPs of Quests for a Questgroup solved by a
+ * Character.
+ *
+ * @param int $questgroupId ID of Questgroup
+ * @param int $characterId ID of Character
+ * @return int Sum of XPs of Quests
+ */
+ private function _getAchievedXPsForQuestgroup($questgroupId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT COALESCE(SUM(quests.xps),0) AS xps '.
+ 'FROM quests '.
+ 'INNER JOIN quests_characters ON quests_characters.quest_id = quests.id AND quests_characters.character_id = ? AND quests_characters.status = ? '.
+ 'WHERE quests.questgroup_id = ?',
+ 'iii',
+ $characterId,
+ \hhu\z\models\QuestsModel::QUEST_STATUS_SOLVED,
+ $questgroupId
+ );
+ if(!empty($data)) {
+ return $data[0]['xps'];
+ }
+ }
+
+
+ /**
+ * Calculate the total amount of achievable XPs for a Quest and
+ * its following Quests by choosing the path with the highest
+ * amount of XPs.
+ *
+ * @param int $quest Quest data
+ * @param array $calculatedQuests Already calculated Quests
+ * @return int Sum of calculated XPs
+ */
+ private function _calculateXPsForQuestgroup($quest, &$calculatedQuests=array())
+ {
+ $xps = $quest['xps'];
+
+ // Related Questgroups
+ $relatedQuestgroups = $this->getRelatedQuestsgroupsOfQuest($quest['id']);
+ foreach($relatedQuestgroups as &$relatedQuestgroup) {
+ $xps += $this->calculateXPsForQuestgroup($relatedQuestgroup['id'], $calculatedQuests);
+ }
+
+ // Next Quests
+ $nextQuests = $this->Quests->getNextQuests($quest['id']);
+ $allNextXPs = array(0);
+ foreach($nextQuests as &$nextQuest)
+ {
+ if(!array_key_exists($nextQuest['id'], $calculatedQuests)) {
+ $calculatedQuests[$nextQuest['id']] = $this->_calculateXPsForQuestgroup($nextQuest, $calculatedQuests);
+ }
+ $allNextXPs[] = $calculatedQuests[$nextQuest['id']];
+ }
+ $xps += max($allNextXPs);
+
+
+ return $xps;
+ }
+
+
+ /**
+ * Set achievable XPs for a Questgroup.
+ *
+ * @param int $questgroupId ID of Questgroup
+ * @param int $xps XPs to set
+ */
+ private function setXPsForQuestgroup($questgroupId, $xps)
+ {
+ $this->db->query(
+ 'UPDATE questgroups '.
+ 'SET achievable_xps = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $xps,
+ $questgroupId
+ );
+ }
+
+ }
?>
diff --git a/models/QuestgroupshierarchyModel.inc b/models/QuestgroupshierarchyModel.inc
index 072de8fc..16a8d326 100644
--- a/models/QuestgroupshierarchyModel.inc
+++ b/models/QuestgroupshierarchyModel.inc
@@ -1,325 +1,325 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Questgroupshierarchy-table.
- *
- * @author Oliver Hanraths
- */
- class QuestgroupshierarchyModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new QuestgroupshierarchyModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get a Questgroup hierarchy by its ID.
- *
- * throws \nre\exceptions\IdNotFoundException
- * @param int $questgroupshierarchyId ID of a Questgroup hierarchy
- * @return array Questgroup hierarchy
- */
- public function getHierarchyById($questgroupshierarchyId)
- {
- $data = $this->db->query(
- 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
- 'FROM questgroupshierarchy '.
- 'WHERE questgroupshierarchy.id = ?',
- 'i',
- $questgroupshierarchyId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Questgroup hierarchy by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryId ID of Seminary
- * @param int $questgroupshierarchyURL URL of a Questgroup hierarchy
- * @return array Questgroup hierarchy
- */
- public function getHierarchyByUrl($seminaryId, $questgroupshierarchyUrl)
- {
- $data = $this->db->query(
- 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
- 'FROM questgroupshierarchy '.
- 'WHERE questgroupshierarchy.seminary_id = ? AND questgroupshierarchy.url = ?',
- 'is',
- $seminaryId,
- $questgroupshierarchyUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get the toplevel hierarchy entries of a Seminary.
- *
- * @param int $seminaryId ID of the seminary to get hierarchy for
- * @return array Toplevel hierarchy
- */
- public function getHierarchyOfSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
- 'FROM questgroupshierarchy '.
- 'WHERE '.
- 'questgroupshierarchy.seminary_id = ? AND '.
- 'questgroupshierarchy.parent_questgroupshierarchy_id IS NULL '.
- 'ORDER BY questgroupshierarchy.pos ASC',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get the Questgroup-Hierarchy for a Questgroup.
- *
- * @param int $questgroupId ID of Questgroup
- * @return array Hierarchy for Questgroup
- */
- public function getHierarchyForQuestgroup($questgroupId)
- {
- $data = $this->db->query(
- 'SELECT questgroups_questgroupshierarchy.parent_questgroup_id, questgroups_questgroupshierarchy.pos AS questgroup_pos, questgroupshierarchy.id, questgroupshierarchy.seminary_id, questgroupshierarchy.parent_questgroupshierarchy_id, questgroupshierarchy.pos, questgroupshierarchy.title_singular, questgroupshierarchy.title_plural, questgroupshierarchy.url '.
- 'FROM questgroups_questgroupshierarchy '.
- 'INNER JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups_questgroupshierarchy.questgroupshierarchy_id '.
- 'WHERE questgroups_questgroupshierarchy.questgroup_id = ?',
- 'i',
- $questgroupId
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return null;
- }
-
-
- /**
- * Get the child hierarchy entries of a Questgroup hierarchy.
- *
- * @param int $questgroupshierarchyId ID of a Questgroup hierarchy
- * @return array Child Questgroup hierarchy entries
- */
- public function getChildQuestgroupshierarchy($questgroupshierarchyId)
- {
- return $this->db->query(
- 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
- 'FROM questgroupshierarchy '.
- 'WHERE questgroupshierarchy.parent_questgroupshierarchy_id = ? '.
- 'ORDER BY questgroupshierarchy.pos ASC',
- 'i',
- $questgroupshierarchyId
- );
- }
-
-
- /**
- * Check if a title for a Questgroupshierarchy already exists
- * for a Seminary.
- *
- * @param string $title
- * @param int $seminaryId
- * @param int $questgroupshierarchyId Do not check this Questgroupshierarchy (for editing)
- * @return Whether title already exists or not
- */
- public function questgroupshierarchyTitleSingularExists($title, $seminaryId, $questgroupshierarchyId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM questgroupshierarchy '.
- 'WHERE seminary_id = ? AND (title_singular = ? OR url = ?) ',
- 'iss',
- $seminaryId,
- $title,
- \nre\core\Linker::createLinkParam($title)
- );
-
-
- return (!empty($data) && (is_null($questgroupshierarchyId) || $questgroupshierarchyId != $data[0]['id']));
- }
-
-
- /**
- * Create a new Questgroupshierarchy for a Seminary
- *
- * @param int $userId ID of creating user
- * @param int $seminaryId ID of Seminary
- * @param int $parentQuestgroupsierarchyId ID of parent Questgroupshierarchy
- * @param string $title Title (singular)
- * @param string $course Title (plural)
- */
- public function createQuestgroupshierarchy($userId, $seminaryId, $parentQuestgroupsierarchyId, $titleSingular, $titlePlural)
- {
- // Get last position
- $pos = $this->db->query(
- 'SELECT COALESCE(MAX(pos),0) AS pos '.
- 'FROM questgroupshierarchy '.
- 'WHERE seminary_id = ? AND '.
- 'parent_questgroupshierarchy_id '.(!is_null($parentQuestgroupsierarchyId) ? sprintf('= %d', $parentQuestgroupsierarchyId) : 'IS NULL'),
- 'i',
- $seminaryId
- );
- $pos = intval($pos[0]['pos']);
-
- // Create Questgroupshierarchy
- $this->db->query(
- 'INSERT INTO questgroupshierarchy '.
- '(created_user_id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?, ?, ?)',
- 'iiiisss',
- $userId,
- $seminaryId,
- $parentQuestgroupsierarchyId,
- $pos + 1,
- $titleSingular,
- $titlePlural,
- \nre\core\Linker::createLinkParam($titleSingular)
- );
-
-
- return $this->db->getInsertId();
- }
-
-
- /**
- * Edit a Questgroupshierarchy.
- *
- * @param int $questgroupshierarchyId ID of Questgroupshierarchy to edit
- * @param string $title New title (singular)
- * @param string $course New title (plural)
- */
- public function editQuestgroupshierarchy($questgroupshierarchyId, $titleSingular, $titlePlural)
- {
- $this->db->query(
- 'UPDATE questgroupshierarchy '.
- 'SET title_singular = ?, title_plural = ?, url = ? '.
- 'WHERE id = ?',
- 'sssi',
- $titleSingular,
- $titlePlural,
- \nre\core\Linker::createLinkParam($titleSingular),
- $questgroupshierarchyId
- );
- }
-
-
- /**
- * Move a Questgroupshierarchy up (decrement position) or down
- * (increment position).
- *
- * @param array $questgroupshierarchy Questgroupshierarchy to move
- * @param boolean $up True for moving up, false for down
- */
- public function moveQuestgroupshierarchy($questgroupshierarchy, $up)
- {
- $this->db->setAutocommit(false);
- try {
- // Set temporary position
- $this->db->query(
- 'UPDATE questgroupshierarchy '.
- 'SET pos = 0 '.
- 'WHERE id = ?',
- 'i',
- $questgroupshierarchy['id']
- );
- // Switch entry
- if(is_null($questgroupshierarchy['parent_questgroupshierarchy_id'])) {
- $this->db->query(
- 'UPDATE questgroupshierarchy '.
- 'SET pos = ? '.
- 'WHERE parent_questgroupshierarchy_id IS NULL AND pos = ?',
- 'ii',
- $questgroupshierarchy['pos'],
- $questgroupshierarchy['pos'] + ($up ? -1 : 1)
- );
- }
- else {
- $this->db->query(
- 'UPDATE questgroupshierarchy '.
- 'SET pos = ? '.
- 'WHERE parent_questgroupshierarchy_id = ? AND pos = ?',
- 'iii',
- $questgroupshierarchy['pos'],
- $questgroupshierarchy['parent_questgroupshierarchy_id'],
- $questgroupshierarchy['pos'] + ($up ? -1 : 1)
- );
- }
- // Set new position
- $this->db->query(
- 'UPDATE questgroupshierarchy '.
- 'SET pos = ? '.
- 'WHERE id = ?',
- 'ii',
- $questgroupshierarchy['pos'] + ($up ? -1 : 1),
- $questgroupshierarchy['id']
- );
-
- $this->db->commit();
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
- $this->db->setAutocommit(true);
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with Questgroupshierarchy-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgroupshierarchyModel extends \hhu\z\Model
+ {
+
+
/**
- * Copy complete Questgroupshierarchy of a Seminary.
- *
- * @param int $userId ID of creating user
- * @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
- * @param int $targetSeminaryId ID of Seminary to copy hierarchy to
+ * Construct a new QuestgroupshierarchyModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get a Questgroup hierarchy by its ID.
+ *
+ * throws \nre\exceptions\IdNotFoundException
+ * @param int $questgroupshierarchyId ID of a Questgroup hierarchy
+ * @return array Questgroup hierarchy
+ */
+ public function getHierarchyById($questgroupshierarchyId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
+ 'FROM questgroupshierarchy '.
+ 'WHERE questgroupshierarchy.id = ?',
+ 'i',
+ $questgroupshierarchyId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Questgroup hierarchy by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryId ID of Seminary
+ * @param int $questgroupshierarchyURL URL of a Questgroup hierarchy
+ * @return array Questgroup hierarchy
+ */
+ public function getHierarchyByUrl($seminaryId, $questgroupshierarchyUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
+ 'FROM questgroupshierarchy '.
+ 'WHERE questgroupshierarchy.seminary_id = ? AND questgroupshierarchy.url = ?',
+ 'is',
+ $seminaryId,
+ $questgroupshierarchyUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get the toplevel hierarchy entries of a Seminary.
+ *
+ * @param int $seminaryId ID of the seminary to get hierarchy for
+ * @return array Toplevel hierarchy
+ */
+ public function getHierarchyOfSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
+ 'FROM questgroupshierarchy '.
+ 'WHERE '.
+ 'questgroupshierarchy.seminary_id = ? AND '.
+ 'questgroupshierarchy.parent_questgroupshierarchy_id IS NULL '.
+ 'ORDER BY questgroupshierarchy.pos ASC',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get the Questgroup-Hierarchy for a Questgroup.
+ *
+ * @param int $questgroupId ID of Questgroup
+ * @return array Hierarchy for Questgroup
+ */
+ public function getHierarchyForQuestgroup($questgroupId)
+ {
+ $data = $this->db->query(
+ 'SELECT questgroups_questgroupshierarchy.parent_questgroup_id, questgroups_questgroupshierarchy.pos AS questgroup_pos, questgroupshierarchy.id, questgroupshierarchy.seminary_id, questgroupshierarchy.parent_questgroupshierarchy_id, questgroupshierarchy.pos, questgroupshierarchy.title_singular, questgroupshierarchy.title_plural, questgroupshierarchy.url '.
+ 'FROM questgroups_questgroupshierarchy '.
+ 'INNER JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups_questgroupshierarchy.questgroupshierarchy_id '.
+ 'WHERE questgroups_questgroupshierarchy.questgroup_id = ?',
+ 'i',
+ $questgroupId
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Get the child hierarchy entries of a Questgroup hierarchy.
+ *
+ * @param int $questgroupshierarchyId ID of a Questgroup hierarchy
+ * @return array Child Questgroup hierarchy entries
+ */
+ public function getChildQuestgroupshierarchy($questgroupshierarchyId)
+ {
+ return $this->db->query(
+ 'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
+ 'FROM questgroupshierarchy '.
+ 'WHERE questgroupshierarchy.parent_questgroupshierarchy_id = ? '.
+ 'ORDER BY questgroupshierarchy.pos ASC',
+ 'i',
+ $questgroupshierarchyId
+ );
+ }
+
+
+ /**
+ * Check if a title for a Questgroupshierarchy already exists
+ * for a Seminary.
+ *
+ * @param string $title
+ * @param int $seminaryId
+ * @param int $questgroupshierarchyId Do not check this Questgroupshierarchy (for editing)
+ * @return Whether title already exists or not
+ */
+ public function questgroupshierarchyTitleSingularExists($title, $seminaryId, $questgroupshierarchyId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM questgroupshierarchy '.
+ 'WHERE seminary_id = ? AND (title_singular = ? OR url = ?) ',
+ 'iss',
+ $seminaryId,
+ $title,
+ \nre\core\Linker::createLinkParam($title)
+ );
+
+
+ return (!empty($data) && (is_null($questgroupshierarchyId) || $questgroupshierarchyId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Questgroupshierarchy for a Seminary
+ *
+ * @param int $userId ID of creating user
+ * @param int $seminaryId ID of Seminary
+ * @param int $parentQuestgroupsierarchyId ID of parent Questgroupshierarchy
+ * @param string $title Title (singular)
+ * @param string $course Title (plural)
+ */
+ public function createQuestgroupshierarchy($userId, $seminaryId, $parentQuestgroupsierarchyId, $titleSingular, $titlePlural)
+ {
+ // Get last position
+ $pos = $this->db->query(
+ 'SELECT COALESCE(MAX(pos),0) AS pos '.
+ 'FROM questgroupshierarchy '.
+ 'WHERE seminary_id = ? AND '.
+ 'parent_questgroupshierarchy_id '.(!is_null($parentQuestgroupsierarchyId) ? sprintf('= %d', $parentQuestgroupsierarchyId) : 'IS NULL'),
+ 'i',
+ $seminaryId
+ );
+ $pos = intval($pos[0]['pos']);
+
+ // Create Questgroupshierarchy
+ $this->db->query(
+ 'INSERT INTO questgroupshierarchy '.
+ '(created_user_id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?, ?, ?)',
+ 'iiiisss',
+ $userId,
+ $seminaryId,
+ $parentQuestgroupsierarchyId,
+ $pos + 1,
+ $titleSingular,
+ $titlePlural,
+ \nre\core\Linker::createLinkParam($titleSingular)
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Edit a Questgroupshierarchy.
+ *
+ * @param int $questgroupshierarchyId ID of Questgroupshierarchy to edit
+ * @param string $title New title (singular)
+ * @param string $course New title (plural)
+ */
+ public function editQuestgroupshierarchy($questgroupshierarchyId, $titleSingular, $titlePlural)
+ {
+ $this->db->query(
+ 'UPDATE questgroupshierarchy '.
+ 'SET title_singular = ?, title_plural = ?, url = ? '.
+ 'WHERE id = ?',
+ 'sssi',
+ $titleSingular,
+ $titlePlural,
+ \nre\core\Linker::createLinkParam($titleSingular),
+ $questgroupshierarchyId
+ );
+ }
+
+
+ /**
+ * Move a Questgroupshierarchy up (decrement position) or down
+ * (increment position).
+ *
+ * @param array $questgroupshierarchy Questgroupshierarchy to move
+ * @param boolean $up True for moving up, false for down
+ */
+ public function moveQuestgroupshierarchy($questgroupshierarchy, $up)
+ {
+ $this->db->setAutocommit(false);
+ try {
+ // Set temporary position
+ $this->db->query(
+ 'UPDATE questgroupshierarchy '.
+ 'SET pos = 0 '.
+ 'WHERE id = ?',
+ 'i',
+ $questgroupshierarchy['id']
+ );
+ // Switch entry
+ if(is_null($questgroupshierarchy['parent_questgroupshierarchy_id'])) {
+ $this->db->query(
+ 'UPDATE questgroupshierarchy '.
+ 'SET pos = ? '.
+ 'WHERE parent_questgroupshierarchy_id IS NULL AND pos = ?',
+ 'ii',
+ $questgroupshierarchy['pos'],
+ $questgroupshierarchy['pos'] + ($up ? -1 : 1)
+ );
+ }
+ else {
+ $this->db->query(
+ 'UPDATE questgroupshierarchy '.
+ 'SET pos = ? '.
+ 'WHERE parent_questgroupshierarchy_id = ? AND pos = ?',
+ 'iii',
+ $questgroupshierarchy['pos'],
+ $questgroupshierarchy['parent_questgroupshierarchy_id'],
+ $questgroupshierarchy['pos'] + ($up ? -1 : 1)
+ );
+ }
+ // Set new position
+ $this->db->query(
+ 'UPDATE questgroupshierarchy '.
+ 'SET pos = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $questgroupshierarchy['pos'] + ($up ? -1 : 1),
+ $questgroupshierarchy['id']
+ );
+
+ $this->db->commit();
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+ $this->db->setAutocommit(true);
+ }
+
+
+ /**
+ * Copy complete Questgroupshierarchy of a Seminary.
+ *
+ * @param int $userId ID of creating user
+ * @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
+ * @param int $targetSeminaryId ID of Seminary to copy hierarchy to
* @return array Mapping of hierarchy-IDs from source Seminary to target Seminary
*/
public function copyQuestgroupshierarchy($userId, $sourceSeminaryId, $targetSeminaryId)
{
// Get Hierarchy of Seminary
- $questgroupshierarchy = $this->getHierarchyOfSeminary($sourceSeminaryId);
+ $questgroupshierarchy = $this->getHierarchyOfSeminary($sourceSeminaryId);
// Copy hierarchy
$hierarchyIds = array();
- foreach($questgroupshierarchy as $hierarchy) {
+ foreach($questgroupshierarchy as $hierarchy) {
$this->copyHierarchy($userId, $sourceSeminaryId, $targetSeminaryId, $hierarchy, $hierarchyIds);
}
@@ -327,26 +327,26 @@
return $hierarchyIds;
}
-
- /**
- * Delete a Questgroupshierarchy.
- *
- * @param int $seminaryId ID of the seminary to delete
- */
- public function deleteQuestgroupshierarchy($questgroupshierarchyId)
- {
- $this->db->query('DELETE FROM questgroupshierarchy WHERE id = ?', 'i', $questgroupshierarchyId);
- }
+
+ /**
+ * Delete a Questgroupshierarchy.
+ *
+ * @param int $seminaryId ID of the seminary to delete
+ */
+ public function deleteQuestgroupshierarchy($questgroupshierarchyId)
+ {
+ $this->db->query('DELETE FROM questgroupshierarchy WHERE id = ?', 'i', $questgroupshierarchyId);
+ }
/**
- * Copy a Questgroupshierarchy and its child hierarchy.
- *
- * @param int $userId ID of creating user
- * @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
- * @param int $targetSeminaryId ID of Seminary to copy hierarchy to
+ * Copy a Questgroupshierarchy and its child hierarchy.
+ *
+ * @param int $userId ID of creating user
+ * @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
+ * @param int $targetSeminaryId ID of Seminary to copy hierarchy to
* @param array $hierarchy Hierarchy to copy
* @return array $hierarchyIds Mapping of hierarchy IDs from source Seminary to target Seminary
*/
@@ -379,7 +379,7 @@
$hierarchy['id']
);
}
- $hierarchyIds[$hierarchy['id']] = $this->db->getInsertId();
+ $hierarchyIds[$hierarchy['id']] = $this->db->getInsertId();
// insert sub hierarchy
$childHierarchy = $this->getChildQuestgroupshierarchy($hierarchy['id']);
@@ -387,7 +387,7 @@
$this->copyHierarchy($userId, $sourceSeminaryId, $targetSeminaryId, $hierarchy, $hierarchyIds);
}
}
-
- }
+
+ }
?>
diff --git a/models/QuestgrouptextsModel.inc b/models/QuestgrouptextsModel.inc
index 6d678d92..0ebb76b1 100644
--- a/models/QuestgrouptextsModel.inc
+++ b/models/QuestgrouptextsModel.inc
@@ -1,111 +1,111 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Questgrouptexts-table.
- *
- * @author Oliver Hanraths
- */
- class QuestgrouptextsModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new QuestgrouptextsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with Questgrouptexts-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestgrouptextsModel extends \hhu\z\Model
+ {
- /**
- * Get texts of a Questgroup.
- *
- * @param int $questgroupId ID of a Questgroup
- * @return array Texts of this Questgroup
- */
- public function getQuestgroupTexts($questgroupId)
- {
- return $this->db->query(
- 'SELECT id, pos, text, questgroup_id '.
- 'FROM questgrouptexts '.
- 'WHERE questgroup_id = ? '.
- 'ORDER BY pos ASC',
- 'i',
- $questgroupId
- );
- }
+ /**
+ * Construct a new QuestgrouptextsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
- /**
- * Add a Questgroup text to a Questgroup.
- *
- * @param int $userId ID of user
- * @param int $questgroupId ID of Questgroup to add text to
- * @param string $text Text to add
- */
- public function addQuestgrouptextToQuestgroup($userId, $questgroupId, $text)
- {
- // Get position
- $pos = $this->db->query(
- 'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
- 'FROM questgrouptexts '.
- 'WHERE questgroup_id = ?',
- 'i',
- $questgroupId
- );
- $pos = $pos[0]['pos'];
-
- // Add Questgroup text
- $this->db->query(
- 'INSERT INTO questgrouptexts '.
- '(created_user_id, questgroup_id, pos, text) '.
- 'VALUES '.
- '(?, ?, ?, ?)',
- 'iiis',
- $userId, $questgroupId, $pos, $text
- );
- }
- /**
- * Edit a Questgroup text.
- *
- * @param int $questgrouptextId ID of Questgroup text to edit
- * @param string $text New text
- */
- public function editQuestgrouptext($questgrouptextId, $text)
- {
- $this->db->query(
- 'UPDATE questgrouptexts '.
- 'SET text = ? '.
- 'WHERE id = ?',
- 'si',
- $text,
- $questgrouptextId
- );
- }
+ /**
+ * Get texts of a Questgroup.
+ *
+ * @param int $questgroupId ID of a Questgroup
+ * @return array Texts of this Questgroup
+ */
+ public function getQuestgroupTexts($questgroupId)
+ {
+ return $this->db->query(
+ 'SELECT id, pos, text, questgroup_id '.
+ 'FROM questgrouptexts '.
+ 'WHERE questgroup_id = ? '.
+ 'ORDER BY pos ASC',
+ 'i',
+ $questgroupId
+ );
+ }
+
+
+ /**
+ * Add a Questgroup text to a Questgroup.
+ *
+ * @param int $userId ID of user
+ * @param int $questgroupId ID of Questgroup to add text to
+ * @param string $text Text to add
+ */
+ public function addQuestgrouptextToQuestgroup($userId, $questgroupId, $text)
+ {
+ // Get position
+ $pos = $this->db->query(
+ 'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
+ 'FROM questgrouptexts '.
+ 'WHERE questgroup_id = ?',
+ 'i',
+ $questgroupId
+ );
+ $pos = $pos[0]['pos'];
+
+ // Add Questgroup text
+ $this->db->query(
+ 'INSERT INTO questgrouptexts '.
+ '(created_user_id, questgroup_id, pos, text) '.
+ 'VALUES '.
+ '(?, ?, ?, ?)',
+ 'iiis',
+ $userId, $questgroupId, $pos, $text
+ );
+ }
+
+
+ /**
+ * Edit a Questgroup text.
+ *
+ * @param int $questgrouptextId ID of Questgroup text to edit
+ * @param string $text New text
+ */
+ public function editQuestgrouptext($questgrouptextId, $text)
+ {
+ $this->db->query(
+ 'UPDATE questgrouptexts '.
+ 'SET text = ? '.
+ 'WHERE id = ?',
+ 'si',
+ $text,
+ $questgrouptextId
+ );
+ }
/**
* Copy Questgroup texts from one Questgroup to another.
- *
+ *
* @param $userId ID of copying user
* @param $sourceQuestgroupId ID of source Questgroup
* @param $targetQuestgroupId ID of target Questgroup
@@ -125,27 +125,27 @@
}
- /**
- * Delete a Questgroup text.
- *
- * @param array $questgrouptext Data of Questgroup text to delete
- */
- public function deleteQuestgrouptext($questgrouptext)
- {
- // Delete Questgroup text
- $this->db->query('DELETE FROM questgrouptexts WHERE id = ?', 'i', $questgrouptext['id']);
+ /**
+ * Delete a Questgroup text.
+ *
+ * @param array $questgrouptext Data of Questgroup text to delete
+ */
+ public function deleteQuestgrouptext($questgrouptext)
+ {
+ // Delete Questgroup text
+ $this->db->query('DELETE FROM questgrouptexts WHERE id = ?', 'i', $questgrouptext['id']);
- // Adjust positions
- $this->db->query(
- 'UPDATE questgrouptexts '.
- 'SET pos = pos - 1 '.
- 'WHERE questgroup_id = ? AND pos > ?',
- 'ii',
- $questgrouptext['questgroup_id'],
- $questgrouptext['pos']
- );
- }
+ // Adjust positions
+ $this->db->query(
+ 'UPDATE questgrouptexts '.
+ 'SET pos = pos - 1 '.
+ 'WHERE questgroup_id = ? AND pos > ?',
+ 'ii',
+ $questgrouptext['questgroup_id'],
+ $questgrouptext['pos']
+ );
+ }
- }
+ }
?>
diff --git a/models/QuestsModel.inc b/models/QuestsModel.inc
index 3bf551d1..7a55a9fd 100644
--- a/models/QuestsModel.inc
+++ b/models/QuestsModel.inc
@@ -1,690 +1,690 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Quests-table.
- *
- * @author Oliver Hanraths
- */
- class QuestsModel extends \hhu\z\Model
- {
- /**
- * Quest-status: Entered
- *
- * @var int;
- */
- const QUEST_STATUS_ENTERED = 0;
- /**
- * Quest-status: submitted
- *
- * @var int;
- */
- const QUEST_STATUS_SUBMITTED = 1;
- /**
- * Quest-status: Unsolved
- *
- * @var int;
- */
- const QUEST_STATUS_UNSOLVED = 2;
- /**
- * Quest-status: Solved
- *
- * @var int;
- */
- const QUEST_STATUS_SOLVED = 3;
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('questtypes', 'questtexts', 'media');
-
-
-
-
- /**
- * Construct a new QuestsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get a Quest and its data by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryId ID of the corresponding Seminary
- * @param int $questgroupId ID of the corresponding Questgroup
- * @param string $questURL URL-title of a Quest
- * @return array Quest data
- */
- public function getQuestByUrl($seminaryId, $questgroupId, $questUrl)
- {
- $data = $this->db->query(
- 'SELECT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.entry_text, quests.task, quests.wrong_text, quests.questsmedia_id '.
- 'FROM quests '.
- 'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
- 'WHERE questgroups.seminary_id = ? AND questgroups.id = ? AND quests.url = ?',
- 'iis',
- $seminaryId, $questgroupId, $questUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get a Quest and its data by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $questId ID of a Quest
- * @return array Quest data
- */
- public function getQuestById($questId)
- {
- $data = $this->db->query(
- 'SELECT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.entry_text, quests.task, quests.wrong_text, quests.questsmedia_id '.
- 'FROM quests '.
- 'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
- 'WHERE quests.id = ?',
- 'i',
- $questId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get the first Quest of a Qusetgroup.
- *
- * @param int $questId ID of Questgroup
- * @return array Data of first Quest
- */
- public function getFirstQuestOfQuestgroup($questgroupId)
- {
- $data = $this->db->query(
- 'SELECT id, questtype_id, title, url, xps, task '.
- 'FROM quests '.
- 'LEFT JOIN quests_previousquests ON quests_previousquests.quest_id = quests.id '.
- 'WHERE questgroup_id = ? AND quests_previousquests.previous_quest_id IS NULL',
- 'i',
- $questgroupId
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return null;
- }
-
-
- /**
- * Get all Quests a Qusetgroup that do not have a following
- * Quest.
- *
- * @param int $questId ID of Questgroup
- * @return array List of last Quests
- */
- public function getLastQuestsOfQuestgroup($questgroupId)
- {
- return $this->db->query(
- 'SELECT id, questtype_id, title, url, xps, task '.
- 'FROM quests '.
- 'WHERE questgroup_id = ? AND NOT EXISTS ('.
- 'SELECT quest_id '.
- 'FROM quests_previousquests '.
- 'WHERE quests_previousquests.previous_quest_id = quests.id'.
- ')',
- 'i',
- $questgroupId
- );
- }
-
-
- /**
- * Get Quests that follow-up a Quest.
- *
- * @param int $questId ID of Quest to get next Quests of
- * @return array Quests data
- */
- public function getNextQuests($questId)
- {
- return $this->db->query(
- 'SELECT quests.id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.entry_text, quests.task, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
- 'FROM quests_previousquests '.
- 'INNER JOIN quests ON quests.id = quests_previousquests.quest_id '.
- 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
- 'WHERE quests_previousquests.previous_quest_id = ?',
- 'i',
- $questId
- );
- }
-
-
- /**
- * Get Quests that the given Quests follows-up to.
- *
- * @param int $questId ID of Quest to get previous Quests of
- * @return array Quests data
- */
- public function getPreviousQuests($questId)
- {
- return $this->db->query(
- 'SELECT quests.id, quests.title, quests.url, quests.entry_text, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
- 'FROM quests_previousquests '.
- 'INNER JOIN quests ON quests.id = quests_previousquests.previous_quest_id '.
- 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
- 'WHERE quests_previousquests.quest_id = ?',
- 'i',
- $questId
- );
- }
+ namespace hhu\z\models;
- /**
- * Set the previous Quest for a Quest.
- *
- * @param int $questId ID of Quest to set previous Quest for
- * @param int $previousQuestId Id of previous Quest
- */
- public function setPreviousQuest($questId, $previousQuestId)
- {
- $this->db->query(
- 'REPLACE INTO quests_previousquests '.
- '(quest_id, previous_quest_id) '.
- 'VALUES '.
- '(?, ?)',
- 'ii',
- $questId,
- $previousQuestId
- );
- }
-
-
- /**
- * Mark a Quest as entered for a Character.
- *
- * @param int $questId ID of Quest to mark as entered
- * @param int $characterId ID of Character that entered the Quest
- */
- public function setQuestEntered($questId, $characterId)
- {
- $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_ENTERED, false);
- }
-
-
- /**
- * Mark a Quest as submitted for a Character.
- *
- * @param int $questId ID of Quest to mark as unsolved
- * @param int $characterId ID of Character that unsolved the Quest
- */
- public function setQuestSubmitted($questId, $characterId)
- {
- $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_SUBMITTED);
- }
-
-
- /**
- * Mark a Quest as unsolved for a Character.
- *
- * @param int $questId ID of Quest to mark as unsolved
- * @param int $characterId ID of Character that unsolved the Quest
- */
- public function setQuestUnsolved($questId, $characterId)
- {
- $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_UNSOLVED);
- }
-
-
- /**
- * Mark a Quest as solved for a Character.
- *
- * @param int $questId ID of Quest to mark as solved
- * @param int $characterId ID of Character that solved the Quest
- */
- public function setQuestSolved($questId, $characterId)
- {
- $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_SOLVED, false);
- }
-
-
- /**
- * Determine if the given Character has entered a Quest.
- *
- * @param int $questId ID of Quest to check
- * @param int $characterId ID of Character to check
- * @result boolean Whether Character has entered the Quest or not
- */
- public function hasCharacterEnteredQuest($questId, $characterId)
- {
- $count = $this->db->query(
- 'SELECT count(id) AS c '.
- 'FROM quests_characters '.
- 'WHERE quest_id = ? AND character_id = ? AND status IN (?,?,?)',
- 'iiiii',
- $questId,
- $characterId,
- self::QUEST_STATUS_ENTERED, self::QUEST_STATUS_SOLVED, self::QUEST_STATUS_UNSOLVED
- );
-
-
- return (!empty($count) && intval($count[0]['c']) > 0);
- }
-
-
- /**
- * Determine if the given Character has tried to solve a Quest.
- *
- * @param int $questId ID of Quest to check
- * @param int $characterId ID of Character to check
- * @result boolean Whether Character has tried to solved the Quest or not
- */
- public function hasCharacterTriedQuest($questId, $characterId)
- {
- $count = $this->db->query(
- 'SELECT count(id) AS c '.
- 'FROM quests_characters '.
- 'WHERE quest_id = ? AND character_id = ? AND status IN (?,?)',
- 'iiii',
- $questId,
- $characterId,
- self::QUEST_STATUS_SOLVED, self::QUEST_STATUS_UNSOLVED
- );
-
-
- return (!empty($count) && intval($count[0]['c']) > 0);
- }
-
-
- /**
- * Determine if the given Character has solved the given Quest.
- *
- * @param int $questId ID of Quest to check
- * @param int $characterId ID of Character to check
- * @result boolean Whether Character has solved the Quest or not
- */
- public function hasCharacterSolvedQuest($questId, $characterId)
- {
- $count = $this->db->query(
- 'SELECT count(id) AS c '.
- 'FROM quests_characters '.
- 'WHERE quest_id = ? AND character_id = ? AND status = ?',
- 'iii',
- $questId,
- $characterId,
- self::QUEST_STATUS_SOLVED
- );
-
-
- return (!empty($count) && intval($count[0]['c']) > 0);
- }
-
-
- /**
- * Get the last Quests for a Character.
- *
- * @param int $characterId ID of Character
- * @retrun array Quest data
- */
- public function getLastQuestForCharacter($characterId)
- {
- $data = $this->db->query(
- 'SELECT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.wrong_text, quests.questsmedia_id '.
- 'FROM quests_characters '.
- 'LEFT JOIN quests ON quests.id = quests_characters.quest_id '.
- 'WHERE quests_characters.character_id = ? AND quests_characters.status IN (?, ?, ?) '.
- 'ORDER BY quests_characters.created desc '.
- 'LIMIT 1',
- 'iiii',
- $characterId,
- self::QUEST_STATUS_ENTERED, self::QUEST_STATUS_SUBMITTED, self::QUEST_STATUS_SOLVED
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return null;
- }
-
-
- /**
- * Get all Quests for a Seminary.
- *
- * @param int $seminaryId ID of Seminary
- * @return array Quests for this Seminary
- */
- public function getQuestsForSeminary($seminaryId)
- {
- 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, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
- 'FROM questgroups '.
- 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
- 'WHERE questgroups.seminary_id = ? '.
- 'ORDER BY quests.title ASC',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Get count of all Quests for a Seminary.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $questgroupId ID of Questgroup (optional)
- * @param int $questtypeId ID of Questtype (optional)
- * @param string $title Part of the title to filter for (optional)
- * @return int Count of Quests for this Seminary
- */
- public function getCountForQuestsForSeminaryByOpenSubmissions($seminaryId, $questgroupId=null, $questtypeId=null, $title=null)
- {
- $data = $this->db->query(
- 'SELECT count(DISTINCT quests.id) AS c '.
- 'FROM questgroups '.
- 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
- 'WHERE questgroups.seminary_id = ? '.
- (!empty($questgroupId) ? sprintf('AND questgroups.id = %d ', $questgroupId) : null).
- (!empty($questtypeId) ? sprintf('AND quests.questtype_id = %d ', $questtypeId) : null).
- (!empty($title) ? sprintf('AND quests.title LIKE \'%%%s%%\' ', $title) : null),
- 'i',
- $seminaryId
- );
- if(!empty($data)) {
- return $data[0]['c'];
- }
-
-
- return 0;
- }
-
-
- /**
- * Get all Quests for a Seminary order by their count of open
- * submissions.
- *
- * @param int $seminaryId ID of Seminary
- * @param int $questgroupId ID of Questgroup (optional)
- * @param int $questtypeId ID of Questtype (optional)
- * @param string $title Part of title to filter for (optional)
- * @param int $limit Limit amount of Quests (optional)
- * @param int $offset Offset (optional)
- * @return array Quests for this Seminary
- */
- public function getQuestsForSeminaryByOpenSubmissions($seminaryId, $questgroupId=null, $questtypeId=null, $title=null, $limit=null, $offset=0)
- {
- 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, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url, ('.
- 'SELECT count(DISTINCT quests_characters.character_id) '.
- 'FROM quests_characters '.
- 'WHERE quests_characters.quest_id = quests.id AND quests_characters.status = ? AND NOT EXISTS ('.
- 'SELECT id '.
- 'FROM quests_characters AS qc '.
- 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
- ')'.
- ') AS opensubmissionscount '.
- 'FROM questgroups '.
- 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
- 'WHERE questgroups.seminary_id = ? '.
- (!empty($questgroupId) ? sprintf('AND questgroups.id = %d ', $questgroupId) : null).
- (!empty($questtypeId) ? sprintf('AND quests.questtype_id = %d ', $questtypeId) : null).
- (!empty($title) ? sprintf('AND quests.title LIKE \'%%%s%%\' ', $title) : null).
- 'ORDER BY opensubmissionscount DESC '.
- (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
- 'ii',
- self::QUEST_STATUS_SUBMITTED,
- $seminaryId
- );
- }
-
-
- /**
- * Get all Quests that are linked to a Questtopic.
- *
- * @param int $questtopicId ID of Questtopic
- * @return array Quests for this Questtopic
- */
- public function getQuestsForQuesttopic($questtopicId)
- {
- 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, questgroups.url AS questgroup_url '.
- 'FROM quests_questsubtopics '.
- 'INNER JOIN questsubtopics ON questsubtopics.id = quests_questsubtopics.questsubtopic_id '.
- 'INNER JOIN quests ON quests.id = quests_questsubtopics.quest_id '.
- 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
- 'WHERE questsubtopics.questtopic_id = ? '.
- 'ORDER BY quests.title ASC',
- 'i',
- $questtopicId
- );
- }
-
-
-
- /**
- * Mark a Quest for a Character.
- *
- * @param int $questId ID of Quest to mark
- * @param int $characterId ID of Character to mark the Quest for
- * @param int $status Quest status to mark
- * @param boolean $repeated Insert although status is already set for this Quest and Character
- */
- private function setQuestStatus($questId, $characterId, $status, $repeated=true)
- {
- // Check if status is already set
- if(!$repeated)
- {
- $count = $this->db->query(
- 'SELECT count(*) AS c '.
- 'FROM quests_characters '.
- 'WHERE quest_id = ? AND character_id = ? AND status = ?',
- 'iii',
- $questId,
- $characterId,
- $status
- );
- if(!empty($count) && intval($count[0]['c']) > 0) {
- return;
- }
- }
-
- // Set status
- $this->db->query(
- 'INSERT INTO quests_characters '.
- '(quest_id, character_id, status) '.
- 'VALUES '.
- '(?, ?, ?) ',
- 'iii',
- $questId,
- $characterId,
- $status
- );
- }
-
-
- /**
- * Get the last status of a Quest for a Character.
- *
- * @param int $questId ID of Quest
- * @param int $characterId ID of Character to get status for
- * @return int Last status
- */
- public function getLastQuestStatus($questId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT id, created, status '.
- 'FROM quests_characters '.
- 'WHERE quest_id = ? AND character_id = ? '.
- 'ORDER BY created DESC '.
- 'LIMIT 1',
- 'ii',
- $questId, $characterId
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return null;
- }
-
-
- /**
- * Check if a Quest title already exists.
- *
- * @param string $title Quest title to check
- * @param int $seminaryId ID of Seminary
- * @param int $questId Do not check this ID (for editing)
- * @return boolean Whether Quest title exists or not
- */
- public function questTitleExists($title, $seminaryId, $questId=null)
- {
- $data = $this->db->query(
- 'SELECT quests.id '.
- 'FROM quests '.
- 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
- 'WHERE questgroups.seminary_id = ? AND (quests.title = ? OR quests.url = ?)',
- 'iss',
- $seminaryId,
- $title,
- \nre\core\Linker::createLinkParam($title)
- );
-
- return (!empty($data) && (is_null($questId) || $questId != $data[0]['id']));
- }
+ /**
+ * Model to interact with Quests-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuestsModel extends \hhu\z\Model
+ {
+ /**
+ * Quest-status: Entered
+ *
+ * @var int;
+ */
+ const QUEST_STATUS_ENTERED = 0;
+ /**
+ * Quest-status: submitted
+ *
+ * @var int;
+ */
+ const QUEST_STATUS_SUBMITTED = 1;
+ /**
+ * Quest-status: Unsolved
+ *
+ * @var int;
+ */
+ const QUEST_STATUS_UNSOLVED = 2;
+ /**
+ * Quest-status: Solved
+ *
+ * @var int;
+ */
+ const QUEST_STATUS_SOLVED = 3;
+
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('questtypes', 'questtexts', 'media');
- /**
- * Create a new Quest.
- *
- * @param int $userId User-ID that creates the new character
- * @param int $questgroupId ID of Questgroup
- * @param int $questtypeId ID of Questtype
- * @param string $title Title for new Quest
- * @param int $xps XPs for new Quest
- * @param string $task Task for new Quest
- * @param string $entrytext Entrytext for new Quest
- * @param string $wrongtext Wrongtext for new Quest
- * @return int ID of new Quest
- */
- public function createQuest($userId, $questgroupId, $questtypeId, $title, $xps, $task, $entrytext, $wrongtext)
- {
- $questId = null;
- $this->db->setAutocommit(false);
- try {
- // Get last Quests of Questgroup
- $lastQuests = $this->getLastQuestsOfQuestgroup($questgroupId);
-
- // Create Quest
- $this->db->query(
- 'INSERT INTO quests '.
- '(created_user_id, questgroup_id, questtype_id, title, url, xps, entry_text, wrong_text, task) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?, ?, ?, ?, ?)',
- 'iiississs',
- $userId, $questgroupId, $questtypeId,
- $title, \nre\core\Linker::createLinkParam($title),
- $xps, $entrytext, $wrongtext, $task
- );
- $questId = $this->db->getInsertId();
-
- // Set previous Quest
- if(count($lastQuests) > 0) {
- $this->setPreviousQuest($questId, $lastQuests[0]['id']);
- }
-
- $this->db->commit();
- }
- catch(\Exception $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
-
- $this->db->setAutocommit(true);
- return $questId;
- }
-
-
- /**
- * Set the media for a Quest.
- *
- * @param int $questId ID of Quest to set media for
- * @param int $questmediaId ID of Questsmedia to set
- */
- public function setQuestmedia($questId, $questsmediaId)
- {
- $this->db->query(
- 'UPDATE quests '.
- 'SET questsmedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $questsmediaId,
- $questId
- );
- }
- /**
- * Edit a new Quest.
- *
- * @param int $questId ID of Quest to edit
- * @param int $questtypeId ID of Questtype
- * @param string $title New title for Quest
- * @param int $xps XPs for Quest
- * @param string $task New task for Quest
- * @param string $entrytext New entrytext for Quest
- * @param string $wrongtext New wrongtext for Quest
- */
- public function editQuest($questId, $questtypeId, $title, $xps, $task, $entrytext, $wrongtext)
- {
- $this->db->query(
- 'UPDATE quests '.
- 'SET questtype_id = ?, title = ?, url = ?, xps = ?, entry_text = ?, wrong_text = ?, task = ? '.
- 'WHERE id = ?',
- 'ississsi',
- $questtypeId,
- $title,
- \nre\core\Linker::createLinkParam($title),
- $xps,
- $entrytext,
- $wrongtext,
- $task,
- $questId
- );
- }
+ /**
+ * Construct a new QuestsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get a Quest and its data by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryId ID of the corresponding Seminary
+ * @param int $questgroupId ID of the corresponding Questgroup
+ * @param string $questURL URL-title of a Quest
+ * @return array Quest data
+ */
+ public function getQuestByUrl($seminaryId, $questgroupId, $questUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.entry_text, quests.task, quests.wrong_text, quests.questsmedia_id '.
+ 'FROM quests '.
+ 'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
+ 'WHERE questgroups.seminary_id = ? AND questgroups.id = ? AND quests.url = ?',
+ 'iis',
+ $seminaryId, $questgroupId, $questUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get a Quest and its data by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $questId ID of a Quest
+ * @return array Quest data
+ */
+ public function getQuestById($questId)
+ {
+ $data = $this->db->query(
+ 'SELECT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.entry_text, quests.task, quests.wrong_text, quests.questsmedia_id '.
+ 'FROM quests '.
+ 'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
+ 'WHERE quests.id = ?',
+ 'i',
+ $questId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get the first Quest of a Qusetgroup.
+ *
+ * @param int $questId ID of Questgroup
+ * @return array Data of first Quest
+ */
+ public function getFirstQuestOfQuestgroup($questgroupId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, questtype_id, title, url, xps, task '.
+ 'FROM quests '.
+ 'LEFT JOIN quests_previousquests ON quests_previousquests.quest_id = quests.id '.
+ 'WHERE questgroup_id = ? AND quests_previousquests.previous_quest_id IS NULL',
+ 'i',
+ $questgroupId
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Get all Quests a Qusetgroup that do not have a following
+ * Quest.
+ *
+ * @param int $questId ID of Questgroup
+ * @return array List of last Quests
+ */
+ public function getLastQuestsOfQuestgroup($questgroupId)
+ {
+ return $this->db->query(
+ 'SELECT id, questtype_id, title, url, xps, task '.
+ 'FROM quests '.
+ 'WHERE questgroup_id = ? AND NOT EXISTS ('.
+ 'SELECT quest_id '.
+ 'FROM quests_previousquests '.
+ 'WHERE quests_previousquests.previous_quest_id = quests.id'.
+ ')',
+ 'i',
+ $questgroupId
+ );
+ }
+
+
+ /**
+ * Get Quests that follow-up a Quest.
+ *
+ * @param int $questId ID of Quest to get next Quests of
+ * @return array Quests data
+ */
+ public function getNextQuests($questId)
+ {
+ return $this->db->query(
+ 'SELECT quests.id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.entry_text, quests.task, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
+ 'FROM quests_previousquests '.
+ 'INNER JOIN quests ON quests.id = quests_previousquests.quest_id '.
+ 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
+ 'WHERE quests_previousquests.previous_quest_id = ?',
+ 'i',
+ $questId
+ );
+ }
+
+
+ /**
+ * Get Quests that the given Quests follows-up to.
+ *
+ * @param int $questId ID of Quest to get previous Quests of
+ * @return array Quests data
+ */
+ public function getPreviousQuests($questId)
+ {
+ return $this->db->query(
+ 'SELECT quests.id, quests.title, quests.url, quests.entry_text, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
+ 'FROM quests_previousquests '.
+ 'INNER JOIN quests ON quests.id = quests_previousquests.previous_quest_id '.
+ 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
+ 'WHERE quests_previousquests.quest_id = ?',
+ 'i',
+ $questId
+ );
+ }
+
+
+ /**
+ * Set the previous Quest for a Quest.
+ *
+ * @param int $questId ID of Quest to set previous Quest for
+ * @param int $previousQuestId Id of previous Quest
+ */
+ public function setPreviousQuest($questId, $previousQuestId)
+ {
+ $this->db->query(
+ 'REPLACE INTO quests_previousquests '.
+ '(quest_id, previous_quest_id) '.
+ 'VALUES '.
+ '(?, ?)',
+ 'ii',
+ $questId,
+ $previousQuestId
+ );
+ }
+
+
+ /**
+ * Mark a Quest as entered for a Character.
+ *
+ * @param int $questId ID of Quest to mark as entered
+ * @param int $characterId ID of Character that entered the Quest
+ */
+ public function setQuestEntered($questId, $characterId)
+ {
+ $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_ENTERED, false);
+ }
+
+
+ /**
+ * Mark a Quest as submitted for a Character.
+ *
+ * @param int $questId ID of Quest to mark as unsolved
+ * @param int $characterId ID of Character that unsolved the Quest
+ */
+ public function setQuestSubmitted($questId, $characterId)
+ {
+ $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_SUBMITTED);
+ }
+
+
+ /**
+ * Mark a Quest as unsolved for a Character.
+ *
+ * @param int $questId ID of Quest to mark as unsolved
+ * @param int $characterId ID of Character that unsolved the Quest
+ */
+ public function setQuestUnsolved($questId, $characterId)
+ {
+ $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_UNSOLVED);
+ }
+
+
+ /**
+ * Mark a Quest as solved for a Character.
+ *
+ * @param int $questId ID of Quest to mark as solved
+ * @param int $characterId ID of Character that solved the Quest
+ */
+ public function setQuestSolved($questId, $characterId)
+ {
+ $this->setQuestStatus($questId, $characterId, self::QUEST_STATUS_SOLVED, false);
+ }
+
+
+ /**
+ * Determine if the given Character has entered a Quest.
+ *
+ * @param int $questId ID of Quest to check
+ * @param int $characterId ID of Character to check
+ * @result boolean Whether Character has entered the Quest or not
+ */
+ public function hasCharacterEnteredQuest($questId, $characterId)
+ {
+ $count = $this->db->query(
+ 'SELECT count(id) AS c '.
+ 'FROM quests_characters '.
+ 'WHERE quest_id = ? AND character_id = ? AND status IN (?,?,?)',
+ 'iiiii',
+ $questId,
+ $characterId,
+ self::QUEST_STATUS_ENTERED, self::QUEST_STATUS_SOLVED, self::QUEST_STATUS_UNSOLVED
+ );
+
+
+ return (!empty($count) && intval($count[0]['c']) > 0);
+ }
+
+
+ /**
+ * Determine if the given Character has tried to solve a Quest.
+ *
+ * @param int $questId ID of Quest to check
+ * @param int $characterId ID of Character to check
+ * @result boolean Whether Character has tried to solved the Quest or not
+ */
+ public function hasCharacterTriedQuest($questId, $characterId)
+ {
+ $count = $this->db->query(
+ 'SELECT count(id) AS c '.
+ 'FROM quests_characters '.
+ 'WHERE quest_id = ? AND character_id = ? AND status IN (?,?)',
+ 'iiii',
+ $questId,
+ $characterId,
+ self::QUEST_STATUS_SOLVED, self::QUEST_STATUS_UNSOLVED
+ );
+
+
+ return (!empty($count) && intval($count[0]['c']) > 0);
+ }
+
+
+ /**
+ * Determine if the given Character has solved the given Quest.
+ *
+ * @param int $questId ID of Quest to check
+ * @param int $characterId ID of Character to check
+ * @result boolean Whether Character has solved the Quest or not
+ */
+ public function hasCharacterSolvedQuest($questId, $characterId)
+ {
+ $count = $this->db->query(
+ 'SELECT count(id) AS c '.
+ 'FROM quests_characters '.
+ 'WHERE quest_id = ? AND character_id = ? AND status = ?',
+ 'iii',
+ $questId,
+ $characterId,
+ self::QUEST_STATUS_SOLVED
+ );
+
+
+ return (!empty($count) && intval($count[0]['c']) > 0);
+ }
+
+
+ /**
+ * Get the last Quests for a Character.
+ *
+ * @param int $characterId ID of Character
+ * @retrun array Quest data
+ */
+ public function getLastQuestForCharacter($characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.wrong_text, quests.questsmedia_id '.
+ 'FROM quests_characters '.
+ 'LEFT JOIN quests ON quests.id = quests_characters.quest_id '.
+ 'WHERE quests_characters.character_id = ? AND quests_characters.status IN (?, ?, ?) '.
+ 'ORDER BY quests_characters.created desc '.
+ 'LIMIT 1',
+ 'iiii',
+ $characterId,
+ self::QUEST_STATUS_ENTERED, self::QUEST_STATUS_SUBMITTED, self::QUEST_STATUS_SOLVED
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Get all Quests for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @return array Quests for this Seminary
+ */
+ public function getQuestsForSeminary($seminaryId)
+ {
+ 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, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
+ 'FROM questgroups '.
+ 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
+ 'WHERE questgroups.seminary_id = ? '.
+ 'ORDER BY quests.title ASC',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get count of all Quests for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $questgroupId ID of Questgroup (optional)
+ * @param int $questtypeId ID of Questtype (optional)
+ * @param string $title Part of the title to filter for (optional)
+ * @return int Count of Quests for this Seminary
+ */
+ public function getCountForQuestsForSeminaryByOpenSubmissions($seminaryId, $questgroupId=null, $questtypeId=null, $title=null)
+ {
+ $data = $this->db->query(
+ 'SELECT count(DISTINCT quests.id) AS c '.
+ 'FROM questgroups '.
+ 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
+ 'WHERE questgroups.seminary_id = ? '.
+ (!empty($questgroupId) ? sprintf('AND questgroups.id = %d ', $questgroupId) : null).
+ (!empty($questtypeId) ? sprintf('AND quests.questtype_id = %d ', $questtypeId) : null).
+ (!empty($title) ? sprintf('AND quests.title LIKE \'%%%s%%\' ', $title) : null),
+ 'i',
+ $seminaryId
+ );
+ if(!empty($data)) {
+ return $data[0]['c'];
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Get all Quests for a Seminary order by their count of open
+ * submissions.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param int $questgroupId ID of Questgroup (optional)
+ * @param int $questtypeId ID of Questtype (optional)
+ * @param string $title Part of title to filter for (optional)
+ * @param int $limit Limit amount of Quests (optional)
+ * @param int $offset Offset (optional)
+ * @return array Quests for this Seminary
+ */
+ public function getQuestsForSeminaryByOpenSubmissions($seminaryId, $questgroupId=null, $questtypeId=null, $title=null, $limit=null, $offset=0)
+ {
+ 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, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url, ('.
+ 'SELECT count(DISTINCT quests_characters.character_id) '.
+ 'FROM quests_characters '.
+ 'WHERE quests_characters.quest_id = quests.id AND quests_characters.status = ? AND NOT EXISTS ('.
+ 'SELECT id '.
+ 'FROM quests_characters AS qc '.
+ 'WHERE qc.quest_id = quests_characters.quest_id AND qc.character_id = quests_characters.character_id AND qc.created > quests_characters.created'.
+ ')'.
+ ') AS opensubmissionscount '.
+ 'FROM questgroups '.
+ 'INNER JOIN quests ON quests.questgroup_id = questgroups.id '.
+ 'WHERE questgroups.seminary_id = ? '.
+ (!empty($questgroupId) ? sprintf('AND questgroups.id = %d ', $questgroupId) : null).
+ (!empty($questtypeId) ? sprintf('AND quests.questtype_id = %d ', $questtypeId) : null).
+ (!empty($title) ? sprintf('AND quests.title LIKE \'%%%s%%\' ', $title) : null).
+ 'ORDER BY opensubmissionscount DESC '.
+ (!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null),
+ 'ii',
+ self::QUEST_STATUS_SUBMITTED,
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Get all Quests that are linked to a Questtopic.
+ *
+ * @param int $questtopicId ID of Questtopic
+ * @return array Quests for this Questtopic
+ */
+ public function getQuestsForQuesttopic($questtopicId)
+ {
+ 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, questgroups.url AS questgroup_url '.
+ 'FROM quests_questsubtopics '.
+ 'INNER JOIN questsubtopics ON questsubtopics.id = quests_questsubtopics.questsubtopic_id '.
+ 'INNER JOIN quests ON quests.id = quests_questsubtopics.quest_id '.
+ 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
+ 'WHERE questsubtopics.questtopic_id = ? '.
+ 'ORDER BY quests.title ASC',
+ 'i',
+ $questtopicId
+ );
+ }
+
+
+
+ /**
+ * Mark a Quest for a Character.
+ *
+ * @param int $questId ID of Quest to mark
+ * @param int $characterId ID of Character to mark the Quest for
+ * @param int $status Quest status to mark
+ * @param boolean $repeated Insert although status is already set for this Quest and Character
+ */
+ private function setQuestStatus($questId, $characterId, $status, $repeated=true)
+ {
+ // Check if status is already set
+ if(!$repeated)
+ {
+ $count = $this->db->query(
+ 'SELECT count(*) AS c '.
+ 'FROM quests_characters '.
+ 'WHERE quest_id = ? AND character_id = ? AND status = ?',
+ 'iii',
+ $questId,
+ $characterId,
+ $status
+ );
+ if(!empty($count) && intval($count[0]['c']) > 0) {
+ return;
+ }
+ }
+
+ // Set status
+ $this->db->query(
+ 'INSERT INTO quests_characters '.
+ '(quest_id, character_id, status) '.
+ 'VALUES '.
+ '(?, ?, ?) ',
+ 'iii',
+ $questId,
+ $characterId,
+ $status
+ );
+ }
+
+
+ /**
+ * Get the last status of a Quest for a Character.
+ *
+ * @param int $questId ID of Quest
+ * @param int $characterId ID of Character to get status for
+ * @return int Last status
+ */
+ public function getLastQuestStatus($questId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, created, status '.
+ 'FROM quests_characters '.
+ 'WHERE quest_id = ? AND character_id = ? '.
+ 'ORDER BY created DESC '.
+ 'LIMIT 1',
+ 'ii',
+ $questId, $characterId
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Check if a Quest title already exists.
+ *
+ * @param string $title Quest title to check
+ * @param int $seminaryId ID of Seminary
+ * @param int $questId Do not check this ID (for editing)
+ * @return boolean Whether Quest title exists or not
+ */
+ public function questTitleExists($title, $seminaryId, $questId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT quests.id '.
+ 'FROM quests '.
+ 'INNER JOIN questgroups ON questgroups.id = quests.questgroup_id '.
+ 'WHERE questgroups.seminary_id = ? AND (quests.title = ? OR quests.url = ?)',
+ 'iss',
+ $seminaryId,
+ $title,
+ \nre\core\Linker::createLinkParam($title)
+ );
+
+ return (!empty($data) && (is_null($questId) || $questId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Quest.
+ *
+ * @param int $userId User-ID that creates the new character
+ * @param int $questgroupId ID of Questgroup
+ * @param int $questtypeId ID of Questtype
+ * @param string $title Title for new Quest
+ * @param int $xps XPs for new Quest
+ * @param string $task Task for new Quest
+ * @param string $entrytext Entrytext for new Quest
+ * @param string $wrongtext Wrongtext for new Quest
+ * @return int ID of new Quest
+ */
+ public function createQuest($userId, $questgroupId, $questtypeId, $title, $xps, $task, $entrytext, $wrongtext)
+ {
+ $questId = null;
+ $this->db->setAutocommit(false);
+ try {
+ // Get last Quests of Questgroup
+ $lastQuests = $this->getLastQuestsOfQuestgroup($questgroupId);
+
+ // Create Quest
+ $this->db->query(
+ 'INSERT INTO quests '.
+ '(created_user_id, questgroup_id, questtype_id, title, url, xps, entry_text, wrong_text, task) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?, ?, ?, ?, ?)',
+ 'iiississs',
+ $userId, $questgroupId, $questtypeId,
+ $title, \nre\core\Linker::createLinkParam($title),
+ $xps, $entrytext, $wrongtext, $task
+ );
+ $questId = $this->db->getInsertId();
+
+ // Set previous Quest
+ if(count($lastQuests) > 0) {
+ $this->setPreviousQuest($questId, $lastQuests[0]['id']);
+ }
+
+ $this->db->commit();
+ }
+ catch(\Exception $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+
+ $this->db->setAutocommit(true);
+ return $questId;
+ }
+
+
+ /**
+ * Set the media for a Quest.
+ *
+ * @param int $questId ID of Quest to set media for
+ * @param int $questmediaId ID of Questsmedia to set
+ */
+ public function setQuestmedia($questId, $questsmediaId)
+ {
+ $this->db->query(
+ 'UPDATE quests '.
+ 'SET questsmedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $questsmediaId,
+ $questId
+ );
+ }
+
+
+ /**
+ * Edit a new Quest.
+ *
+ * @param int $questId ID of Quest to edit
+ * @param int $questtypeId ID of Questtype
+ * @param string $title New title for Quest
+ * @param int $xps XPs for Quest
+ * @param string $task New task for Quest
+ * @param string $entrytext New entrytext for Quest
+ * @param string $wrongtext New wrongtext for Quest
+ */
+ public function editQuest($questId, $questtypeId, $title, $xps, $task, $entrytext, $wrongtext)
+ {
+ $this->db->query(
+ 'UPDATE quests '.
+ 'SET questtype_id = ?, title = ?, url = ?, xps = ?, entry_text = ?, wrong_text = ?, task = ? '.
+ 'WHERE id = ?',
+ 'ississsi',
+ $questtypeId,
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $xps,
+ $entrytext,
+ $wrongtext,
+ $task,
+ $questId
+ );
+ }
/**
* Copy all Quests from a Seminary.
- *
+ *
* @param int $userId ID of creating user
* @param int $seminaryId ID of Seminary to copy from
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
@@ -781,38 +781,38 @@
}
- /**
- * Delete a Quest of a Seminary.
- *
- * @param int $questId ID of Quest to delete
- */
- public function deleteQuest($questId)
- {
- $this->db->setAutocommit(false);
- try {
- // Set previous Quests of following Quests
- $previousQuests = $this->getPreviousQuests($questId);
- $nextQuests = $this->getNextQuests($questId);
- foreach($nextQuests as &$nextQuest) {
- foreach($previousQuests as &$previousQuest) {
- $this->setPreviousQuest($nextQuest['id'], $previousQuest['id']);
- }
- }
+ /**
+ * Delete a Quest of a Seminary.
+ *
+ * @param int $questId ID of Quest to delete
+ */
+ public function deleteQuest($questId)
+ {
+ $this->db->setAutocommit(false);
+ try {
+ // Set previous Quests of following Quests
+ $previousQuests = $this->getPreviousQuests($questId);
+ $nextQuests = $this->getNextQuests($questId);
+ foreach($nextQuests as &$nextQuest) {
+ foreach($previousQuests as &$previousQuest) {
+ $this->setPreviousQuest($nextQuest['id'], $previousQuest['id']);
+ }
+ }
- // Delete Quest
- $this->db->query('DELETE FROM quests WHERE id = ?', 'i', $questId);
+ // Delete Quest
+ $this->db->query('DELETE FROM quests WHERE id = ?', 'i', $questId);
- $this->db->commit();
- }
- catch(\Exception $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
+ $this->db->commit();
+ }
+ catch(\Exception $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
- $this->db->setAutocommit(true);
- }
-
- }
+ $this->db->setAutocommit(true);
+ }
+
+ }
?>
diff --git a/models/QuesttextsModel.inc b/models/QuesttextsModel.inc
index 4a0c2e0c..950d9b7b 100644
--- a/models/QuesttextsModel.inc
+++ b/models/QuesttextsModel.inc
@@ -1,320 +1,320 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Questtexts-table.
- *
- * @author Oliver Hanraths
- */
- class QuesttextsModel extends \hhu\z\Model
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('media');
-
-
-
-
- /**
- * Construct a new QuesttextsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get the first text of a Quest.
- *
- * @param int $questId ID of a Quest
- * @return string First text of this Quest or NULL
- */
- public function getFirstQuestText($questId)
- {
- $prolog = $this->getQuesttextsOfQuest($questId, 'Prolog');
- if(!empty($prolog)) {
- return $prolog[0]['text'];
- }
-
-
- return null;
- }
-
-
- /**
- * Get all Questtexts for a Quest.
- *
- * @param int $questId ID of the Quest
- * @param string $questtexttypeUrl URL of the Questtexttype
- * @return array All Questtexts for a Quest
- */
- public function getQuesttextsOfQuest($questId, $questtexttypeUrl=null)
- {
- if(is_null($questtexttypeUrl))
- {
- return $this->db->query(
- '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 = ?',
- 'i',
- $questId
- );
- }
- else
- {
- return $this->db->query(
- '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 = ?',
- 'is',
- $questId,
- $questtexttypeUrl
- );
- }
- }
-
-
- /**
- * Get count of Questtexts for a Quest.
- *
- * @param int $questId ID of the Quest
- * @param string $questtexttypeUrl URL of the Questtexttype
- * @return int Amount of Questtexts for a Quest
- */
- public function getQuesttextCountOfQuest($questId, $questtexttypeUrl=null)
- {
- if(is_null($questtexttypeUrl))
- {
- $data = $this->db->query(
- 'SELECT count(questtexts.id) AS c '.
- 'FROM questtexts '.
- 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
- 'WHERE questtexts.quest_id = ?',
- 'i',
- $questId
- );
- }
- else
- {
- $data = $this->db->query(
- 'SELECT count(questtexts.id) AS c '.
- 'FROM questtexts '.
- 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
- 'WHERE questtexts.quest_id = ? and questtexttypes.url = ?',
- 'is',
- $questId,
- $questtexttypeUrl
- );
- }
- if(!empty($data)) {
- return $data[0]['c'];
- }
-
-
- return 0;
- }
-
-
- /**
- * Get corresponding Questtexts for a Questgroup.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $questgroupId ID of Questgroup to get the Questtexst for
- * @param array List of Questtexts
- */
- public function getRelatedQuesttextsForQuestgroup($questgroupId)
- {
- return $this->db->query(
- 'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexts.quest_id, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '.
- 'FROM questgroups_questtexts '.
- 'LEFT JOIN questtexts ON questtexts.id = questgroups_questtexts.questtext_id '.
- 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
- 'WHERE questgroups_questtexts.questgroup_id = ?',
- 'i',
- $questgroupId
- );
- }
-
-
- /**
- * Get the Questtext that was last entered by a Character.
- *
- * @param int $characterId ID of Character
- * @param array $questtexts List of Questtexts to look into
- * @return array Questtext data
- */
- public function pickQuesttextLastEnteredByCharacter($characterId, $questtexts)
- {
- if(count($questtexts) == 0) {
- return null;
- }
- $data = $this->db->query(
- sprintf(
- 'SELECT quest_id '.
- 'FROM quests_characters '.
- 'WHERE character_id = ? AND quest_id IN (%s) AND status = ? '.
- 'ORDER BY created DESC '.
- 'LIMIT 1',
- implode(',', array_map(function($q) { return intval($q['quest_id']); }, $questtexts))
- ),
- 'ii',
- $characterId,
- \hhu\z\models\QuestsModel::QUEST_STATUS_ENTERED
- );
- if(count($data) == 0) {
- return $questtexts[0];
- }
- foreach($questtexts as &$questtext) {
- if($questtext['quest_id'] == $data[0]['quest_id']) {
- return $questtext;
- }
- }
-
-
- return null;
- }
-
-
- /**
- * Get all registered Questtexttypes.
- *
- * @return array Registered Questtexttypes
- */
- public function getQuesttexttypes()
- {
- return $this->db->query(
- 'SELECT id, type, url '.
- 'FROM questtexttypes'
- );
- }
-
-
- /**
- * Get a Questtexttype by its URL.
- *
- * @param string $questtexttypeUrl URL-type of Questtexttype
- * @return array Questtexttype data
- */
- public function getQuesttexttypeByUrl($questtexttypeUrl)
- {
- $data = $this->db->query(
- 'SELECT id, type, url '.
- 'FROM questtexttypes '.
- 'WHERE url = ?',
- 's',
- $questtexttypeUrl
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return null;
- }
-
-
- /**
- * 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 string $text Text to add.
- */
- public function addQuesttextToQuest($userId, $questId, $questtexttypeUrl, $text)
- {
- $questtexttype = $this->getQuesttexttypeByUrl($questtexttypeUrl);
- if(is_null($questtexttype)) {
- return;
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
- // 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
- );
+ namespace hhu\z\models;
- // Return ID
- return $this->db->getInsertId();
- }
+ /**
+ * Model to interact with Questtexts-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttextsModel extends \hhu\z\Model
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('media');
- /**
- * 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
- );
- }
+
+ /**
+ * Construct a new QuesttextsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get the first text of a Quest.
+ *
+ * @param int $questId ID of a Quest
+ * @return string First text of this Quest or NULL
+ */
+ public function getFirstQuestText($questId)
+ {
+ $prolog = $this->getQuesttextsOfQuest($questId, 'Prolog');
+ if(!empty($prolog)) {
+ return $prolog[0]['text'];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Get all Questtexts for a Quest.
+ *
+ * @param int $questId ID of the Quest
+ * @param string $questtexttypeUrl URL of the Questtexttype
+ * @return array All Questtexts for a Quest
+ */
+ public function getQuesttextsOfQuest($questId, $questtexttypeUrl=null)
+ {
+ if(is_null($questtexttypeUrl))
+ {
+ return $this->db->query(
+ '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 = ?',
+ 'i',
+ $questId
+ );
+ }
+ else
+ {
+ return $this->db->query(
+ '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 = ?',
+ 'is',
+ $questId,
+ $questtexttypeUrl
+ );
+ }
+ }
+
+
+ /**
+ * Get count of Questtexts for a Quest.
+ *
+ * @param int $questId ID of the Quest
+ * @param string $questtexttypeUrl URL of the Questtexttype
+ * @return int Amount of Questtexts for a Quest
+ */
+ public function getQuesttextCountOfQuest($questId, $questtexttypeUrl=null)
+ {
+ if(is_null($questtexttypeUrl))
+ {
+ $data = $this->db->query(
+ 'SELECT count(questtexts.id) AS c '.
+ 'FROM questtexts '.
+ 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
+ 'WHERE questtexts.quest_id = ?',
+ 'i',
+ $questId
+ );
+ }
+ else
+ {
+ $data = $this->db->query(
+ 'SELECT count(questtexts.id) AS c '.
+ 'FROM questtexts '.
+ 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
+ 'WHERE questtexts.quest_id = ? and questtexttypes.url = ?',
+ 'is',
+ $questId,
+ $questtexttypeUrl
+ );
+ }
+ if(!empty($data)) {
+ return $data[0]['c'];
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Get corresponding Questtexts for a Questgroup.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $questgroupId ID of Questgroup to get the Questtexst for
+ * @param array List of Questtexts
+ */
+ public function getRelatedQuesttextsForQuestgroup($questgroupId)
+ {
+ return $this->db->query(
+ 'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexts.quest_id, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '.
+ 'FROM questgroups_questtexts '.
+ 'LEFT JOIN questtexts ON questtexts.id = questgroups_questtexts.questtext_id '.
+ 'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
+ 'WHERE questgroups_questtexts.questgroup_id = ?',
+ 'i',
+ $questgroupId
+ );
+ }
+
+
+ /**
+ * Get the Questtext that was last entered by a Character.
+ *
+ * @param int $characterId ID of Character
+ * @param array $questtexts List of Questtexts to look into
+ * @return array Questtext data
+ */
+ public function pickQuesttextLastEnteredByCharacter($characterId, $questtexts)
+ {
+ if(count($questtexts) == 0) {
+ return null;
+ }
+ $data = $this->db->query(
+ sprintf(
+ 'SELECT quest_id '.
+ 'FROM quests_characters '.
+ 'WHERE character_id = ? AND quest_id IN (%s) AND status = ? '.
+ 'ORDER BY created DESC '.
+ 'LIMIT 1',
+ implode(',', array_map(function($q) { return intval($q['quest_id']); }, $questtexts))
+ ),
+ 'ii',
+ $characterId,
+ \hhu\z\models\QuestsModel::QUEST_STATUS_ENTERED
+ );
+ if(count($data) == 0) {
+ return $questtexts[0];
+ }
+ foreach($questtexts as &$questtext) {
+ if($questtext['quest_id'] == $data[0]['quest_id']) {
+ return $questtext;
+ }
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Get all registered Questtexttypes.
+ *
+ * @return array Registered Questtexttypes
+ */
+ public function getQuesttexttypes()
+ {
+ return $this->db->query(
+ 'SELECT id, type, url '.
+ 'FROM questtexttypes'
+ );
+ }
+
+
+ /**
+ * Get a Questtexttype by its URL.
+ *
+ * @param string $questtexttypeUrl URL-type of Questtexttype
+ * @return array Questtexttype data
+ */
+ public function getQuesttexttypeByUrl($questtexttypeUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, type, url '.
+ 'FROM questtexttypes '.
+ 'WHERE url = ?',
+ 's',
+ $questtexttypeUrl
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * 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 string $text Text to add.
+ */
+ public function addQuesttextToQuest($userId, $questId, $questtexttypeUrl, $text)
+ {
+ $questtexttype = $this->getQuesttexttypeByUrl($questtexttypeUrl);
+ if(is_null($questtexttype)) {
+ return;
+ }
+
+ // 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
+ );
+ }
/**
* Copy Quest texts from one Quest to another.
- *
+ *
* @param int $userId ID of copying user
* @param int $sourceQuestId ID of source Quest
* @param int $targetQuestId ID of target Quest
@@ -325,7 +325,7 @@
$questtextIds = array();
// Get Questtexts
- $questtexts = $this->getQuesttextsOfQuest($sourceQuestId);
+ $questtexts = $this->getQuesttextsOfQuest($sourceQuestId);
// Copy each text
foreach($questtexts as &$text)
@@ -361,29 +361,29 @@
return $questtextIds;
}
-
-
- /**
- * 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']
- );
- }
-
- }
+
+ /**
+ * 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/models/QuesttopicsModel.inc b/models/QuesttopicsModel.inc
index 8950eacf..ac906fb3 100644
--- a/models/QuesttopicsModel.inc
+++ b/models/QuesttopicsModel.inc
@@ -1,110 +1,110 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Questtopics-table.
- *
- * @author Oliver Hanraths
- */
- class QuesttopicsModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new QuesttopicsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get a Questtopic by its URL.
- *
- * @param int $seminaryId ID of Seminary
- * @param string $questtopicUrl URL-Title of Questtopic
- * @return array Questtopic data
- */
- public function getQuesttopicByUrl($seminaryId, $questtopicUrl)
- {
- $data = $this->db->query(
- 'SELECT id, title, url '.
- 'FROM questtopics '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
- $seminaryId, $questtopicUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questtopicUrl);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * 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.
- *
- * @param int $seminaryId ID of Seminary
- * @return array List of Questtopics
- */
- public function getQuesttopicsForSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT id, title, url '.
- 'FROM questtopics '.
- 'WHERE seminary_id = ? '.
- 'ORDER BY title ASC',
- 'i',
- $seminaryId
- );
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with Questtopics-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttopicsModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new QuesttopicsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get a Questtopic by its URL.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @param string $questtopicUrl URL-Title of Questtopic
+ * @return array Questtopic data
+ */
+ public function getQuesttopicByUrl($seminaryId, $questtopicUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, title, url '.
+ 'FROM questtopics '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
+ $seminaryId, $questtopicUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questtopicUrl);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * 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.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @return array List of Questtopics
+ */
+ public function getQuesttopicsForSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT id, title, url '.
+ 'FROM questtopics '.
+ 'WHERE seminary_id = ? '.
+ 'ORDER BY title ASC',
+ 'i',
+ $seminaryId
+ );
+ }
/**
* Copy all Questtopics and their subtopics of a Seminary.
- *
+ *
* @param int $userId ID of creating user
* @param int $sourceSeminaryId ID of Seminary to copy from
* @param int $targetSeminaryId ID of Seminary to copy to
@@ -175,301 +175,301 @@
return $questsubtopicIds;
}
-
-
- /**
- * Get count of Quests that are linked to a Questtopic.
- *
- * @param int $questtopicId ID of Questtopic
- * @return int Count of Quests
- */
- public function getQuestCountForQuesttopic($questtopicId)
- {
- $data = $this->db->query(
- 'SELECT count(DISTINCT quests_questsubtopics.quest_id) AS c ' .
- 'FROM questsubtopics '.
- 'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
- 'WHERE questsubtopics.questtopic_id = ?',
- 'i',
- $questtopicId
- );
- if(!empty($data)) {
- return $data[0]['c'];
- }
-
-
- return 0;
- }
-
-
- /**
- * Get count of Quests that are linked to a Questtopic and are
- * unlocked by a Character.
- *
- * @param int $questtopicId ID of Questtopic
- * @param int $characterId ID of Character
- * @return int Count of Quests
- */
- public function getCharacterQuestCountForQuesttopic($questtopicId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT count(DISTINCT quests_characters.quest_id) AS c '.
- 'FROM questsubtopics '.
- 'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
- 'INNER JOIN quests_characters ON quests_characters.quest_id = quests_questsubtopics.quest_id AND quests_characters.character_id = ? AND quests_characters.status = 3 '.
- 'WHERE questsubtopics.questtopic_id = ?',
- 'ii',
- $characterId,
- $questtopicId
- );
- if(!empty($data)) {
- return $data[0]['c'];
- }
-
-
- return 0;
- }
-
-
- /**
- * Get alle Questsubtopics for a Questtopic.
- *
- * @param int $questtopicId ID of Questtopic
- * @return array List of Questsubtopics for this Questtopic
- */
- public function getSubtopicsForQuesttopic($questtopicId)
- {
- return $this->db->query(
- 'SELECT id, questtopic_id, title, url '.
- 'FROM questsubtopics '.
- 'WHERE questsubtopics.questtopic_id = ? '.
- 'ORDER BY title ASC',
- 'i',
- $questtopicId
- );
- }
-
-
- /**
- * Get all Questsubtopics for a Quest.
- *
- * @param int $questId ID of Quest
- * @return array List of Questsubtopics
- */
- public function getQuestsubtopicsForQuest($questId)
- {
- return $this->db->query(
- '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 = ? '.
- 'ORDER BY questsubtopics.title ASC',
- 'i',
- $questId
- );
- }
-
-
- /**
- * Set Questsubtopics for a Quest.
- *
- * @param int $questId ID of Quest to set subtopics for
- * @param array $questsubtopicIds List of IDs of subtopics to set
- */
- public function setQuestsubtopicsForQuest($questId, $questsubtopicIds)
- {
- $this->db->setAutocommit(false);
- try {
- // Remove Questsubtopics
- $this->db->query(
- 'DELETE FROM quests_questsubtopics '.
- 'WHERE quest_id = ?',
- 'i',
- $questId
- );
-
- // Add Questsubtopics
- foreach($questsubtopicIds as &$questsubtopicId)
- {
- $this->db->query(
- 'INSERT INTO quests_questsubtopics '.
- '(quest_id, questsubtopic_id) '.
- 'VALUES '.
- '(?, ?)',
- 'ii',
- $questId, $questsubtopicId
- );
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
-
- $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);
- }
-
- }
+
+
+ /**
+ * Get count of Quests that are linked to a Questtopic.
+ *
+ * @param int $questtopicId ID of Questtopic
+ * @return int Count of Quests
+ */
+ public function getQuestCountForQuesttopic($questtopicId)
+ {
+ $data = $this->db->query(
+ 'SELECT count(DISTINCT quests_questsubtopics.quest_id) AS c ' .
+ 'FROM questsubtopics '.
+ 'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
+ 'WHERE questsubtopics.questtopic_id = ?',
+ 'i',
+ $questtopicId
+ );
+ if(!empty($data)) {
+ return $data[0]['c'];
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Get count of Quests that are linked to a Questtopic and are
+ * unlocked by a Character.
+ *
+ * @param int $questtopicId ID of Questtopic
+ * @param int $characterId ID of Character
+ * @return int Count of Quests
+ */
+ public function getCharacterQuestCountForQuesttopic($questtopicId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT count(DISTINCT quests_characters.quest_id) AS c '.
+ 'FROM questsubtopics '.
+ 'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
+ 'INNER JOIN quests_characters ON quests_characters.quest_id = quests_questsubtopics.quest_id AND quests_characters.character_id = ? AND quests_characters.status = 3 '.
+ 'WHERE questsubtopics.questtopic_id = ?',
+ 'ii',
+ $characterId,
+ $questtopicId
+ );
+ if(!empty($data)) {
+ return $data[0]['c'];
+ }
+
+
+ return 0;
+ }
+
+
+ /**
+ * Get alle Questsubtopics for a Questtopic.
+ *
+ * @param int $questtopicId ID of Questtopic
+ * @return array List of Questsubtopics for this Questtopic
+ */
+ public function getSubtopicsForQuesttopic($questtopicId)
+ {
+ return $this->db->query(
+ 'SELECT id, questtopic_id, title, url '.
+ 'FROM questsubtopics '.
+ 'WHERE questsubtopics.questtopic_id = ? '.
+ 'ORDER BY title ASC',
+ 'i',
+ $questtopicId
+ );
+ }
+
+
+ /**
+ * Get all Questsubtopics for a Quest.
+ *
+ * @param int $questId ID of Quest
+ * @return array List of Questsubtopics
+ */
+ public function getQuestsubtopicsForQuest($questId)
+ {
+ return $this->db->query(
+ '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 = ? '.
+ 'ORDER BY questsubtopics.title ASC',
+ 'i',
+ $questId
+ );
+ }
+
+
+ /**
+ * Set Questsubtopics for a Quest.
+ *
+ * @param int $questId ID of Quest to set subtopics for
+ * @param array $questsubtopicIds List of IDs of subtopics to set
+ */
+ public function setQuestsubtopicsForQuest($questId, $questsubtopicIds)
+ {
+ $this->db->setAutocommit(false);
+ try {
+ // Remove Questsubtopics
+ $this->db->query(
+ 'DELETE FROM quests_questsubtopics '.
+ 'WHERE quest_id = ?',
+ 'i',
+ $questId
+ );
+
+ // Add Questsubtopics
+ foreach($questsubtopicIds as &$questsubtopicId)
+ {
+ $this->db->query(
+ 'INSERT INTO quests_questsubtopics '.
+ '(quest_id, questsubtopic_id) '.
+ 'VALUES '.
+ '(?, ?)',
+ 'ii',
+ $questId, $questsubtopicId
+ );
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+
+ $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/models/QuesttypesModel.inc b/models/QuesttypesModel.inc
index 58b36648..091de2d6 100644
--- a/models/QuesttypesModel.inc
+++ b/models/QuesttypesModel.inc
@@ -1,77 +1,77 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with Questtypes-table.
- *
- * @author Oliver Hanraths
- */
- class QuesttypesModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new QuesttypesModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get all registered Questtypes.
- *
- * @return array List of registered Questtypes
- */
- public function getQuesttypes()
- {
- return $this->db->query(
- 'SELECT id, title, url, classname '.
- 'FROM questtypes '.
- 'ORDER BY title ASC'
- );
- }
-
-
- /**
- * Get a Questtype by its ID
- *
- * @param int $questtypeId ID of Questtype
- * @return array Questtype data
- */
- public function getQuesttypeById($questtypeId)
- {
- $data = $this->db->query(
- 'SELECT title, classname '.
- 'FROM questtypes '.
- 'WHERE id = ?',
- 'i',
- $questtypeId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($questtypeId);
- }
-
-
- return $data = $data[0];
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with Questtypes-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class QuesttypesModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new QuesttypesModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get all registered Questtypes.
+ *
+ * @return array List of registered Questtypes
+ */
+ public function getQuesttypes()
+ {
+ return $this->db->query(
+ 'SELECT id, title, url, classname '.
+ 'FROM questtypes '.
+ 'ORDER BY title ASC'
+ );
+ }
+
+
+ /**
+ * Get a Questtype by its ID
+ *
+ * @param int $questtypeId ID of Questtype
+ * @return array Questtype data
+ */
+ public function getQuesttypeById($questtypeId)
+ {
+ $data = $this->db->query(
+ 'SELECT title, classname '.
+ 'FROM questtypes '.
+ 'WHERE id = ?',
+ 'i',
+ $questtypeId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($questtypeId);
+ }
+
+
+ return $data = $data[0];
+ }
+
+ }
?>
diff --git a/models/SeminariesModel.inc b/models/SeminariesModel.inc
index d1e972a3..ff53815c 100644
--- a/models/SeminariesModel.inc
+++ b/models/SeminariesModel.inc
@@ -1,314 +1,314 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model of the SeminariesAgent to list registered seminaries.
- *
- * @author Oliver Hanraths
- */
- class SeminariesModel extends \hhu\z\Model
- {
- /**
- * Required models
- *
- * @var array
- */
- public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields');
-
-
-
-
- /**
- * Construct a new SeminariesModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get registered seminaries.
- *
- * @return array Seminaries
- */
- public function getSeminaries()
- {
- // Get seminaries
- return $this->db->query(
- 'SELECT id, created, created_user_id, title, url, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
- 'FROM seminaries '.
- 'ORDER BY created DESC'
- );
- }
-
-
- /**
- * Get a seminary and its data by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryId ID of a seminary
- * @return array Seminary
- */
- public function getSeminaryById($seminaryId)
- {
- $seminary = $this->db->query(
- 'SELECT id, created, created_user_id, title, url, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
- 'FROM seminaries '.
- 'WHERE id = ?',
- 'i',
- $seminaryId
- );
- if(empty($seminary)) {
- throw new \nre\exceptions\IdNotFoundException($seminaryId);
- }
-
-
- return $seminary[0];
- }
-
-
- /**
- * Get a seminary and its data by its URL-title.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param string $seminaryUrl URL-Title of a seminary
- * @return array Seminary
- */
- public function getSeminaryByUrl($seminaryUrl)
- {
- $seminary = $this->db->query(
- 'SELECT id, created, created_user_id, title, url, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
- 'FROM seminaries '.
- 'WHERE url = ?',
- 's',
- $seminaryUrl
- );
- if(empty($seminary)) {
- throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
- }
-
-
- return $seminary[0];
- }
-
-
- /**
- * Calculate sum of XPs for a Seminary.
- *
- * @param int $seminaryId ID of Seminary
- * @return int Total sum of XPs
- */
- public function getTotalXPs($seminaryId)
- {
- $xps = 0;
-
- // Questgroups
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
- foreach($questgroupshierarchy as &$hierarchy)
- {
- // Get Questgroups
- $questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
- foreach($questgroups as &$questgroup) {
- $xps += $questgroup['achievable_xps'];
- }
- }
-
-
- return $xps;
- }
-
-
- /**
- * Check if a Seminary title already exists.
- *
- * @param string $title Seminary title to check
- * @param int $seminaryId Do not check this ID (for editing)
- * @return boolean Whether Seminary title exists or not
- */
- public function seminaryTitleExists($title, $seminaryId=null)
- {
- $data = $this->db->query(
- 'SELECT id '.
- 'FROM seminaries '.
- 'WHERE title = ? OR url = ?',
- 'ss',
- $title,
- \nre\core\Linker::createLinkParam($title)
- );
-
- return (!empty($data) && (is_null($seminaryId) || $seminaryId != $data[0]['id']));
- }
-
-
- /**
- * Create a new Seminary.
- *
- * @param int $userId ID of creating user
- * @param string $title Title of Seminary to create
- * @param string $course Course of Seminary
- * @param string $description Description of new Seminary
- * @return int ID of the newly created Seminary
- */
- public function createSeminary($userId, $title, $course, $description)
- {
- $this->db->query(
- 'INSERT INTO seminaries '.
- '(created_user_id, title, url, course, description) '.
- 'VALUES '.
- '(?, ?, ?, ?, ?)',
- 'issss',
- $userId,
- $title,
- \nre\core\Linker::createLinkParam($title),
- $course,
- $description
- );
-
-
- return $this->db->getInsertId();
- }
-
-
- /**
- * Set the moodpic for a Seminary.
- *
- * @param int $seminaryId ID of Seminary to set moodpic for
- * @param int $mediaId ID of moodpic media
- */
- public function setMoodpicForSeminary($seminaryId, $mediaId)
- {
- $this->db->query(
- 'UPDATE seminaries '.
- 'SET seminarymedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $mediaId,
- $seminaryId
- );
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model of the SeminariesAgent to list registered seminaries.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminariesModel extends \hhu\z\Model
+ {
+ /**
+ * Required models
+ *
+ * @var array
+ */
+ public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields');
+
+
+
+
+ /**
+ * Construct a new SeminariesModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get registered seminaries.
+ *
+ * @return array Seminaries
+ */
+ public function getSeminaries()
+ {
+ // Get seminaries
+ return $this->db->query(
+ 'SELECT id, created, created_user_id, title, url, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
+ 'FROM seminaries '.
+ 'ORDER BY created DESC'
+ );
+ }
+
+
+ /**
+ * Get a seminary and its data by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryId ID of a seminary
+ * @return array Seminary
+ */
+ public function getSeminaryById($seminaryId)
+ {
+ $seminary = $this->db->query(
+ 'SELECT id, created, created_user_id, title, url, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
+ 'FROM seminaries '.
+ 'WHERE id = ?',
+ 'i',
+ $seminaryId
+ );
+ if(empty($seminary)) {
+ throw new \nre\exceptions\IdNotFoundException($seminaryId);
+ }
+
+
+ return $seminary[0];
+ }
+
+
+ /**
+ * Get a seminary and its data by its URL-title.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param string $seminaryUrl URL-Title of a seminary
+ * @return array Seminary
+ */
+ public function getSeminaryByUrl($seminaryUrl)
+ {
+ $seminary = $this->db->query(
+ 'SELECT id, created, created_user_id, title, url, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
+ 'FROM seminaries '.
+ 'WHERE url = ?',
+ 's',
+ $seminaryUrl
+ );
+ if(empty($seminary)) {
+ throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
+ }
+
+
+ return $seminary[0];
+ }
+
+
+ /**
+ * Calculate sum of XPs for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary
+ * @return int Total sum of XPs
+ */
+ public function getTotalXPs($seminaryId)
+ {
+ $xps = 0;
+
+ // Questgroups
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
+ foreach($questgroupshierarchy as &$hierarchy)
+ {
+ // Get Questgroups
+ $questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
+ foreach($questgroups as &$questgroup) {
+ $xps += $questgroup['achievable_xps'];
+ }
+ }
+
+
+ return $xps;
+ }
+
+
+ /**
+ * Check if a Seminary title already exists.
+ *
+ * @param string $title Seminary title to check
+ * @param int $seminaryId Do not check this ID (for editing)
+ * @return boolean Whether Seminary title exists or not
+ */
+ public function seminaryTitleExists($title, $seminaryId=null)
+ {
+ $data = $this->db->query(
+ 'SELECT id '.
+ 'FROM seminaries '.
+ 'WHERE title = ? OR url = ?',
+ 'ss',
+ $title,
+ \nre\core\Linker::createLinkParam($title)
+ );
+
+ return (!empty($data) && (is_null($seminaryId) || $seminaryId != $data[0]['id']));
+ }
+
+
+ /**
+ * Create a new Seminary.
+ *
+ * @param int $userId ID of creating user
+ * @param string $title Title of Seminary to create
+ * @param string $course Course of Seminary
+ * @param string $description Description of new Seminary
+ * @return int ID of the newly created Seminary
+ */
+ public function createSeminary($userId, $title, $course, $description)
+ {
+ $this->db->query(
+ 'INSERT INTO seminaries '.
+ '(created_user_id, title, url, course, description) '.
+ 'VALUES '.
+ '(?, ?, ?, ?, ?)',
+ 'issss',
+ $userId,
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $course,
+ $description
+ );
+
+
+ return $this->db->getInsertId();
+ }
+
+
+ /**
+ * Set the moodpic for a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary to set moodpic for
+ * @param int $mediaId ID of moodpic media
+ */
+ public function setMoodpicForSeminary($seminaryId, $mediaId)
+ {
+ $this->db->query(
+ 'UPDATE seminaries '.
+ 'SET seminarymedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $mediaId,
+ $seminaryId
+ );
+ }
/**
* Set the moodpic for the Character groups of a Seminary.
- *
+ *
* @param int $seminaryId ID of Seminary to set moodpic for Character groups for
* @param int $seminaryMediaId ID of Seminarymedia to set as moodpic
*/
public function setMoodpicForCharactergroups($seminaryId, $seminaryMediaId)
{
- $this->db->query(
- 'UPDATE seminaries '.
- 'SET charactergroups_seminarymedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $seminaryMediaId,
- $seminaryId
- );
+ $this->db->query(
+ 'UPDATE seminaries '.
+ 'SET charactergroups_seminarymedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $seminaryMediaId,
+ $seminaryId
+ );
}
/**
* Set the moodpic for the Achievements of a Seminary.
- *
+ *
* @param int $seminaryId ID of Seminary to set moodpic for Achievements for
* @param int $seminaryMediaId ID of Seminarymedia to set as moodpic
*/
public function setMoodpicForAchievements($seminaryId, $seminaryMediaId)
{
- $this->db->query(
- 'UPDATE seminaries '.
- 'SET achievements_seminarymedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $seminaryMediaId,
- $seminaryId
- );
+ $this->db->query(
+ 'UPDATE seminaries '.
+ 'SET achievements_seminarymedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $seminaryMediaId,
+ $seminaryId
+ );
}
/**
* Set the moodpic for the library of a Seminary.
- *
+ *
* @param int $seminaryId ID of Seminary to set moodpic for Library for
* @param int $seminaryMediaId ID of Seminarymedia to set as moodpic
*/
public function setMoodpicForLibrary($seminaryId, $seminaryMediaId)
{
- $this->db->query(
- 'UPDATE seminaries '.
- 'SET library_seminarymedia_id = ? '.
- 'WHERE id = ?',
- 'ii',
- $seminaryMediaId,
- $seminaryId
- );
+ $this->db->query(
+ 'UPDATE seminaries '.
+ 'SET library_seminarymedia_id = ? '.
+ 'WHERE id = ?',
+ 'ii',
+ $seminaryMediaId,
+ $seminaryId
+ );
}
/**
- * (Re-) Calculate the amount of achievable XPs for a Seminary.
- *
+ * (Re-) Calculate the amount of achievable XPs for a Seminary.
+ *
* @param int $seminaryId ID of Seminary to calculate XPs for
*/
public function calculateXPsForSeminary($seminaryId)
{
- // Questgrouphierarchy and Questgroups
- $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
- foreach($questgroupshierarchy as &$hierarchy)
- {
- // Get Questgroups
- $hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
- foreach($hierarchy['questgroups'] as &$questgroup)
- {
- // Calculate achievable XPs
- $this->Questgroups->calculateXPsForQuestgroup($questgroup['id']);
- }
- }
+ // Questgrouphierarchy and Questgroups
+ $questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
+ foreach($questgroupshierarchy as &$hierarchy)
+ {
+ // Get Questgroups
+ $hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
+ foreach($hierarchy['questgroups'] as &$questgroup)
+ {
+ // Calculate achievable XPs
+ $this->Questgroups->calculateXPsForQuestgroup($questgroup['id']);
+ }
+ }
+ }
+
+
+ /**
+ * Edit a seminary.
+ *
+ * @throws \nre\exceptions\DatamodelException
+ * @param int $seminaryId ID of Seminary to edit
+ * @param string $title New title of Seminary
+ * @param string $course New course of Seminary
+ * @param string $description New description of Seminary
+ */
+ public function editSeminary($seminaryId, $title, $course, $description)
+ {
+ $this->db->query(
+ 'UPDATE seminaries '.
+ 'SET title = ?, url = ?, course = ?, description = ? '.
+ 'WHERE id = ?',
+ 'ssssi',
+ $title,
+ \nre\core\Linker::createLinkParam($title),
+ $course,
+ $description,
+ $seminaryId
+ );
}
-
-
- /**
- * Edit a seminary.
- *
- * @throws \nre\exceptions\DatamodelException
- * @param int $seminaryId ID of Seminary to edit
- * @param string $title New title of Seminary
- * @param string $course New course of Seminary
- * @param string $description New description of Seminary
- */
- public function editSeminary($seminaryId, $title, $course, $description)
- {
- $this->db->query(
- 'UPDATE seminaries '.
- 'SET title = ?, url = ?, course = ?, description = ? '.
- 'WHERE id = ?',
- 'ssssi',
- $title,
- \nre\core\Linker::createLinkParam($title),
- $course,
- $description,
- $seminaryId
- );
- }
/**
* Copy a Seminary and its content.
- *
+ *
* @param int $userId ID of copying user
* @param int $sourceSeminaryId ID of Seminary to copy
* @param string $title Title of new Seminary
@@ -328,8 +328,8 @@
* @param boolean $copyCharactergroupsquests Whether to copy Character groups Quests or not
* @return ID of newly created Seminary
*/
- public function copySeminary($userId, $sourceSeminaryId, $title, $course, $description, $copySeminaryfields, $copyMedia, $copyQuestgroupshierarchy, $copyQuestgroups, $copyQuests, $copyQuesttopics, $copyCharactertypes, $copyXPlevels, $copyAvatars, $copyAchievements, $copyCharactergroupsgroups, $copyCharactergroupsquests)
- {
+ public function copySeminary($userId, $sourceSeminaryId, $title, $course, $description, $copySeminaryfields, $copyMedia, $copyQuestgroupshierarchy, $copyQuestgroups, $copyQuests, $copyQuesttopics, $copyCharactertypes, $copyXPlevels, $copyAvatars, $copyAchievements, $copyCharactergroupsgroups, $copyCharactergroupsquests)
+ {
// Get Seminary
$seminary = $this->getSeminaryById($sourceSeminaryId);
@@ -426,31 +426,31 @@
// Recalculate XPs
$this->calculateXPsForSeminary($targetSeminaryId);
- $this->db->commit();
- }
+ $this->db->commit();
+ }
catch(\Exception $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- throw $e;
- }
- $this->db->setAutocommit(true);
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ throw $e;
+ }
+ $this->db->setAutocommit(true);
return $targetSeminaryId;
}
-
-
- /**
- * Delete a seminary.
- * TODO Delete media
- *
- * @param int $seminaryId ID of the seminary to delete
- */
- public function deleteSeminary($seminaryId)
- {
- $this->db->query('DELETE FROM seminaries WHERE id = ?', 'i', $seminaryId);
- }
- }
+
+ /**
+ * Delete a seminary.
+ * TODO Delete media
+ *
+ * @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/SeminarycharacterfieldsModel.inc b/models/SeminarycharacterfieldsModel.inc
index 78dc3c18..af2feb8d 100644
--- a/models/SeminarycharacterfieldsModel.inc
+++ b/models/SeminarycharacterfieldsModel.inc
@@ -1,133 +1,133 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with the Seminarycharacterfields-tables.
- *
- * @author Oliver Hanraths
- */
- class SeminarycharacterfieldsModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new SeminarycharacterfieldsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get all Character fields of a Seminary.
- *
- * @param int $seminaryId ID of Seminary to get fields of
- * @param array Seminary Character fields
- */
- public function getFieldsForSeminary($seminaryId)
- {
- return $this->db->query(
- 'SELECT seminarycharacterfields.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url '.
- 'FROM seminarycharacterfields '.
- 'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
- 'WHERE seminarycharacterfields.seminary_id = ? '.
- 'ORDER BY pos ASC',
- 'i',
- $seminaryId
- );
- }
-
-
- /**
- * Set the value of a Seminary field for a Character.
- *
- * @param int $characterId ID of Character
- * @param int $seminarycharacterfieldId ID of seminarycharacterfield to set value of
- * @param string $value Value to set
- */
- public function setSeminaryFieldOfCharacter($seminarycharacterfieldId, $characterId, $value)
- {
- $this->db->query(
- 'INSERT INTO characters_seminarycharacterfields '.
- '(character_id, seminarycharacterfield_id, value) '.
- 'VALUES '.
- '(?, ?, ?) '.
- 'ON DUPLICATE KEY UPDATE '.
- 'value = ?',
- 'iiss',
- $characterId,
- $seminarycharacterfieldId,
- $value,
- $value
- );
- }
-
-
- /**
- * Get Seminary Character fields of a Character.
- *
- * @param int $fieldId ID of Seminary Character field
- * @param int $characterId ID of the Character
- * @return array Seminary Character fields
- */
- public function getSeminaryFieldOfCharacter($fieldId, $characterId)
- {
- $data = $this->db->query(
- 'SELECT created, value '.
- 'FROM characters_seminarycharacterfields '.
- 'WHERE seminarycharacterfield_id = ? AND character_id = ?',
- 'ii',
- $fieldId,
- $characterId
- );
- if(!empty($data)) {
- return $data[0];
- }
-
-
- return null;
- }
-
-
- /**
- * Get Seminary Character fields of a Character.
- *
- * @param int $characterId ID of the Character
- * @return array Seminary Character fields
- */
- public function getFieldsForCharacter($characterId)
- {
- return $this->db->query(
- 'SELECT seminarycharacterfields.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url, characters_seminarycharacterfields.value '.
- 'FROM characters_seminarycharacterfields '.
- 'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id '.
- 'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
- 'WHERE characters_seminarycharacterfields.character_id = ?',
- 'i',
- $characterId
- );
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with the Seminarycharacterfields-tables.
+ *
+ * @author Oliver Hanraths
+ */
+ class SeminarycharacterfieldsModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new SeminarycharacterfieldsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get all Character fields of a Seminary.
+ *
+ * @param int $seminaryId ID of Seminary to get fields of
+ * @param array Seminary Character fields
+ */
+ public function getFieldsForSeminary($seminaryId)
+ {
+ return $this->db->query(
+ 'SELECT seminarycharacterfields.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url '.
+ 'FROM seminarycharacterfields '.
+ 'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
+ 'WHERE seminarycharacterfields.seminary_id = ? '.
+ 'ORDER BY pos ASC',
+ 'i',
+ $seminaryId
+ );
+ }
+
+
+ /**
+ * Set the value of a Seminary field for a Character.
+ *
+ * @param int $characterId ID of Character
+ * @param int $seminarycharacterfieldId ID of seminarycharacterfield to set value of
+ * @param string $value Value to set
+ */
+ public function setSeminaryFieldOfCharacter($seminarycharacterfieldId, $characterId, $value)
+ {
+ $this->db->query(
+ 'INSERT INTO characters_seminarycharacterfields '.
+ '(character_id, seminarycharacterfield_id, value) '.
+ 'VALUES '.
+ '(?, ?, ?) '.
+ 'ON DUPLICATE KEY UPDATE '.
+ 'value = ?',
+ 'iiss',
+ $characterId,
+ $seminarycharacterfieldId,
+ $value,
+ $value
+ );
+ }
+
+
+ /**
+ * Get Seminary Character fields of a Character.
+ *
+ * @param int $fieldId ID of Seminary Character field
+ * @param int $characterId ID of the Character
+ * @return array Seminary Character fields
+ */
+ public function getSeminaryFieldOfCharacter($fieldId, $characterId)
+ {
+ $data = $this->db->query(
+ 'SELECT created, value '.
+ 'FROM characters_seminarycharacterfields '.
+ 'WHERE seminarycharacterfield_id = ? AND character_id = ?',
+ 'ii',
+ $fieldId,
+ $characterId
+ );
+ if(!empty($data)) {
+ return $data[0];
+ }
+
+
+ return null;
+ }
+
+
+ /**
+ * Get Seminary Character fields of a Character.
+ *
+ * @param int $characterId ID of the Character
+ * @return array Seminary Character fields
+ */
+ public function getFieldsForCharacter($characterId)
+ {
+ return $this->db->query(
+ 'SELECT seminarycharacterfields.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url, characters_seminarycharacterfields.value '.
+ 'FROM characters_seminarycharacterfields '.
+ 'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id '.
+ 'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
+ 'WHERE characters_seminarycharacterfields.character_id = ?',
+ 'i',
+ $characterId
+ );
+ }
/**
* Copy all Character fields of a Seminary.
- *
+ *
* @param int $userId ID of copying user
* @param int $sourceSeminaryId ID of Seminary to copy from
* @param int $targetSeminaryId ID of Seminary to copy to
@@ -145,7 +145,7 @@
$sourceSeminaryId
);
}
-
- }
+
+ }
?>
diff --git a/models/UploadsModel.inc b/models/UploadsModel.inc
index 26f188a0..7a555659 100644
--- a/models/UploadsModel.inc
+++ b/models/UploadsModel.inc
@@ -1,157 +1,157 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to handle files to upload.
- *
- * @author Oliver Hanraths
- */
- class UploadsModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new UploadsModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Upload a file and create a database record.
- *
- * @param int $userId ID of user that uploads the file
- * @param int $seminaryId ID of Seminary
- * @param string $name Name of file to upload
- * @param string $filename Filename of file to upload
- * @param string $tmpFilename Name of temporary uploaded file
- * @param string $mimetype Mimetype of file to upload
- * @return mixed ID of database record or false
- */
- public function uploadSeminaryFile($userId, $seminaryId, $name, $filename, $tmpFilename, $mimetype)
- {
- $uploadId = false;
- $this->db->setAutocommit(false);
-
- try {
- // Create database record
- $this->db->query(
- 'INSERT INTO seminaryuploads '.
- '(created_user_id, seminary_id, name, url, mimetype) '.
- 'VALUES '.
- '(?, ? ,? ,?, ?)',
- 'iisss',
- $userId,
- $seminaryId,
- $name,
- \nre\core\Linker::createLinkParam($filename),
- $mimetype
- );
- $uploadId = $this->db->getInsertId();
-
- // Create filename
- $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$filename;
- if(!move_uploaded_file($tmpFilename, $filename))
- {
- $this->db->rollback();
- $uploadId = false;
- }
- }
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
-
- $this->db->setAutocommit(true);
- return $uploadId;
- }
-
-
- /**
- * Get an upload by its ID.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $uploadId ID of the uploaded file
- * @return array Upload data
- */
- public function getSeminaryuploadById($seminaryuploadId)
- {
- $data = $this->db->query(
- 'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
- 'FROM seminaryuploads '.
- 'WHERE id = ?',
- 'i',
- $seminaryuploadId
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($seminaryuploadId);
- }
-
-
- return $data[0];
- }
-
-
- /**
- * Get an upload by its URL.
- *
- * @throws \nre\exceptions\IdNotFoundException
- * @param int $seminaryId ID of Seminary
- * @param int $uploadId ID of the uploaded file
- * @return array Upload data
- */
- public function getSeminaryuploadByUrl($seminaryId, $seminaryuploadUrl)
- {
- $data = $this->db->query(
- 'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
- 'FROM seminaryuploads '.
- 'WHERE seminary_id = ? AND url = ?',
- 'is',
- $seminaryId,
- $seminaryuploadUrl
- );
- if(empty($data)) {
- throw new \nre\exceptions\IdNotFoundException($seminaryuploadUrl);
- }
-
-
- return $data[0];
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to handle files to upload.
+ *
+ * @author Oliver Hanraths
+ */
+ class UploadsModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new UploadsModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Upload a file and create a database record.
+ *
+ * @param int $userId ID of user that uploads the file
+ * @param int $seminaryId ID of Seminary
+ * @param string $name Name of file to upload
+ * @param string $filename Filename of file to upload
+ * @param string $tmpFilename Name of temporary uploaded file
+ * @param string $mimetype Mimetype of file to upload
+ * @return mixed ID of database record or false
+ */
+ public function uploadSeminaryFile($userId, $seminaryId, $name, $filename, $tmpFilename, $mimetype)
+ {
+ $uploadId = false;
+ $this->db->setAutocommit(false);
+
+ try {
+ // Create database record
+ $this->db->query(
+ 'INSERT INTO seminaryuploads '.
+ '(created_user_id, seminary_id, name, url, mimetype) '.
+ 'VALUES '.
+ '(?, ? ,? ,?, ?)',
+ 'iisss',
+ $userId,
+ $seminaryId,
+ $name,
+ \nre\core\Linker::createLinkParam($filename),
+ $mimetype
+ );
+ $uploadId = $this->db->getInsertId();
+
+ // Create filename
+ $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$filename;
+ if(!move_uploaded_file($tmpFilename, $filename))
+ {
+ $this->db->rollback();
+ $uploadId = false;
+ }
+ }
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+
+ $this->db->setAutocommit(true);
+ return $uploadId;
+ }
+
+
+ /**
+ * Get an upload by its ID.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $uploadId ID of the uploaded file
+ * @return array Upload data
+ */
+ public function getSeminaryuploadById($seminaryuploadId)
+ {
+ $data = $this->db->query(
+ 'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
+ 'FROM seminaryuploads '.
+ 'WHERE id = ?',
+ 'i',
+ $seminaryuploadId
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($seminaryuploadId);
+ }
+
+
+ return $data[0];
+ }
+
+
+ /**
+ * Get an upload by its URL.
+ *
+ * @throws \nre\exceptions\IdNotFoundException
+ * @param int $seminaryId ID of Seminary
+ * @param int $uploadId ID of the uploaded file
+ * @return array Upload data
+ */
+ public function getSeminaryuploadByUrl($seminaryId, $seminaryuploadUrl)
+ {
+ $data = $this->db->query(
+ 'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
+ 'FROM seminaryuploads '.
+ 'WHERE seminary_id = ? AND url = ?',
+ 'is',
+ $seminaryId,
+ $seminaryuploadUrl
+ );
+ if(empty($data)) {
+ throw new \nre\exceptions\IdNotFoundException($seminaryuploadUrl);
+ }
+
+
+ return $data[0];
+ }
/**
* Delete a Seminary upload.
- *
+ *
* @param int $uploadId ID of Seminary upload to delete
*/
public function deleteSeminaryupload($uploadId)
{
- $this->db->setAutocommit(false);
-
- try {
+ $this->db->setAutocommit(false);
+
+ try {
// Get Upload
$upload = $this->getSeminaryuploadById($uploadId);
-
+
// Delete database record
- $this->db->query(
+ $this->db->query(
'DELETE FROM seminaryuploads '.
'WHERE id = ?',
'i',
@@ -162,14 +162,14 @@
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$upload['url'];
unlink($filename);
}
- catch(\nre\exceptions\DatamodelException $e) {
- $this->db->rollback();
- $this->db->setAutocommit(true);
- }
-
- $this->db->setAutocommit(true);
+ catch(\nre\exceptions\DatamodelException $e) {
+ $this->db->rollback();
+ $this->db->setAutocommit(true);
+ }
+
+ $this->db->setAutocommit(true);
}
-
- }
+
+ }
?>
diff --git a/models/UserrolesModel.inc b/models/UserrolesModel.inc
index ebdd00f1..f9064b49 100644
--- a/models/UserrolesModel.inc
+++ b/models/UserrolesModel.inc
@@ -1,120 +1,120 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model to interact with userroles-table.
- *
- * @author Oliver Hanraths
- */
- class UserrolesModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new UserrolesModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get all userroles for an user referenced by its ID.
- *
- * @param int $userId ID of an user
- * @return array Userroles for an user
- */
- public function getUserrolesForUserById($userId)
- {
- return $this->db->query(
- 'SELECT userroles.id, userroles.created, userroles.name '.
- 'FROM users_userroles '.
- 'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
- 'WHERE users_userroles.user_id = ?',
- 'i',
- $userId
- );
- }
-
-
- /**
- * Get all userroles for an user referenced by its URL-username.
- *
- * @param string $userUrl URL-Username of an user
- * @return array Userroles for an user
- */
- public function getUserrolesForUserByUrl($userUrl)
- {
- return $this->db->query(
- 'SELECT userroles.id, userroles.created, userroles.name '.
- 'FROM users '.
- 'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
- 'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
- 'WHERE users.url = ?',
- 's',
- $userUrl
- );
- }
-
-
- /**
- * Add a role to a user.
- *
- * @param int $userId ID of user to add role to
- * @param string $userrole Role to add
- */
- public function addUserroleToUser($userId, $userrole)
- {
- $this->db->query(
- 'INSERT IGNORE INTO users_userroles '.
- '(user_id, userrole_id) '.
- 'SELECT ?, id '.
- 'FROM userroles '.
- 'WHERE name = ?',
- 'is',
- $userId,
- $userrole
- );
- }
-
-
- /**
- * Remove a role from a user.
- *
- * @param int $userId ID of user to remove role from
- * @param string $userrole Role to remove
- */
- public function removeUserroleFromUser($userId, $userrole)
- {
- $this->db->query(
- 'DELETE FROM users_userroles '.
- 'WHERE user_id = ? AND userrole_id = ('.
- 'SELECT id '.
- 'FROM userroles '.
- 'WHERE name = ?'.
- ')',
- 'is',
- $userId,
- $userrole
- );
- }
-
- }
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model to interact with userroles-table.
+ *
+ * @author Oliver Hanraths
+ */
+ class UserrolesModel extends \hhu\z\Model
+ {
+
+
+
+
+ /**
+ * Construct a new UserrolesModel.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+
+
+ /**
+ * Get all userroles for an user referenced by its ID.
+ *
+ * @param int $userId ID of an user
+ * @return array Userroles for an user
+ */
+ public function getUserrolesForUserById($userId)
+ {
+ return $this->db->query(
+ 'SELECT userroles.id, userroles.created, userroles.name '.
+ 'FROM users_userroles '.
+ 'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
+ 'WHERE users_userroles.user_id = ?',
+ 'i',
+ $userId
+ );
+ }
+
+
+ /**
+ * Get all userroles for an user referenced by its URL-username.
+ *
+ * @param string $userUrl URL-Username of an user
+ * @return array Userroles for an user
+ */
+ public function getUserrolesForUserByUrl($userUrl)
+ {
+ return $this->db->query(
+ 'SELECT userroles.id, userroles.created, userroles.name '.
+ 'FROM users '.
+ 'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
+ 'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
+ 'WHERE users.url = ?',
+ 's',
+ $userUrl
+ );
+ }
+
+
+ /**
+ * Add a role to a user.
+ *
+ * @param int $userId ID of user to add role to
+ * @param string $userrole Role to add
+ */
+ public function addUserroleToUser($userId, $userrole)
+ {
+ $this->db->query(
+ 'INSERT IGNORE INTO users_userroles '.
+ '(user_id, userrole_id) '.
+ 'SELECT ?, id '.
+ 'FROM userroles '.
+ 'WHERE name = ?',
+ 'is',
+ $userId,
+ $userrole
+ );
+ }
+
+
+ /**
+ * Remove a role from a user.
+ *
+ * @param int $userId ID of user to remove role from
+ * @param string $userrole Role to remove
+ */
+ public function removeUserroleFromUser($userId, $userrole)
+ {
+ $this->db->query(
+ 'DELETE FROM users_userroles '.
+ 'WHERE user_id = ? AND userrole_id = ('.
+ 'SELECT id '.
+ 'FROM userroles '.
+ 'WHERE name = ?'.
+ ')',
+ 'is',
+ $userId,
+ $userrole
+ );
+ }
+
+ }
?>
diff --git a/models/UsersModel.inc b/models/UsersModel.inc
index 6d4de5e7..d4cc1961 100644
--- a/models/UsersModel.inc
+++ b/models/UsersModel.inc
@@ -1,47 +1,47 @@
- * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
- * @license http://www.gnu.org/licenses/gpl.html
- * @link https://bitbucket.org/coderkun/the-legend-of-z
- */
-
- namespace hhu\z\models;
-
-
- /**
- * Model of the UsersAgent to list users and get their data.
- *
- * @author Oliver Hanraths
- */
- class UsersModel extends \hhu\z\Model
- {
-
-
-
-
- /**
- * Construct a new UsersModel.
- */
- public function __construct()
- {
- parent::__construct();
- }
-
-
-
-
- /**
- * Get count of registered users.
- *
- * @param string $username Only get users with the given username (optional)
- * @return int Count of users
- */
- public function getUsersCount($username=null, $name=null, $email=null)
- {
+ /**
+ * The Legend of Z
+ *
+ * @author Oliver Hanraths
+ * @copyright 2014 Heinrich-Heine-Universität Düsseldorf
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @link https://bitbucket.org/coderkun/the-legend-of-z
+ */
+
+ namespace hhu\z\models;
+
+
+ /**
+ * Model of the UsersAgent to list users and get their data.
+ *
+ * @author Oliver Hanraths