Piwik\DataTable\Renderer\Xml::renderDataTable PHP Метод

renderDataTable() защищенный Метод

Computes the output for the given data array
protected renderDataTable ( array $array, string $prefixLine = "" ) : string
$array array
$prefixLine string
Результат string
    protected function renderDataTable($array, $prefixLine = "")
    {
        $columnsHaveInvalidChars = $this->areTableLabelsInvalidXmlTagNames(reset($array));
        $out = '';
        foreach ($array as $rowId => $row) {
            if (!is_array($row)) {
                $value = self::formatValueXml($row);
                if (strlen($value) == 0) {
                    $out .= $prefixLine . "\t\t<{$rowId} />\n";
                } else {
                    $out .= $prefixLine . "\t\t<{$rowId}>" . $value . "</{$rowId}>\n";
                }
                continue;
            }
            // Handing case idgoal=7, creating a new array for that one
            $rowAttribute = '';
            if (strstr($rowId, '=') !== false) {
                $rowAttribute = explode('=', $rowId);
                $rowAttribute = " " . $rowAttribute[0] . "='" . $rowAttribute[1] . "'";
            }
            $out .= $prefixLine . "\t<row{$rowAttribute}>";
            if (count($row) === 1 && key($row) === 0) {
                $value = self::formatValueXml(current($row));
                $out .= $prefixLine . $value;
            } else {
                $out .= "\n";
                foreach ($row as $name => $value) {
                    // handle the recursive dataTable case by XML outputting the recursive table
                    if (is_array($value)) {
                        $value = "\n" . $this->renderDataTable($value, $prefixLine . "\t\t");
                        $value .= $prefixLine . "\t\t";
                    } else {
                        $value = self::formatValueXml($value);
                    }
                    list($tagStart, $tagEnd) = $this->getTagStartAndEndFor($name, $columnsHaveInvalidChars);
                    if (strlen($value) == 0) {
                        $out .= $prefixLine . "\t\t<{$tagStart} />\n";
                    } else {
                        $out .= $prefixLine . "\t\t<{$tagStart}>" . $value . "</{$tagEnd}>\n";
                    }
                }
                $out .= "\t";
            }
            $out .= $prefixLine . "</row>\n";
        }
        return $out;
    }