/**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $data = ['sender' => 1, 'recipient' => 1, 'subject' => 'Welcome to the Accounting System!', 'message' => 'Welcome to the Accounting System for A-1 Driving School.
<br /><br />
This system is part of the requirements for completing a Bachelor\'s Degree in Information Technology at the University of the East, College of Computer Studies and Systems.'];
        $msg = new Messages();
        foreach ($data as $column => $value) {
            $msg->{$column} = $value;
        }
        $msg->save();
    }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $bookings = Bookings::where('bookings.id', '=', $id)->join('users', 'users.id', '=', 'bookings.host_id')->join('listings', 'listings.id', '=', 'bookings.listing_id')->select('bookings.id', 'bookings.checkin', 'bookings.checkout', 'bookings.status', 'bookings.host_id', 'listings.title', 'listings.address', 'listings.city', 'users.name', 'users.avatar', 'bookings.total')->first();
     $messages = Messages::where('messages.bookings_id', '=', $bookings->id)->join('users', 'users.id', '=', 'messages.user_id')->select('users.avatar', 'users.name', 'users.id', 'messages.content', 'messages.created_at')->orderBy('created_at', 'DESC')->get();
     $bookings['messages'] = $messages;
     $bookings['auth'] = Auth::user()->id;
     return response()->json($bookings);
 }
 public function read()
 {
     $id = Request::segment(3);
     $messages = Messages::find($id);
     $messages->read = 1;
     $messages->save();
     $replies = Reply::leftjoin('users', 'users.id', '=', 'reply.user_id')->where('reply.message_id', $id)->where('reply.Active', '1')->orderby('reply.created_at', 'desc')->paginate(5);
     return view('read', compact('messages', 'replies'));
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('messages', function ($id) {
         return \App\Messages::findOrFail($id);
     });
     $router->bind('tweets', function ($id) {
         return \App\Tweet::findOrFail($id);
     });
     $router->bind('users', function ($id) {
         return \App\User::findOrFail($id);
     });
     parent::boot($router);
 }
Example #5
0
 public static function checkUnreadMessages(Request $request)
 {
     $msgs = Messages::where('user_id_received', $request->user()->id)->where('read', 0)->get();
     $count = 0;
     $people = [];
     foreach ($msgs as $msg) {
         if (!in_array($msg->user_id_sent, $people)) {
             $count++;
             $people[] = $msg->user_id_sent;
         }
     }
     return $count;
 }
 /**
  * Returns a view with pre-assigned information.
  *
  * @param $view
  * @param array $opts
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function view($view, $opts = array())
 {
     $user = User::findOrFail(Auth::user()['id']);
     if ($user->avatar == "") {
         $user->avatar = "http://gravatar.com/avatar/" . md5($user->email);
     }
     // Get unread messages
     $messages = \App\Messages::where('unread', true)->where('recipient', $user->id)->get();
     $unread = count($messages);
     $data = ['user' => $user];
     $data['unread'] = $unread;
     foreach ($opts as $key => $value) {
         $data[$key] = $value;
     }
     return view($view, $data);
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('layouts.master', function ($view) {
         $notification_obj = Notification::read(Auth::user()->id, true, 3);
         $notification_list = Notification::format($notification_obj);
         $view->with('user_notification_count', Notification::count(Auth::user()->id));
         $view->with('user_notification_list', $notification_list);
         $view->with('user_messages_count', Messages::countUnseen());
         $view->with('user_messages_list', Messages::topUnseen(3));
     });
     view()->composer('users.list', function ($view) {
         $view->with('company_id', User::where('id', Auth::user()->id)->with(['company' => function ($q) {
             $q->select('companies.id', 'companies.name');
         }])->first()->company->pluck('id')->toArray()[0] ?? "");
         $view->with('company_name', User::where('id', Auth::user()->id)->with(['company' => function ($q) {
             $q->select('companies.id', 'companies.name');
         }])->first()->company->pluck('name')->toArray()[0] ?? "");
     });
 }
 public function addToCalendar(Request $request, $dialog, $id)
 {
     $client = new Google_Client();
     $client->setScopes(SCOPES);
     $client->setAuthConfigFile(CLIENT_SECRET_PATH);
     //$client->setAccessType('offline');
     $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/google_calendar_callback');
     //  $credentialsPath = $this->expandHomeDirectory(CREDENTIALS_PATH);
     $request->session()->put('dialog', $dialog);
     $request->session()->put('seance', $id);
     // Request authorization from the user.
     if ($request->session()->get('access_token')) {
         $accessToken = $request->session()->get('access_token');
         $client->setAccessToken($accessToken);
         // Refresh the token if it's expired.
         if ($client->isAccessTokenExpired()) {
             $client->refreshToken(Session::find($request->session()->getId()));
         }
     } else {
         // Request authorization from the user.
         $authUrl = $client->createAuthUrl();
         return Response::make('', 302)->header('Location', filter_var($authUrl, FILTER_SANITIZE_URL));
     }
     $d = Messages::where('dialog_num', $dialog)->first();
     $user = User::where('id', $d->user_id_received == $request->user()->id ? $d->user_id_sent : $d->user_id_received)->first();
     $seance = Seances::where('id', $id)->with('getCinema')->with('getMovie')->first();
     $service = new Google_Service_Calendar($client);
     $start_date = new DateTime($seance->start_time);
     $start_date->sub(new DateInterval('PT3H'));
     $end_date = new DateTime($seance->start_time);
     $end_date->add(new DateInterval('PT' . $seance->getMovie->duration . 'M'));
     $end_date->sub(new DateInterval('PT3H'));
     $event = new Google_Service_Calendar_Event(array('summary' => 'Поход в кино', 'location' => Cities::find($seance->getCinema->city_id)->first()->city . ", " . $seance->getCinema->address, 'description' => $seance->getMovie->title, 'start' => array('dateTime' => $start_date->format('Y-m-d\\TH:i:sP'), 'timeZone' => 'Europe/Moscow'), 'end' => array('dateTime' => $end_date->format('Y-m-d\\TH:i:sP'), 'timeZone' => 'Europe/Moscow'), 'recurrence' => array('RRULE:FREQ=DAILY;COUNT=1'), 'attendees' => array(array('email' => $user->email)), 'reminders' => array('useDefault' => FALSE, 'overrides' => array(array('method' => 'email', 'minutes' => 24 * 60), array('method' => 'popup', 'minutes' => 10)))));
     $calendarId = 'primary';
     $event = $service->events->insert($calendarId, $event);
     return Response::make('', 302)->header('Location', filter_var($event->htmlLink, FILTER_SANITIZE_URL));
 }
Example #9
0
 public static function deleteChat()
 {
     $input = Input::all();
     return Messages::deleteChat($input);
 }
Example #10
0
 public static function markAsRead($message_id)
 {
     $notification = Messages::find($message_id);
     $notification->is_read = 1;
     $notification->save();
 }
 public function saveMessage(Request $request)
 {
     $message = [];
     $message['seance_id'] = $request->input('seanceHidden');
     $message['user_id_received'] = $request->input('userHidden');
     $message['user_id_sent'] = $request->user()->id;
     $message['message'] = $request->input('textArea');
     $ids = [$message['user_id_sent'], $message['user_id_received']];
     $b = $message['user_id_sent'] == $message['user_id_received'];
     if ($b) {
         $res = Messages::whereIn('user_id_sent', $ids)->whereIn('user_id_received', $ids)->first();
     } else {
         $res = Messages::whereIn('user_id_sent', $ids)->whereIn('user_id_received', $ids)->whereRaw('user_id_received <> user_id_sent')->first();
     }
     if (count($res) == 0) {
         $message['dialog_num'] = Messages::orderBy('dialog_num', 'DESC')->first()->dialog_num + 1;
     } else {
         $message['dialog_num'] = $res->dialog_num;
     }
     Messages::create($message);
     return redirect()->back()->with('error', 0)->with('message', 'Сообщение отправлено.');
 }
 public function deleteMessage($id)
 {
     $user_id = Messages::where('id', $id)->first()->pluck('user_id');
     if (Auth::user()->id != $user_id) {
         abort(401, "Unauthorized");
     }
     Messages::destroy($id);
     abort(200, "All done");
 }
 public function viewMessage(Request $request, $id)
 {
     $user = User::findOrFail(Auth::user()['id']);
     // Check if user owns this message
     $message = Messages::findOrFail($id);
     if ($user->id != $message->recipient) {
         $request->session()->flash('error', 'You are not allowed to perform that action.');
         return redirect('/messages');
     }
     // Mark as read
     $message->unread = false;
     $message->save();
     // Sender info
     $sender = User::findOrFail($message->sender);
     return $this->view('home.message-view', ['message' => $message, 'sender' => $sender, 'attachments' => explode('|', $message->attachments)]);
 }
 public function sendMessage(Request $request)
 {
     $this->validate($request, array('messageArea' => 'required'), array('messageArea.required' => 'Сообщение не должно быть пустым'));
     $msg = [];
     $msg['message'] = $request->input('messageArea');
     $msg['user_id_sent'] = $request->user()->id;
     $msg['user_id_received'] = $request->input('userHidden');
     $ids = [$msg['user_id_sent'], $msg['user_id_received']];
     $b = $msg['user_id_sent'] == $msg['user_id_received'];
     if ($b) {
         $res = Messages::whereIn('user_id_sent', $ids)->whereIn('user_id_received', $ids)->first();
     } else {
         $res = Messages::whereIn('user_id_sent', $ids)->whereIn('user_id_received', $ids)->whereRaw('user_id_received <> user_id_sent')->first();
     }
     if (count($res) == 0) {
         if (Messages::count() != 0) {
             $msg['dialog_num'] = Messages::orderBy('dialog_num', 'DESC')->first()->dialog_num + 1;
         } else {
             $msg['dialog_num'] = 1;
         }
     } else {
         $msg['dialog_num'] = $res->dialog_num;
     }
     Messages::create($msg);
     return redirect()->back();
 }