Breadcrumb::render()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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