Пример #1
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;
     }
 }
Пример #2
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);
     }
 }