@param DataTable $table

@return string
516993
protected function renderDataTable($table)
    {
        if ($table->getRowsCount() == 0) {
            return "<strong><em>Empty table</em></strong><br />\n";
        }

        $i = 1;
        $tableStructure = array();

        /*
         * table = array
         * ROW1 = col1 | col2 | col3 | metadata | idSubTable
         * ROW2 = col1 | col2 (no value but appears) | col3 | metadata | idSubTable
         * 		subtable here
         */
        $allColumns = array();
        foreach ($table->getRows() as $row) {
            foreach ($row->getColumns() as $column => $value) {
                // for example, goals data is array: not supported in export RSS
                // in the future we shall reuse ViewDataTable for html exports in RSS anyway
                if (is_array($value)) {
                    continue;
                }
                $allColumns[$column] = true;
                $tableStructure[$i][$column] = $value;
            }
            $i++;
        }
        $html = "\n";
        $html .= "<table border=1 width=70%>";
        $html .= "\n<tr>";
        foreach ($allColumns as $name => $toDisplay) {
            if ($toDisplay !== false) {
                if ($this->translateColumnNames) {
                    $name = $this->translateColumnName($name);
                }
                $html .= "\n\t<td><strong>$name</strong></td>";
            }
        }
        $html .= "\n</tr>";

        foreach ($tableStructure as $row) {
            $html .= "\n\n<tr>";
            foreach ($allColumns as $columnName => $toDisplay) {
                if ($toDisplay !== false) {
                    $value = "-";
                    if (isset($row[$columnName])) {
                        $value = urldecode($row[$columnName]);
                    }

                    $html .= "\n\t<td>$value</td>";
                }
            }
            $html .= "</tr>";
        }
        $html .= "\n\n</table>";
        return $html;
    }
887582
private function getTableId(): string
    {
        if ('' === $this->tableId) {
            $this->tableId = 'table-datatable-' . md5($this->preSaveId);
        }

        return $this->tableId;
    }
475386
public function tableClass($table)
    {
        $tables = $this->getTableNames();
        $class = array_search($table, $tables, true);
        if ($class) {
            return $class;
        }

        // If there is no class for this table, strip table modifiers (e.g. _Live / _Versions)
        // from the end and re-attempt a search.
        if (preg_match('/^(?<class>.+)(_[^_]+)$/i', $table, $matches)) {
            $table = $matches['class'];
            $class = array_search($table, $tables, true);
            if ($class) {
                return $class;
            }
        }
        return null;
    }
1265341
private static function _get_table_where(string $table): ?string
  {
    if (
      bbn\str::check_name($table) &&
      ($db = self::_get_db()) &&
      ($databases_obj = self::_get_databases()) &&
      ($model = $databases_obj->modelize($table))
    ){
      $col = $db->escape('col');
      $where_ar = [];
      foreach ( $model['fields'] as $k => $f ){
        if ( !empty($f['id_option']) ){
          $where_ar[] = $col.' = UNHEX("'.$db->escape_value($f['id_option']).'")';
        }
      }
      if ( \count($where_ar) ){
        return implode(' OR ', $where_ar);
      }
    }
    return null;
  }
693152
public function filter($table)
    {
        $row = new DataTableSummaryRow($table);
        $row->setColumn('label', $this->labelSummaryRow);
        $table->addSummaryRow($row);
    }
1339352
public function build(DataTable $table)
    {
        $this->qb->select($this->entityAlias);
        $this->qb->from($table->entityName, $this->entityAlias);
        $this->buildJoin($table->columns);

        if ($table->queryClosure) {
            call_user_func($table->queryClosure, $this->qb);
        }
    }
369448
public function get(DataTable $datatable)
    {
        if (php_sapi_name() === 'cli') {
            return 10;
        }

        if (!$this->request->hasSession()) {
            return;
        }
        $key     = $this->getSessionKey(get_class($datatable));
        $perPage = $this->getFromSession($key, (int) request('length', $datatable->perPage));
        return is_null($perPage) ? 10 : $perPage;
    }
