/**
  * {@inheritdoc}
  */
 public function getViewValue($value)
 {
     switch ($value['type']) {
         case AbstractDateFilterType::TYPE_MORE_THAN:
             return sprintf('%s %s', $this->translator->trans('oro.filter.form.label_date_type_more_than'), $this->formatter->formatDate($value['start']));
         case AbstractDateFilterType::TYPE_LESS_THAN:
             return sprintf('%s %s', $this->translator->trans('oro.filter.form.label_date_type_less_than'), $this->formatter->formatDate($value['end']));
     }
     return sprintf('%s - %s', $this->formatter->formatDate($value['start']), $this->formatter->formatDate($value['end']));
 }
 /**
  * @param Reminder $reminder
  * @return array
  */
 public function getMessageParams(Reminder $reminder)
 {
     $now = new \DateTime();
     $expiredDate = $this->dateTimeFormatter->formatDate($reminder->getExpireAt(), \IntlDateFormatter::SHORT);
     $nowDate = $this->dateTimeFormatter->formatDate($now, \IntlDateFormatter::SHORT);
     if ($expiredDate === $nowDate) {
         $expireAt = $this->dateTimeFormatter->formatTime($reminder->getExpireAt());
     } else {
         $expireAt = $this->dateTimeFormatter->format($reminder->getExpireAt());
     }
     return array('templateId' => $this->getTemplateId($reminder), 'expireAt' => $expireAt, 'subject' => $reminder->getSubject(), 'url' => $this->urlProvider->getUrl($reminder), 'id' => $reminder->getId(), 'uniqueId' => md5($reminder->getRelatedEntityClassName() . $reminder->getRelatedEntityId()));
 }
Example #3
0
 /**
  * @param CaseComment $comment
  * @return array
  */
 public function createCommentView(CaseComment $comment)
 {
     $result = ['id' => $comment->getId(), 'message' => nl2br(htmlspecialchars($comment->getMessage())), 'briefMessage' => htmlspecialchars(mb_substr(preg_replace('/[\\n\\r]+/', ' ', $comment->getMessage()), 0, 200)), 'public' => $comment->isPublic(), 'createdAt' => $comment->getCreatedAt() ? $this->dateTimeFormatter->format($comment->getCreatedAt()) : null, 'updatedAt' => $comment->getUpdatedAt() ? $this->dateTimeFormatter->format($comment->getUpdatedAt()) : null, 'permissions' => array('edit' => $this->securityFacade->isGranted('EDIT', $comment), 'delete' => $this->securityFacade->isGranted('DELETE', $comment))];
     if ($comment->getContact()) {
         $result['createdBy'] = $this->createAuthorView($comment->getContact());
     } elseif ($comment->getOwner()) {
         $result['createdBy'] = $this->createAuthorView($comment->getOwner());
     }
     if ($comment->getUpdatedBy()) {
         $result['updatedBy'] = $this->createAuthorView($comment->getUpdatedBy());
     }
     return $result;
 }
