Esempio n. 1
0
 public function delete($id)
 {
     if (is_object($id)) {
         $id = $id->id;
     }
     $notification = Notification::whereId($id)->first();
     if ($notification) {
         $notification->delete();
     }
     return $this->listener->statusResponse(['notification' => $notification]);
 }
Esempio n. 2
0
 public function createNotification($event)
 {
     $type = get_class($event['object']);
     $id = $event['object']->id;
     $name = $event['name'];
     $exist = Notification::where('object_id', '=', $id)->where('object_type', '=', $type)->where('event', '=', $name)->first();
     $notification = Notification::create(['object_type' => $type, 'object_id' => $id, 'event' => $name]);
     $notification->save();
     if ($exist == NULL) {
         if (!$notification->id) {
             dd("Error Saving Notification", $notification);
         }
     }
     return $notification;
 }
Esempio n. 3
0
 public function fire()
 {
     $options = $this->option();
     $debug = is_true($options['debug']);
     if ($options['job'] == 'expired_tasks') {
         $this->info("Looking for expired tasks...");
         $tasks = Task::unClaimed()->get()->filter(function ($task) {
             if ($task->notifications()->forEvent(Notification::NOTIFICATION_TASK_EXPIRED)->get()->count() == 0 && $task->isExpired()) {
                 return $task;
             }
         });
         foreach ($tasks as $task) {
             $ago = $task->date->diffForHumans();
             $this->info("({$task->id}) {$task->title} Expired - {$ago}");
             $n = $task->notifications()->forEvent(Notification::NOTIFICATION_TASK_EXPIRED)->get()->count();
             if ($n == 0) {
                 Notification::fire($task, Notification::NOTIFICATION_TASK_EXPIRED);
                 $this->info("\tNotification Created " . $task->id);
             } else {
                 $this->info("*** Notification not sent");
             }
         }
         if ($tasks->count() == 0) {
             $this->info("*** No expired tasks found ***");
         }
         return;
     }
     if ($options['job'] == 'notifications') {
         // first get all users that want to receive notifications
         $users = User::where('notifications', '=', 1)->get();
         // get all notifications that have not been sent out
         $notifications = Notification::whereNull('sent_at')->get();
         if ($notifications->count() == 0) {
             $this->info("*** No New Notification ***");
             return;
         }
         $results = [];
         foreach ($notifications as $notice) {
             $this->info("Notification: " . $notice->getTitle() . " : " . $notice->event);
             $status = $notice->send($debug);
             $this->info("\t status: " . strbool($status));
         }
         return $results;
     }
 }
Esempio n. 4
0
 public function getViewPath()
 {
     return Notification::getViewEvent($this->event);
 }
Esempio n. 5
0
 public function seedUsers()
 {
     $user_photos = File::files($this->seed_path);
     Asset::setFromSeed(true);
     foreach (User::all() as $user) {
         $user->delete();
     }
     $faker = Faker\Factory::create();
     $seeder = new LOFaker();
     $n = 50;
     // also creat admin users (kim & I)
     $admins = array(['username' => 'tvanderlin', 'firstname' => 'Todd', 'lastname' => 'Vanderlin', 'email' => '*****@*****.**'], ['username' => 'kmiller', 'firstname' => 'Kim', 'lastname' => 'Miller', 'email' => '*****@*****.**']);
     foreach ($admins as $data) {
         $data = (object) $data;
         $user = new User();
         $user->timestamps = false;
         $user->email = $data->email;
         $user->username = $data->username;
         $user->firstname = $data->firstname;
         $user->lastname = $data->lastname;
         $password = Hash::make($user->username);
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmed = 1;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->created_at = $user->updated_at = $faker->dateTimeBetween('-3 years', 'now');
         $user->save();
         $role = Role::where('name', '=', 'Admin')->first();
         $user->save();
         $user->attachRole($role);
         $user->save();
         $this->info('Creating *** Admin *** User: '******'men', 'women']);
         $photo = array_random_item($user_photos);
         $role = Role::where('name', '=', 'Writer')->first();
         $joinDate = $faker->dateTimeBetween('-3 years', 'now');
         $user = new User();
         $user->timestamps = false;
         $user->email = 'fake_' . $faker->unique()->email;
         $user->firstname = $faker->firstname;
         $user->lastname = $faker->lastname;
         $user->username = preg_replace("/[^A-Za-z0-9 ]/", '', $faker->unique()->userName);
         $password = Hash::make($faker->password);
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmed = 1;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->created_at = $user->updated_at = $joinDate;
         if ($user->save() == false) {
             $this->error($user->errors() . " " . $user->username);
         }
         $userImage = new Asset();
         $userImage->path = 'assets/content/users';
         $userImage->saveLocalFile($photo, $user->username . ".jpg", Asset::ASSET_TYPE_IMAGE);
         $userImage->save();
         $user->profileImage()->save($userImage);
         $user->profileImage->user()->associate($user);
         $user->save();
         $user->attachRole($role);
         $user->save();
         $this->info($user->id . ' Creating User: ' . $user->getName() . " [{$user->username}, {$user->email}]");
     }
     foreach (User::all() as $user) {
         Notification::fire($user, Notification::NOTIFICATION_HALP_WELCOME);
     }
 }
