Classes

File phpboost/module/tree-links/ModuleLink.class.php

File phpboost/module/tree-links/ModuleLink.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 
<?php
/**
 * @package     PHPBoost
 * @subpackage  Module\tree-links
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Kevin MASSY <reidlos@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2017 05 30
 * @since       PHPBoost 4.1 - 2013 11 15
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class ModuleLink
{
    protected $name;
    protected $url;
    protected $sub_link = array();
    protected $visibility = true;

    public function __construct($name, $url, $visibility = true)
    {
        $this->name = $name;
        $this->visibility = $visibility;
        $this->set_url($url);
    }

    public function set_name($name)
    {
        $this->name = $name;
    }

    public function get_name()
    {
        return $this->name;
    }

    public function set_url($url)
    {
        if (!($url instanceof Url))
        {
            $url = new Url($url);
        }
        $this->url = $url;
    }

    public function get_url()
    {
        return $this->url;
    }

    public function add_sub_link(ModuleLink $sub_link)
    {
        $this->sub_link[] = $sub_link;
    }

    public function get_sub_link()
    {
        return $this->sub_link;
    }

    public function has_sub_link()
    {
        return !empty($this->sub_link);
    }

    public function set_visibility($visibility)
    {
        $this->visibility = $visibility;
    }

    public function is_visible()
    {
        return (bool)$this->visibility;
    }

    public function is_active()
    {
        return Url::is_current_url($this->get_url()->relative());
    }

    public function export()
    {
        $tpl = new FileTemplate('framework/module/module_actions_link.tpl');

        $tpl->put_all(array(
            'C_HAS_SUB_LINK' => $this->has_sub_link(),
            'C_IS_ACTIVE'    => $this->is_active(),
            'NAME'           => $this->get_name(),
            'FULLNAME'       => LangLoader::get_message('menu.link-to', 'user-common') . $this->get_name(),
            'U_LINK'         => $this->get_url()->rel(),
        ));

        foreach ($this->get_sub_link() as $element)
        {
            if ($element->is_visible())
            {
                $tpl->assign_block_vars('element', array(), array(
                    'ELEMENT' => $element->export()
                ));
            }
        }

        return $tpl;
    }
}
?>