Example #4
0
 /**
  * @dataProvider getRevenueOverTimeChartViewDataProvider
  */
 public function testGetRevenueOverTimeChartView($sourceData, $expectedArrayData, $expectedOptions, $chartConfig)
 {
     $from = new DateTime('2015-05-10');
     $to = new DateTime('2015-05-15');
     $previousFrom = new DateTime('2015-05-05');
     $previousTo = new DateTime('2015-05-10');
     $this->dateHelper->expects($this->any())->method('getFormatStrings')->willReturn(['viewType' => 'day']);
     $this->dateHelper->expects($this->once())->method('getPeriod')->willReturnCallback(function ($dateRange) {
         return [$dateRange['start'], $dateRange['end']];
     });
     $this->dateHelper->expects($this->once())->method('convertToCurrentPeriod')->will($this->returnValue($expectedArrayData['2015-05-10 - 2015-05-15']));
     $this->dateHelper->expects($this->once())->method('combinePreviousDataWithCurrentPeriod')->will($this->returnValue($expectedArrayData['2015-05-05 - 2015-05-10']));
     $this->dateTimeFormatter->expects($this->exactly(4))->method('formatDate')->will($this->onConsecutiveCalls('2015-05-05', '2015-05-10', '2015-05-10', '2015-05-15'));
     $orderRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\OrderRepository')->disableOriginalConstructor()->getMock();
     $orderRepository->expects($this->at(0))->method('getRevenueOverTime')->with($this->aclHelper, $this->dateHelper, $from, $to)->will($this->returnValue($sourceData[0]));
     $orderRepository->expects($this->at(1))->method('getRevenueOverTime')->with($this->aclHelper, $this->dateHelper, $previousFrom, $previousTo)->will($this->returnValue($sourceData[1]));
     $this->registry->expects($this->any())->method('getRepository')->with('OroCRMMagentoBundle:Order')->will($this->returnValue($orderRepository));
     $chartView = $this->getMockBuilder('Oro\\Bundle\\ChartBundle\\Model\\ChartView')->disableOriginalConstructor()->getMock();
     $chartViewBuilder = $this->getMockBuilder('Oro\\Bundle\\ChartBundle\\Model\\ChartViewBuilder')->disableOriginalConstructor()->getMock();
     $chartViewBuilder->expects($this->once())->method('setOptions')->with($expectedOptions)->will($this->returnSelf());
     $chartViewBuilder->expects($this->once())->method('setArrayData')->with($expectedArrayData)->will($this->returnSelf());
     $chartViewBuilder->expects($this->once())->method('getView')->will($this->returnValue($chartView));
     $this->configProvider->expects($this->once())->method('getChartConfig')->with('revenue_over_time_chart')->will($this->returnValue($chartConfig));
     $this->assertEquals($chartView, $this->dataProvider->getRevenueOverTimeChartView($chartViewBuilder, ['start' => $from, 'end' => $to]));
 }
