Archived
1
0

Initial commit as of 2018-10-16

This commit is contained in:
Marcel
2018-10-16 18:28:42 +02:00
commit 29d7c2ffdc
3601 changed files with 358427 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Notification\Admin;
use Notification;
require_once 'Notification.php';
class NewFeedbackNotification extends \Notification
{
public function __construct(array $data)
{
$data['type'] = 'admin.feedback';
parent::__construct($data);
}
public function getNotificationLink()
{
return '/admin/feedback';
}
public function getNotificationImage()
{
return $this->sender->getProfilePicture();
}
public function messageForNotification(Notification $notification)
{
return ['line' => 'admin.feedback.single', 'attributes' => [$this->sender->getName()]];
}
public function messageForNotifications(array $notifications, $realCount = 0)
{
if ($realCount === 0) {
$realCount = count($notifications);
}
if ($realCount < 5) {
$names = $this->manyNames($notifications);
return ['line' => 'admin.feedback.multiple', 'attributes' => [$names]];
} else {
$names = $this->manyNamesCutoff($notifications, $realCount);
return ['line' => 'admin.feedback.many', 'attributes' => [$names]];
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Notification\Users;
use Notification;
require_once 'Notification.php';
class NewFollowerNotification extends \Notification
{
public function __construct(array $data)
{
$data['type'] = 'users.newFollower';
parent::__construct($data);
}
public function getNotificationLink()
{
return '/user/' . $this->recipient->getUsername() . '/followers';
}
public function getNotificationImage()
{
return $this->sender->getProfilePicture();
}
public function messageForNotification(Notification $notification)
{
return ['line' => 'users.newFollower.single', 'attributes' => [$this->sender->getName()]];
}
public function messageForNotifications(array $notifications, $realCount = 0)
{
if ($realCount === 0) {
$realCount = count($notifications);
}
if ($realCount < 5) {
$names = $this->manyNames($notifications);
return ['line' => 'users.newFollower.multiple', 'attributes' => [$names]];
} else {
$names = $this->manyNamesCutoff($notifications, $realCount);
return ['line' => 'users.newFollower.many', 'attributes' => [$names]];
}
}
}

View File

@@ -0,0 +1,63 @@
<?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);
}
}

View File

@@ -0,0 +1,33 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once 'Notification.php';
class NotificationGroup
{
protected $notifications;
protected $realCount;
public function __construct(array $notifications, $count)
{
$this->notifications = $notifications;
$this->realCount = $count;
}
public function message() {
if($this->realCount == 1) {
return $this->notifications[0]->messageForNotification($this->notifications[0]);
}
return $this->notifications[0]->messageForNotifications($this->notifications, $this->realCount);
}
public function __get($attribute)
{
return $this->notifications[0]->{$attribute};
}
public function __call($name, $arguments)
{
return call_user_func_array([$this->notifications[0], $name], $arguments);
}
}

View File

@@ -0,0 +1,42 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class NotificationUser
{
protected $id;
protected $username;
protected $displayname;
protected $profilePicture;
public function __construct($id, $username, $displayname)
{
$this->id = $id;
$this->username = $username;
$this->displayname = $displayname;
}
public function getId()
{
return $this->id;
}
public function getUsername()
{
return $this->username;
}
public function getName()
{
return $this->displayname;
}
public function getProfilePicture()
{
return $this->profilePicture;
}
public function setProfilePicture($profilePicture)
{
$this->profilePicture = $profilePicture;
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Notification\Users;
use Notification;
require_once 'Notification.php';
class PostLikeNotification extends \Notification
{
public function __construct(array $data)
{
$data['type'] = 'users.likedPost';
parent::__construct($data);
}
public function getNotificationLink()
{
return '/user/' . $this->recipient->getUsername() . '/post/' . $this->parameters;
}
public function getNotificationImage()
{
return $this->sender->getProfilePicture();
}
public function messageForNotification(Notification $notification)
{
return ['line' => 'users.likedPost.single', 'attributes' => [$this->sender->getName()]];
}
public function messageForNotifications(array $notifications, $realCount = 0)
{
if ($realCount === 0) {
$realCount = count($notifications);
}
if ($realCount < 5) {
$names = $this->manyNames($notifications);
return ['line' => 'users.likedPost.multiple', 'attributes' => [$names]];
} else {
$names = $this->manyNamesCutoff($notifications, $realCount);
return ['line' => 'users.likedPost.many', 'attributes' => [$names]];
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Notification\Users;
use Notification;
require_once 'Notification.php';
class PostMentionNotification extends \Notification
{
public function __construct(array $data)
{
$data['type'] = 'users.mentionedPost';
parent::__construct($data);
}
public function getNotificationLink()
{
return '/user/' . $this->sender->getUsername() . '/post/' . $this->parameters;
}
public function getNotificationImage()
{
return $this->sender->getProfilePicture();
}
public function messageForNotification(Notification $notification)
{
return ['line' => 'users.mentionedPost.single', 'attributes' => [$this->sender->getName()]];
}
public function messageForNotifications(array $notifications, $realCount = 0)
{
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Notification\Users;
use Notification;
require_once 'Notification.php';
class PostReplyNotification extends \Notification
{
public function __construct(array $data)
{
$data['type'] = 'users.repliedPost';
parent::__construct($data);
}
public function getNotificationLink()
{
return '/user/' . $this->recipient->getUsername() . '/post/' . $this->parameters;
}
public function getNotificationImage()
{
return $this->sender->getProfilePicture();
}
public function messageForNotification(Notification $notification)
{
return ['line' => 'users.repliedPost.single', 'attributes' => [$this->sender->getName()]];
}
public function messageForNotifications(array $notifications, $realCount = 0)
{
if ($realCount === 0) {
$realCount = count($notifications);
}
if ($realCount < 5) {
$names = $this->manyNames($notifications);
return ['line' => 'users.replied.multiple', 'attributes' => [$names]];
} else {
$names = $this->manyNamesCutoff($notifications, $realCount);
return ['line' => 'users.replied.many', 'attributes' => [$names]];
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Notification\Users;
use Notification;
require_once 'Notification.php';
class PostReportNotification extends \Notification
{
public function __construct(array $data)
{
$data['type'] = 'users.reportedPost';
parent::__construct($data);
}
public function getNotificationLink()
{
return '/user/' . $this->recipient->getUsername() . '/post/' . $this->parameters;
}
public function getNotificationImage()
{
return $this->recipient->getProfilePicture();
}
public function messageForNotification(Notification $notification)
{
return ['line' => 'users.reportedPost.single', 'attributes' => [$this->recipient->getName()]];
}
public function messageForNotifications(array $notifications, $realCount = 0)
{
if ($realCount === 0) {
$realCount = count($notifications);
}
if ($realCount < 5) {
$names = $this->manyNames($notifications);
return ['line' => 'users.reportedPost.multiple', 'attributes' => [$names]];
} else {
$names = $this->manyNamesCutoff($notifications, $realCount);
return ['line' => 'users.reportedPost.many', 'attributes' => [$names]];
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Notification\Admin;
use Notification;
require_once 'Notification.php';
class UserRegisteredNotification extends \Notification
{
public function __construct(array $data)
{
$data['type'] = 'admin.newUserRegistered';
parent::__construct($data);
}
public function getNotificationLink()
{
return '/user/' . $this->sender->getUsername();
}
public function getNotificationImage()
{
return $this->sender->getProfilePicture();
}
public function messageForNotification(Notification $notification)
{
return ['line' => 'admin.newUserRegistered.single', 'attributes' => [$this->sender->getName()]];
}
public function messageForNotifications(array $notifications, $realCount = 0)
{
}
}