public function randomize()
 {
     $users = User::all();
     $tasks = Task::all();
     srand((double) microtime() * 10000);
     foreach ($users as $user) {
         if (rand(0, 2) == 1) {
             $taskExemption = new TaskExemption();
             $taskExemption->user_id = $user->id;
             $taskExemption->task_id = $tasks[rand(0, count($tasks) - 1)]->id;
             $taskExemption->save();
         }
     }
 }
Exemple #2
0
 public static function start()
 {
     $lastRun = fopen(ENV('LAST_RUN'), 'c+');
     $now = Carbon::now();
     if (filesize(ENV('LAST_RUN')) == 19 && Carbon::parse(fgets($lastRun)) < $now->endOfWeek()) {
         fclose($lastRun);
         return false;
     } else {
         fwrite($lastRun, $now->startOfWeek());
         fclose($lastRun);
         Week::create();
     }
     $users = User::prefsFirst();
     //$users = User::whereIn('name', ['Sean Fraser', 'John Hodges', 'Warren Wilansky'])->with('taskPrefs')->get();
     $tasks = Task::all()->pluck('id')->diff(TaskExemption::common($users->pluck('id')))->shuffle();
     static::run($tasks, $users, 0);
 }