Example #5
0
 /**
  * Apply formatting to totals values
  *
  * @param mixed|null $val
  * @param string|null $formatter
  * @return string|null
  */
 protected function applyFrontendFormatting($val = null, $formatter = null)
 {
     if (null != $formatter) {
         switch ($formatter) {
             case PropertyInterface::TYPE_DATE:
                 $val = $this->dateTimeFormatter->formatDate($val);
                 break;
             case PropertyInterface::TYPE_DATETIME:
                 $val = $this->dateTimeFormatter->format($val);
                 break;
             case PropertyInterface::TYPE_TIME:
                 $val = $this->dateTimeFormatter->formatTime($val);
                 break;
             case PropertyInterface::TYPE_DECIMAL:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_INTEGER:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_PERCENT:
                 $val = $this->numberFormatter->formatPercent($val);
                 break;
             case PropertyInterface::TYPE_CURRENCY:
                 $val = $this->numberFormatter->formatCurrency($val);
                 break;
         }
     }
     return $val;
 }
 /**
  * Formats date time according to locale settings.
  *
  * Options format:
  * array(
  *     'timeType' => <timeType>,
  *     'locale' => <locale>,
  *     'timeZone' => <timeZone>,
  * )
  *
  * @param \DateTime|string|int $date
  * @param array $options
  * @return string
  */
 public function formatTime($date, array $options = array())
 {
     $timeType = $this->getOption($options, 'timeType');
     $locale = $this->getOption($options, 'locale');
     $timeZone = $this->getOption($options, 'timeZone');
     return $this->formatter->formatTime($date, $timeType, $locale, $timeZone);
 }
 /**
  * @param string $value
  * @param array $options
  * @return string
  */
 protected function applyFrontendFormatting($value, array $options)
 {
     $frontendType = isset($options['frontend_type']) ? $options['frontend_type'] : null;
     switch ($frontendType) {
         case PropertyInterface::TYPE_DATE:
             $value = $this->dateTimeFormatter->formatDate($value);
             break;
         case PropertyInterface::TYPE_DATETIME:
             $value = $this->dateTimeFormatter->format($value);
             break;
         case PropertyInterface::TYPE_DECIMAL:
             $value = $this->numberFormatter->formatDecimal($value);
             break;
         case PropertyInterface::TYPE_INTEGER:
             $value = $this->numberFormatter->formatDecimal($value);
             break;
         case PropertyInterface::TYPE_BOOLEAN:
             $value = $this->translator->trans((bool) $value ? self::YES_LABEL_KEY : self::NO_LABEL_KEY);
             break;
         case PropertyInterface::TYPE_PERCENT:
             $value = $this->numberFormatter->formatPercent($value);
             break;
         case PropertyInterface::TYPE_CURRENCY:
             $value = $this->numberFormatter->formatCurrency($value);
             break;
         case PropertyInterface::TYPE_SELECT:
             if (isset($options['choices'][$value])) {
                 $value = $this->translator->trans($options['choices'][$value]);
             }
             break;
     }
     return $value;
 }
 /**
  * @param array $ownerIds
  * @param \DateTime|string|int $date
  * @return mixed
  */
 protected function getOwnersValues(array $ownerIds, $date)
 {
     $key = sha1(implode('_', $ownerIds) . $this->dateTimeFormatter->formatDate($date));
     if (!isset($this->ownersValues[$key])) {
         $this->ownersValues[$key] = $this->doctrine->getRepository('OroCRMSalesBundle:Opportunity')->getForecastOfOpporunitiesData($ownerIds, $date, $this->aclHelper);
     }
     return $this->ownersValues[$key];
 }
 /**
  * @param ValueRenderEvent $fieldValueEvent
  */
 public function beforeValueRender(ValueRenderEvent $fieldValueEvent)
 {
     $originalValue = $fieldValueEvent->getOriginalValue();
     $metadata = $fieldValueEvent->getMetadata();
     if ($originalValue instanceof AddressInterface) {
         $fieldValueEvent->setConvertedValue($this->addressFormatter->format($originalValue));
     } elseif ($originalValue instanceof NamePrefixInterface || $originalValue instanceof FirstNameInterface || $originalValue instanceof MiddleNameInterface || $originalValue instanceof LastNameInterface || $originalValue instanceof NameSuffixInterface) {
         $fieldValueEvent->setConvertedValue($this->nameFormatter->format($originalValue));
     } elseif ($originalValue instanceof \DateTime) {
         $dateType = $metadata->get('render_date_type');
         $timeType = $metadata->get('render_time_type');
         $dateTimePattern = $metadata->get('render_datetime_pattern');
         $fieldValueEvent->setConvertedValue($this->dateTimeFormatter->format($originalValue, $dateType, $timeType, null, null, $dateTimePattern));
     } elseif (is_numeric($originalValue)) {
         $numberStyle = $metadata->get('render_number_style');
         if (!$numberStyle) {
             $numberStyle = 'default_style';
         }
         $fieldValueEvent->setConvertedValue($this->numberFormatter->format($originalValue, $numberStyle));
     }
 }
