コード例 #1
0
ファイル: Archive.php プロジェクト: BeezyT/piwik-sitesearch
 /** Get data table from archive
  * @return Piwik_DataTable */
 public static function getDataTable($name, $idsite, $period, $date, $numeric = false)
 {
     Piwik::checkUserHasViewAccess($idsite);
     if (is_array($name)) {
         foreach ($name as &$col) {
             $col = 'SiteSearch_' . $col;
         }
     } else {
         $name = 'SiteSearch_' . $name;
     }
     if (!is_string($period) && get_class($period) != 'Piwik_Period_Range') {
         $periodMap = array('Piwik_Period_Day' => 'day', 'Piwik_Period_Week' => 'week', 'Piwik_Period_Month' => 'month', 'Piwik_Period_Year' => 'year');
         $period = $periodMap[get_class($period)];
     }
     $archive = Piwik_Archive::build($idsite, $period, $date);
     if ($numeric) {
         // numeric archives are only used for search evolution
         $dataTable = $archive->getDataTableFromNumeric($name);
         $dataTable->queueFilter('ReplaceColumnNames', array(array('SiteSearch_totalSearches' => self::HITS, 'SiteSearch_visitsWithSearches' => self::UNIQUE_HITS)));
         $dataTable->applyQueuedFilters();
     } else {
         $dataTable = $archive->getDataTable($name);
     }
     return $dataTable;
 }
コード例 #2
0
 /**
  * Returns the list of metrics (pages, downloads, outlinks)
  * 
  * @param int $idSite
  * @param string $period
  * @param string $date
  * @param string $segment
  */
 public function get($idSite, $period, $date, $segment = false, $columns = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     $metrics = array('Actions_nb_pageviews' => 'nb_pageviews', 'Actions_nb_uniq_pageviews' => 'nb_uniq_pageviews', 'Actions_nb_downloads' => 'nb_downloads', 'Actions_nb_uniq_downloads' => 'nb_uniq_downloads', 'Actions_nb_outlinks' => 'nb_outlinks', 'Actions_nb_uniq_outlinks' => 'nb_uniq_outlinks');
     // get requested columns
     $columns = Piwik::getArrayFromApiParameter($columns);
     if (!empty($columns)) {
         // get the columns that are available and requested
         $columns = array_intersect($columns, array_values($metrics));
         $columns = array_values($columns);
         // make sure indexes are right
         $nameReplace = array();
         foreach ($columns as $i => $column) {
             $fullColumn = array_search($column, $metrics);
             $columns[$i] = $fullColumn;
             $nameReplace[$fullColumn] = $column;
         }
     } else {
         // get all columns
         $columns = array_keys($metrics);
         $nameReplace =& $metrics;
     }
     $table = $archive->getDataTableFromNumeric($columns);
     // replace labels (remove Actions_)
     $table->filter('ReplaceColumnNames', array($nameReplace));
     return $table;
 }
コード例 #3
0
ファイル: API.php プロジェクト: Gninety/Microweber
 protected function getNumeric($idSite, $period, $date, $segment, $toFetch)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     $dataTable = $archive->getNumeric($toFetch);
     return $dataTable;
 }
コード例 #4
0
ファイル: IndexedBySite.php プロジェクト: nnnnathann/piwik
 /**
  * @param array          $sites      array of siteIds
  * @param string         $strPeriod  eg. 'day' 'week' etc.
  * @param string         $strDate    A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  * @param Piwik_Segment  $segment
  * @param string         $_restrictSitesToLogin
  */
 function __construct($sites, $strPeriod, $strDate, Piwik_Segment $segment, $_restrictSitesToLogin)
 {
     foreach ($sites as $idSite) {
         $archive = Piwik_Archive::build($idSite, $strPeriod, $strDate, $segment, $_restrictSitesToLogin);
         $this->archives[$idSite] = $archive;
     }
     ksort($this->archives);
 }
コード例 #5
0
ファイル: API.php プロジェクト: neolf/PIWIK4MOBILE
 protected function getDataTable($name, $idSite, $period, $date, $segment, $column = Piwik_Archive::INDEX_NB_VISITS)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     $dataTable = $archive->getDataTable($name);
     $dataTable->queueFilter('ReplaceColumnNames');
     return $dataTable;
 }
