/** * @param \Tx_News_Domain_Model_News $newsItem * @param \GeorgRinger\Eventnews\Domain\Model\Dto\Demand $demand * @return mixed */ public function render($newsItem, $demand) { $currentDay = \DateTime::createFromFormat('d-m-Y H:i:s', sprintf('%s-%s-%s 00:00:01', $demand->getDay(), $demand->getMonth(), $demand->getYear())); $found = FALSE; if ($demand->getDay() > 0) { $newsBeginDate = $newsItem->getDatetime()->format('Y-m-d'); $day = date('Y-m-d', $currentDay->getTimestamp()); if ($newsItem->getEventEnd() == 0) { if ($newsBeginDate === $day) { $found = TRUE; } } else { $newsEndDate = $newsItem->getEventEnd(); $newsEndDate->setTime(23, 59, 59); $newsBeginDate = $newsItem->getDatetime(); $newsBeginDate->setTime(0, 0); $currentDay->setTime(0, 0); if ($newsBeginDate <= $currentDay && $newsEndDate >= $currentDay) { $found = TRUE; } } } if ($found) { return $this->renderThenChild(); } else { return $this->renderElseChild(); } }
/** * @test */ public function setLocation() { $value = array(4 => 4, 5 => 5, 6 => NULL); $valueCleaned = array(4 => 4, 5 => 5); $this->subject->setLocations($value); $this->assertEquals($valueCleaned, $this->subject->getLocations()); }
/** * Get a date configuration of the given time offset * * @param \GeorgRinger\Eventnews\Domain\Model\Dto\Demand $demand * @param string $timeString * @return array */ protected function getDateConfig($demand, $timeString = '') { $date = \DateTime::createFromFormat('d.m.Y', sprintf('1.%s.%s', $demand->getMonth(), $demand->getYear())); if (!empty($timeString)) { $date->modify($timeString); } return array('date' => $date, 'month' => $date->format('n'), 'year' => $date->format('Y')); }
/** * @param mixed $newsList * @param \GeorgRinger\Eventnews\Domain\Model\Dto\Demand $demand * @param int $firstDayOfWeek 0 for Sunday, 1 for Monday * @return string Rendered result */ public function render($newsList, $demand, $firstDayOfWeek = 0) { $month = $demand->getMonth(); $year = $demand->getYear(); $firstDayOfMonth = mktime(0, 0, 0, $month, 1, $year); $dayOfWeekOfFirstDay = (int) date('w', $firstDayOfMonth); $firstDayOfCalendar = 1 - $dayOfWeekOfFirstDay + $firstDayOfWeek; $ld = (int) date('t', $firstDayOfMonth); if ($firstDayOfCalendar > 1) { $firstDayOfCalendar -= 7; } $weeks = array(); $inCurrentMonthBefore = FALSE; $inCurrentMonthAfter = FALSE; while ($firstDayOfCalendar <= $ld) { $week = array(); for ($d = 0; $d < 7; $d++) { $day = array(); $dts = mktime(0, 0, 0, $month, $firstDayOfCalendar, $year); $currentDay = (int) date('j', $dts); if ($inCurrentMonthBefore && $currentDay === 1) { $inCurrentMonthAfter = TRUE; } if ($currentDay === 1) { $inCurrentMonthBefore = TRUE; } $day['dayBelongsToCurrentMonth'] = $inCurrentMonthBefore; $day['ts'] = $dts; $day['day'] = (int) date('j', $dts); $day['month'] = (int) date('n', $dts); $day['curmonth'] = $day['month'] == $month; $day['curday'] = date('Ymd') == date('Ymd', $day['ts']); if ($inCurrentMonthBefore && !$inCurrentMonthAfter) { $t = \DateTime::createFromFormat('d-m-Y H:i:s', sprintf('%s-%s-%s 00:00:01', $day['day'], $month, $year)); $day['news'] = $this->getNewsForDay($newsList, $t); } $firstDayOfCalendar++; $week[] = $day; } $weeks[] = $week; } $this->templateVariableContainer->add('weeks', $weeks); $output = $this->renderChildren(); $this->templateVariableContainer->remove('weeks'); return $output; }
/** * Update the main event constraints * * @param Demand $demand * @param bool $respectEnableFields * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param array $constraints * @return void */ protected function updateEventConstraints(Demand $demand, $respectEnableFields, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$constraints) { // reset datetime constraint unset($constraints['datetime']); $eventRestriction = $demand->getEventRestriction(); if ($eventRestriction === Demand::EVENT_RESTRICTION_NO_EVENTS) { $constraints[] = $query->equals('isEvent', 0); } elseif ($eventRestriction === Demand::EVENT_RESTRICTION_ONLY_EVENTS) { $dateField = $demand->getDateField(); $begin = mktime(0, 0, 0, $demand->getMonth(), 1, $demand->getYear()); $end = mktime(23, 59, 59, $demand->getMonth() + 1, 0, $demand->getYear()); $eventsWithNoEndDate = array($query->logicalAnd($query->greaterThanOrEqual($demand->getDateField(), $begin), $query->lessThanOrEqual($demand->getDateField(), $end))); $eventsWithEndDate = array($query->logicalAnd($query->greaterThanOrEqual('datetime', $begin), $query->lessThanOrEqual('datetime', $end), $query->lessThanOrEqual('eventEnd', $end)), $query->logicalAnd($query->lessThanOrEqual($dateField, $begin), $query->greaterThanOrEqual('eventEnd', $end)), $query->logicalAnd($query->lessThanOrEqual($dateField, $begin), $query->greaterThanOrEqual('eventEnd', $begin)), $query->logicalAnd($query->lessThanOrEqual($dateField, $end), $query->greaterThanOrEqual('eventEnd', $end))); $dateConstraints1 = array($query->logicalAnd($eventsWithNoEndDate), $query->logicalOr($eventsWithEndDate)); $constraints['datetime'] = $query->logicalOr($dateConstraints1); $organizers = $demand->getOrganizers(); if (!empty($organizers)) { $constraints[] = $query->in('organizer', $organizers); } $locations = $demand->getLocations(); if (!empty($locations)) { $constraints[] = $query->in('location', $locations); } } }
/** * Update the main event constraints * * @param Demand $demand * @param bool $respectEnableFields * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param array $constraints * @return void */ protected function updateEventConstraints(Demand $demand, $respectEnableFields, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$constraints) { $eventRestriction = $demand->getEventRestriction(); if ($eventRestriction === Demand::EVENT_RESTRICTION_NO_EVENTS) { $constraints[] = $query->equals('isEvent', 0); } elseif ($eventRestriction === Demand::EVENT_RESTRICTION_ONLY_EVENTS) { $constraints[] = $query->equals('isEvent', 1); $monthFromDemand = $demand->getMonth(); $yearFromDemand = $demand->getYear(); if (!empty($monthFromDemand) && !empty($yearFromDemand)) { // reset datetime constraint unset($constraints['datetime']); $dateField = $demand->getDateField(); $begin = mktime(0, 0, 0, $demand->getMonth(), 1, $demand->getYear()); $end = mktime(23, 59, 59, $demand->getMonth() + 1, 0, $demand->getYear()); $eventsWithNoEndDate = array($query->logicalAnd($query->greaterThanOrEqual($demand->getDateField(), $begin), $query->lessThanOrEqual($demand->getDateField(), $end))); $eventsWithEndDate = array($query->logicalAnd($query->greaterThanOrEqual('datetime', $begin), $query->lessThanOrEqual('datetime', $end), $query->lessThanOrEqual('eventEnd', $end)), $query->logicalAnd($query->lessThanOrEqual($dateField, $begin), $query->greaterThanOrEqual('eventEnd', $end)), $query->logicalAnd($query->lessThanOrEqual($dateField, $begin), $query->greaterThanOrEqual('eventEnd', $begin)), $query->logicalAnd($query->lessThanOrEqual($dateField, $end), $query->greaterThanOrEqual('eventEnd', $end))); $dateConstraints1 = array($query->logicalAnd($eventsWithNoEndDate), $query->logicalOr($eventsWithEndDate)); $constraints['datetime'] = $query->logicalOr($dateConstraints1); } $archiveRestriction = $demand->getArchiveRestriction(); if (!empty($archiveRestriction)) { $timestamp = time(); $beginningOfDay = strtotime("midnight", $timestamp); $endOfDay = strtotime("tomorrow", $beginningOfDay) - 1; $activeConstraint = $query->logicalOr($query->greaterThan('datetime', $timestamp), $query->logicalAnd($query->equals('full_day', 0), $query->lessThan('datetime', $timestamp), $query->greaterThan('event_end', $timestamp)), $query->logicalAnd($query->equals('full_day', 1), $query->lessThan('datetime', $beginningOfDay), $query->greaterThan('event_end', $beginningOfDay), $query->lessThan('event_end', $endOfDay)), $query->logicalAnd($query->equals('full_day', 1), $query->lessThan('datetime', $timestamp), $query->greaterThan('event_end', $endOfDay)), $query->logicalAnd($query->equals('full_day', 1), $query->greaterThanOrEqual('datetime', $beginningOfDay), $query->equals('event_end', 0))); // reset existing archived constraint unset($constraints['archived']); if ($demand->getArchiveRestriction() == 'archived') { $constraints['archived'] = $query->logicalNot($activeConstraint); } elseif ($demand->getArchiveRestriction() == 'active') { $constraints['archived'] = $activeConstraint; } } $organizers = $demand->getOrganizers(); if (!empty($organizers)) { $constraints[] = $query->in('organizer', $organizers); } $locations = $demand->getLocations(); if (!empty($locations)) { $constraints[] = $query->in('location', $locations); } } }