/**
  * Index method
  *
  * @return void
  */
 public function indexToday($dayOffset = 0)
 {
     $dayStart = null;
     $dayEnd = null;
     $this->getDay($dayOffset, $dayStart, $dayEnd, "America/Chicago");
     $query = $this->Sessions->find()->where(['Sessions.created >=' => $dayStart])->where(['Sessions.created <=' => $dayEnd])->contain(['Users', 'Projects', 'Tasks'])->order(['Sessions.created' => 'DESC']);
     // this is just total elapsed time for the day not a real datetime
     $totalTime = new Time('2000-01-01');
     //debug($totalTime);
     $recs = $query->toArray();
     //debug($recs);die;
     $index = 0;
     foreach ($recs as $session) {
         $start = new Time($session['created']);
         $stop = new Time($session['stopped']);
         $interval = $start->diff($stop);
         $totalTime->add($interval);
         // if elapsed time is more than 0 days, show the day part too
         if ($interval->days > 0) {
             $timeLapse = $interval->format('%D:%H:%I');
         } else {
             $timeLapse = $interval->format('%H:%I');
         }
         // just show MM:SS
         /* show state */
         if ($session->state == 0) {
             $state = "not started";
         } else {
             if ($session->state == 1) {
                 $state = "<span style='font-weight: normal;'>STARTED</span>";
             } else {
                 if ($session->state == 2) {
                     $state = "stopped";
                 } else {
                     $state = "invalid";
                 }
             }
         }
         $recs[$index]['timeLapse'] = $timeLapse;
         $recs[$index]['totalTime'] = $totalTime->format('H:i');
         $recs[$index]['stateDesc'] = $state;
         $index++;
     }
     $this->set('sessions', $recs);
     $this->set('totalTime', $totalTime);
     //debug($sessions);die;
     $this->set('_serialize', ['sessions']);
 }
Example #2
0
 /**
  * Unlock all badges related to comments.
  *
  * @param \Cake\Event\Event $event The Model.BlogArticlesComments.add event that was fired.
  *
  * @return bool
  */
 public function registerBadge(Event $event)
 {
     $this->Badges = TableRegistry::get('Badges');
     if (!$event->data['user'] instanceof User) {
         return false;
     }
     $badges = $this->Badges->find('all')->select(['id', 'name', 'picture', 'rule'])->where(['type' => 'registration'])->hydrate(false)->toArray();
     if (empty($badges)) {
         return true;
     }
     $this->Users = TableRegistry::get('Users');
     $userId = $event->data['user']->id;
     $user = $this->Users->find()->where(['id' => $userId])->select(['created'])->first();
     $today = new Time();
     $created = $user->created;
     $diff = $today->diff($created)->y;
     foreach ($badges as $badge) {
         if ($diff >= $badge['rule']) {
             $this->_unlockBadge($badge, $userId);
         }
     }
     return true;
 }
Example #3
0
 /**
  * Convenience method for getting the remaining time from a given time.
  *
  * @param \DateTime|\DateTimeImmutable $datetime The date to get the remaining time from.
  * @return \DateInterval|bool The DateInterval object representing the difference between the two dates or FALSE on failure.
  */
 public static function fromNow($datetime)
 {
     $timeNow = new Time();
     return $timeNow->diff($datetime);
 }