コード例 #6
0
ファイル: Archive.php プロジェクト: BeezyT/piwik-siteusers
 /** Get data table from archive
  * @return Piwik_DataTable */
 public static function getDataTable($name, $idsite, $period, $date)
 {
     Piwik::checkUserHasViewAccess($idsite);
     $name = 'SiteUsers_' . $name;
     $archive = Piwik_Archive::build($idsite, $period, $date);
     $dataTable = $archive->getDataTable($name);
     return $dataTable;
 }
コード例 #7
0
ファイル: API.php プロジェクト: BeezyT/piwik-sitesearch
 /** Get evolution of search percentage
  * @return Piwik_DataTable */
 public function getSearchPercentageEvolution($idSite, $period, $date)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date);
     $dataTable = $archive->getDataTableFromNumeric(array('SiteSearch_visitsWithSearches', 'nb_visits'));
     $dataTable->filter('ColumnCallbackAddColumnQuotient', array('search_percentage', 'SiteSearch_visitsWithSearches', 'nb_visits', 4));
     $dataTable->filter('ColumnCallbackReplace', array('search_percentage', array($this, 'quotientToPercentageSafe')));
     return $dataTable;
 }
コード例 #8
0
ファイル: IndexedBySite.php プロジェクト: Doluci/tomatocart
 /**
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct($sites, $strPeriod, $strDate)
 {
     foreach ($sites as $idSite) {
         $archive = Piwik_Archive::build($idSite, $strPeriod, $strDate);
         $archive->setSite(new Piwik_Site($idSite));
         $archive->prepareArchive();
         $this->archives[$idSite] = $archive;
     }
     ksort($this->archives);
 }
コード例 #9
0
ファイル: IndexedBySite.php プロジェクト: Gninety/Microweber
 /**
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct($sites, $strPeriod, $strDate, Piwik_Segment $segment)
 {
     foreach ($sites as $idSite) {
         $archive = Piwik_Archive::build($idSite, $strPeriod, $strDate, $segment->getString());
         $archive->setSite(new Piwik_Site($idSite));
         $archive->setSegment($segment);
         $this->archives[$idSite] = $archive;
     }
     ksort($this->archives);
 }
コード例 #10
0
ファイル: API.php プロジェクト: BackupTheBerlios/oos-svn
	protected function getDataTable($name, $idSite, $period, $date, $segment )
	{
		Piwik::checkUserHasViewAccess( $idSite );
		$archive = Piwik_Archive::build($idSite, $period, $date, $segment );
		$dataTable = $archive->getDataTable($name);
		$dataTable->filter('Sort', array('label', 'asc', true));
		$dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getTimeLabel'));
		$dataTable->queueFilter('ReplaceColumnNames');
		return $dataTable;
	}
コード例 #11
0
ファイル: API.php プロジェクト: klando/pgpiwik
 protected function getDataTable($name, $idSite, $period, $date)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date);
     $dataTable = $archive->getDataTable($name);
     $dataTable->filter('Sort', array(Piwik_Archive::INDEX_NB_VISITS));
     $dataTable->queueFilter('ReplaceColumnNames');
     $dataTable->queueFilter('Sort', array('label', 'asc', true));
     return $dataTable;
 }
コード例 #12
0
ファイル: IndexedByDate.php プロジェクト: Gninety/Microweber
 /**
  * Builds an array of Piwik_Archive of a given date range
  *
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct(Piwik_Site $oSite, $strPeriod, $strDate, Piwik_Segment $segment)
 {
     $rangePeriod = new Piwik_Period_Range($strPeriod, $strDate, $oSite->getTimezone());
     foreach ($rangePeriod->getSubperiods() as $subPeriod) {
         $startDate = $subPeriod->getDateStart();
         $archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate, $segment->getString());
         $archive->setSegment($segment);
         $this->archives[] = $archive;
     }
 }
コード例 #13
0
ファイル: API.php プロジェクト: BackupTheBerlios/oos-svn
 public function getProvider($idSite, $period, $date)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date);
     $dataTable = $archive->getDataTable('Provider_hostnameExt');
     $dataTable->filter('Sort', array(Piwik_Archive::INDEX_NB_VISITS));
     $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', 'Piwik_getHostnameUrl'));
     $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getHostnameName'));
     $dataTable->queueFilter('ReplaceColumnNames');
     return $dataTable;
 }
コード例 #14
0
 /**
  * Builds an array of Piwik_Archive of a given date range
  *
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct(Piwik_Site $oSite, $strPeriod, $strDate)
 {
     $rangePeriod = new Piwik_Period_Range($strPeriod, $strDate);
     foreach ($rangePeriod->getSubperiods() as $subPeriod) {
         $startDate = $subPeriod->getDateStart();
         $archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate);
         $archive->prepareArchive();
         $timestamp = $archive->getTimestampStartDate();
         $this->archives[$timestamp] = $archive;
     }
     ksort($this->archives);
 }
コード例 #15
0
 /**
  * Test that Archive_Single::preFetchBlob won't fetch extra unnecessary blobs.
  * 
  * @group        Integration
  * @group        OneVisitorTwoVisits
  */
 public function testArchiveSinglePreFetchBlob()
 {
     $archive = Piwik_Archive::build(self::$idSite, 'day', self::$dateTime);
     $archive->preFetchBlob('Actions_actions');
     $cache = $archive->getBlobCache();
     $foundSubtable = false;
     $this->assertTrue(count($cache) > 0, "empty blob cache");
     foreach ($cache as $name => $value) {
         $this->assertTrue(strpos($name, "Actions_actions_url") === false, "found blob w/ name '{$name}'");
         if (strpos($name, "Actions_actions_") !== false) {
             $foundSubtable = true;
         }
     }
     $this->assertTrue($foundSubtable, "Actions_actions subtable was not loaded");
 }
