Exemplo n.º 1
0
 public function seedTasks()
 {
     foreach (Task::all() as $task) {
         $task->delete();
     }
     Task::truncate();
     Notification::truncate();
     $options = $this->option();
     $task_repo = App::make('TasksRepository');
     $task_titles = ["Draw me a picture", "Proof-read a email", "Using the espresso machine", "Render a building", "Take a picture", "Make a latte", "Sing a song", "Giving a hug", "Use the 3D printer", "Setup a wordpress site", "Make a ios prototype", "Finding a place to eat", "Move a couch", "Chop veggies", "Talk about life..."];
     $durs = ['a min', 'couple of hours', 'a day', 'few mins', "2 minutes", "an hour", "1/2 hour", "5 minutes", "20 minutes", "10 minutes"];
     $n = isset($options['count']) ? min($options['count'], 1500) : 250;
     $faker = Faker\Factory::create();
     for ($i = 0; $i < $n; $i++) {
         $created_at = $faker->dateTimeBetween('-3 days', '3 days');
         if ($faker->boolean(80)) {
             $created_at = $faker->dateTimeBetween('-3 months', '3 months');
         }
         $data = ['title' => array_random_item($task_titles), 'project' => Project::getRandom()->title, 'creator_id' => User::getRandomID(), 'duration' => array_random_item($durs), 'created_at' => $created_at];
         // dd($data);
         if ($faker->boolean(80)) {
             $data['details'] = implode("\n", $faker->sentences(4));
         }
         if ($faker->boolean(10)) {
             $data['does_not_expire'] = true;
             $data['task_date'] = NULL;
         }
         $task = $task_repo->store($data);
         $this->info("{$task->id} Creating Task:{$task->title}");
     }
     $this->comment("----- Seed Claiming -----");
     // Get a bunch for a few users
     for ($i = 0; $i <= User::count() / 2; $i++) {
         $user_id = User::getRandomID();
         for ($j = 0; $j <= $faker->numberBetween(5, 120); $j++) {
             $task = Task::orderByRaw("RAND()")->where('creator_id', '<>', $user_id)->take(1)->first();
             $task->claimed_id = $user_id;
             $task->claimed_at = $task->date->subDays($faker->randomDigit);
             $task->save();
             $this->info("{$task->title} Claimed at: " . $task->claimed_at->diffForHumans($task->created_at));
             Notification::fire($task, Notification::NOTIFICATION_TASK_CLAIMED);
         }
     }
     // now claime some randomly
     foreach (Task::orderByRaw("RAND()")->take(Task::count() / 2)->get() as $task) {
         $task->claimed_id = User::getRandomID([$task->creator_id]);
         $task->claimed_at = $task->date->subDays($faker->randomDigit);
         $task->save();
         $this->info("{$task->title} Claimed at: " . $task->claimed_at->diffForHumans($task->created_at));
         Notification::fire($task, Notification::NOTIFICATION_TASK_CLAIMED);
     }
     $this->call('halp:awards', array('--full' => 'true'));
 }