Updates
This commit is contained in:
@@ -4,32 +4,33 @@ namespace App\Http\Controllers\Common;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Model\helpdesk\Notification\Notification;
|
||||
use App\Model\helpdesk\Notification\NotificationType;
|
||||
use App\Model\helpdesk\Notification\UserNotification;
|
||||
use App\Model\helpdesk\Ticket\Tickets;
|
||||
use App\Model\helpdesk\Ticket\Ticket_Thread;
|
||||
use App\User;
|
||||
use App\Model\helpdesk\Notification\NotificationType;
|
||||
|
||||
class NotificationController extends Controller {
|
||||
|
||||
class NotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
*********************************************
|
||||
* ********************************************
|
||||
* Class Notification Controller
|
||||
*********************************************
|
||||
* ********************************************
|
||||
* This controller is used to generate in app notification
|
||||
* under the folling occurrence
|
||||
* under the folling occurrence
|
||||
* 1. Ticket Creation
|
||||
* 2. Ticket Reply
|
||||
* 3. User Creation.
|
||||
*
|
||||
* 3. User Creation
|
||||
*
|
||||
* @author Ladybird <info@ladybirdweb.com>
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
public function __construct() {
|
||||
|
||||
$user = new User();
|
||||
$this->user = $user;
|
||||
// checking authentication
|
||||
@@ -40,7 +41,6 @@ class NotificationController extends Controller
|
||||
|
||||
/**
|
||||
* This function is used to create in app notifications.
|
||||
*
|
||||
* @param type $model_id
|
||||
* @param type $userid_created
|
||||
* @param type $type_id
|
||||
@@ -68,62 +68,49 @@ class NotificationController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is to mark all ticket to read status.
|
||||
*
|
||||
* This function is to mark all ticket to read status
|
||||
* @param type $id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function markAllRead($id)
|
||||
{
|
||||
public function markAllRead($id) {
|
||||
$markasread = UserNotification::where('user_id', '=', \Auth::user()->id)->where('is_read', '=', '0')->get();
|
||||
foreach ($markasread as $mark) {
|
||||
$mark->is_read = '1';
|
||||
$mark->save();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function to mark read.
|
||||
*
|
||||
* This function to mark read
|
||||
* @param type $id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function markRead($id)
|
||||
{
|
||||
public function markRead($id) {
|
||||
$markasread = UserNotification::where('notification_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->where('is_read', '=', '0')->get();
|
||||
foreach ($markasread as $mark) {
|
||||
$mark->is_read = '1';
|
||||
$mark->save();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* function to show all the notifications.
|
||||
*
|
||||
* function to show all the notifications
|
||||
* @return type
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
public function show() {
|
||||
$notifications = $this->getNotifications();
|
||||
|
||||
//dd($notifications);
|
||||
return view('notifications-all', compact('notifications'));
|
||||
}
|
||||
|
||||
/**
|
||||
* function to delete notifications.
|
||||
*
|
||||
* function to delete notifications
|
||||
* @param type $id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
public function delete($id) {
|
||||
$markasread = UserNotification::where('notification_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->get();
|
||||
foreach ($markasread as $mark) {
|
||||
$mark->delete();
|
||||
@@ -132,25 +119,36 @@ class NotificationController extends Controller
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function deleteAll() {
|
||||
try{
|
||||
$notifications = new Notification();
|
||||
if ($notifications->count()>0) {
|
||||
foreach ($notifications->get() as $notification) {
|
||||
$notification->delete();
|
||||
}
|
||||
}
|
||||
$notifications->dummyDelete();
|
||||
return redirect()->back()->with('success', 'deleted');
|
||||
} catch (\Exception $ex){
|
||||
return redirect()->back()->with('fails',$ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the page to list the notifications.
|
||||
*
|
||||
* @return response
|
||||
*/
|
||||
public static function getNotifications()
|
||||
{
|
||||
$notifications = UserNotification::join('notifications', 'user_notification.notification_id', '=', 'notifications.id')
|
||||
->join('notification_types', 'notifications.type_id', '=', 'notification_types.id')
|
||||
->where('user_notification.user_id', '=', \Auth::user()->id)
|
||||
->select('notification_types.id as id', 'notifications.id as notification_id',
|
||||
'user_notification.user_id as user_id', 'user_notification.is_read as is_read',
|
||||
'user_notification.created_at as created_at', 'user_notification.updated_at as updated_at', 'notifications.model_id as model_id',
|
||||
'notifications.userid_created as userid_created',
|
||||
'notifications.type_id as type_id', 'notification_types.message as message',
|
||||
'notification_types.type as type', 'notification_types.icon_class as icon_class')
|
||||
->orderBy('user_notification.created_at', 'desc')
|
||||
->paginate(10);
|
||||
|
||||
public static function getNotifications() {
|
||||
$notifications = UserNotification::with([
|
||||
'notification.type' => function($query) {
|
||||
$query->select('id', 'message', 'type');
|
||||
}, 'users' => function($query) {
|
||||
$query->select('id', 'email', 'profile_pic');
|
||||
}, 'notification.model' => function($query) {
|
||||
$query->select('id', 'ticket_number');
|
||||
},
|
||||
]);
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user