diff --git a/app/controllers/SeminaryController.inc b/app/controllers/SeminaryController.inc index b20f4d3c..abd18350 100644 --- a/app/controllers/SeminaryController.inc +++ b/app/controllers/SeminaryController.inc @@ -25,7 +25,7 @@ * * @var array */ - public $components = array('achievement', 'auth'); + public $components = array('achievement', 'auth', 'notification'); /** * Required models * @@ -166,7 +166,7 @@ foreach($achievements as &$achievement) { // Check deadline - if($achievement['deadline'] < date('Y-m-d H:i:s')) { + if(!is_null($achievement['deadline']) && $achievement['deadline'] < date('Y-m-d H:i:s')) { continue; } @@ -278,9 +278,19 @@ } - // Set status - if($achieved) { + // 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/controllers/HtmlController.inc b/controllers/HtmlController.inc index 2d7eef25..4c85e074 100644 --- a/controllers/HtmlController.inc +++ b/controllers/HtmlController.inc @@ -19,6 +19,12 @@ */ class HtmlController extends \hhu\z\Controller { + /** + * Required components + * + * @var array + */ + public $components = array('notification'); @@ -52,6 +58,9 @@ $this->set('loggedUser', IntermediateController::$user); $this->set('loggedSeminary', SeminaryController::$seminary); $this->set('loggedCharacter', SeminaryController::$character); + + // Set notifications + $this->set('notifications', $this->Notification->getNotifications()); } } diff --git a/controllers/QuestsController.inc b/controllers/QuestsController.inc index 8a60b3bc..9c91a9b3 100644 --- a/controllers/QuestsController.inc +++ b/controllers/QuestsController.inc @@ -600,6 +600,16 @@ { // Mark Quest as solved $this->Quests->setQuestSolved($quest['id'], $character['id']); + + // Notify of XP-level change + $newXPLevel = $this->Characters->getXPLevelOfCharacters($character['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')); diff --git a/controllers/SeminarymenuController.inc b/controllers/SeminarymenuController.inc index 30311c93..1a3002c2 100644 --- a/controllers/SeminarymenuController.inc +++ b/controllers/SeminarymenuController.inc @@ -18,7 +18,7 @@ * * @author Oliver Hanraths */ - class SeminarymenuController extends \hhu\z\controllers\SeminaryController + class SeminarymenuController extends \hhu\z\Controller { @@ -35,8 +35,8 @@ parent::preFilter($request, $response); // Set userdata - $this->set('loggedUser', self::$user); - $this->set('loggedSeminary', self::$seminary); + $this->set('loggedUser', \hhu\z\controllers\IntermediateController::$user); + $this->set('loggedSeminary', \hhu\z\controllers\SeminaryController::$seminary); } diff --git a/controllers/components/NotificationComponent.inc b/controllers/components/NotificationComponent.inc new file mode 100644 index 00000000..bddffc80 --- /dev/null +++ b/controllers/components/NotificationComponent.inc @@ -0,0 +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(); + } + + } + +?> diff --git a/models/CharactersModel.inc b/models/CharactersModel.inc index 329a7403..3fef517d 100644 --- a/models/CharactersModel.inc +++ b/models/CharactersModel.inc @@ -405,6 +405,12 @@ } + /** + * Get all XP-levels for a Seminary. + * + * @param int $seminaryId ID of Seminary + * @return array List of XP-levels + */ public function getXPLevelsForSeminary($seminaryId) { return $this->db->query( diff --git a/views/html/html.tpl b/views/html/html.tpl index d66846bb..32acd4c2 100644 --- a/views/html/html.tpl +++ b/views/html/html.tpl @@ -51,6 +51,34 @@
+ 0) : ?> +
    + + +
  • + + + + : + + + + + +
  • + +
  • + : + + + + + +
  • + + +
+