コード例 #16
0
ファイル: Array.php プロジェクト: Doluci/tomatocart
 /**
  * Builds an array of Piwik_Archive of a given date range
  *
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct(Piwik_Site $oSite, $strPeriod, $strDate)
 {
     $rangePeriod = new Piwik_Period_Range($strPeriod, $strDate);
     // TODO fix this when aggregating data from multiple websites
     // CAREFUL this class wouldnt work as is if handling archives from multiple websites
     // works only when managing archives from multiples dates/periods
     foreach ($rangePeriod->getSubperiods() as $subPeriod) {
         $startDate = $subPeriod->getDateStart();
         $archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate);
         $archive->prepareArchive();
         $timestamp = $archive->getTimestampStartDate();
         $this->archives[$timestamp] = $archive;
     }
     ksort($this->archives);
 }
コード例 #17
0
ファイル: API.php プロジェクト: Doluci/tomatocart
 protected function getDataTable($name, $idSite, $period, $date, $expanded, $idSubtable)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date);
     if ($idSubtable === false) {
         $idSubtable = null;
     }
     if ($expanded) {
         $dataTable = $archive->getDataTableExpanded($name, $idSubtable);
     } else {
         $dataTable = $archive->getDataTable($name, $idSubtable);
     }
     $dataTable->filter('Sort', array('nb_visits', 'desc', $naturalSort = false, $expanded));
     $dataTable->queueFilter('ReplaceSummaryRowLabel');
     return $dataTable;
 }
コード例 #18
0
ファイル: API.php プロジェクト: nnnnathann/piwik
 /**
  * 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;
 }
コード例 #19
0
ファイル: API.php プロジェクト: nachopavon/IntranetSubNetwork
 public function getIntranetSubNetwork($idSite, $period, $date, $segment = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     $dataTable = $archive->getDataTable('IntranetSubNetwork_networkNameExt');
     $dataTable->filter('Sort', array(Piwik_Archive::INDEX_NB_VISITS));
     $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getSubnetName'));
     $dataTable->queueFilter('ReplaceColumnNames');
     //$dataTable->queueFilter('ReplaceSummaryRowLabel');
     $column = 'nb_visits';
     $percCol = 'nb_visits_percentage';
     $percColName = 'General_ColumnPercentageVisits';
     $visitsSums = $archive->getNumeric($column);
     //$visitsSum = Piwik_VisitsSummary_API::getInstance()->getVisits($idSite, $period, $date);
     //print_r($visitsSums);
     // check whether given tables are arrays
     if ($dataTable instanceof Piwik_DataTable_Array) {
         $tableArray = $dataTable->getArray();
         $visitSumsArray = $visitsSums->getArray();
     } else {
         $tableArray = array($dataTable);
         $visitSumsArray = array($visitsSums);
     }
     // walk through the results and calculate the percentage
     foreach ($tableArray as $key => $table) {
         foreach ($visitSumsArray as $k => $visits) {
             if ($k == $key) {
                 if (is_object($visits)) {
                     $visitsSumTotal = (double) $visits->getFirstRow()->getColumn(0);
                 } else {
                     $visitsSumTotal = (double) $visits;
                 }
             }
         }
         $table->filter('ColumnCallbackAddColumnPercentage', array($percCol, Piwik_Archive::INDEX_NB_VISITS, $visitsSumTotal, 1));
         // we don't want <0% or >100%:
         $table->filter('RangeCheck', array($percCol));
     }
     return $dataTable;
 }
コード例 #20
0
ファイル: API.php プロジェクト: arminiusdc/goobi-contrib
 /**
  * Gibt eine sortierte DataTable mit Kollektionen aus den Archiven zur�ck.
  * @param int $idSite
  * @param unknown_type $period
  * @param unknown_type $date
  * @param boolean $segment
  * @return Piwik_DataTable
  */
 protected function getCollectionTableFromArchive($idSite, $period, $date, $segment)
 {
     //	defined('PIWIK_INCLUDE_PATH') or die('Restricted access');
     Piwik_cdebug::clog('getCollectionTableFromArchive: ' . $idSite . ' period: ' . $period);
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     $dataTable = $archive->getDataTable("DigitalCollections_value");
     Piwik_cdebug::clog('getCollectionTableFromArchive: dataTable: ' . count($dataTable));
     Piwik_cdebug::clog('getCollectionTableFromArchive: dataTable: ' . print_r($dataTable, 1));
     $dataTable->filter('Sort', array(Piwik_DigitalCollections::$valuefield, 'desc'));
     $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'url', 'getCollectionUrlFromID', array($date, $period)));
     $dataTable->filter('ColumnCallbackReplace', array('label', 'getCollectionNames'));
     $dataTable->filter('ReplaceColumnNames');
     //INDEX_NB_VISITS-Spalte zur richtigen Graphen-Anzeige hinzuf�gen --> ACHTUNG! Muss im Controller ausgeblendet werden!
     $rows = $dataTable->getRows();
     Piwik_cdebug::clog('getCollectionTableFromArchive: rows: ' . count($rows));
     foreach ($rows as $i => $row) {
         Piwik_cdebug::clog('getCollectionTableFromArchive: ' . $i);
         $row->addColumn(Piwik_Archive::INDEX_NB_VISITS, $row->getColumn("visits"));
     }
     return $dataTable;
 }
