use NotificationComponent to notify of new Achievements and Level-ups and show them in HTML-layout view (Issue #128)
This commit is contained in:
parent
87fe1f9754
commit
fc35d5fdc2
4 changed files with 61 additions and 4 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'));
|
||||
|
|
|
|||
|
|
@ -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