Breadcrumb   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addLink() 0 5 1
A __construct() 0 3 1
A render() 0 14 3
1
<?php
2
3
namespace XoopsModules\Blocksadmin\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     Blocksadmin
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\Blocksadmin;
32
use XoopsModules\Blocksadmin\Common;
33
34
/**
35
 * Class Breadcrumb
36
 */
37
class Breadcrumb
38
{
39
    public  $dirname;
40
    private $bread = [];
41
42
    public function __construct()
43
    {
44
        $this->dirname = \basename(\dirname(__DIR__, 2));
45
    }
46
47
    /**
48
     * Add link to breadcrumb
49
     *
50
     * @param string $title
51
     * @param string $link
52
     */
53
    public function addLink($title = '', $link = '')
54
    {
55
        $this->bread[] = [
56
            'link'  => $link,
57
            'title' => $title,
58
        ];
59
    }
60
61
    /**
62
     * Render BreadCrumb
63
     */
64
    public function render()
65
    {
66
        if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) {
67
            require $GLOBALS['xoops']->path('class/theme.php');
68
            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
69
        }
70
71
        require $GLOBALS['xoops']->path('class/template.php');
72
        $breadcrumbTpl = new \XoopsTpl();
73
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
74
        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
75
        unset($breadcrumbTpl);
76
77
        return $html;
78
    }
79
}
80