コード例 #21
0
ファイル: API.php プロジェクト: BackupTheBerlios/oos-svn
	public function getPlugin( $idSite, $period, $date, $segment = false )
	{
		// fetch all archive data required
		$dataTable = $this->getDataTable('UserSettings_plugin', $idSite, $period, $date, $segment);
		$browserTypes	= $this->getDataTable('UserSettings_browserType', $idSite, $period, $date, $segment);
		$archive		= Piwik_Archive::build($idSite, $period, $date, $segment);
		$visitsSums		= $archive->getNumeric('nb_visits');

		// check whether given tables are arrays
		if($dataTable instanceof Piwik_DataTable_Array) {
			$tableArray			= $dataTable->getArray();
			$browserTypesArray	= $browserTypes->getArray();
			$visitSumsArray		= $visitsSums->getArray();
		} else {
			$tableArray 		= Array($dataTable);
			$browserTypesArray 	= Array($browserTypes);
			$visitSumsArray 	= Array($visitsSums);
		}
		
		// walk through the results and calculate the percentage
		foreach($tableArray as $key => $table) {
			
			// get according browserType table
			foreach($browserTypesArray AS $k => $browsers) {
				if($k == $key) {
					$browserType = $browsers;
				}
			}
			
			// get according visitsSum
			foreach($visitSumsArray AS $k => $visits) {
				if($k == $key) {
					if(is_object($visits)) {
						$visitsSumTotal = (float)$visits->getFirstRow()->getColumn(0);
					} else {
						$visitsSumTotal = (float)$visits;
					}
				}
			}
			
			$ieStats		= $browserType->getRowFromLabel('ie');

			$ieVisits 	= 0;
			if($ieStats !== false)
			{
				$ieVisits = $ieStats->getColumn(Piwik_Archive::INDEX_NB_VISITS);
			}
			$visitsSum		= $visitsSumTotal - $ieVisits;
		
			// Calculate percentage, but ignore IE users cause plugin detection doesn't work on IE
			// The filter must be applied now so that the new column can 
			// be sorted by the generic filters (applied right after this function exits)
			$table->filter('ColumnCallbackAddColumnPercentage', array('nb_visits_percentage', Piwik_Archive::INDEX_NB_VISITS, $visitsSum, 1));
		
			// correct the cookie and java value (as detection works in IE, too)
			$row = $table->getRowFromLabel('cookie');
			if($row) {
				$percentage = Piwik::getPercentageSafe($row->getColumn(Piwik_Archive::INDEX_NB_VISITS), $visitsSumTotal, 1) . '%';
				$row->setColumn('nb_visits_percentage', $percentage);
			}
			$row = $table->getRowFromLabel('java');
			if($row) {
				$percentage = Piwik::getPercentageSafe($row->getColumn(Piwik_Archive::INDEX_NB_VISITS), $visitsSumTotal, 1) . '%';
				$row->setColumn('nb_visits_percentage', $percentage);
			}
			
		}
		
		$dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getPluginsLogo'));
		$dataTable->queueFilter('ColumnCallbackReplace', array('label', 'ucfirst'));
		
		return $dataTable;
	}