720071
protected function renderTable($table, $prefix = "")
    {
        if (is_array($table)) {
            // convert array to DataTable

            $table = DataTable::makeFromSimpleArray($table);
        }

        if ($table instanceof DataTable\Map) {
            return $this->renderDataTableMap($table, $prefix);
        }

        if ($table->getRowsCount() == 0) {
            return "Empty table<br />\n";
        }

        static $depth = 0;
        $output = '';
        $i = 1;
        foreach ($table->getRows() as $row) {
            $dataTableMapBreak = false;
            $columns = array();
            foreach ($row->getColumns() as $column => $value) {
                if ($value instanceof DataTable\Map) {
                    $output .= $this->renderDataTableMap($value, $prefix);
                    $dataTableMapBreak = true;
                    break;
                }
                if (is_string($value)) {
                    $value = "'$value'";
                } elseif (is_array($value)) {
                    $value = var_export($value, true);
                }

                $columns[] = "'$column' => $value";
            }
            if ($dataTableMapBreak === true) {
                continue;
            }
            $columns = implode(", ", $columns);

            $metadata = array();
            foreach ($row->getMetadata() as $name => $value) {
                if (is_string($value)) {
                    $value = "'$value'";
                } elseif (is_array($value)) {
                    $value = var_export($value, true);
                }
                $metadata[] = "'$name' => $value";
            }
            $metadata = implode(", ", $metadata);

            $output .= str_repeat($this->prefixRows, $depth)
                . "- $i [" . $columns . "] [" . $metadata . "] [idsubtable = "
                . $row->getIdSubDataTable() . "]<br />\n";

            if (!is_null($row->getIdSubDataTable())) {
                $subTable = $row->getSubtable();
                if ($subTable) {
                    $depth++;
                    $output .= $this->renderTable($subTable, $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
                    $depth--;
                } else {
                    $output .= "-- Sub DataTable not loaded<br />\n";
                }
            }
            $i++;
        }

        $metadata = $table->getAllTableMetadata();
        if (!empty($metadata)) {
            $output .= "<hr />Metadata<br />";
            foreach ($metadata as $id => $metadataIn) {
                $output .= "<br />";
                $output .= $prefix . " <b>$id</b><br />";
                if (is_array($metadataIn)) {
                    foreach ($metadataIn as $name => $value) {
                        if (is_object($value) && !method_exists( $value, '__toString' )) {
                            $value = 'Object [' . get_class($value) . ']';
                        }
                        $output .= $prefix . $prefix . "$name => $value";
                    }
                }
            }
        }
        return $output;
    }
1203206
protected function renderTable($table)
    {
        if (is_array($table)) {
            $array = $table;
            if (self::shouldWrapArrayBeforeRendering($array, $wrapSingleValues = true)) {
                $array = array($array);
            }

            foreach ($array as $key => $tab) {
                if ($tab instanceof DataTable\Map
                    || $tab instanceof DataTable
                    || $tab instanceof DataTable\Simple) {
                    $array[$key] = $this->convertDataTableToArray($tab);

                    if (!is_array($array[$key])) {
                        $array[$key] = array('value' => $array[$key]);
                    }
                }
            }
        } else {
            $array = $this->convertDataTableToArray($table);
        }

        if (!is_array($array)) {
            $array = array('value' => $array);
        }

        // decode all entities
        $callback = function (&$value, $key) {
            if (is_string($value)) {
                $value = html_entity_decode($value, ENT_QUOTES, "UTF-8");
            };
        };
        array_walk_recursive($array, $callback);

        // silence "Warning: json_encode(): Invalid UTF-8 sequence in argument"
        $str = @json_encode($array);

        if ($str === false
            && json_last_error() === JSON_ERROR_UTF8
            && $this->canMakeArrayUtf8()) {
            $array = $this->makeArrayUtf8($array);
            $str = json_encode($array);
        }

        return $str;
    }
1066762
public function getPrimaryKey($table){
		$key = '';
		$q = $this->runQuery('SHOW FULL COLUMNS FROM ' . $table);
		while($col = $this->fetch($q)){
			if(strtolower($col['Key']) === 'pri' && $key === '')
				$key = $col['Field'];
		}
		return $key;
	}
266912
protected function getRealTableName($table)
	{
		$prefix = $this->db->getPrefix();

		// Replace the magic prefix if found.
		$table = preg_replace('|^#__|', $prefix, $table);

		return $table;
	}
1046436
protected function renderTable($table)
    {
        if (!($table instanceof DataTable\Map)
            || $table->getKeyName() != 'date'
        ) {
            throw new Exception("RSS feeds can be generated for one specific website &idSite=X." .
                "\nPlease specify only one idSite or consider using &format=XML instead.");
        }

        $idSite = Common::getRequestVar('idSite', 1, 'int');
        $period = Common::getRequestVar('period');

        $piwikUrl = SettingsPiwik::getPiwikUrl()
            . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
        $out = "";
        $moreRecentFirst = array_reverse($table->getDataTables(), true);
        foreach ($moreRecentFirst as $date => $subtable) {
            /** @var DataTable $subtable */
            $timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp();
            $site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX);

            $pudDate = date('r', $timestamp);

            $dateInSiteTimezone = Date::factory($timestamp);
            if($site) {
                $dateInSiteTimezone = $dateInSiteTimezone->setTimezone($site->getTimezone());
            }
            $dateInSiteTimezone = $dateInSiteTimezone->toString('Y-m-d');
            $thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date=$dateInSiteTimezone");
            $siteName = $site ? $site->getName() : '';
            $title = $siteName . " on " . $date;

            $out .= "\t<item>
		<pubDate>$pudDate</pubDate>
		<guid>$thisPiwikUrl</guid>
		<link>$thisPiwikUrl</link>
		<title>$title</title>
		<author>https://matomo.org</author>
		<description>";

            $out .= Common::sanitizeInputValue($this->renderDataTable($subtable));
            $out .= "</description>\n\t</item>\n";
        }

        $header = $this->getRssHeader();
        $footer = $this->getRssFooter();

        return $header . $out . $footer;
    }
