Skip to content
Extraits de code Groupes Projets
Valider 91208f5b rédigé par Benaka Moorthi's avatar Benaka Moorthi
Parcourir les fichiers

Refactored ViewDataTable::getRequestString to return an array so building a...

Refactored ViewDataTable::getRequestString to return an array so building a URL is not necessary. Also changed request_string_suffix view property to request_parameters_to_modify.
parent 349f2808
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -173,6 +173,7 @@ abstract class Piwik_ViewDataTable ...@@ -173,6 +173,7 @@ abstract class Piwik_ViewDataTable
Piwik_Metrics::getDefaultMetrics(), Piwik_Metrics::getDefaultMetrics(),
Piwik_Metrics::getDefaultProcessedMetrics() Piwik_Metrics::getDefaultProcessedMetrics()
); );
$this->viewProperties['request_parameters_to_modify'] = array();
$this->viewProperties['columns_to_display'] = array(); $this->viewProperties['columns_to_display'] = array();
$columns = Piwik_Common::getRequestVar('columns', false); $columns = Piwik_Common::getRequestVar('columns', false);
...@@ -536,11 +537,11 @@ abstract class Piwik_ViewDataTable ...@@ -536,11 +537,11 @@ abstract class Piwik_ViewDataTable
return; return;
} }
// we build the request string (URL) to call the API // we build the request (URL) to call the API
$requestString = $this->getRequestString(); $requestArray = $this->getRequestArray();
// we make the request to the API // we make the request to the API
$request = new Piwik_API_Request($requestString); $request = new Piwik_API_Request($requestArray);
// and get the DataTable structure // and get the DataTable structure
$dataTable = $request->process(); $dataTable = $request->process();
...@@ -589,8 +590,8 @@ abstract class Piwik_ViewDataTable ...@@ -589,8 +590,8 @@ abstract class Piwik_ViewDataTable
if (!$this->areGenericFiltersDisabled()) { if (!$this->areGenericFiltersDisabled()) {
// Second, generic filters (Sort, Limit, Replace Column Names, etc.) // Second, generic filters (Sort, Limit, Replace Column Names, etc.)
$requestString = $this->getRequestString(); $requestArray = $this->getRequestArray();
$request = Piwik_API_Request::getRequestArrayFromString($requestString); $request = Piwik_API_Request::getRequestArrayFromString($requestArray);
if (!empty($this->viewProperties['enable_sort']) if (!empty($this->viewProperties['enable_sort'])
&& $this->viewProperties['enable_sort'] === 'false' && $this->viewProperties['enable_sort'] === 'false'
...@@ -692,15 +693,17 @@ abstract class Piwik_ViewDataTable ...@@ -692,15 +693,17 @@ abstract class Piwik_ViewDataTable
/** /**
* @return string URL to call the API, eg. "method=Referers.getKeywords&period=day&date=yesterday"... * @return string URL to call the API, eg. "method=Referers.getKeywords&period=day&date=yesterday"...
*/ */
protected function getRequestString() protected function getRequestArray()
{ {
// we prepare the string to give to the API Request // we prepare the array to give to the API Request
// we setup the method and format variable // we setup the method and format variable
// - we request the method to call to get this specific DataTable // - we request the method to call to get this specific DataTable
// - the format = original specifies that we want to get the original DataTable structure itself, not rendered // - the format = original specifies that we want to get the original DataTable structure itself, not rendered
$requestString = 'method=' . $this->viewProperties['apiMethodToRequestDataTable']; $requestArray = array(
$requestString .= '&format=original'; 'method' => $this->viewProperties['apiMethodToRequestDataTable'],
$requestString .= '&disable_generic_filters=' . Piwik_Common::getRequestVar('disable_generic_filters', 1, 'int'); 'format' => 'original',
'disable_generic_filters' => Piwik_Common::getRequestVar('disable_generic_filters', 1, 'int')
);
$toSetEventually = array( $toSetEventually = array(
'filter_limit', 'filter_limit',
...@@ -717,26 +720,18 @@ abstract class Piwik_ViewDataTable ...@@ -717,26 +720,18 @@ abstract class Piwik_ViewDataTable
foreach ($toSetEventually as $varToSet) { foreach ($toSetEventually as $varToSet) {
$value = $this->getDefaultOrCurrent($varToSet); $value = $this->getDefaultOrCurrent($varToSet);
if (false !== $value) { if (false !== $value) {
if (is_array($value)) { $requestArray[$varToSet] = $value;
foreach ($value as $v) {
$requestString .= "&" . $varToSet . '[]=' . $v;
}
} else {
$requestString .= '&' . $varToSet . '=' . $value;
}
} }
} }
$segment = $this->getRawSegmentFromRequest(); $segment = $this->getRawSegmentFromRequest();
if(!empty($segment)) { if(!empty($segment)) {
$requestString .= '&segment=' . $segment; $requestArray['segment'] = $segment;
} }
if (!empty($this->viewProperties['request_string_suffix'])) { $requestArray = array_merge($requestArray, $this->viewProperties['request_parameters_to_modify']);
$requestString .= $this->viewProperties['request_string_suffix'];
}
return $requestString; return $requestArray;
} }
/** /**
...@@ -933,13 +928,13 @@ abstract class Piwik_ViewDataTable ...@@ -933,13 +928,13 @@ abstract class Piwik_ViewDataTable
} }
/** /**
* Makes sure the supplied suffix is appended to the URL used to query API data. * Sets a set of extra request query parameters to be used when querying API data.
* *
* @param string $suffix * @param array $params
*/ */
public function setRequestStringSuffix($suffix) public function setRequestParametersToModify($params)
{ {
$this->viewProperties['request_string_suffix'] = $suffix; $this->viewProperties['request_parameters_to_modify'] = $params;
} }
/** /**
......
...@@ -605,7 +605,7 @@ class Piwik_Goals extends Piwik_Plugin ...@@ -605,7 +605,7 @@ class Piwik_Goals extends Piwik_Plugin
unset($columns['orders']); unset($columns['orders']);
unset($columns['conversion_rate']); unset($columns['conversion_rate']);
$result['request_string_suffix'] = '&abandonedCarts=1'; $result['request_parameters_to_modify'] = array('abandonedCarts' => '1');
} }
$result['translations'] = array_merge(array('label' => $label), $columns); $result['translations'] = array_merge(array('label' => $label), $columns);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter