Classes

File content/category/SearchCategoryChildrensOptions.class.php

File content/category/SearchCategoryChildrensOptions.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: 108: 109: 110: 111: 112: 113: 114: 
<?php
/**
 * This class allows you to manage options of children used in CategoriesManager::get_children() and CategoriesManager::get_select_categories_form_field().
 * You will be able to manage one or more permission bits, exclude certain categories disable recursive search of one, several or all categories
 * @package     Content
 * @subpackage  Category
 * @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: 2016 10 24
 * @since       PHPBoost 4.0 - 2013 02 26
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class SearchCategoryChildrensOptions
{
    private $authorizations_bits = array();
    private $check_all_bits = false;
    private $excluded_categories_ids = array();
    private $excluded_categories_recursive = true;
    private $enable_recursive_exploration = true;
    private $allow_only_member_level_authorizations = false;

    public function add_authorizations_bits($authorizations_bits)
    {
        $this->authorizations_bits[] = $authorizations_bits;
    }

    public function get_authorizations_bits()
    {
        return $this->authorizations_bits;
    }

    public function check_authorizations(Category $category)
    {
        $nbr_bits = count($this->authorizations_bits);
        if ($nbr_bits == 0)
        {
            return true;
        }
        else
        {
            $authorized_bits = array();
            foreach ($this->authorizations_bits as $bit)
            {
                if (($this->allow_only_member_level_authorizations && Authorizations::check_auth(RANK_TYPE, User::MEMBER_LEVEL, $category->get_authorizations(), $bit)) || $category->check_auth($bit))
                    $authorized_bits[] = $bit;
            }

            $nbr_authorized_bits = count($authorized_bits);
            if ($this->check_all_bits)
            {
                return $nbr_authorized_bits == $nbr_bits;
            }
            else
            {
                return $nbr_authorized_bits >= 1;
            }
        }
    }

    public function set_check_all_bits($check_all_bits)
    {
        $this->check_all_bits = $check_all_bits;
    }

    public function get_check_all_bits()
    {
        return $this->check_all_bits;
    }

    public function add_category_in_excluded_categories($id)
    {
        $this->excluded_categories_ids[] = $id;
    }

    public function category_is_excluded(Category $category)
    {
        return in_array($category->get_id(), $this->excluded_categories_ids);
    }

    public function get_excluded_categories()
    {
        return $this->excluded_categories_ids;
    }

    public function set_excluded_categories_recursive($excluded_categories_recursive)
    {
        $this->excluded_categories_recursive = $excluded_categories_recursive;
    }

    public function is_excluded_categories_recursive()
    {
        return $this->excluded_categories_recursive;
    }

    public function set_enable_recursive_exploration($enable_recursive_exploration)
    {
        $this->enable_recursive_exploration = $enable_recursive_exploration;
    }

    public function is_enabled_recursive_exploration()
    {
        return $this->enable_recursive_exploration;
    }

    public function set_allow_only_member_level_authorizations($allow_only_member_level_authorizations)
    {
        $this->allow_only_member_level_authorizations = $allow_only_member_level_authorizations;
    }
}
?>
Annonces