Breadcrumb::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace Xoopsmodules\instruction\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   The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @author      lucio <[email protected]>
18
 * @package     pedigree
19
 * @since       3.23
20
 * @version     $Id: breadcrumb.php 12865 2014-11-22 07:03:35Z beckmi $
21
 *
22
 * Example:
23
 * $breadcrumb = new \Breadcrumb();
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
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined');
30
31
/**
32
 * Class PedigreeBreadcrumb
33
 */
34
class Breadcrumb
35
{
36
    public $dirname;
37
    private $bread = [];
38
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        $this->dirname = basename(dirname(dirname(__DIR__)));
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
     */
65
    public function render()
66
    {
67
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
68
            require_once $GLOBALS['xoops']->path('class/theme.php');
69
            $GLOBALS['xoTheme'] = new xos_opal_Theme();
70
        }
71
72
        require_once $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