Esempio n. 1
0
 /** Render the area left of the iframe */
 public function renderSidebar()
 {
     $idSite = Common::getRequestVar('idSite');
     $period = Common::getRequestVar('period');
     $date = Common::getRequestVar('date');
     $currentUrl = Common::getRequestVar('currentUrl');
     $currentUrl = Common::unsanitizeInputValue($currentUrl);
     $normalizedCurrentUrl = PageUrl::excludeQueryParametersFromUrl($currentUrl, $idSite);
     $normalizedCurrentUrl = Common::unsanitizeInputValue($normalizedCurrentUrl);
     // load the appropriate row of the page urls report using the label filter
     ArchivingHelper::reloadConfig();
     $path = ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Action::TYPE_PAGE_URL);
     $path = array_map('urlencode', $path);
     $label = implode('>', $path);
     $request = new Request('method=Actions.getPageUrls' . '&idSite=' . urlencode($idSite) . '&date=' . urlencode($date) . '&period=' . urlencode($period) . '&label=' . urlencode($label) . '&format=original' . '&format_metrics=0');
     $dataTable = $request->process();
     $formatter = new Metrics\Formatter\Html();
     $data = array();
     if ($dataTable->getRowsCount() > 0) {
         $row = $dataTable->getFirstRow();
         $translations = Metrics::getDefaultMetricTranslations();
         $showMetrics = array('nb_hits', 'nb_visits', 'nb_users', 'nb_uniq_visitors', 'bounce_rate', 'exit_rate', 'avg_time_on_page');
         foreach ($showMetrics as $metric) {
             $value = $row->getColumn($metric);
             if ($value === false) {
                 // skip unique visitors for period != day
                 continue;
             }
             if ($metric == 'bounce_rate' || $metric == 'exit_rate') {
                 $value = $formatter->getPrettyPercentFromQuotient($value);
             } else {
                 if ($metric == 'avg_time_on_page') {
                     $value = $formatter->getPrettyTimeFromSeconds($value, $displayAsSentence = true);
                 }
             }
             $data[] = array('name' => $translations[$metric], 'value' => $value);
         }
     }
     // generate page url string
     foreach ($path as &$part) {
         $part = preg_replace(';^/;', '', urldecode($part));
     }
     $page = '/' . implode('/', $path);
     $page = preg_replace(';/index$;', '/', $page);
     if ($page == '/') {
         $page = '/index';
     }
     // render template
     $view = new View('@Overlay/renderSidebar');
     $view->data = $data;
     $view->location = $page;
     $view->normalizedUrl = $normalizedCurrentUrl;
     $view->label = $label;
     $view->idSite = $idSite;
     $view->period = $period;
     $view->date = $date;
     $this->outputCORSHeaders();
     return $view->render();
 }
 public function testApiWithRankingQuery()
 {
     // custom setup
     self::deleteArchiveTables();
     Config::getInstance()->General['archiving_ranking_query_row_limit'] = 3;
     ArchivingHelper::reloadConfig();
     foreach ($this->getApiForTesting() as $pair) {
         list($apiToCall, $params) = $pair;
         if (empty($params['testSuffix'])) {
             $params['testSuffix'] = '';
         }
         $params['testSuffix'] .= '_rankingQuery';
         $this->runApiTests($apiToCall, $params);
     }
 }
Esempio n. 3
0
 private function aggregateDayInteractions()
 {
     $select = "\n                log_action_content_name.name as contentName,\n                log_action_content_interaction.name as contentInteraction,\n                log_action_content_piece.name as contentPiece,\n\n\t\t\t\tcount(*) as `" . Metrics::INDEX_CONTENT_NB_INTERACTIONS . "`\n        ";
     $from = array("log_link_visit_action", array("table" => "log_action", "tableAlias" => "log_action_content_piece", "joinOn" => "log_link_visit_action.idaction_content_piece = log_action_content_piece.idaction"), array("table" => "log_action", "tableAlias" => "log_action_content_interaction", "joinOn" => "log_link_visit_action.idaction_content_interaction = log_action_content_interaction.idaction"), array("table" => "log_action", "tableAlias" => "log_action_content_name", "joinOn" => "log_link_visit_action.idaction_content_name = log_action_content_name.idaction"));
     $where = "log_link_visit_action.server_time >= ?\n                    AND log_link_visit_action.server_time <= ?\n                    AND log_link_visit_action.idsite = ?\n                    AND log_link_visit_action.idaction_content_name IS NOT NULL\n                    AND log_link_visit_action.idaction_content_interaction IS NOT NULL";
     $groupBy = "log_action_content_piece.idaction,\n                    log_action_content_interaction.idaction,\n                    log_action_content_name.idaction";
     $orderBy = "`" . Metrics::INDEX_CONTENT_NB_INTERACTIONS . "` DESC";
     $rankingQueryLimit = ArchivingHelper::getRankingQueryLimit();
     $rankingQuery = null;
     if ($rankingQueryLimit > 0) {
         $rankingQuery = new RankingQuery($rankingQueryLimit);
         $rankingQuery->setOthersLabel(DataTable::LABEL_SUMMARY_ROW);
         $rankingQuery->addLabelColumn(array('contentPiece', 'contentInteraction', 'contentName'));
         $rankingQuery->addColumn(array(Metrics::INDEX_CONTENT_NB_INTERACTIONS), 'sum');
     }
     $resultSet = $this->archiveDayQueryProcess($select, $from, $where, $groupBy, $orderBy, $rankingQuery);
     while ($row = $resultSet->fetch()) {
         $this->aggregateInteractionRow($row);
     }
 }
