Пример #1
0
 public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true, $idDimension = false)
 {
     // validation of requested $period & $date
     if ($period == 'range') {
         // load days in the range
         $period = 'day';
     }
     if (!Period::isMultiplePeriod($date, $period)) {
         throw new Exception("Row evolutions can not be processed with this combination of \\'date\\' and \\'period\\' parameters.");
     }
     $label = DataTablePostProcessor::unsanitizeLabelParameter($label);
     $labels = Piwik::getArrayFromApiParameter($label);
     $metadata = $this->getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal, $idDimension);
     $dataTable = $this->loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $idGoal, $idDimension);
     if (empty($labels)) {
         $labels = $this->getLabelsFromDataTable($dataTable, $labels);
         $dataTable = $this->enrichRowAddMetadataLabelIndex($labels, $dataTable);
     }
     if (count($labels) != 1) {
         $data = $this->getMultiRowEvolution($dataTable, $metadata, $apiModule, $apiAction, $labels, $column, $legendAppendMetric, $labelUseAbsoluteUrl);
     } else {
         $data = $this->getSingleRowEvolution($idSite, $dataTable, $metadata, $apiModule, $apiAction, $labels[0], $labelUseAbsoluteUrl);
     }
     return $data;
 }
Пример #2
0
 /**
  * The constructor
  * Initialize some local variables from the request
  * @param int $idSite
  * @param Date $date ($this->date from controller)
  * @param null|string $graphType
  * @throws Exception
  */
 public function __construct($idSite, $date, $graphType = 'graphEvolution')
 {
     $this->apiMethod = Common::getRequestVar('apiMethod', '', 'string');
     if (empty($this->apiMethod)) {
         throw new Exception("Parameter apiMethod not set.");
     }
     $this->label = DataTablePostProcessor::getLabelFromRequest($_GET);
     if (!is_array($this->label)) {
         throw new Exception("Expected label to be an array, got instead: " . $this->label);
     }
     $this->label = $this->label[0];
     if ($this->label === '') {
         throw new Exception("Parameter label not set.");
     }
     $this->period = Common::getRequestVar('period', '', 'string');
     PeriodFactory::checkPeriodIsEnabled($this->period);
     $this->idSite = $idSite;
     $this->graphType = $graphType;
     if ($this->period != 'range') {
         // handle day, week, month and year: display last X periods
         $end = $date->toString();
         list($this->date, $lastN) = EvolutionViz::getDateRangeAndLastN($this->period, $end);
     }
     $this->segment = \Piwik\API\Request::getRawSegmentFromRequest();
     $this->loadEvolutionReport();
 }
Пример #3
0
 /**
  * Makes sure to not have any subtables anymore.
  *
  * So if $table is
  * array(
  *    site1
  *    site2
  *        subtable => site3
  *                    site4
  *                    site5
  *    site6
  *    site7
  * )
  *
  * it will return
  *
  * array(
  *    site1
  *    site2
  *    site3
  *    site4
  *    site5
  *    site6
  *    site7
  * )
  *
  * in a sorted order
  *
  * @param DataTable $table
  * @param array $request
  */
 private function makeSitesFlatAndApplyGenericFilters(DataTable $table, $request)
 {
     // we handle limit here as we have to apply sort filter, then make sites flat, then apply limit filter.
     $filterOffset = $request['filter_offset'];
     $filterLimit = $request['filter_limit'];
     unset($request['filter_offset']);
     unset($request['filter_limit']);
     // filter_sort_column does not work correctly is a bug in MultiSites.getAll
     if (!empty($request['filter_sort_column']) && $request['filter_sort_column'] === 'nb_pageviews') {
         $request['filter_sort_column'] = 'Actions_nb_pageviews';
     } elseif (!empty($request['filter_sort_column']) && $request['filter_sort_column'] === 'revenue') {
         $request['filter_sort_column'] = 'Goal_revenue';
     }
     // make sure no limit filter is applied, we will do this manually
     $table->disableFilter('Limit');
     // this will apply the sort filter
     /** @var DataTable $table */
     $genericFilter = new DataTablePostProcessor('MultiSites', 'getAll', $request);
     $table = $genericFilter->applyGenericFilters($table);
     // make sure from now on the sites will be no longer sorted, they were already sorted
     $table->disableFilter('Sort');
     // make sites flat and limit
     $table->filter('Piwik\\Plugins\\MultiSites\\DataTable\\Filter\\NestedSitesLimiter', array($filterOffset, $filterLimit));
 }
Пример #4
0
 private function makeDataTablePostProcessor()
 {
     $request = $this->buildApiRequestArray();
     $module = $this->requestConfig->getApiModuleToRequest();
     $method = $this->requestConfig->getApiMethodToRequest();
     $processor = new DataTablePostProcessor($module, $method, $request);
     $processor->setFormatter($this->metricsFormatter);
     return $processor;
 }
Пример #5
0
 private function handleDataTable(DataTableInterface $datatable)
 {
     if ($this->postProcessDataTable) {
         $postProcessor = new DataTablePostProcessor($this->apiModule, $this->apiMethod, $this->request);
         $datatable = $postProcessor->process($datatable);
     }
     return $this->apiRenderer->renderDataTable($datatable);
 }