Breadcrumb::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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