Пример #1
0
 /**
  * @see Form::execute()
  */
 function execute($request)
 {
     parent::execute();
     $router = $request->getRouter();
     /* @var $router PageRouter */
     $context = $router->getContext($request);
     $statsHelper = new StatisticsHelper();
     $columns = $this->getData('columns');
     $filter = array();
     if ($this->getData('objectTypes')) {
         $filter[STATISTICS_DIMENSION_ASSOC_TYPE] = $this->getData('objectTypes');
     }
     if ($this->getData('objectIds') && count($filter[STATISTICS_DIMENSION_ASSOC_TYPE] == 1)) {
         $objectIds = explode(',', $this->getData('objectIds'));
         $filter[STATISTICS_DIMENSION_ASSOC_ID] = $objectIds;
     }
     if ($this->getData('fileTypes')) {
         $filter[STATISTICS_DIMENSION_FILE_TYPE] = $this->getData('fileTypes');
     }
     $filter[STATISTICS_DIMENSION_CONTEXT_ID] = $context->getId();
     if ($this->getData('issues')) {
         $filter[STATISTICS_DIMENSION_ISSUE_ID] = $this->getData('issues');
     }
     if ($this->getData('articles')) {
         $filter[STATISTICS_DIMENSION_SUBMISSION_ID] = $this->getData('articles');
     }
     // Get the time filter data, if any.
     $startTime = $request->getUserDateVar('dateStart', 1, 1, 1, 23, 59, 59);
     $endTime = $request->getUserDateVar('dateEnd', 1, 1, 1, 23, 59, 59);
     if ($startTime && $endTime) {
         $startYear = date('Y', $startTime);
         $endYear = date('Y', $endTime);
         $startMonth = date('m', $startTime);
         $endMonth = date('m', $endTime);
         $startDay = date('d', $startTime);
         $endDay = date('d', $endTime);
     }
     $timeFilterOption = $this->getData('timeFilterOption');
     switch ($timeFilterOption) {
         case TIME_FILTER_OPTION_YESTERDAY:
             $filter[STATISTICS_DIMENSION_DAY] = STATISTICS_YESTERDAY;
             break;
         case TIME_FILTER_OPTION_CURRENT_MONTH:
             $filter[STATISTICS_DIMENSION_MONTH] = STATISTICS_CURRENT_MONTH;
             break;
         case TIME_FILTER_OPTION_RANGE_DAY:
         case TIME_FILTER_OPTION_RANGE_MONTH:
             if ($timeFilterOption == TIME_FILTER_OPTION_RANGE_DAY) {
                 $startDate = $startYear . $startMonth . $startDay;
                 $endDate = $endYear . $endMonth . $endDay;
             } else {
                 $startDate = $startYear . $startMonth;
                 $endDate = $endYear . $endMonth;
             }
             if ($startTime == $endTime) {
                 // The start and end date are the same, there is no range defined
                 // only one specific date. Use the start time.
                 $filter[STATISTICS_DIMENSION_MONTH] = $startDate;
             } else {
                 $filter[STATISTICS_DIMENSION_DAY]['from'] = $startDate;
                 $filter[STATISTICS_DIMENSION_DAY]['to'] = $endDate;
             }
             break;
         default:
             break;
     }
     if ($this->getData('countries')) {
         $filter[STATISTICS_DIMENSION_COUNTRY] = $this->getData('countries');
     }
     if ($this->getData('regions')) {
         $filter[STATISTICS_DIMENSION_REGION] = $this->getData('regions');
     }
     if ($this->getData('cityNames')) {
         $cityNames = explode(',', $this->getData('cityNames'));
         $filter[STATISTICS_DIMENSION_CITY] = $cityNames;
     }
     $orderBy = array();
     if ($this->getData('orderByColumn') && $this->getData('orderByDirection')) {
         $orderByColumn = $this->getData('orderByColumn');
         $orderByDirection = $this->getData('orderByDirection');
         $columnIndex = 0;
         foreach ($orderByColumn as $column) {
             if ($column != '0' && !isset($orderBy[$column])) {
                 $orderByDir = $orderByDirection[$columnIndex];
                 if ($orderByDir == STATISTICS_ORDER_ASC || $orderByDir == STATISTICS_ORDER_DESC) {
                     $orderBy[$column] = $orderByDir;
                 }
             }
             $columnIndex++;
         }
     }
     return $statsHelper->getReportUrl($request, $this->_metricType, $columns, $filter, $orderBy);
 }