| <?php |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Plugins\CustomVariables; |
|
|
| use Piwik\API\Request; |
| use Piwik\Archive; |
| use Piwik\Container\StaticContainer; |
| use Piwik\DataTable; |
| use Piwik\Date; |
| use Piwik\Metrics; |
| use Piwik\Piwik; |
|
|
| |
| |
| |
| |
| |
| class API extends \Piwik\Plugin\API |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| protected function getDataTable($idSite, $period, $date, $segment, $expanded, $flat, $idSubtable) |
| { |
| $dataTable = Archive::createDataTableFromArchive(Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat, $idSubtable); |
| $dataTable->queueFilter('ColumnDelete', 'nb_uniq_visitors'); |
|
|
| if ($flat) { |
| $dataTable->filterSubtables('Sort', array(Metrics::INDEX_NB_ACTIONS, 'desc', $naturalSort = false, $expanded)); |
| $dataTable->queueFilterSubtables('ColumnDelete', 'nb_uniq_visitors'); |
| } |
|
|
| return $dataTable; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getCustomVariables($idSite, $period, $date, $segment = false, $expanded = false, $_leavePiwikCoreVariables = false, $flat = false) |
| { |
| Piwik::checkUserHasViewAccess($idSite); |
|
|
| $dataTable = $this->getDataTable($idSite, $period, $date, $segment, $expanded, $flat, $idSubtable = null); |
|
|
| if ( |
| $dataTable instanceof DataTable |
| && !$_leavePiwikCoreVariables |
| ) { |
| $mapping = self::getReservedCustomVariableKeys(); |
| foreach ($mapping as $name) { |
| $row = $dataTable->getRowFromLabel($name); |
| if ($row) { |
| $dataTable->deleteRow($dataTable->getRowIdFromLabel($name)); |
| } |
| } |
| } |
|
|
|
|
| if ($flat) { |
| $dataTable->filterSubtables('Piwik\Plugins\CustomVariables\DataTable\Filter\CustomVariablesValuesFromNameId'); |
| } else { |
| $dataTable->filter('AddSegmentByLabel', array('customVariableName')); |
| } |
|
|
| return $dataTable; |
| } |
|
|
| |
| |
| |
| |
| public static function getReservedCustomVariableKeys() |
| { |
| |
| return array('_pks', '_pkn', '_pkc', '_pkp', '_pk_scat', '_pk_scount'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment = false, $_leavePriceViewedColumn = false) |
| { |
| Piwik::checkUserHasViewAccess($idSite); |
|
|
| $dataTable = $this->getDataTable($idSite, $period, $date, $segment, $expanded = false, $flat = false, $idSubtable); |
|
|
| if (!$_leavePriceViewedColumn) { |
| $dataTable->deleteColumn('price_viewed'); |
| } else { |
| |
| $dataTable->renameColumn('price_viewed', 'price'); |
| } |
|
|
| $dataTable->filter('Piwik\Plugins\CustomVariables\DataTable\Filter\CustomVariablesValuesFromNameId'); |
|
|
| return $dataTable; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getUsagesOfSlots($idSite) |
| { |
| Piwik::checkUserHasAdminAccess($idSite); |
|
|
| $numVars = CustomVariables::getNumUsableCustomVariables(); |
|
|
| $usedCustomVariables = array( |
| 'visit' => array_fill(1, $numVars, array()), |
| 'page' => array_fill(1, $numVars, array()), |
| ); |
|
|
| |
| $today = StaticContainer::get('CustomVariables.today'); |
| $date = '2008-12-12,' . $today; |
| $customVarUsages = Request::processRequest( |
| 'CustomVariables.getCustomVariables', |
| array('idSite' => $idSite, 'period' => 'range', 'date' => $date, |
| 'format' => 'original') |
| ); |
|
|
| foreach ($customVarUsages->getRows() as $row) { |
| $slots = $row->getMetadata('slots'); |
|
|
| if (!empty($slots)) { |
| foreach ($slots as $slot) { |
| $usedCustomVariables[$slot['scope']][$slot['index']][] = array( |
| 'name' => $row->getColumn('label'), |
| 'nb_visits' => $row->getColumn('nb_visits'), |
| 'nb_actions' => $row->getColumn('nb_actions'), |
| ); |
| } |
| } |
| } |
|
|
| $grouped = array(); |
| foreach ($usedCustomVariables as $scope => $scopes) { |
| foreach ($scopes as $index => $cvars) { |
| $grouped[] = array( |
| 'scope' => $scope, |
| 'index' => $index, |
| 'usages' => $cvars |
| ); |
| } |
| } |
|
|
| return $grouped; |
| } |
| } |
|
|