merge
This commit is contained in:
commit
4b0830c930
7 changed files with 178 additions and 7 deletions
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
108
controllers/components/NotificationComponent.inc
Normal file
108
controllers/components/NotificationComponent.inc
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @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 <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -51,6 +51,34 @@
|
|||
</nav>
|
||||
</header>
|
||||
<article class="wrap">
|
||||
<?php if(count($notifications) > 0) : ?>
|
||||
<ul class="notifications">
|
||||
<?php foreach($notifications as &$notification) : ?>
|
||||
<?php if($notification['type'] == \hhu\z\controllers\components\NotificationComponent::TYPE_ACHIEVEMENT) : ?>
|
||||
<li class="achievement">
|
||||
<?php if(!is_null($notification['image'])) : ?>
|
||||
<img src="<?=$notification['image']?>" />
|
||||
<?php endif ?>
|
||||
<small><?=_('Achievement achieved')?>:</small>
|
||||
<?php if(!is_null($notification['link'])) : ?>
|
||||
<a href="<?=$notification['link']?>"><?=$notification['message']?></a>
|
||||
<?php else : ?>
|
||||
<?=$notification['message']?>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php else : ?>
|
||||
<li class="lvlup">
|
||||
<small><?=_('Level-up')?>:</small>
|
||||
<?php if(!is_null($notification['link'])) : ?>
|
||||
<a href="<?=$notification['link']?>"><?=sprintf(_('You have reached level %d'), $notification['message'])?></a>
|
||||
<?php else : ?>
|
||||
<?=sprintf(_('You have reached level %d'), $notification['message'])?>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<?=$intermediate?>
|
||||
</article>
|
||||
<aside>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue