checkCustomVariablesPluginEnabled() public static method

Example #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;
 }