Passed
Pull Request — master (#9)
by Michael
03:24
created

Breadcrumb::__construct()   A

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