Skip to content
Extraits de code Groupes Projets
API.php 3,63 ko
Newer Older
  • Learn to ignore specific revisions
  • <?php
    /**
     * Piwik - Open source web analytics
    
     * @link http://piwik.org
     * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
    
     * @category Piwik_Plugins
    
    mattab's avatar
    mattab a validé
    use Piwik\Archive;
    
    use Piwik\Tracker\Action;
    
    mattpiwik's avatar
    mattpiwik a validé
     * The Custom Variables API lets you access reports for your <a href='http://piwik.org/docs/custom-variables/' target='_blank'>Custom Variables</a> names and values.
    
        /**
         * @param int $idSite
         * @param string $period
    
         * @param string $segment
         * @param bool $expanded
         * @param int $idSubtable
    
    sgiehl's avatar
    sgiehl a validé
         *
    
    sgiehl's avatar
    sgiehl a validé
         */
    
        protected function getDataTable($idSite, $period, $date, $segment, $expanded, $idSubtable)
        {
    
            $dataTable = Archive::getDataTableFromArchive(Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $idSubtable);
    
            $dataTable->filter('Sort', array(Metrics::INDEX_NB_ACTIONS, 'desc', $naturalSort = false, $expanded));
    
            $dataTable->queueFilter('ReplaceColumnNames');
    
            $dataTable->queueFilter('ColumnDelete', 'nb_uniq_visitors');
    
    sgiehl's avatar
    sgiehl a validé
        /**
    
         * @param int $idSite
         * @param string $period
    
         * @param string|bool $segment
         * @param bool $expanded
         * @param bool $_leavePiwikCoreVariables
    
    sgiehl's avatar
    sgiehl a validé
         *
    
    sgiehl's avatar
    sgiehl a validé
         */
    
        public function getCustomVariables($idSite, $period, $date, $segment = false, $expanded = false, $_leavePiwikCoreVariables = false)
        {
            $dataTable = $this->getDataTable($idSite, $period, $date, $segment, $expanded, $idSubtable = null);
    
            if ($dataTable instanceof DataTable
    
                $mapping = self::getReservedCustomVariableKeys();
    
                foreach ($mapping as $name) {
                    $row = $dataTable->getRowFromLabel($name);
                    if ($row) {
                        $dataTable->deleteRow($dataTable->getRowIdFromLabel($name));
                    }
                }
            }
            return $dataTable;
        }
    
        /**
         * @ignore
         * @return array
         */
        public static function getReservedCustomVariableKeys()
        {
    
            return array('_pks', '_pkn', '_pkc', '_pkp', Action::CVAR_KEY_SEARCH_COUNT, Action::CVAR_KEY_SEARCH_CATEGORY);
    
    sgiehl's avatar
    sgiehl a validé
        /**
    
         * @param int $idSite
         * @param string $period
    
         * @param int $idSubtable
         * @param string|bool $segment
         * @param bool $_leavePriceViewedColumn
    
    sgiehl's avatar
    sgiehl a validé
         *
    
    sgiehl's avatar
    sgiehl a validé
         */
    
        public function getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment = false, $_leavePriceViewedColumn = false)
        {
            $dataTable = $this->getDataTable($idSite, $period, $date, $segment, $expanded = false, $idSubtable);
    
            if (!$_leavePriceViewedColumn) {
                $dataTable->deleteColumn('price_viewed');
            } else {
                // Hack Ecommerce product price tracking to display correctly
                $dataTable->renameColumn('price_viewed', 'price');
            }
    
            $dataTable->queueFilter('ColumnCallbackReplace', array('label', function ($label) {
                return $label == \Piwik\Plugins\CustomVariables\Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED
    
                    ? Piwik::translate('General_NotDefined', Piwik::translate('CustomVariables_ColumnCustomVariableValue'))