コード例 #22
0
 private function addReportData()
 {
     $archive = Piwik_Archive::build($this->idSite, 'year', $this->dateTime);
     $archive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'year', $this->dateTime);
     // months are added via the 'year' period, but weeks must be done manually
     for ($daysAgo = $this->daysAgoStart; $daysAgo > 0; $daysAgo -= 7) {
         $dateTime = $this->dateTime->subDay($daysAgo);
         $archive = Piwik_Archive::build($this->idSite, 'week', $dateTime);
         $archive->getNumeric('nb_visits');
         Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'week', $dateTime);
     }
     // add segment for one day
     $archive = Piwik_Archive::build($this->idSite, 'day', '2012-01-14', 'browserName==FF');
     $archive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'day', '2012-01-14', 'browserName==FF');
     // add range within January
     $rangeEnd = Piwik_Date::factory('2012-01-29');
     $rangeStart = $rangeEnd->subDay(1);
     $range = $rangeStart->toString('Y-m-d') . "," . $rangeEnd->toString('Y-m-d');
     $rangeArchive = Piwik_Archive::build($this->idSite, 'range', $range);
     $rangeArchive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'range', $range);
     // add range between January & February
     $rangeStart = $rangeEnd;
     $rangeEnd = $rangeStart->addDay(3);
     $range = $rangeStart->toString('Y-m-d') . "," . $rangeEnd->toString('Y-m-d');
     $rangeArchive = Piwik_Archive::build($this->idSite, 'range', $range);
     $rangeArchive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'range', $range);
     // when archiving is initiated, the archive metrics & reports for EVERY loaded plugin
     // are archived. don't want this test to depend on every possible metric, so get rid of
     // the unwanted archive data now.
     $metricsToSave = array('nb_visits', 'nb_actions', Piwik_Goals::getRecordName('revenue'), Piwik_Goals::getRecordName('nb_conversions', 1), Piwik_Goals::getRecordName('revenue', Piwik_Tracker_GoalManager::IDGOAL_ORDER));
     $archiveTables = $this->getArchiveTableNames();
     foreach ($archiveTables['numeric'] as $table) {
         $realTable = Piwik_Common::prefixTable($table);
         Piwik_Query("DELETE FROM {$realTable} WHERE name NOT IN ('" . implode("','", $metricsToSave) . "') AND name NOT LIKE 'done%'");
     }
     foreach ($archiveTables['blob'] as $table) {
         $realTable = Piwik_Common::prefixTable($table);
         Piwik_Query("DELETE FROM {$realTable} WHERE name NOT IN ('VisitorInterest_timeGap')");
     }
     // add garbage metrics
     $janDate1 = '2012-01-05';
     $febDate1 = '2012-02-04';
     $sql = "INSERT INTO %s (idarchive,name,idsite,date1,date2,period,ts_archived,value)\n\t\t                VALUES (10000,?,1,?,?,?,?,?)";
     // one metric for jan & one for feb
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['numeric'][0])), array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 1, 100));
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['numeric'][1])), array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 1, 200));
     // add garbage reports
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['blob'][0])), array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 10, 'blobval'));
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['blob'][1])), array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 20, 'blobval'));
 }
