91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Subclass for representing a row from the 'st_notification' table.
|
|
*
|
|
*
|
|
*
|
|
* @package plugins.stNotificationPlugin.lib.model
|
|
*/
|
|
class Notification extends BaseNotification
|
|
{
|
|
public function getTypeLabel()
|
|
{
|
|
$types = stNotification::getTypes(sfContext::getInstance()->getI18N());
|
|
|
|
return $types[$this->type];
|
|
}
|
|
|
|
public function getAction()
|
|
{
|
|
$action = parent::getAction();
|
|
|
|
if (is_callable($action))
|
|
{
|
|
return call_user_func($action, sfContext::getInstance());
|
|
}
|
|
|
|
return $action;
|
|
}
|
|
|
|
public function getMessage()
|
|
{
|
|
$formatNumberChoice = null;
|
|
$messageParams = array();
|
|
$i18n = sfContext::getInstance()->getI18N();
|
|
$catalogue = $this->getI18nCatalogue();
|
|
$message = parent::getMessage();
|
|
|
|
if ($message[0] == '@')
|
|
{
|
|
list($message, $messageParams) = unserialize(ltrim($message, '@'));
|
|
}
|
|
|
|
if (false !== strpos($message, '::') && is_callable($message))
|
|
{
|
|
return call_user_func($message, $messageParams, sfContext::getInstance());
|
|
}
|
|
|
|
if (isset($messageParams['format_number_choice']) && $messageParams['format_number_choice'])
|
|
{
|
|
$formatNumberChoice = $messageParams['format_number_choice'];
|
|
unset($messageParams['format_number_choice']);
|
|
}
|
|
|
|
$messageParams['%number%'] = $this->getCallCount();
|
|
|
|
$translatedMessage = $i18n->__($message, $messageParams, 'stNotificationBackend');
|
|
|
|
if ($i18n->hasTranslation($message, $catalogue))
|
|
{
|
|
$translatedMessage = $i18n->__($message, $messageParams, $catalogue);
|
|
}
|
|
|
|
if ($formatNumberChoice)
|
|
{
|
|
$choice = new sfChoiceFormat();
|
|
$translatedMessage = $choice->format($translatedMessage, is_numeric($formatNumberChoice) ? $formatNumberChoice : $messageParams[$formatNumberChoice]);
|
|
}
|
|
|
|
return $translatedMessage;
|
|
}
|
|
|
|
public function updateNotifiedAt()
|
|
{
|
|
$this->setCreatedAt(time());
|
|
$this->setIsMarkedAsRead(false);
|
|
}
|
|
|
|
public function incrementCallCount()
|
|
{
|
|
$this->setCallCount($this->getCallCount() + 1);
|
|
}
|
|
|
|
public function decrementCallCount()
|
|
{
|
|
$callCount = $this->getCallCount() - 1;
|
|
|
|
$this->setCallCount($callCount >= 0 ? $callCount : 0);
|
|
}
|
|
}
|