Exemplo n.º 1
0
 public function start(RedmineUser $user)
 {
     if ($oldJob = $user->getJobDescription()) {
         $this->resqueManager->delete($oldJob);
     }
     $now = Carbon::now();
     if ($now->dayOfWeek == Carbon::SATURDAY) {
         $now->addDays(2);
     } elseif ($now->dayOfWeek == Carbon::SUNDAY) {
         $now->addDay();
     }
     if ($now->format('H:i') < $user->getSettings()->getCheckFirst()->format('H:i')) {
         $nextDate = $now->copy();
         $nextDate->startOfDay()->hour((int) $user->getSettings()->getCheckFirst()->format('H'))->minute((int) $user->getSettings()->getCheckFirst()->format('i'));
         $job = $this->resqueManager->put('redmine.timeChecker', ['userId' => $user->getId(), 'date' => $nextDate->format('Y-m-d'), 'checkNum' => 1], $this->queueName, $nextDate);
         $user->setJobDescription($job);
         $this->em->flush();
     }
     if ($now->format('H:i') > $user->getSettings()->getCheckFirst()->format('H:i') and $now->format('H:i') < $user->getSettings()->getCheckSecond()->format('H:i')) {
         $nextDate = $now->copy();
         $nextDate->startOfDay()->hour((int) $user->getSettings()->getCheckSecond()->format('H'))->minute((int) $user->getSettings()->getCheckSecond()->format('i'));
         $job = $this->resqueManager->put('redmine.timeChecker', ['userId' => $user->getId(), 'date' => $nextDate->format('Y-m-d'), 'checkNum' => 2], $this->queueName, $nextDate);
         $user->setJobDescription($job);
         $this->em->flush();
     }
     if ($now->format('H:i') > $user->getSettings()->getCheckSecond()->format('H:i')) {
         $nextDate = $now->copy();
         $nextDate->startOfDay()->hour((int) $user->getSettings()->getCheckThird()->format('H'))->minute((int) $user->getSettings()->getCheckThird()->format('i'));
         $lastWorkDate = Carbon::now();
         $nowTmp = Carbon::now();
         if ($nowTmp->dayOfWeek == Carbon::SATURDAY) {
             $lastWorkDate->subDays(1);
         } elseif ($nowTmp->dayOfWeek == Carbon::SUNDAY) {
             $lastWorkDate->subDays(2);
         }
         $job = $this->resqueManager->put('redmine.timeChecker', ['userId' => $user->getId(), 'date' => $lastWorkDate->format('Y-m-d'), 'checkNum' => 3], $this->queueName, $nextDate);
         $user->setJobDescription($job);
         $this->em->flush();
     }
 }