コード例 #23
0
ファイル: API.php プロジェクト: neolf/PIWIK4MOBILE
 private function getNumeric($name, $idSite, $period, $date, $segment)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     return $archive->getDataTableFromNumeric($name);
 }
コード例 #24
0
ファイル: API.php プロジェクト: BackupTheBerlios/oos-svn
 public function getNumberOfDistinctCountries($idSite, $period, $date)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date);
     return $archive->getDataTableFromNumeric('UserCountry_distinctCountries');
 }
コード例 #25
0
ファイル: API.php プロジェクト: kamermans/MobileAnalytics
 public function getDeviceMobile($idSite, $period, $date)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date);
     $dataTable = $archive->getDataTable('MobileAnalytics_mobile');
     $dataTable->filter('Sort', array(Piwik_Archive::INDEX_NB_VISITS));
     $dataTable->queueFilter('ColumnCallbackReplace', array('label', array('Piwik_MobileAnalytics_API', 'mobileLabel')));
     $dataTable->queueFilter('ReplaceColumnNames');
     $dataTable->queueFilter('ReplaceSummaryRowLabel');
     return $dataTable;
 }
コード例 #26
0
ファイル: API.php プロジェクト: neolf/PIWIK4MOBILE
 /**
  * Returns a report displaying the total visits, actions and revenue, as
  * well as the evolution of these values, of all existing sites over a
  * specified period of time.
  * 
  * If the specified period is not a 'range', this function will calculcate
  * evolution metrics. Evolution metrics are metrics that display the
  * percent increase/decrease of another metric since the last period.
  * 
  * This function will merge the result of the archive query so each
  * row in the result DataTable will correspond to the metrics of a single
  * site. If a date range is specified, the result will be a
  * DataTable_Array, but it will still be merged.
  * 
  * @param string $period The period type to get data for.
  * @param string $date The date(s) to get data for.
  * @param string $segment The segments to get data for.
  */
 public function getAll($period, $date, $segment = false)
 {
     Piwik::checkUserHasSomeViewAccess();
     $isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled();
     // get site data for every viewable site and cache them
     if (Piwik::isUserIsSuperUser()) {
         $sites = Piwik_SitesManager_API::getInstance()->getAllSites();
         Piwik_Site::setSites($sites);
     } else {
         $sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
         Piwik_Site::setSitesFromArray($sites);
     }
     // build the archive type used to query archive data
     $archive = Piwik_Archive::build('all', $period, $date, $segment);
     // determine what data will be displayed
     $fieldsToGet = array('nb_visits', 'nb_actions');
     if ($isGoalPluginEnabled) {
         $revenueMetric = Piwik_Goals::getRecordName('revenue');
         $fieldsToGet[] = $revenueMetric;
     }
     // get the data
     $dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
     // get rid of the DataTable_Array that is created by the IndexedBySite archive type
     $dataTable = $dataTable->mergeChildren();
     // if the period isn't a range & a lastN/previousN date isn't used, we get the same
     // data for the last period to show the evolution of visits/actions/revenue
     if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
         if (strpos($date, ',')) {
             $rangePeriod = new Piwik_Period_Range($period, $date);
             $lastStartDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateStart(), $n = 1);
             $lastEndDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateEnd(), $n = 1);
             $strLastDate = "{$lastStartDate},{$lastEndDate}";
         } else {
             $strLastDate = Piwik_Period_Range::removePeriod($period, Piwik_Date::factory($date), $n = 1)->toString();
         }
         $pastArchive = Piwik_Archive::build('all', $period, $strLastDate, $segment);
         $pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
         $pastData = $pastData->mergeChildren();
         // use past data to calculate evolution percentages
         $this->calculateEvolutionPercentages($dataTable, $pastData, $fieldsToGet);
     }
     // move the site id to a metadata column
     $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'idsite'));
     // set the label of each row to the site name
     $getNameFor = array('Piwik_Site', 'getNameFor');
     $dataTable->filter('ColumnCallbackReplace', array('label', $getNameFor));
     // rename the revenue column from the metric name to 'revenue'
     if ($isGoalPluginEnabled) {
         $mapping = array($revenueMetric => 'revenue');
         $dataTable->filter('ReplaceColumnNames', array($mapping));
     }
     // Ensures data set sorted, for Metadata output
     $dataTable->filter('Sort', array('nb_visits', 'desc', $naturalSort = false));
     return $dataTable;
 }
