1<?php
2/**
3 * Copyright (c) 2020. ComboStrap, Inc. and its affiliates. All Rights Reserved.
4 *
5 * This source code is licensed under the GPL license found in the
6 * COPYING  file in the root directory of this source tree.
7 *
8 * @license  GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html)
9 * @author   ComboStrap <support@combostrap.com>
10 *
11 */
12
13namespace ComboStrap\Tag;
14
15use ComboStrap\ExceptionCompile;
16use ComboStrap\Outline;
17use ComboStrap\PluginUtility;
18use ComboStrap\TagAttributes;
19
20/**
21 *
22 * Class TableUtility
23 * @package ComboStrap
24 *
25 * @see <a href="https://datatables.net/examples/styling/bootstrap4">DataTables (May be)</a>
26 *
27 * See also: https://www.dokuwiki.org/tips:table_editing
28 */
29class TableTag
30{
31
32    const TABLE_SNIPPET_ID = "table";
33    const BOOT_TABLE_CLASSES = 'table table-non-fluid table-hover table-striped';
34    const TAG = "table";
35    const TAG_CONTAINER = "table-container";
36    const TABLE_RESPONSIVE_CLASS = "table-responsive";
37
38
39    /**
40     * @param \Doku_Renderer_xhtml $renderer
41     * @param $class
42     * @return void
43     * The call is created during an outline scan at {@link Outline::buildOutline()}
44     */
45    static function renderEnterXhtml(TagAttributes $tagAttributes, \Doku_Renderer_xhtml $renderer)
46    {
47
48
49        try {
50            $position = $tagAttributes->getValueAsInteger(PluginUtility::POSITION);
51        } catch (ExceptionCompile $e) {
52            $position = null;
53        }
54
55        /**
56         * We call table_open, to init the {@link \Doku_Renderer_xhtml::$_counter} number that is private otherwise, there
57         * is a class name created with the name `row` that is a known bootstrap class
58         */
59        $doc = $renderer->doc;
60        $renderer->table_open(null, null, $position);
61        $renderer->doc = $doc;
62
63
64        // Add non-fluid to not have a table that takes 100% of the space
65        // Otherwise we can't have floating element at the right and the visual space is too big
66        PluginUtility::getSnippetManager()->attachCssInternalStyleSheet(self::TABLE_SNIPPET_ID);
67
68        $renderer->doc .= TagAttributes::createEmpty(self::TAG_CONTAINER)
69            ->addClassName(self::TABLE_RESPONSIVE_CLASS)
70            ->toHtmlEnterTag("div");
71        $renderer->doc .= TagAttributes::createEmpty(self::TAG)
72            ->addClassName("inline") // dokuwiki
73            ->addClassName(self::BOOT_TABLE_CLASSES)
74            ->toHtmlEnterTag("table");
75
76    }
77
78}
79