public function testNonExistingOptionsOfOptionsBag()
 {
     $bag = new WidgetOptionBag(['option1' => 'val', 'option2' => null]);
     $this->assertFalse($bag->has('option3'));
     $this->assertNull($bag->get('option3'));
     $this->assertEquals('def', $bag->get('option3', 'def'));
 }
 /**
  * @param WidgetOptionBag $widgetOptions
  * @param                 $providerAlias
  * @param                 $getterName
  * @param                 $dataType
  * @param bool            $lessIsBetter
  * @param bool            $lastWeek
  * @return array
  */
 public function getBigNumberValues(WidgetOptionBag $widgetOptions, $providerAlias, $getterName, $dataType, $lessIsBetter = false, $lastWeek = false)
 {
     $getter = $this->getGetter($providerAlias, $getterName);
     $lessIsBetter = (bool) $lessIsBetter;
     $dateRange = $lastWeek ? $this->dateHelper->getLastWeekPeriod() : $widgetOptions->get('dateRange');
     $value = call_user_func($getter, $dateRange);
     $previousInterval = $widgetOptions->get('usePreviousInterval', []);
     $previousData = [];
     if (count($previousInterval)) {
         if ($lastWeek) {
             $previousInterval = $this->dateHelper->getLastWeekPeriod(-1);
         }
         $previousData['value'] = call_user_func($getter, $previousInterval);
         $previousData['dateRange'] = $previousInterval;
         $previousData['lessIsBetter'] = $lessIsBetter;
     }
     return $this->bigNumberFormatter->formatResult($value, $dataType, $previousData);
 }
Beispiel #3
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;
 }
Beispiel #4
0
 /**
  * @param array           $widgetConfig
  * @param WidgetOptionBag $widgetOptions
  * @return array|mixed
  */
 protected function getEnabledItems(array $widgetConfig, WidgetOptionBag $widgetOptions)
 {
     if (isset($widgetConfig['configuration'])) {
         foreach ($widgetConfig['configuration'] as $parameterName => $config) {
             if ($config['type'] === WidgetItemsChoiceType::NAME) {
                 return $widgetOptions->get($parameterName, []);
             }
         }
     }
     return [];
 }
 /**
  * @param WidgetOptionBag $widgetOptions
  *
  * @return array
  */
 protected function getBusinessUnitsIds(WidgetOptionBag $widgetOptions)
 {
     $businessUnits = $widgetOptions->get('businessUnits');
     $businessUnits = is_array($businessUnits) ? $businessUnits : [$businessUnits];
     $businessUnitIds = [];
     foreach ($businessUnits as $businessUnit) {
         if (is_object($businessUnit)) {
             $businessUnitIds[] = $businessUnit->getId();
         }
     }
     return $businessUnitIds;
 }