null|string, 'startTime' => string, 'endTime' => string], ...] */ protected $_ranges; /** * @param array $ranges [['startTime' => string, 'endTime' => string], ...] * @param array $options * @return string */ public function timeRange(array $ranges, array $options = array()) { $this->_setOptions($options); $this->_ranges = $ranges; return $this->_renderRanges(); } protected function _renderRanges() { if (empty($this->_ranges)) { return null; } $rangesCount = count($this->_ranges); if (1 == $rangesCount) { return '' . $this->_renderRange(reset($this->_ranges)) . ''; } if (self::MODE_DAY_NUM == $this->mode) { $wrapTag = 'div'; $itemTag = 'div'; } else { $wrapTag = 'ol'; $itemTag = 'li'; } $html = ''; $idx = 0; foreach ($this->_ranges as $range) { $prefix = (self::MODE_DAY_NUM == $this->mode) ? 'Day ' . ++$idx . ': ' : ''; $html .= '<' . $itemTag . '>' . $this->_renderRange($range, $prefix) . ''; } $html = "<{$wrapTag} class=\"timerange multi\">{$html}"; return ($html) ? $html : null; } protected function _renderRange($range, $prefix = '') { $start = ($range[$this->startTimeField]) ? date_create($range[$this->startTimeField])->format($this->timeFormat): ''; $end = ($range[$this->endTimeField]) ? date_create($range[$this->endTimeField])->format($this->timeFormat) : ''; if (!$start && !$end) { return "{$prefix}  - "; } return "{$prefix}{$start} " . (($end && $start) ? " - " : '') . "{$end}"; } protected function _setOptions(array $options) { $options = array_intersect_key($options, array_fill_keys($this->_knownOptions, null)); foreach ($options as $name => $value) { $this->{$name} = $value; } return $this; } }