Breadcrumb::addLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopsfaq\Common;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
/**
15
 * Breadcrumb Class
16
 *
17
 * @copyright   XOOPS Project (https://xoops.org)
18
 * @license     GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author      lucio <[email protected]>
20
 *
21
 * Example:
22
 * $breadcrumb = new Breadcrumb();
23
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
24
 * $breadcrumb->addLink( 'bread 2', '' );
25
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
26
 * echo $breadcrumb->render();
27
 */
28
29
/**
30
 * Class Breadcrumb
31
 */
32
class Breadcrumb
33
{
34
    /**
35
     * @var string
36
     */
37
    public  $dirname;
38
    private $bread = [];
39
40
    public function __construct()
41
    {
42
        $this->dirname = \basename(\dirname(__DIR__, 2));
43
    }
44
45
    /**
46
     * Add link to breadcrumb
47
     */
48
    final public function addLink(string $title = '', string $link = ''): void
49
    {
50
        $this->bread[] = [
51
            'link'  => $link,
52
            'title' => $title,
53
        ];
54
    }
55
56
    /**
57
     * Render BreadCrumb
58
     */
59
    final public function render(): void
60
    {
61
        /*
62
        TODO if you want to use the render code below,
63
        1) create ./templates/chess_common_breadcrumb.tpl)
64
        2) add declaration to  xoops_version.php
65
        */
66
        /*
67
        if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) {
68
            require $GLOBALS['xoops']->path('class/theme.php');
69
70
            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
71
        }
72
73
        require $GLOBALS['xoops']->path('class/template.php');
74
75
        $breadcrumbTpl = new \XoopsTpl();
76
77
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
78
79
        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
80
81
        unset($breadcrumbTpl);
82
83
        return $html;
84
        */
85
    }
86
}
87