Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/models/notifications/Notification.php

63 lines
2.5 KiB
PHP
Raw Normal View History

2018-10-16 16:28:42 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once 'NotificationGroup.php';
abstract class Notification
{
public $recipient;
public $sender;
public $unread;
public $type;
public $parameters;
public $referenceID;
public $createdAt;
public function __construct(array $data)
{
$this->recipient = new NotificationUser($data['recipientID'],
isset($data['recipientName']) ? $data['recipientName'] : '',
isset($data['recipientDisplayname']) ? $data['recipientDisplayname'] : ($data['recipientID'] == -1 ? 'Anonym' : ($data['recipientID'] == -2 ? 'System' : 'Unbekannt')));
$this->sender = new NotificationUser($data['senderID'],
isset($data['senderName']) ? $data['senderName'] : '',
isset($data['senderDisplayname']) ? $data['senderDisplayname'] : ($data['senderID'] == -1 ? 'Anonym' : ($data['senderID'] == -2 ? 'System' : 'Unbekannt')));
$this->sender->setProfilePicture(isset($data['senderPicture']) ? $data['senderPicture'] : '');
$this->unread = isset($data['unread']) ? $data['unread'] : 1;
$this->type = $data['type'];
$this->parameters = isset($data['parameters']) ? $data['parameters'] : '';
$this->referenceID = $data['referenceID'];
$this->createdAt = isset($data['createdAt']) ? $data['createdAt'] : time();
}
public abstract function getNotificationLink();
public abstract function getNotificationImage();
public abstract function messageForNotification(Notification $notification);
public abstract function messageForNotifications(array $notifications);
public function message()
{
return $this->messageForNotification($this);
}
protected function manyNames(array $names) {
$last = array_pop($names);
$finalNames = '';
foreach ($names as $name) {
$finalNames .= $name->sender->getName() . ', ';
}
return sprintf(lang('notification.multiple'), substr($finalNames, 0, -2), $last->sender->getName());
}
protected function manyNamesCutoff(array $names, $realCount) {
list($first, $second) = array_slice($names, 0, 2);
return sprintf(lang('notification.many'), $first->sender->getName(), $second->sender->getName(), $realCount);
}
}