Esempio n. 4
0
 public function aggregateMultipleReports()
 {
     ArchivingHelper::reloadConfig();
     $dataTableToSum = array(self::PAGE_TITLES_RECORD_NAME, self::PAGE_URLS_RECORD_NAME);
     $this->getProcessor()->aggregateDataTableRecords($dataTableToSum, ArchivingHelper::$maximumRowsInDataTableLevelZero, ArchivingHelper::$maximumRowsInSubDataTable, ArchivingHelper::$columnToSortByBeforeTruncation, self::$columnsAggregationOperation, self::$columnsToRenameAfterAggregation);
     $dataTableToSum = array(self::DOWNLOADS_RECORD_NAME, self::OUTLINKS_RECORD_NAME, self::SITE_SEARCH_RECORD_NAME);
     $aggregation = null;
     $nameToCount = $this->getProcessor()->aggregateDataTableRecords($dataTableToSum, ArchivingHelper::$maximumRowsInDataTableLevelZero, ArchivingHelper::$maximumRowsInSubDataTable, ArchivingHelper::$columnToSortByBeforeTruncation, $aggregation, self::$columnsToRenameAfterAggregation);
     $this->getProcessor()->aggregateNumericMetrics($this->getMetricNames());
     // Unique Keywords can't be summed, instead we take the RowsCount() of the keyword table
     $this->getProcessor()->insertNumericRecord(self::METRIC_KEYWORDS_RECORD_NAME, $nameToCount[self::SITE_SEARCH_RECORD_NAME]['level0']);
 }
Esempio n. 5
0
 private function getPageLabel(&$pageRecord, $type)
 {
     if ($type == Action::TYPE_PAGE_TITLE) {
         $label = $pageRecord['name'];
         if (empty($label)) {
             $label = ArchivingHelper::getUnknownActionName(Action::TYPE_PAGE_TITLE);
         }
         return $label;
     }
     if ($type == Action::TYPE_OUTLINK || $type == Action::TYPE_DOWNLOAD) {
         return PageUrl::reconstructNormalizedUrl($pageRecord['name'], $pageRecord['url_prefix']);
     }
     return $pageRecord['name'];
 }
Esempio n. 6
0
 /**
  * Will search in the DataTable for a Label matching the searched string
  * and return only the matching row, or an empty datatable
  */
 protected function getFilterPageDatatableSearch($callBackParameters, $search, $actionType, $table = false, $searchTree = false)
 {
     if ($searchTree === false) {
         // build the query parts that are searched inside the tree
         if ($actionType == Action::TYPE_PAGE_TITLE) {
             $searchedString = Common::unsanitizeInputValue($search);
         } else {
             $idSite = $callBackParameters[1];
             try {
                 $searchedString = PageUrl::excludeQueryParametersFromUrl($search, $idSite);
             } catch (Exception $e) {
                 $searchedString = $search;
             }
         }
         ArchivingHelper::reloadConfig();
         $searchTree = ArchivingHelper::getActionExplodedNames($searchedString, $actionType);
     }
     if ($table === false) {
         // fetch the data table
         $table = call_user_func_array(array($this, 'getDataTableFromArchive'), $callBackParameters);
         if ($table instanceof DataTable\Map) {
             // search an array of tables, e.g. when using date=last30
             // note that if the root is an array, we filter all children
             // if an array occurs inside the nested table, we only look for the first match (see below)
             $dataTableMap = $table->getEmptyClone();
             foreach ($table->getDataTables() as $label => $subTable) {
                 $newSubTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);
                 $dataTableMap->addTable($newSubTable, $label);
             }
             return $dataTableMap;
         }
     }
     return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
 }
Esempio n. 7
0
 /**
  * @dataProvider getActionNameTestData
  */
 public function testGetActionExplodedNames($params, $expected)
 {
     ArchivingHelper::reloadConfig();
     $processed = ArchivingHelper::getActionExplodedNames($params['name'], $params['type'], isset($params['urlPrefix']) ? $params['urlPrefix'] : null);
     $this->assertEquals($expected, $processed);
 }
