Ejemplo n.º 1
0
 /** @inheritdoc */
 protected function init()
 {
     $this->setShortcodeTag('op-is-open');
     $this->defaultAttributes = array('set_id' => null, 'open_text' => __('We\'re currently open.', self::TEXTDOMAIN), 'closed_text' => __('We\'re currently closed.', self::TEXTDOMAIN), 'show_next' => false, 'next_format' => __('We\'re open again on %2$s (%1$s) from %3$s to %4$s', self::TEXTDOMAIN), 'before_widget' => null, 'after_widget' => null, 'before_title' => null, 'after_title' => null, 'title' => null, 'classes' => null, 'next_period_classes' => null, 'open_class' => 'op-open', 'closed_class' => 'op-closed', 'date_format' => Dates::getDateFormat(), 'time_format' => Dates::getTimeFormat());
     $this->validAttributeValues = array('show_next' => array(false, true));
     $this->templatePath = 'shortcode/is-open.php';
 }
Ejemplo n.º 2
0
 public function testCompareDate()
 {
     $d1 = new DateTime('2016-02-03 12:30');
     $d2 = new DateTime('2016-04-02 11:30');
     $d3 = new DateTime('2016-02-03 13:30');
     $this->assertEquals(-1, Dates::compareDate($d1, $d2));
     $this->assertEquals(0, Dates::compareDate($d1, $d3));
     $this->assertEquals(1, Dates::compareDate($d2, $d1));
 }
Ejemplo n.º 3
0
 /** Action: Render Single Period */
 public static function renderSinglePeriod()
 {
     $weekday = $_POST['weekday'];
     $timeStart = $_POST['timeStart'];
     $timeEnd = $_POST['timeEnd'];
     $config = array('weekday' => $weekday);
     $config['timeStart'] = Dates::isValidTime($timeStart) ? $timeStart : '00:00';
     $config['timeEnd'] = Dates::isValidTime($timeEnd) ? $timeEnd : '00:00';
     $period = new Period($config['weekday'], $config['timeStart'], $config['timeEnd']);
     echo self::renderTemplate('ajax/op-set-period.php', array('period' => $period), 'always');
     die;
 }
Ejemplo n.º 4
0
 /**
  * Renders an Irregular Opening Item for Overview table
  *
  * @param     IrregularOpening  $io           The Irregular Opening to show
  * @param     array             $attributes   The shortcode attributes
  */
 public static function renderIrregularOpening(IrregularOpening $io, array $attributes)
 {
     $name = $io->getName();
     $date = $io->getTimeStart()->format(Dates::getDateFormat());
     $heading = $attributes['hide_io_date'] ? $name : sprintf('%s (%s)', $name, $date);
     $now = Dates::getNow();
     $highlighted = ($attributes['highlight'] == 'period' and $io->getTimeStart() <= $now and $now <= $io->getTimeEnd()) ? $attributes['highlighted_period_class'] : null;
     echo '<span class="op-period-time irregular-opening ' . $highlighted . '">' . $heading . '</span>';
     $time_start = $io->getTimeStart()->format($attributes['time_format']);
     $time_end = $io->getTimeEnd()->format($attributes['time_format']);
     $period = sprintf('%s – %s', $time_start, $time_end);
     echo '<span class="op-period-time ' . $highlighted . ' ' . $attributes['span_period_classes'] . '">' . $period . '</span>';
 }
 /** @inheritdoc */
 protected function init()
 {
     $this->setShortcodeTag('op-irregular-openings');
     $this->defaultAttributes = array('title' => null, 'set_id' => null, 'highlight' => false, 'before_widget' => null, 'after_widget' => null, 'before_title' => null, 'after_title' => null, 'class_io' => 'op-irregular-opening', 'class_highlighted' => 'highlighted', 'date_format' => Dates::getDateFormat(), 'time_format' => Dates::getTimeFormat());
     $this->templatePath = 'shortcode/irregular-openings.php';
 }
Ejemplo n.º 6
0
 /**
  * Returns a copy of this Period in another time context meaning the dates of the start and end time may be
  * in another week depending on $date
  *
  * @param     DateTime  $date     The date context for the new Period
  *
  * @return    Period              The new Period in another date context
  */
 public function getCopyInDateContext(DateTime $date)
 {
     $period = clone $this;
     $period->timeStart = Dates::applyWeekContext(clone $this->timeStart, $this->weekday, $date);
     $period->timeEnd = Dates::applyWeekContext(clone $this->timeEnd, $this->weekday, $date);
     if ($period->spansTwoDays) {
         $period->timeEnd->add(new DateInterval('P1D'));
     }
     return $period;
 }