Esempio n. 6
0
 public function findNotifications()
 {
     $notifications = [];
     $commentRepository = App::make('CommentRepository');
     // -------------------------------------
     Comment::withTrashed()->withSpot()->get()->each(function ($item) use(&$notifications, &$commentRepository) {
         $spot = $item->spot()->withTrashed()->first();
         if ($spot == NULL) {
             // remove this comment its dead
             $commentRepository->destroy($item->id);
             return;
         }
         if ($spot->user !== null) {
             $from_user_id = $item->user_id;
             $to_user_id = $spot->user_id;
             if ($from_user_id !== $to_user_id) {
                 $notification_event = array('event' => Notification::NOTIFICATION_USER_COMMENTED, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'parent' => $item, 'timestamp' => $this->timestamp($item->created_at), 'is_read' => false);
                 array_push($notifications, $notification_event);
             }
         }
     });
     // -------------------------------------
     Visit::withTrashed()->get()->each(function ($item) use(&$notifications) {
         $spot = $item->spot()->withTrashed()->first();
         if ($spot == NULL) {
             // remove this comment its dead
             dd($spot);
             return;
         }
         if ($spot->user !== null) {
             $from_user_id = $item->user_id;
             $to_user_id = $spot->user_id;
             if ($from_user_id !== $to_user_id) {
                 $notification_event = array('event' => Notification::NOTIFICATION_USER_VISITED, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'parent' => $item, 'timestamp' => $this->timestamp($item->created_at), 'is_read' => false);
                 array_push($notifications, $notification_event);
             }
         }
     });
     // -------------------------------------
     Illuminate\Support\Collection::make(DB::table('userables')->get())->each(function ($item) use(&$notifications) {
         $type = $item->userable_type;
         $parent = $type::withTrashed()->whereId($item->userable_id)->first();
         $notification_event = array('event' => Notification::NOTIFICATION_USER_ITINERARY_SHARED, 'to_user_id' => $item->user_id, 'from_user_id' => $parent->user->id, 'parent' => $parent, 'timestamp' => $this->timestamp(new Carbon($item->created_at)), 'is_read' => false);
         array_push($notifications, $notification_event);
     });
     // -------------------------------------
     User::all()->each(function ($user) use(&$notifications) {
         // welcome message
         $notification_event = array('event' => Notification::NOTIFICATION_USER_WELCOME, 'to_user_id' => $user->id, 'from_user_id' => null, 'parent' => $user, 'timestamp' => $this->timestamp($user->created_at), 'is_read' => false);
         array_push($notifications, $notification_event);
         // when someone added your spot to favs
         foreach ($user->favorites->getLocations() as $location) {
             if ($location->hasSpot() && $location->spot->user_id !== $user->id) {
                 // send to the owner of the spot
                 $to_user_id = $location->spot->user_id;
                 // who is doing this...?
                 $from_user_id = $user->id;
                 // welcome message
                 $notification_event = array('event' => Notification::NOTIFICATION_USER_FAVORITED, 'to_user_id' => $to_user_id, 'from_user_id' => $from_user_id, 'parent' => $location->spot, 'timestamp' => $this->timestamp($location->pivot->created_at), 'is_read' => false);
                 array_push($notifications, $notification_event);
             }
         }
     });
     foreach ($notifications as $notice) {
         Notification::fireNotification($notice);
     }
     return $notifications;
 }