Esempio n. 8
0
 protected function aggregateDayEvents()
 {
     $select = "\n                log_action_event_category.name as eventCategory,\n                log_action_event_action.name as eventAction,\n                log_action_event_name.name as eventName,\n\n\t\t\t\tcount(distinct log_link_visit_action.idvisit) as `" . Metrics::INDEX_NB_VISITS . "`,\n\t\t\t\tcount(distinct log_link_visit_action.idvisitor) as `" . Metrics::INDEX_NB_UNIQ_VISITORS . "`,\n\t\t\t\tcount(*) as `" . Metrics::INDEX_EVENT_NB_HITS . "`,\n\n\t\t\t\tsum(\n\t\t\t\t\tcase when " . Action::DB_COLUMN_CUSTOM_FLOAT . " is null\n\t\t\t\t\t\tthen 0\n\t\t\t\t\t\telse " . Action::DB_COLUMN_CUSTOM_FLOAT . "\n\t\t\t\t\tend\n\t\t\t\t) as `" . Metrics::INDEX_EVENT_SUM_EVENT_VALUE . "`,\n\t\t\t\tsum( case when " . Action::DB_COLUMN_CUSTOM_FLOAT . " is null then 0 else 1 end )\n\t\t\t\t    as `" . Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE . "`,\n\t\t\t\tmin(" . Action::DB_COLUMN_CUSTOM_FLOAT . ") as `" . Metrics::INDEX_EVENT_MIN_EVENT_VALUE . "`,\n\t\t\t\tmax(" . Action::DB_COLUMN_CUSTOM_FLOAT . ") as `" . Metrics::INDEX_EVENT_MAX_EVENT_VALUE . "`\n        ";
     $from = array("log_link_visit_action", array("table" => "log_action", "tableAlias" => "log_action_event_category", "joinOn" => "log_link_visit_action.idaction_event_category = log_action_event_category.idaction"), array("table" => "log_action", "tableAlias" => "log_action_event_action", "joinOn" => "log_link_visit_action.idaction_event_action = log_action_event_action.idaction"), array("table" => "log_action", "tableAlias" => "log_action_event_name", "joinOn" => "log_link_visit_action.idaction_name = log_action_event_name.idaction"));
     $where = "log_link_visit_action.server_time >= ?\n                    AND log_link_visit_action.server_time <= ?\n                    AND log_link_visit_action.idsite = ?\n                    AND log_link_visit_action.idaction_event_category IS NOT NULL";
     $groupBy = "log_action_event_category.idaction,\n                    log_action_event_action.idaction,\n                    log_action_event_name.idaction";
     $orderBy = "`" . Metrics::INDEX_NB_VISITS . "` DESC";
     $rankingQueryLimit = ArchivingHelper::getRankingQueryLimit();
     $rankingQuery = null;
     if ($rankingQueryLimit > 0) {
         $rankingQuery = new RankingQuery($rankingQueryLimit);
         $rankingQuery->setOthersLabel(DataTable::LABEL_SUMMARY_ROW);
         $rankingQuery->addLabelColumn(array('eventCategory', 'eventAction', 'eventName'));
         $rankingQuery->addColumn(array(Metrics::INDEX_NB_UNIQ_VISITORS));
         $rankingQuery->addColumn(array(Metrics::INDEX_EVENT_NB_HITS, Metrics::INDEX_NB_VISITS, Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE), 'sum');
         $rankingQuery->addColumn(Metrics::INDEX_EVENT_SUM_EVENT_VALUE, 'sum');
         $rankingQuery->addColumn(Metrics::INDEX_EVENT_MIN_EVENT_VALUE, 'min');
         $rankingQuery->addColumn(Metrics::INDEX_EVENT_MAX_EVENT_VALUE, 'max');
     }
     $this->archiveDayQueryProcess($select, $from, $where, $groupBy, $orderBy, $rankingQuery);
 }
Esempio n. 9
0
 /**
  * For rows which have subtables (eg. directories with sub pages),
  * deletes columns which don't make sense when all values of sub pages are summed.
  *
  * @param $dataTable DataTable
  */
 public static function deleteInvalidSummedColumnsFromDataTable($dataTable)
 {
     foreach ($dataTable->getRows() as $id => $row) {
         if (($idSubtable = $row->getIdSubDataTable()) !== null || $id === DataTable::ID_SUMMARY_ROW) {
             $subTable = $row->getSubtable();
             if ($subTable) {
                 self::deleteInvalidSummedColumnsFromDataTable($subTable);
             }
             if ($row instanceof DataTableSummaryRow) {
                 $row->recalculate();
             }
             foreach (Metrics::$columnsToDeleteAfterAggregation as $name) {
                 $row->deleteColumn($name);
             }
         }
     }
     // And this as well
     ArchivingHelper::removeEmptyColumns($dataTable);
 }