public static function getEvents(eZContentObjectTreeNode $node, array $parameters) { $events = array(); $base = array('name' => $node->attribute('name'), 'main_node_id' => $node->attribute('main_node_id'), 'main_url_alias' => $node->attribute('url_alias'), 'fields' => array('attr_from_time_dt' => 0, 'attr_to_time_dt' => 0)); try { $startDate = new DateTime('now', OCCalendarData::timezone()); $startDate->setDate(date('Y', $parameters['search_from_timestamp']), date('n', $parameters['search_from_timestamp']), date('j', $parameters['search_from_timestamp'])); $endDate = clone $startDate; $endDate->add(new DateInterval($parameters['interval'])); $byDayInterval = new DateInterval('P1D'); /** @var DateTime[] $byDayPeriod */ $byDayPeriod = new DatePeriod($startDate, $byDayInterval, $endDate); $timeTable = self::getTimeTableFromNode($node); foreach ($byDayPeriod as $date) { $weekDay = $date->format('w'); if (isset($timeTable[$weekDay])) { foreach ($timeTable[$weekDay] as $value) { $newEvent = $base; $date->setTime($value['from_time']['hour'], $value['from_time']['minute']); $newEvent['fields']['attr_from_time_dt'] = $date->format('Y-m-d\\TH:i:s\\Z'); $date->setTime($value['to_time']['hour'], $value['to_time']['minute']); $newEvent['fields']['attr_to_time_dt'] = $date->format('Y-m-d\\TH:i:s\\Z'); $item = OCCalendarItem::fromEzfindResultArray($newEvent); $events[] = $item; } } } } catch (Exception $e) { eZDebug::writeError($e->getMessage(), __METHOD__); } return $events; }
function __construct($identifier) { $locale = eZLocale::instance(); $format = OCCalendarData::FULLDAY_IDENTIFIER_FORMAT; $this->identifier = $identifier; $dateTime = DateTime::createFromFormat($format, $identifier, OCCalendarData::timezone()); if (!$dateTime instanceof DateTime) { throw new Exception("{$identifier} in format '{$format}' is not a valid DateTime"); } $dateTime->setTime(0, 0, 0); $this->day = $dateTime->format('j'); $this->shortDayName = $locale->shortDayName($dateTime->format('w')); $this->longDayName = $locale->longDayName($dateTime->format('w')); $this->month = $dateTime->format('n'); $this->longMonthName = $locale->longMonthName($this->month); $this->shortMonthName = $locale->shortMonthName($this->month); $this->year = $dateTime->format('Y'); $this->urlSuffix = "/(day)/{$this->day}/(month)/{$this->month}/(year)/{$this->year}"; $this->dayStartDateTime = clone $dateTime; $this->dayStartDateTime->setTime(0, 0, 0); $this->dayStartTimestamp = $this->dayStartDateTime->format('U'); $today = mktime(0, 0, 0, date('n'), date('j'), date('Y')); $tomorrow = mktime(0, 0, 0, date('n'), date('j') + 1, date('Y')); $this->isToday = $this->dayStartTimestamp == $today; $this->isTomorrow = $this->dayStartTimestamp == $tomorrow; $this->isInWeek = date('W', $this->dayStartTimestamp) == date('W', $today); $this->isInMonth = date('n', $this->dayStartTimestamp) == date('n', $today); $this->dayEndDateTime = clone $dateTime; $this->dayEndDateTime->setTime(23, 59, 59); $this->dayEndTimestamp = $this->dayEndDateTime->format('U'); $this->container = array(); }
protected static function getDateTime($string) { // '%Y-%m-%dT%H:%M:%SZ' -> Y-m-d\TH:i:s\Z $date = DateTime::createFromFormat('Y-m-d\\TH:i:s\\Z', $string, OCCalendarData::timezone()); return $date; }
$parameters['day'] = $dateTime->format(OCCalendarData::DAY_IDENTIFIER_FORMAT); $parameters['month'] = $dateTime->format(OCCalendarData::MONTH_IDENTIFIER_FORMAT); $parameters['year'] = $dateTime->format(OCCalendarData::YEAR_IDENTIFIER_FORMAT); } } if ($http->hasGetVariable('PrevMonthCalendarButton')) { $dateTime = DateTime::createFromFormat(OCCalendarData::PICKER_DATE_FORMAT, $http->getVariable('SearchDate'), OCCalendarData::timezone()); if ($dateTime instanceof DateTime) { $dateTime->sub(new DateInterval('P1M')); $parameters['day'] = $dateTime->format(OCCalendarData::DAY_IDENTIFIER_FORMAT); $parameters['month'] = $dateTime->format(OCCalendarData::MONTH_IDENTIFIER_FORMAT); $parameters['year'] = $dateTime->format(OCCalendarData::YEAR_IDENTIFIER_FORMAT); } } if ($http->hasGetVariable('SearchBlockButton')) { $parameters['interval'] = $http->hasGetVariable('SearchBlockInterval') ? $http->getVariable('SearchBlockInterval') : 'P1M'; // intervallo per la ricerca dal blocco: 1 anno di default } foreach (array_keys(OCCalendarData::defaultParameters()) as $key) { if ($http->hasGetVariable($key)) { $value = $http->getVariable($key); if (!empty($value)) { $parameters[$key] = $value; } } } $redirect = rtrim($redirect, '/'); foreach ($parameters as $key => $value) { $redirect .= "/({$key})/{$value}"; } $module->redirectTo($redirect . $redirectSuffix);
function modify(&$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { switch ($operatorName) { case 'repository_list': $operatorValue = OCCrossSearch::listAvailableRepositories(); break; case 'class_search_result': try { $operatorValue = OCClassSearchFormHelper::result($namedParameters['parameters'], $namedParameters['fields'], true); } catch (Exception $e) { eZDebug::writeError($e->getMessage(), $operatorName); } break; case 'attribute_search_form': try { $operatorValue = OCClassSearchFormHelper::displayAttribute($namedParameters['helper'], $namedParameters['input_field']); } catch (Exception $e) { eZDebug::writeError($e->getMessage(), $operatorName); } break; case 'class_search_form': try { $operatorValue = OCClassSearchFormHelper::displayForm($namedParameters['class_identifier'], $namedParameters['parameters']); } catch (Exception $e) { eZDebug::writeError($e->getMessage(), $operatorName); } break; case 'strtotime': $operatorValue = strtotime($operatorValue); break; case 'calendar': $data = new OCCalendarData($namedParameters['node']); $data->setParameters($namedParameters['parameters']); $data->fetch(); $operatorValue = $data->data; break; case 'facet_navigation': $operatorValue = OCFacetNavgationHelper::data($namedParameters['base_query'], $namedParameters['override'], $namedParameters['base_uri']); break; case 'setFilterParameter': self::$filters[$namedParameters['name']][] = $namedParameters['value']; $this->log($namedParameters, 'setFilterParameter'); $operatorValue = self::$filters[$namedParameters['name']]; break; case 'getFilterParameter': $this->getAllFilters(); if (isset(self::$query_filters[$namedParameters['name']])) { $this->log($namedParameters['name'] . ': ' . var_export(self::$query_filters[$namedParameters['name']], true), 'getFilterParameter'); $operatorValue = is_array(self::$query_filters[$namedParameters['name']]) ? self::$query_filters[$namedParameters['name']] : array(self::$query_filters[$namedParameters['name']]); return true; } $operatorValue = array(); return false; break; case 'removeFilterParameter': $this->getAllFilters(); if (isset(self::$query_filters[$namedParameters['name']])) { self::$query_filters[$namedParameters['name']] = array(); return true; } return false; break; case 'getFilterParameters': $http = eZHTTPTool::instance(); $this->getAllFilters(); $filterList = self::$query_filters; if ($namedParameters['as_array']) { $operatorValue = $filterList; return; } $filterSearchHash = array(); if ($namedParameters['cond']) { $filterSearchHash[] = $namedParameters['cond']; } foreach ($filterList as $name => $value) { if (count($value) > 1) { $temp_array = array('or'); foreach ($value as $v) { $temp_array[] = $name . ':' . $v; } $filterSearchHash[] = $temp_array; } else { $filterSearchHash[] = $name . ':' . $value[0]; } } $this->log($filterSearchHash, 'getFilterParameters'); $operatorValue = $filterSearchHash; break; case 'getFilterUrlSuffix': $filterSearchHash = $operatorValue; $urlSuffix = ''; $tempArray = array(); foreach ($filterSearchHash as $filter) { if (is_array($filter)) { foreach ($filter as $f) { if ('and' != $f and 'or' != $f) { if (!in_array($f, $tempArray)) { $tempArray[] = $f; $urlSuffix .= '&filter[]=' . rawurlencode($f); } } } } else { if (!in_array($filter, $tempArray)) { $tempArray[] = $filter; $urlSuffix .= '&filter[]=' . rawurlencode($filter); } } } $operatorValue = $urlSuffix; break; case 'getFilterHiddenInput': $filterSearchHash = $operatorValue; $input = array(); $tempArray = array(); foreach ($filterSearchHash as $filter) { if (is_array($filter)) { foreach ($filter as $f) { if ('and' != $f and 'or' != $f) { if (!in_array($f, $tempArray)) { $tempArray[] = $f; $input[] = $f; } } } } else { if (!in_array($filter, $tempArray)) { $tempArray[] = $filter; $input[] = $filter; } } } $html = ''; foreach ($input as $i) { $html .= "<input type='hidden' name='filter[]' value='{$i}' />"; } $operatorValue = $html; break; case 'addQuoteOnFilter': $tempVar = $operatorValue; list($name, $value) = explode(':', $tempVar); $operatorValue = $name . ':"' . $value . '"'; break; case 'in_array_r': if ($this->recursiveArraySearch($namedParameters['needle'], $namedParameters['haystack']) !== false) { $operatorValue = true; return true; } $operatorValue = false; return false; break; case 'sort': sort($operatorValue); break; case 'asort': asort($operatorValue); break; case 'parsedate': $operatorValue = str_replace('"', '', $operatorValue); if (DateTime::createFromFormat("Y-m-d\\TH:i:sP", $operatorValue)) { $operatorValue = DateTime::createFromFormat("Y-m-d\\TH:i:sP", $operatorValue)->format("U"); } else { eZDebug::writeError($operatorValue . ': ' . var_export(DateTime::getLastErrors(), 1), 'parsedate'); $operatorValue = 0; } break; default: break; } }