Exemplo n.º 1
0
    /**
     * Add task to current user
     * @param $userId id of the user adding task
     * @param Task $task object to add
     * @return true if inserted
     */
    public function addTask($userId, Task $task)
    {
        $days = new Days($this->site);
        $dayId = $days->getDayId($task->getDay());
        $sql = <<<SQL
INSERT INTO {$this->tableName}(title, notes, priority, userid, dayid)
VALUES(?, ?, ?, ?, ?)
SQL;
        $pdo = $this->pdo();
        $statement = $pdo->prepare($sql);
        $statement->execute(array($task->getTitle(), $task->getNotes(), $task->getPriority(), $userId, $dayId));
        if ($statement->rowCount() === 0) {
            return false;
        }
        return true;
    }
Exemplo n.º 2
0
    public function present()
    {
        $html = '<form class="tasksForm">';
        $tasks = new Tasks($this->site);
        $days = new Days($this->site);
        $userId = $this->session[User::SESSION_NAME]->getId();
        for ($i = 1; $i <= 7; $i++) {
            $day = $days->getDayName($i);
            $html .= '<div class="day"><a href=""><img src="images/plus.png" alt="Add button"></a>
			<h2>' . $day . '</h2><p class="message">&nbsp;</p>';
            $taskList = $tasks->getTasksByDay($userId, $i);
            if ($taskList !== null) {
                $html .= '<div class="day-tasks"><ul class="day-list">';
                foreach ($taskList as $taskItem) {
                    $html .= '<li><a href="">' . $taskItem['title'] . '</a><input type="hidden" name="taskId" value="' . $taskItem['id'] . '"/><input type="hidden" name="taskPriority" value="' . $taskItem['priority'] . '"/></li>';
                }
                $html .= '</ul></div>';
            }
            $html .= '</div>';
        }
        $html .= '<div class="clear"></div></form>';
        return $html;
    }
Exemplo n.º 3
0
 protected function setDayOfWeek($dayOfWeek)
 {
     if (!in_array($dayOfWeek, Days::toArray())) {
         throw new \InvalidArgumentException(sprintf('Invalid day of week "%s".', $dayOfWeek));
     }
     $this->dayOfWeek = $dayOfWeek;
 }
Exemplo n.º 4
0
 /**
  * Gets the business date after the given date (excluding holidays).
  *
  * @param \DateTime $date
  *
  * @return \DateTime
  */
 private function getDateAfter(\DateTime $date)
 {
     $tmpDate = clone $date;
     $tmpDate->modify('+1 day');
     $dayOfWeek = (int) $tmpDate->format('N');
     $closestDay = $this->getClosestDayAfter($dayOfWeek);
     if ($closestDay->getDayOfWeek() !== $dayOfWeek) {
         $tmpDate->modify(sprintf('next %s', Days::toString($closestDay->getDayOfWeek())));
     }
     return $tmpDate;
 }
Exemplo n.º 5
0
         $location->save();
         $formmessage = 'Changes saved.';
         $formmessageclass = 'green';
         break;
     } catch (Exception $e) {
         $errormessage = $e->getMessage();
         trigger_error($errormessage, E_USER_WARNING);
         $formmessage = $errormessage;
         $formmessageclass = 'red';
         break;
     }
 } else {
     if ($action == 'savehourstab') {
         $tab = 'hours';
         try {
             $days = Days::load();
         } catch (Exception $e) {
             header("Location: restaurants");
             exit;
         }
         foreach ($days as $day => $dayname) {
             $day = strtolower($day);
             $opentime = '';
             $closetime = '';
             if (isset($_POST[$day . 'opentime'])) {
                 $opentime = $_POST[$day . 'opentime'];
             }
             if (isset($_POST[$day . 'closetime'])) {
                 $closetime = $_POST[$day . 'closetime'];
             }
             try {
Exemplo n.º 6
0
 public function isWorkingNow2($place)
 {
     $this->setPlace($place);
     //???????
     $days = [];
     $r = new \ReflectionClass('Business\\Days');
     foreach ($place->getBusinessHours() as $bh) {
         foreach (Days::toArray() as $key => $day) {
             $dayName = strtoupper(Days::toString($day));
             $nextDayName = strtoupper(date('l', strtotime($dayName . " + 1 day")));
             $method = 'getDay' . $dayName;
             //TODO AFTER MIDNIGHT
             if ($exception = $this->isExceptionDay($day)) {
                 if ($exception->getStartsAt() > $exception->getEndsAt()) {
                     if (array_intersect([$exception->getStartsAt()->format('H:i'), '00:00'], $days[$dayName])) {
                         echo 'in_array';
                         var_dump($days[$dayName], [$exception->getStartsAt()->format('H:i'), '00:00']);
                         die;
                         $days[$dayName][] = [$exception->getStartsAt()->format('H:i'), '00:00'];
                         $days[$nextDayName][] = ['00:00', $exception->getEndsAt()->format('H:i')];
                         continue;
                     }
                 }
                 $days[$dayName][] = [$exception->getStartsAt()->format('H:i'), $exception->getEndsAt()->format('H:i')];
                 var_dump($days);
                 die;
             }
             if ($bh->{$method}()) {
                 if ($bh->getStartsAt() > $bh->getEndsAt()) {
                     $days[$dayName][] = [$bh->getStartsAt()->format('H:i'), '00:00'];
                     //var_dump($days);die();
                     $days[$nextDayName][] = ['00:00', $bh->getEndsAt()->format('H:i')];
                     continue;
                 }
                 $days[$dayName][] = [$bh->getStartsAt()->format('H:i'), $bh->getEndsAt()->format('H:i')];
             }
         }
     }
     //        foreach($place->getBusinessHoursException() as $bhE){
     //            if($bhE->getStartsAt()){
     //                $dayName = strtoupper($bhE->getDay()->format('l'));
     //                $nextDayName = strtoupper(date('l',  strtotime($dayName . " + 1 day")));
     //
     //                if($bhE->getStartsAt() > $bhE->getEndsAt())
     //                {
     //                    var_dump(in_array([$bhE->getStartsAt()->format('H:i'), '00:00'], $days[$dayName]), 'diff');
     //                    if(!in_array([$bhE->getStartsAt()->format('H:i'), '00:00'], $days[$dayName])){
     //                        $days[$dayName][] = [$bhE->getStartsAt()->format('H:i'), '00:00'];
     //                        $days[$nextDayName][] = ['00:00', $bhE->getEndsAt()->format('H:i')];
     //                        continue;
     //                    }
     //                }
     //
     //                $days[$dayName][] = [$bhE->getStartsAt()->format('H:i'), $bhE->getEndsAt()->format('H:i')];
     //                //unset($days[$nextDayName][0]);
     //            }
     //        }
     var_dump($days, $holidaysFinal);
     die;
 }