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
ac04034825
commit
72ab7505be
4 changed files with 61 additions and 4 deletions
|
|
@ -25,7 +25,7 @@
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $components = array('achievement', 'auth');
|
public $components = array('achievement', 'auth', 'notification');
|
||||||
/**
|
/**
|
||||||
* Required models
|
* Required models
|
||||||
*
|
*
|
||||||
|
|
@ -166,7 +166,7 @@
|
||||||
foreach($achievements as &$achievement)
|
foreach($achievements as &$achievement)
|
||||||
{
|
{
|
||||||
// Check deadline
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,9 +278,19 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set status
|
// Achievement achieved
|
||||||
if($achieved) {
|
if($achieved)
|
||||||
|
{
|
||||||
|
// Set status
|
||||||
$this->Achievements->setAchievementAchieved($achievement['id'], self::$character['id']);
|
$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
|
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('loggedUser', IntermediateController::$user);
|
||||||
$this->set('loggedSeminary', SeminaryController::$seminary);
|
$this->set('loggedSeminary', SeminaryController::$seminary);
|
||||||
$this->set('loggedCharacter', SeminaryController::$character);
|
$this->set('loggedCharacter', SeminaryController::$character);
|
||||||
|
|
||||||
|
// Set notifications
|
||||||
|
$this->set('notifications', $this->Notification->getNotifications());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -600,6 +600,16 @@
|
||||||
{
|
{
|
||||||
// Mark Quest as solved
|
// Mark Quest as solved
|
||||||
$this->Quests->setQuestSolved($quest['id'], $character['id']);
|
$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
|
// Redirect
|
||||||
$this->redirect($this->linker->link(array(), 5, true, array('status'=>'solved'), false, 'task'));
|
$this->redirect($this->linker->link(array(), 5, true, array('status'=>'solved'), false, 'task'));
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,34 @@
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
<article class="wrap">
|
<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?>
|
<?=$intermediate?>
|
||||||
</article>
|
</article>
|
||||||
<aside>
|
<aside>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue