public function testFindByTaskUuid()
 {
     $task1 = new Task(\stdClass::class, 'Test 1', '123-123-123');
     $task2 = new Task(\stdClass::class, 'Test 1');
     $executions = [new TaskExecution($task1, \stdClass::class, new \DateTime('+1 day'), 'Test 1'), new TaskExecution($task2, \stdClass::class, new \DateTime('1 day ago'), 'Test 1'), new TaskExecution($task1, \stdClass::class, new \DateTime('1 hour ago'), 'Test 1')];
     $repository = new ArrayTaskExecutionRepository(new ArrayCollection($executions));
     $this->assertEquals([$executions[0], $executions[2]], $repository->findByTaskUuid($task1->getUuid()));
     $this->assertEquals([$executions[1]], $repository->findByTask($task2));
 }
Example #2
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;
     }
 }
Example #3
0
    $user = User::mostHelpfulForProject()->first();
    return [$user, Project::find($user->most_helped_project)];
    // with('claimedTasks')
    // ->join('tasks', 'users.id', '=', 'tasks.claimed_id')
    // select([
    // 	'users.*',
    // 	DB::raw($sql)
    // ]);
    // ->sortByDesc(function($item) {
    //        return $item->claimedTasks->count();
    //    })->each(function($item) {
    //        return $item->totalClaimedTasks = $item->claimedTasks->count();
    //    })->values()->first();
    // return $leader->toSql();
    return $leader->first();
    $q = Task::query();
    $q->notExpired()->withIsExpired();
    // $q->whereRaw("IFNULL(`task_date`, `created_at`) > '$today'");
    // $q->whereRaw(DB::raw("
    // 	IFNULL(`task_date`, `created_at`) >
    // 		(CASE WHEN `task_date` IS NULL THEN DATE_ADD(CURDATE(), INTERVAL $n_days DAY) ELSE CURRENT_DATE END)"));
    //$q->select('tasks.*', DB::raw("IFNULL(`task_date`, `created_at`) > (CASE WHEN `task_date` IS NULL THEN DATE_ADD(CURDATE(), INTERVAL $n_days DAY) ELSE CURRENT_DATE END) AS is_expired"));
    $q->withTrashed();
    // return $q->toSql();
    return $q->get();
    return $r;
});
// ------------------------------------------------------------------------
Route::get('php', function () {
    phpinfo();
});
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function setInterval(CronExpression $interval, \DateTime $firstExecution = null, \DateTime $lastExecution = null)
 {
     parent::setInterval($interval, $firstExecution, $lastExecution);
     $this->intervalExpression = $interval->getExpression();
 }
Example #5
0
        $seeder = new LOFaker();
        $n = 4;
        for ($i = 0; $i < $n; $i++) {
            $seeder->createFakeUser();
        }
    }
    if (Project\Project::all()->count() < 2) {
        $project_names = ["Bravo", "Tinker", "Pando", "Denso", "Rabbit"];
        foreach ($project_names as $name) {
            $prj = new Project\Project(['title' => $name, 'user_id' => User::getRandomID()]);
            $prj->save();
        }
    }
    $task_titles = ["Draw me a picture", "Proof-read a email", "Using the espresso machine", "Render a building", "Take a picture", "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..."];
    $n = 10;
    $tasks = [];
    $faker = Faker\Factory::create();
    $durs = ['a min', 'couple of hours', 'a day', 'few mins', "10 minutes"];
    for ($i = 0; $i < $n; $i++) {
        $data = ['title' => array_random_item($task_titles), 'creator_id' => User::getRandomID(), 'claimed_id' => rand() % 10 > 5 ? User::getRandomID() : null, 'project_id' => Project\Project::getRandomID(), 'duration' => $durs[array_rand($durs)]];
        $task = new Task($data);
        $task->save();
        array_push($tasks, $task);
    }
    return $tasks;
});
// ------------------------------------------------------------------------
Route::get('seeder/users', function () {
    $seeder = new LOFaker();
    return $seeder->createFakeUser();
});
Example #6
0
 public function delete($id)
 {
     if (is_object($id)) {
         $id = $id->id;
     }
     $task = Task::withTrashed()->whereId($id)->first();
     if ($task) {
         if ($task->isClaimed) {
             // fire a new notification to the system
             Event::fire(Notification::NOTIFICATION_NEW_TASK, array(['object' => $task, 'name' => Notification::NOTIFICATION_TASK_DELETED]));
         }
         $task->delete();
     }
     return $this->listener->statusResponse(['task' => $task]);
 }
Example #7
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'));
 }