Ejemplo n.º 7
0
 /** @inheritdoc */
 protected function init()
 {
     $this->setShortcodeTag('op-holidays');
     $this->defaultAttributes = array('title' => null, 'set_id' => null, 'highlight' => false, 'before_widget' => null, 'after_widget' => null, 'before_title' => null, 'after_title' => null, 'class_holiday' => 'op-holiday', 'class_highlighted' => 'highlighted', 'date_format' => Dates::getDateFormat());
     $this->templatePath = 'shortcode/holidays.php';
 }
Ejemplo n.º 8
0
echo $before_widget;
if ($title) {
    echo $before_title . $title . $after_title;
}
OpeningHours::setCurrentSetId($set->getId());
echo '<table class="op-table op-table-overview ' . $table_classes . '" id="' . $table_id_prefix . $set->getId() . '">';
if ($show_description and $set->getDescription()) {
    echo '<tr class="op-row op-row-description">';
    echo '<td class="op-cell ' . $cell_classes . ' ' . $cell_description_classes . '" colspan="2">';
    echo $set->getDescription();
    echo '</td>';
    echo '</tr>';
}
$periods = $compress ? $set->getPeriodsGroupedByDayCompressed() : $set->getPeriodsGroupedByDay();
foreach ($periods as $day => $d_periods) {
    $highlighted_day = ($highlight == 'day' and Dates::isToday($day)) ? $highlighted_day_class : null;
    echo '<tr class="op-row op-row-day ' . $row_classes . ' ' . $highlighted_day . '">';
    echo '<th scope="row" class="op-cell op-cell-heading ' . $cell_heading_classes . ' ' . $cell_classes . '">';
    echo Weekdays::getDaysCaption($day, $short);
    echo '</th>';
    echo '<td class="op-cell op-cell-periods ' . $cell_periods_classes . ' ' . $cell_classes . '">';
    if ($include_io) {
        $io = $set->getActiveIrregularOpeningOnWeekday($day);
        if ($io instanceof IrregularOpening) {
            Shortcode::renderIrregularOpening($io, $attributes);
            continue;
        }
    }
    if ($include_holidays) {
        $holiday = $set->getActiveHolidayOnWeekday($day);
        if ($holiday instanceof Holiday) {
Ejemplo n.º 9
0
 /**
  * Universal setter for dates
  *
  * @param     DateTime|string $date         The date to set, either as string or DateTime instance
  * @param     string          $property     The name of the property to set
  * @param     bool            $end_of_day   Whether the time should be shifted to the end of the day
  */
 protected function setDateUniversal($date, $property, $end_of_day = false)
 {
     if (is_string($date) and (preg_match(Dates::STD_DATE_FORMAT_REGEX, $date) or preg_match(Dates::STD_DATE_FORMAT_REGEX . ' ' . Dates::STD_TIME_FORMAT_REGEX, $date))) {
         $date = new DateTime($date);
     }
     if (!$date instanceof DateTime) {
         add_notice(sprintf('Argument one for %s has to be of type string or DateTime, %s given', __CLASS__ . '::' . __METHOD__, gettype($date)));
     }
     $date = Dates::applyTimeZone($date);
     if ($end_of_day === true) {
         $date->setTime(23, 59, 59);
     }
     $this->{$property} = Dates::applyTimeZone($date);
 }
Ejemplo n.º 10
0
 /**
  * Getter: Date
  * @return    DateTime
  */
 public function getDate()
 {
     return new DateTime($this->getTimeStart()->format(Dates::STD_DATE_FORMAT), Dates::getTimezone());
 }
Ejemplo n.º 11
0
 public function testCreateDummy()
 {
     $p = Period::createDummy();
     $expectedStart = Dates::applyWeekContext(new DateTime('now'), 0);
     $expectedStart->setTime(0, 0, 0);
     $this->assertEquals(0, $p->getWeekday());
     $this->assertEquals($expectedStart, $p->getTimeStart());
     $this->assertEquals($expectedStart->add(new DateInterval('P1D')), $p->getTimeEnd());
     $this->assertTrue($p->isDummy());
 }
Ejemplo n.º 12
0
 /**
  * Returns first active irregular opening on a specific weekday
  *
  * @param     int       $weekday  weekday number, 0-6
  * @param     DateTime  $now      custom time
  *
  * @return    IrregularOpening    The first active irregular opening fpr the current weekday
  */
 public function getActiveIrregularOpeningOnWeekday($weekday, DateTime $now = null)
 {
     $date = Dates::applyWeekContext(new DateTime('now'), $weekday, $now);
     return $this->getActiveIrregularOpening($date);
 }