コード例 #27
0
ファイル: API.php プロジェクト: nnnnathann/piwik
 private function buildDataTable($sites, $period, $date, $segment, $_restrictSitesToLogin, $enhanced)
 {
     $allWebsitesRequested = $sites == 'all';
     if ($allWebsitesRequested) {
         if (Piwik::isUserIsSuperUser() && !Piwik_TaskScheduler::isTaskBeingExecuted()) {
             Piwik_Site::setSites(Piwik_SitesManager_API::getInstance()->getAllSites());
         } else {
             Piwik_Site::setSitesFromArray(Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin));
         }
     }
     // build the archive type used to query archive data
     $archive = Piwik_Archive::build($sites, $period, $date, $segment, $_restrictSitesToLogin);
     // determine what data will be displayed
     $fieldsToGet = array();
     $columnNameRewrites = array();
     $apiECommerceMetrics = array();
     $apiMetrics = Piwik_MultiSites_API::getApiMetrics($enhanced);
     foreach ($apiMetrics as $metricName => $metricSettings) {
         $fieldsToGet[] = $metricSettings[self::METRIC_RECORD_NAME_KEY];
         $columnNameRewrites[$metricSettings[self::METRIC_RECORD_NAME_KEY]] = $metricName;
         if ($metricSettings[self::METRIC_IS_ECOMMERCE_KEY]) {
             $apiECommerceMetrics[$metricName] = $metricSettings;
         }
     }
     // get the data
     // $dataTable instanceOf Piwik_DataTable_Array
     $dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
     // get rid of the DataTable_Array that is created by the IndexedBySite archive type
     if ($dataTable instanceof Piwik_DataTable_Array && $allWebsitesRequested) {
         $dataTable = $dataTable->mergeChildren();
     } else {
         if (!$dataTable instanceof Piwik_DataTable_Array) {
             $firstDataTableRow = $dataTable->getFirstRow();
             $firstDataTableRow->setColumn('label', $sites);
         }
     }
     // if the period isn't a range & a lastN/previousN date isn't used, we get the same
     // data for the last period to show the evolution of visits/actions/revenue
     if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
         if (strpos($date, ',')) {
             $rangePeriod = new Piwik_Period_Range($period, $date);
             $lastStartDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateStart(), $n = 1);
             $lastEndDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateEnd(), $n = 1);
             $strLastDate = "{$lastStartDate},{$lastEndDate}";
         } else {
             $strLastDate = Piwik_Period_Range::removePeriod($period, Piwik_Date::factory($date), $n = 1)->toString();
         }
         $pastArchive = Piwik_Archive::build('all', $period, $strLastDate, $segment, $_restrictSitesToLogin);
         $pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
         $pastData = $pastData->mergeChildren();
         // use past data to calculate evolution percentages
         $this->calculateEvolutionPercentages($dataTable, $pastData, $apiMetrics);
     }
     // remove eCommerce related metrics on non eCommerce Piwik sites
     // note: this is not optimal in terms of performance: those metrics should not be retrieved in the first place
     if ($enhanced) {
         // $dataTableRows instanceOf Piwik_DataTable_Row[]
         $dataTableRows = $dataTable->getRows();
         foreach ($dataTableRows as $dataTableRow) {
             $siteId = $dataTableRow->getColumn('label');
             if (!Piwik_Site::isEcommerceEnabledFor($siteId)) {
                 foreach ($apiECommerceMetrics as $metricSettings) {
                     $dataTableRow->deleteColumn($metricSettings[self::METRIC_RECORD_NAME_KEY]);
                     $dataTableRow->deleteColumn($metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY]);
                 }
             }
         }
     }
     // move the site id to a metadata column
     $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'idsite'));
     // set the label of each row to the site name
     if ($allWebsitesRequested) {
         $getNameFor = array('Piwik_Site', 'getNameFor');
         $dataTable->filter('ColumnCallbackReplace', array('label', $getNameFor));
     } else {
         $dataTable->filter('ColumnDelete', array('label'));
     }
     // replace record names with user friendly metric names
     $dataTable->filter('ReplaceColumnNames', array($columnNameRewrites));
     // Ensures data set sorted, for Metadata output
     $dataTable->filter('Sort', array(self::NB_VISITS_METRIC, 'desc', $naturalSort = false));
     // filter rows without visits
     // note: if only one website is queried and there are no visits, we can not remove the row otherwise Piwik_API_ResponseBuilder throws 'Call to a member function getColumns() on a non-object'
     if ($allWebsitesRequested) {
         $dataTable->filter('ColumnCallbackDeleteRow', array(self::NB_VISITS_METRIC, create_function('$value', 'return $value != 0;')));
     }
     return $dataTable;
 }
