original_string: 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')), // Note: this should never happen
              '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);
          }
      }
code: 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')), // Note: this should never happen
              '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);
          }
      }
code_tokens: 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' ) ) , // Note: this should never happen '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 ) ; } }
docstring: Enhances the dataTable with Items attributes found in the Custom Variables report.
  
  @param $dataTable
  @param $recordName
  @param $idSite
  @param $period
  @param $date
  @param $segment
docstring_tokens: Enhances the dataTable with Items attributes found in the Custom Variables report .