/** * Returns datatable describing the number of visits for each day of the week. * * @param string $idSite The site ID. Cannot refer to multiple sites. * @param string $period The period type: day, week, year, range... * @param string $date The start date of the period. Cannot refer to multiple dates. * @param string $segment The segment. * @return Piwik_DataTable */ public function getByDayOfWeek($idSite, $period, $date, $segment = false) { Piwik::checkUserHasViewAccess($idSite); // disabled for multiple sites/dates if (Piwik_Archive::isMultipleSites($idSite)) { throw new Exception("VisitTime.getByDayOfWeek does not support multiple sites."); } if (Piwik_Archive::isMultiplePeriod($date, $period)) { throw new Exception("VisitTime.getByDayOfWeek does not support multiple dates."); } // metrics to query $metrics = Piwik_ArchiveProcessing::getCoreMetrics(); // get metric data for every day within the supplied period $oSite = new Piwik_Site($idSite); $oPeriod = Piwik_Archive::makePeriodFromQueryParams($oSite, $period, $date); $dateRange = $oPeriod->getDateStart()->toString() . ',' . $oPeriod->getDateEnd()->toString(); $archive = Piwik_Archive::build($idSite, 'day', $dateRange, $segment); $dataTable = $archive->getDataTableFromNumeric($metrics)->mergeChildren(); // if there's no data for this report, don't bother w/ anything else if ($dataTable->getRowsCount() == 0) { return $dataTable; } // group by the day of the week (see below for dayOfWeekFromDate function) $dataTable->filter('GroupBy', array('label', 'Piwik_VisitTime_dayOfWeekFromDate')); // create new datatable w/ empty rows, then add calculated datatable $rows = array(); foreach (array(1, 2, 3, 4, 5, 6, 7) as $day) { $rows[] = array('label' => $day, 'nb_visits' => 0); } $result = new Piwik_DataTable(); $result->addRowsFromSimpleArray($rows); $result->addDataTable($dataTable); // set day of week integer as metadata $result->filter('ColumnCallbackAddMetadata', array('label', 'day_of_week')); // translate labels $result->filter('ColumnCallbackReplace', array('label', 'Piwik_VisitTime_translateDayOfWeek')); // set datatable metadata for period start & finish $result->setMetadata('date_start', $oPeriod->getDateStart()); $result->setMetadata('date_end', $oPeriod->getDateEnd()); return $result; }
/** * Returns the name of the report (the named collection of metrics) that contains the * specified metric. * * @param string $metric The metric whose report is being requested. If this does * not belong to a known report, its assumed to be the report * itself. * @return string */ public static function getRequestedReportFor($metric) { // Core metrics are always processed in Core, for the requested date/period/segment if (in_array($metric, Piwik_ArchiveProcessing::getCoreMetrics()) || $metric == 'max_actions') { return 'VisitsSummary_CoreMetrics'; } // VisitFrequency metrics don't follow the same naming convention (HACK) if (strpos($metric, '_returning') > 0 && strpos($metric, 'Goal_') === false) { return 'VisitFrequency_Metrics'; } // Goal_* metrics are processed by the Goals plugin (HACK) if (strpos($metric, 'Goal_') === 0) { return 'Goals_Metrics'; } // Actions metrics are processed by the Actions plugin (HACK) (3RD HACK IN FACT) (YES, THIS IS TOO MUCH HACKING) // (FIXME PLEASE). if (in_array($metric, Piwik_Archive::$actionsMetrics)) { return 'Actions_Metrics'; } return $metric; }
protected function getRequestedReport() { // Core metrics are always processed in Core, for the requested date/period/segment if(in_array($this->requestedReport, Piwik_ArchiveProcessing::getCoreMetrics()) || $this->requestedReport == 'max_actions') { return 'VisitsSummary_CoreMetrics'; } // VisitFrequency metrics don't follow the same naming convention (HACK) if(strpos($this->requestedReport, '_returning') > 0 // ignore Goal_visitor_returning_1_1_nb_conversions && strpos($this->requestedReport, 'Goal_') === false) { return 'VisitFrequency_Metrics'; } // Goal_* metrics are processed by the Goals plugin (HACK) if(strpos($this->requestedReport, 'Goal_') === 0) { return 'Goals_Metrics'; } return $this->requestedReport; }