コード例 #28
0
ファイル: Archive.php プロジェクト: neolf/PIWIK4MOBILE
 /**
  * Helper - Loads a DataTable from the Archive.
  * Optionally loads the table recursively,
  * or optionally fetches a given subtable with $idSubtable
  */
 public static function getDataTableFromArchive($name, $idSite, $period, $date, $segment, $expanded, $idSubtable = null)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     if ($idSubtable === false) {
         $idSubtable = null;
     }
     if ($expanded) {
         $dataTable = $archive->getDataTableExpanded($name, $idSubtable);
     } else {
         $dataTable = $archive->getDataTable($name, $idSubtable);
     }
     $dataTable->queueFilter('ReplaceSummaryRowLabel');
     return $dataTable;
 }
コード例 #29
0
ファイル: API.php プロジェクト: nnnnathann/piwik
 /**
  * Utility method that retrieve an archived DataTable for a specific site, date range,
  * segment and goal. If not goal is specified, this method will retrieve and sum the
  * data for every goal.
  *
  * @param string $recordName The archive entry name.
  * @param int|string $idSite The site(s) to select data for.
  * @param string $period The period type.
  * @param string $date The date type.
  * @param string $segment The segment.
  * @param int|bool $idGoal The id of the goal to get data for. If this is set to false,
  *                         data for every goal that belongs to $idSite is returned.
  */
 protected function getGoalSpecificDataTable($recordName, $idSite, $period, $date, $segment, $idGoal)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date, $segment);
     // check for the special goal ids
     $realGoalId = $idGoal != true ? false : self::convertSpecialGoalIds($idGoal);
     // get the data table
     $dataTable = $archive->getDataTable(Piwik_Goals::getRecordName($recordName, $realGoalId), $idSubtable = null);
     $dataTable->queueFilter('ReplaceColumnNames');
     return $dataTable;
 }
コード例 #30
0
ファイル: API.php プロジェクト: ep123/funnels
 public function get($idSite, $period, $date, $idFunnel = false, $columns = array())
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Piwik_Archive::build($idSite, $period, $date);
     if (!empty($columns)) {
         $toFetch = $columns;
     } else {
         $toFetch = array();
         $funnels = $this->getFunnels($idSite);
         $stepNumericColumnNames = array('nb_entry', 'nb_exit', 'nb_actions', 'nb_next_step_actions', 'percent_next_step_actions');
         foreach ($stepNumericColumnNames as $columnName) {
             if (!empty($idFunnel)) {
                 $funnel = $funnels[$idFunnel];
                 foreach ($funnel['steps'] as $step) {
                     $toFetch[] = Piwik_Funnels::getRecordName($columnName, $idFunnel, $step['idstep']);
                 }
             }
         }
         $funnelColumnNames = array('nb_actions', 'conversion_rate');
         foreach ($funnelColumnNames as $columnName) {
             if (!empty($idFunnel)) {
                 $funnel = $funnels[$idFunnel];
                 $toFetch[] = Piwik_Funnels::getRecordName($columnName, $idFunnel, false);
             }
         }
     }
     $dataTable = $archive->getDataTableFromNumeric($toFetch);
     return $dataTable;
 }