示例#1
0
文件: API.php 项目: nnnnathann/piwik
 /**
  * Add the main metrics (pageviews, exits, bounces) to the full report.
  * Data is loaded from Actions.getPageUrls using the label filter.
  */
 private function addMainPageMetricsToReport(&$report, $pageUrl, $idSite, $period, $date, $segment)
 {
     $label = Piwik_Actions::getActionExplodedNames($pageUrl, Piwik_Tracker_Action::TYPE_ACTION_URL);
     if (count($label) == 1) {
         $label = $label[0];
     } else {
         $label = array_map('urlencode', $label);
         $label = implode('>', $label);
     }
     $parameters = array('method' => 'Actions.getPageUrls', 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'label' => $label, 'format' => 'original', 'serialize' => '0', 'expanded' => '0');
     if (!empty($segment)) {
         $parameters['segment'] = $segment;
     }
     $url = Piwik_Url::getQueryStringFromParameters($parameters);
     $request = new Piwik_API_Request($url);
     try {
         /** @var $dataTable Piwik_DataTable */
         $dataTable = $request->process();
     } catch (Exception $e) {
         throw new Exception("Actions.getPageUrls returned an error: " . $e->getMessage() . "\n");
     }
     if ($dataTable->getRowsCount() == 0) {
         throw new Exception("The label '{$label}' could not be found in Actions.getPageUrls\n");
     }
     $row = $dataTable->getFirstRow();
     if ($row !== false) {
         $report['pageMetrics'] = array('pageviews' => intval($row->getColumn('nb_hits')), 'exits' => intval($row->getColumn('exit_nb_visits')), 'bounces' => intval($row->getColumn('entry_bounce_count')));
     } else {
         $report['pageMetrics'] = array('pageviews' => 0, 'exits' => 0, 'bounces' => 0);
     }
 }
示例#2
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 == Piwik_Tracker_Action::TYPE_ACTION_NAME) {
             $searchedString = Piwik_Common::unsanitizeInputValue($search);
         } else {
             $idSite = $callBackParameters[1];
             try {
                 $searchedString = Piwik_Tracker_Action::excludeQueryParametersFromUrl($search, $idSite);
             } catch (Exception $e) {
                 $searchedString = $search;
             }
         }
         $searchTree = Piwik_Actions::getActionExplodedNames($searchedString, $actionType);
     }
     if ($table === false) {
         // fetch the data table
         $table = call_user_func_array(array('Piwik_Archive', 'getDataTableFromArchive'), $callBackParameters);
         if ($table instanceof Piwik_DataTable_Array) {
             // 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)
             $newTableArray = new Piwik_DataTable_Array();
             $newTableArray->metadata = $table->metadata;
             $newTableArray->setKeyName($table->getKeyName());
             foreach ($table->getArray() as $label => $subTable) {
                 $subTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);
                 $newTableArray->addTable($subTable, $label);
             }
             return $newTableArray;
         }
     }
     return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
 }
示例#3
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, $searchCurrentLevel = 0 )
	{
		if($table === false)
		{
			$table = call_user_func_array(array('Piwik_Archive', 'getDataTableFromArchive'), $callBackParameters);
		}
		if($searchTree === false)
		{
    		if($actionType == Piwik_Tracker_Action::TYPE_ACTION_NAME)
    		{
    			$searchedString = Piwik_Common::unsanitizeInputValue($search);
    		}
    		else
    		{
    			$searchedString = Piwik_Tracker_Action::excludeQueryParametersFromUrl($search, $idSite = $callBackParameters[1]);
    		}
			$searchTree = Piwik_Actions::getActionExplodedNames($searchedString, $actionType);
		}
		if(!($table instanceof Piwik_DataTable))
		{
			throw new Exception("For this API function, date=lastN or date=previousM is not supported");
		}
		$rows = $table->getRows();
		$labelSearch = $searchTree[$searchCurrentLevel];
		$isEndSearch = ((count($searchTree)-1) == $searchCurrentLevel);
		foreach($rows as $key => $row)
		{
			$found = false;
			// Found a match at this level
			$label = $row->getColumn('label');
			if($label === $labelSearch)
			{
				// Is this the end of the search tree? then we found the requested row
				if($isEndSearch)
				{
//					var_dump($label); var_dump($labelSearch); exit;
					$table = new Piwik_DataTable();
					$table->addRow($row);
					return $table;
				}
				
				// If we still need to search deeper, call search 
				$idSubTable = $row->getIdSubDataTable();
				// Update the idSubtable in the callback parameter list, to fetch this subtable from the archive
				$callBackParameters[6] = $idSubTable;
				$subTable = call_user_func_array(array('Piwik_Archive', 'getDataTableFromArchive'), $callBackParameters);
				$found = $this->getFilterPageDatatableSearch($callBackParameters, $search, $actionType, $subTable, $searchTree, $searchCurrentLevel+1);
				if($found)
				{
					return $found;
				}
			}
			if(!$found)
			{
				$table->deleteRow($key);
			}
		}
		// Case the DataTable was searched but nothing was found, @see getFilterPageDatatableSearch()
		if($searchCurrentLevel == 0)
		{
			return new Piwik_DataTable;
		}
		return false;
	}