Various changes including contact messages in database, contact message notifications, notification emails, bugfixes and more
This commit is contained in:
@@ -49,6 +49,14 @@
|
||||
$this->NotificationModel->rankNotificationNewFeedback($userID != NULL ? $userID : -1, 9, $pageUrl);
|
||||
}
|
||||
|
||||
function addContactMessage($email, $userID, $message) {
|
||||
$this->db->query('INSERT INTO contact_messages (userID, userEmail, message) VALUES (?, ?, ?)', [$userID, $email, $message]);
|
||||
$this->db->cache_delete('admin', 'contact');
|
||||
|
||||
// Send notifications
|
||||
$this->NotificationModel->rankNotificationContactMessage($userID != NULL ? $userID : -1, 8, substr($message, 0, 30));
|
||||
}
|
||||
|
||||
function getRankName($rankID)
|
||||
{
|
||||
$ranks = [
|
||||
|
@@ -10,6 +10,7 @@
|
||||
require_once 'notifications/PostReportNotification.php';
|
||||
require_once 'notifications/NotificationUser.php';
|
||||
require_once 'notifications/NewFeedbackNotification.php';
|
||||
require_once 'notifications/ContactMessageNotification.php';
|
||||
|
||||
class NotificationModel extends CI_Model
|
||||
{
|
||||
@@ -20,6 +21,7 @@
|
||||
$_SESSION['site_lang'] = $lang;
|
||||
$this->lang->load('notification', 'de');
|
||||
$this->lang->load('notification', $_SESSION['site_lang']);
|
||||
$this->load->model('EmailModel', '', TRUE);
|
||||
}
|
||||
|
||||
public function getUserNotificationsRaw($userID, $limit = 20, $offset = 0)
|
||||
@@ -78,6 +80,13 @@
|
||||
]);
|
||||
}
|
||||
$this->db->cache_delete('Main', 'getNotifications');
|
||||
|
||||
// Send email
|
||||
$email = $this->UserModel->getUserEmailByID($notification->sender->getId());
|
||||
$group = new NotificationGroup([$notification], 1);
|
||||
$messageData = $group->message();
|
||||
$message = sprintf(lang($messageData['line']), ...$messageData['attributes']);
|
||||
$this->EmailModel->sendMail($email, sprintf('Neue Benachrichtigung auf KingOfDog.eu: "%1$s"', $message), 'notification', ['group' => $group, 'message' => $message]);
|
||||
}
|
||||
|
||||
public function markAsRead(array $notifications) {
|
||||
@@ -117,6 +126,9 @@
|
||||
case 'admin.reportedPost':
|
||||
$items[] = new \Notification\Users\PostReportNotification($item);
|
||||
break;
|
||||
case 'admin.contactMessage':
|
||||
$items[] = new \Notification\Admin\ContactMessageNotification($item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$groups[] = new NotificationGroup($items, $group['count']);
|
||||
@@ -171,7 +183,7 @@
|
||||
}
|
||||
|
||||
public function rankNotificationNewUserRegistered($senderID, $rankRecipientID) {
|
||||
$rankUsers = $this->db->query('SELECT ID FROM users WHERE rank >= ?', [$rankRecipientID])->result_array();
|
||||
$rankUsers = $this->getRankUsers($rankRecipientID);
|
||||
foreach ($rankUsers as $user) {
|
||||
$notification = new \Notification\Admin\UserRegisteredNotification([
|
||||
'senderID' => $senderID,
|
||||
@@ -183,7 +195,7 @@
|
||||
}
|
||||
|
||||
public function rankNotificationNewFeedback($senderID, $rankRecipientID, $pageName) {
|
||||
$rankUsers = $this->db->query('SELECT ID FROM users WHERE rank >= ?', [$rankRecipientID])->result_array();
|
||||
$rankUsers = $this->getRankUsers($rankRecipientID);
|
||||
foreach ($rankUsers as $user) {
|
||||
$notification = new \Notification\Admin\NewFeedbackNotification([
|
||||
'senderID' => $senderID,
|
||||
@@ -194,8 +206,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
public function rankNotificationContactMessage($senderID, $rankRecipientID, $message) {
|
||||
$rankUsers = $this->getRankUsers($rankRecipientID);
|
||||
foreach ($rankUsers as $user) {
|
||||
$notification = new \Notification\Admin\ContactMessageNotification([
|
||||
'senderID' => $senderID,
|
||||
'recipientID' => $user['ID'],
|
||||
'referenceID' => $senderID,
|
||||
'parameters' => $message
|
||||
]);
|
||||
$this->add($notification);
|
||||
}
|
||||
}
|
||||
|
||||
public function rankNotificationPostReport($senderID, $rankRecipientID, $postID, $postUUID) {
|
||||
$rankUsers = $this->db->query('SELECT ID FROM users WHERE rank >= ?', [$rankRecipientID])->result_array();
|
||||
$rankUsers = $this->getRankUsers($rankRecipientID);
|
||||
foreach ($rankUsers as $user) {
|
||||
$notification = new \Notification\Users\PostReportNotification([
|
||||
'senderID' => $senderID,
|
||||
@@ -207,6 +232,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
private function getRankUsers($rankID) {
|
||||
return $this->db->query('SELECT ID FROM users WHERE rank >= ?', [$rankID])->result_array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -26,7 +26,7 @@
|
||||
{
|
||||
for ($i = 0; $i < sizeof($userList); $i++) {
|
||||
if ((isset($userList[$i]['header_image']) && ($userList[$i]['header_image'] == '' || $userList[$i]['header_image'] == NULL)) || !isset($userList[$i]['header_image'])) {
|
||||
$userList[$i]['header_image'] = substr(base_url(), 0, base_url() - 1) . ':3000/' . $userList[$i]['displayname'];
|
||||
$userList[$i]['header_image'] = substr(base_url(), 0, base_url() - 1) . ':5000/' . $userList[$i]['displayname'];
|
||||
}
|
||||
if (isset($userList[$i]['profile_picture']) && $userList[$i]['profile_picture'] == '') {
|
||||
$userList[$i]['profile_picture'] = base_url('/f/8d204712d8132b36d765640ce775ce15');
|
||||
@@ -82,6 +82,11 @@
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getUserEmailByID($id) {
|
||||
$result = $this->db->query('SELECT email FROM users WHERE ID = ? AND is_activated = TRUE', [$id])->result_array();
|
||||
return !empty($result) ? $result[0]['email'] : '';
|
||||
}
|
||||
|
||||
public function getFollowing($id)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Notification\Admin;
|
||||
|
||||
use Notification;
|
||||
|
||||
require_once 'Notification.php';
|
||||
|
||||
class ContactMessageNotification extends \Notification
|
||||
{
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$data['type'] = 'admin.contactMessage';
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
public function getNotificationLink()
|
||||
{
|
||||
return '/admin/contact';
|
||||
}
|
||||
|
||||
public function getNotificationImage()
|
||||
{
|
||||
return $this->sender->getProfilePicture();
|
||||
}
|
||||
|
||||
public function messageForNotification(Notification $notification)
|
||||
{
|
||||
return ['line' => 'admin.contactMessage.single', 'attributes' => [$this->sender->getName(), $notification->parameters]];
|
||||
}
|
||||
|
||||
public function messageForNotifications(array $notifications, $realCount = 0)
|
||||
{
|
||||
if ($realCount === 0) {
|
||||
$realCount = count($notifications);
|
||||
}
|
||||
|
||||
if ($realCount < 5) {
|
||||
$names = $this->manyNames($notifications);
|
||||
return ['line' => 'admin.contactMessage.multiple', 'attributes' => [$names]];
|
||||
} else {
|
||||
$names = $this->manyNamesCutoff($notifications, $realCount);
|
||||
return ['line' => 'admin.contactMessage.many', 'attributes' => [$names]];
|
||||
}
|
||||
}
|
||||
}
|
@@ -23,6 +23,13 @@
|
||||
|
||||
public function __get($attribute)
|
||||
{
|
||||
if($attribute == 'unread') {
|
||||
foreach ($this->notifications as $notification) {
|
||||
if($notification->unread)
|
||||
return TRUE;
|
||||
}
|
||||
RETURN FALSE;
|
||||
}
|
||||
return !empty($this->notifications) ? $this->notifications[0]->{$attribute} : null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user