Breadcrumb::addLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopsheadline\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
/**
16
 * Breadcrumb Class
17
 *
18
 * @copyright   XOOPS Project (https://xoops.org)
19
 * @license     https://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @author      lucio <[email protected]>
21
 *
22
 * Example:
23
 * $breadcrumb = new Breadcrumb();
24
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
25
 * $breadcrumb->addLink( 'bread 2', '' );
26
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
27
 * echo $breadcrumb->render();
28
 */
29
30
/**
31
 * Class Breadcrumb
32
 */
33
class Breadcrumb
34
{
35
    /**
36
     * @var string
37
     */
38
    public  $dirname;
39
    private $bread = [];
40
41
    public function __construct()
42
    {
43
        $this->dirname = \basename(\dirname(__DIR__, 2));
44
    }
45
46
    /**
47
     * Add link to breadcrumb
48
     */
49
    public function addLink(string $title = '', string $link = ''): void
50
    {
51
        $this->bread[] = [
52
            'link'  => $link,
53
            'title' => $title,
54
        ];
55
    }
56
57
    /**
58
     * Render BreadCrumb
59
     */
60
    public function render()
61
    {
62
        if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) {
63
            require $GLOBALS['xoops']->path('class/theme.php');
64
65
            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
66
        }
67
68
        require $GLOBALS['xoops']->path('class/template.php');
69
70
        $breadcrumbTpl = new \XoopsTpl();
71
72
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
73
74
        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
75
76
        unset($breadcrumbTpl);
77
78
        return $html;
79
    }
80
}
81