Example #10
0
 /**
  * @param WidgetOptionBag $widgetOptions
  * @param                 $getterName
  * @param                 $dataType
  * @param bool            $lessIsBetter
  * @return array
  */
 public function getBigNumberValues(WidgetOptionBag $widgetOptions, $getterName, $dataType, $lessIsBetter = false)
 {
     $lessIsBetter = (bool) $lessIsBetter;
     $result = [];
     $dateRange = $widgetOptions->get('dateRange');
     $value = $this->{$getterName}($dateRange);
     $result['value'] = $this->formatValue($value, $dataType);
     $previousInterval = $widgetOptions->get('usePreviousInterval', []);
     if (count($previousInterval)) {
         $pastResult = $this->{$getterName}($previousInterval);
         $result['deviation'] = $this->translator->trans('orocrm.magento.dashboard.e_commerce_statistic.no_changes');
         $deviation = $value - $pastResult;
         if ($pastResult != 0 && $dataType !== 'percent') {
             if ($deviation != 0) {
                 $deviationPercent = $deviation / $pastResult;
                 $result['deviation'] = sprintf('%s (%s)', $this->formatValue($deviation, $dataType, true), $this->formatValue($deviationPercent, 'percent', true));
                 if (!$lessIsBetter) {
                     $result['isPositive'] = $deviation > 0;
                 } else {
                     $result['isPositive'] = !($deviation > 0);
                 }
             }
         } else {
             if (round($deviation * 100, 0) != 0) {
                 $result['deviation'] = $this->formatValue($deviation, $dataType, true);
                 if (!$lessIsBetter) {
                     $result['isPositive'] = $deviation > 0;
                 } else {
                     $result['isPositive'] = !($deviation > 0);
                 }
             }
         }
         $result['previousRange'] = sprintf('%s - %s', $this->dateTimeFormatter->formatDate($previousInterval['start']), $this->dateTimeFormatter->formatDate($previousInterval['end']));
     }
     return $result;
 }
 /**
  * @param array $result
  * @param bool  $addValue
  */
 protected function addCurrentDateAndTime(array &$result, $addValue)
 {
     if ($addValue) {
         $dateTime = new \DateTime('now', new \DateTimeZone('UTC'));
         $dateTimeVal = $dateTime;
         $dateVal = $this->dateTimeFormatter->formatDate($dateTime);
         $timeVal = $this->dateTimeFormatter->formatTime($dateTime);
     } else {
         $dateTimeVal = ['type' => 'datetime', 'label' => $this->translator->trans('oro.email.emailtemplate.current_datetime')];
         $dateVal = ['type' => 'string', 'label' => $this->translator->trans('oro.email.emailtemplate.current_date')];
         $timeVal = ['type' => 'string', 'label' => $this->translator->trans('oro.email.emailtemplate.current_time')];
     }
     // @todo: the datetime object cannot be added due __toString of DateTime is not allowed error
     //        this code can be uncommented after validation and formatting are fixed
     //$result['currentDateTime'] = $dateTimeVal;
     $result['currentDate'] = $dateVal;
     $result['currentTime'] = $timeVal;
 }
 /**
  * @param mixed       $val
  * @param array       $options
  *
  * @return string|null
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function applyFrontendFormatting($val, $options)
 {
     if (null !== $val) {
         $frontendType = isset($options['frontend_type']) ? $options['frontend_type'] : null;
         switch ($frontendType) {
             case PropertyInterface::TYPE_DATE:
                 $val = $this->dateTimeFormatter->formatDate($val);
                 break;
             case PropertyInterface::TYPE_DATETIME:
                 $val = $this->dateTimeFormatter->format($val);
                 break;
             case PropertyInterface::TYPE_TIME:
                 $val = $this->dateTimeFormatter->formatTime($val);
                 break;
             case PropertyInterface::TYPE_DECIMAL:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_INTEGER:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_BOOLEAN:
                 $val = $this->translator->trans((bool) $val ? 'Yes' : 'No', [], 'jsmessages');
                 break;
             case PropertyInterface::TYPE_PERCENT:
                 $val = $this->numberFormatter->formatPercent($val);
                 break;
             case PropertyInterface::TYPE_CURRENCY:
                 $val = $this->numberFormatter->formatCurrency($val);
                 break;
             case PropertyInterface::TYPE_SELECT:
                 if (isset($options['choices'][$val])) {
                     $val = $this->translator->trans($options['choices'][$val]);
                 }
                 break;
             case PropertyInterface::TYPE_HTML:
                 $val = $this->formatHtmlFrontendType($val, isset($options['export_type']) ? $options['export_type'] : null);
                 break;
         }
     }
     return $val;
 }
Example #13
0
 /**
  * Returns a string represents a range between $startDate and $endDate, formatted according the given parameters
  * Examples:
  *      $endDate is not specified
  *          Thu Oct 17, 2013 - when $skipTime = true
  *          Thu Oct 17, 2013 5:30pm - when $skipTime = false
  *      $startDate equals to $endDate
  *          Thu Oct 17, 2013 - when $skipTime = true
  *          Thu Oct 17, 2013 5:30pm - when $skipTime = false
  *      $startDate and $endDate are the same day
  *          Thu Oct 17, 2013 - when $skipTime = true
  *          Thu Oct 17, 2013 5:00pm – 5:30pm - when $skipTime = false
  *      $startDate and $endDate are different days
  *          Thu Oct 17, 2013 5:00pm – Thu Oct 18, 2013 5:00pm - when $skipTime = false
  *          Thu Oct 17, 2013 – Thu Oct 18, 2013 - when $skipTime = true
  *
  * @param \DateTime|null    $startDate
  * @param \DateTime|null    $endDate
  * @param bool              $skipTime
  * @param string|null       $dateTimeFormat
  * @param string|int|null   $dateType \IntlDateFormatter constant or it's string name
  * @param string|int|null   $timeType \IntlDateFormatter constant or it's string name
  * @param string|null       $locale
  * @param string|null       $timeZone
  *
  * @return string
  */
 public function formatCalendarDateRange(\DateTime $startDate = null, \DateTime $endDate = null, $skipTime = false, $dateTimeFormat = null, $dateType = null, $timeType = null, $locale = null, $timeZone = null)
 {
     if (is_null($startDate)) {
         // exit because nothing to format.
         // We have to accept null as $startDate because the validator of email templates calls functions
         // with empty arguments
         return '';
     }
     // check if $endDate is not specified or $startDate equals to $endDate
     if (is_null($endDate) || $startDate == $endDate) {
         return $skipTime ? $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone) : $this->formatter->format($startDate, $dateType, $timeType, $locale, $timeZone);
     }
     // check if $startDate and $endDate are the same day
     if ($startDate->format('Ymd') == $endDate->format('Ymd')) {
         if ($skipTime) {
             return $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone);
         }
         return sprintf('%s %s - %s', $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone), $this->formatter->formatTime($startDate, $timeType, $locale, $timeZone), $this->formatter->formatTime($endDate, $timeType, $locale, $timeZone));
     }
     // $startDate and $endDate are different days
     if ($skipTime) {
         return sprintf('%s - %s', $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone), $this->formatter->formatDate($endDate, $dateType, $locale, $timeZone));
     }
     return sprintf('%s - %s', $this->formatter->format($startDate, $dateTimeFormat, $locale, $timeZone), $this->formatter->format($endDate, $dateTimeFormat, $locale, $timeZone));
 }
 /**
  * @param int|string|null $dateType Constant of IntlDateFormatter (NONE, FULL, LONG, MEDIUM, SHORT) or it's name
  * @param int|string|null $timeType Constant of IntlDateFormatter (NONE, FULL, LONG, MEDIUM, SHORT) or it's name
  * @param string|null $locale
  * @return string
  */
 protected function getFormat($dateType, $timeType, $locale)
 {
     return $this->convertFormat($this->formatter->getPattern($dateType, $timeType, $locale));
 }
 /**
  * {@inheritdoc}
  */
 public function format($parameter, array $formatterArguments = [])
 {
     return $this->formatter->format($parameter);
 }
 /**
  * @dataProvider getDatePatternDataProvider
  */
 public function testGetDatePattern($expectedDateType, $expectedTimeType, $dateType, $timeType, $locale)
 {
     $expected = $this->getPattern($locale, $expectedDateType, $expectedTimeType);
     $this->assertEquals($expected, $this->formatter->getPattern($dateType, $timeType, $locale));
 }
 /**
  * @param \DateTime $value
  * @return string
  */
 protected function getValueForDateTime(\DateTime $value)
 {
     return $this->dateTimeFormatter->formatDate($value);
 }
Example #18
0
 /**
  * @param DateTime $from
  * @param DateTime $to
  *
  * @return string
  */
 protected function createPeriodLabel(DateTime $from, DateTime $to)
 {
     return sprintf('%s - %s', $this->dateTimeFormatter->formatDate($from), $this->dateTimeFormatter->formatDate($to));
 }