/** * Gets the time. * Returns a localized string "will be announced" if there's no time set (i.e. both begin time and end time are 00:00). * Returns only the begin time if begin time and end time are the same. * * @param tx_seminars_Model_AbstractTimeSpan $timeSpan the timespan to get the date for * @param string $dash the character or HTML entity used to separate begin time and end time * * @return string the time */ public function render(tx_seminars_Model_AbstractTimeSpan $timeSpan, $dash = '–') { if (!$this->hasTime($timeSpan)) { return $this->translator->translate('message_willBeAnnounced'); } $beginTime = $this->getAsTime($timeSpan->getBeginDateAsUnixTimeStamp()); $endTime = $this->getAsTime($timeSpan->getEndDateAsUnixTimeStamp()); $result = $beginTime; // Only display the end time if the event has an end date/time set // and the end time is not the same as the begin time. if ($this->hasEndTime($timeSpan) && $beginTime !== $endTime) { $result .= $dash . $endTime; } $result .= ' ' . $this->translator->translate('label_hours'); return $result; }
/** * Creates an e-mail introduction with the given event's title, date and * time prepended with the given introduction string. * * @param string $introductionBegin * the start of the introduction, must not be empty and contain %s as * place to fill the title of the event in * @param tx_seminars_seminar $event the event the introduction is for * * @return string the introduction with the event's title and if available * date and time, will not be empty */ public function createIntroduction($introductionBegin, tx_seminars_seminar $event) { $result = sprintf($introductionBegin, $event->getTitle()); if (!$event->hasDate()) { return $result; } $result .= ' ' . sprintf($this->translator->translate('email_eventDate'), $event->getDate('-')); if ($event->hasTime() && !$event->hasTimeslots()) { $timeToLabel = $this->translator->translate('email_timeTo'); $time = $event->getTime(' ' . $timeToLabel . ' '); $label = ' ' . (!$event->isOpenEnded() ? $this->translator->translate('email_timeFrom') : $this->translator->translate('email_timeAt')); $result .= sprintf($label, $time); } return $result; }
/** * Creates an e-mail introduction with the given event's title, date and * time prepended with the given introduction string. * * @param string $introductionBegin * the start of the introduction, must not be empty and contain %s as * place to fill the title of the event in * @param tx_seminars_seminar $event the event the introduction is for * * @return string the introduction with the event's title and if available date and time, will not be empty * * @throws \InvalidArgumentException */ public function createIntroduction($introductionBegin, tx_seminars_seminar $event) { if ($introductionBegin === '') { throw new \InvalidArgumentException('$introductionBegin must not be empty.', 1440109640); } $result = sprintf($introductionBegin, $event->getTitle()); if (!$event->hasDate()) { return $result; } $result .= ' ' . sprintf($this->translator->translate('email_eventDate'), $event->getDate('-')); if ($event->hasTime() && !$event->hasTimeslots()) { $timeToLabelWithPlaceholders = $this->translator->translate('email_timeTo'); $time = $event->getTime(' ' . $timeToLabelWithPlaceholders . ' '); $label = ' ' . (!$event->isOpenEnded() ? $this->translator->translate('email_timeFrom') : $this->translator->translate('email_timeAt')); $result .= sprintf($label, $time); } return $result; }
/** * @test */ public function renderWithTimeSpanWithBeginDateWithZeroHoursReturnsMessageWillBeAnnounced() { $timeSpan = new tx_seminars_tests_fixtures_TestingTimeSpan(); $timeSpan->setBeginDateAsUnixTimeStamp(self::BEGIN_DATE); self::assertSame($this->translator->translate('message_willBeAnnounced'), $this->subject->render($timeSpan)); }
/** * @test */ public function translateForLabelInexistentInEnglishAndAlternativeLanguageGermanReturnsGermanLabel() { $localizedLabels = array('de' => array('label_test' => array(0 => array('source' => 'English', 'target' => 'Deutsch')))); $subject = new Tx_Oelib_Translator('default', 'de', $localizedLabels); self::assertSame('Deutsch', $subject->translate('label_test')); }