Exemplo n.º 1
0
 /**
  * @param int $idSite
  * @param string $period
  * @param Date $date
  * @param bool $segment
  *
  * @return DataTable|DataTable\Map
  */
 public function getSiteSearchCategories($idSite, $period, $date, $segment = false)
 {
     Actions::checkCustomVariablesPluginEnabled();
     $customVariables = APICustomVariables::getInstance()->getCustomVariables($idSite, $period, $date, $segment, $expanded = false, $_leavePiwikCoreVariables = true);
     $customVarNameToLookFor = ActionSiteSearch::CVAR_KEY_SEARCH_CATEGORY;
     $dataTable = new DataTable();
     // Handle case where date=last30&period=day
     // FIXMEA: this logic should really be refactored somewhere, this is ugly!
     if ($customVariables instanceof DataTable\Map) {
         $dataTable = $customVariables->getEmptyClone();
         $customVariableDatatables = $customVariables->getDataTables();
         foreach ($customVariableDatatables as $key => $customVariableTableForDate) {
             // we do not enter the IF, in the case idSite=1,3 AND period=day&date=datefrom,dateto,
             if ($customVariableTableForDate instanceof DataTable && $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)) {
                 $row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor);
                 if ($row) {
                     $dateRewrite = $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->toString();
                     $idSubtable = $row->getIdSubDataTable();
                     $categories = APICustomVariables::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $dateRewrite, $idSubtable, $segment);
                     $dataTable->addTable($categories, $key);
                 }
             }
         }
     } elseif ($customVariables instanceof DataTable) {
         $row = $customVariables->getRowFromLabel($customVarNameToLookFor);
         if ($row) {
             $idSubtable = $row->getIdSubDataTable();
             $dataTable = APICustomVariables::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment);
         }
     }
     $this->filterActionsDataTable($dataTable);
     $this->addPagesPerSearchColumn($dataTable, $columnToRead = 'nb_actions');
     return $dataTable;
 }
Exemplo n.º 2
0
 /**
  * Enhances the dataTable with Items attributes found in the Custom Variables report.
  *
  * @param $dataTable
  * @param $recordName
  * @param $idSite
  * @param $period
  * @param $date
  * @param $segment
  */
 protected function enrichItemsTableWithViewMetrics($dataTable, $recordName, $idSite, $period, $date, $segment)
 {
     // Enrich the datatable with Product/Categories views, and conversion rates
     $customVariables = \Piwik\Plugins\CustomVariables\API::getInstance()->getCustomVariables($idSite, $period, $date, $segment, $expanded = false, $_leavePiwikCoreVariables = true);
     $mapping = array('Goals_ItemsSku' => '_pks', 'Goals_ItemsName' => '_pkn', 'Goals_ItemsCategory' => '_pkc');
     $reportToNotDefinedString = array('Goals_ItemsSku' => Piwik::translate('General_NotDefined', Piwik::translate('Goals_ProductSKU')), 'Goals_ItemsName' => Piwik::translate('General_NotDefined', Piwik::translate('Goals_ProductName')), 'Goals_ItemsCategory' => Piwik::translate('General_NotDefined', Piwik::translate('Goals_ProductCategory')));
     $notDefinedStringPretty = $reportToNotDefinedString[$recordName];
     $customVarNameToLookFor = $mapping[$recordName];
     // Handle case where date=last30&period=day
     if ($customVariables instanceof DataTable\Map) {
         $customVariableDatatables = $customVariables->getDataTables();
         $dataTables = $dataTable->getDataTables();
         foreach ($customVariableDatatables as $key => $customVariableTableForDate) {
             $dataTableForDate = isset($dataTables[$key]) ? $dataTables[$key] : new DataTable();
             // we do not enter the IF
             // if case idSite=1,3 AND period=day&date=datefrom,dateto,
             if ($customVariableTableForDate instanceof DataTable && $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)) {
                 $dateRewrite = $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->toString();
                 $row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor);
                 if ($row) {
                     $idSubtable = $row->getIdSubDataTable();
                     $this->enrichItemsDataTableWithItemsViewMetrics($dataTableForDate, $idSite, $period, $dateRewrite, $segment, $idSubtable);
                 }
                 $dataTable->addTable($dataTableForDate, $key);
             }
             $this->renameNotDefinedRow($dataTableForDate, $notDefinedStringPretty);
         }
     } elseif ($customVariables instanceof DataTable) {
         $row = $customVariables->getRowFromLabel($customVarNameToLookFor);
         if ($row) {
             $idSubtable = $row->getIdSubDataTable();
             $this->enrichItemsDataTableWithItemsViewMetrics($dataTable, $idSite, $period, $date, $segment, $idSubtable);
         }
         $this->renameNotDefinedRow($dataTable, $notDefinedStringPretty);
     }
 }
Exemplo n.º 3
0
 protected static function isReservedKey($key)
 {
     return in_array($key, API::getReservedCustomVariableKeys());
 }