Breadcrumb   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

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