Passed
Pull Request — master (#2)
by Michael
02:17
created

Breadcrumb   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

3 Methods

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