1056191
protected function renderTable($table, &$allColumns = array())
    {
        if (is_array($table)) {
            // convert array to DataTable
            $table = DataTable::makeFromSimpleArray($table);
        }

        if ($table instanceof DataTable\Map) {
            $str = $this->renderDataTableMap($table, $allColumns);
        } else {
            $str = $this->renderDataTable($table, $allColumns);
        }
        return $str;
    }
531301
public function getTableDefinition($table)
    {
        foreach ($this->getTableDefinitions() as $definition) {
            if ($definition->getName() === $table) {
                return $definition;
            }
        }

        return null;
    }
481057
protected function getParsedColumnTable($table)
    {
        $this->validateTableName($table);

        $table = DB::connection($this->connection)->select(
            DB::connection($this->connection)->raw("PRAGMA table_info({$table});")
        );

        $columns = [];

        foreach ($table as $columnData) {
            $columns[ $columnData->name ] = (array) $columnData;
        }

        return $columns;
    }
244298
protected function getTableName($table)
    {
        $database = $this->getTableDatabase($table);

        # If we found a database for this table then include it in the return value
        if ($database) {
            $database = $this->quoteField($database);

            if (substr($this->mode, 0, 5) === "mssql") {
                $database .= ".dbo";
            }

            return $database . "." . $this->quoteField($table);
        }

        # If we didn't find a database, and this table already looks like it includes
        if (strpos($table, ".") !== false) {
            return $table;
        }


        return $this->quoteField($table);
    }
1240624
public function describeTable($table)
    {
        if (!$this->connection->expr('show tables like []', [$table])->get()) {
            return []; // no such table
        }

        $result = [];

        foreach ($this->connection->expr('describe {}', [$table]) as $row) {
            $row2 = [];
            $row2['name'] = $row['Field'];
            $row2['pk'] = $row['Key'] == 'PRI';
            $row2['type'] = preg_replace('/\(.*/', '', $row['Type']);

            $result[] = $row2;
        }

        return $result;
    }