Classes

File content/category/Category.class.php

File content/category/Category.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: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 
<?php
/**
 * @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 30
 * @since       PHPBoost 4.0 - 2013 01 29
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class Category
{
    protected $id;
    protected $name;
    protected $rewrited_name;
    protected $order;
    protected $special_authorizations = false;
    protected $auth = array();
    protected $id_parent;
    protected $elements_number;
    protected $allowed_to_have_childs = true;

    const READ_AUTHORIZATIONS = 1;
    const WRITE_AUTHORIZATIONS = 2;
    const CONTRIBUTION_AUTHORIZATIONS = 4;
    const MODERATION_AUTHORIZATIONS = 8;
    const CATEGORIES_MANAGEMENT_AUTHORIZATIONS = 16;

    const ROOT_CATEGORY = '0';

    public function get_id()
    {
        return $this->id;
    }

    public function set_id($id)
    {
        $this->id = $id;
    }

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

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

    public function get_rewrited_name()
    {
        return $this->rewrited_name;
    }

    public function set_rewrited_name($rewrited_name)
    {
        $this->rewrited_name = $rewrited_name;
    }

    public function rewrited_name_is_personalized()
    {
        return $this->rewrited_name != Url::encode_rewrite($this->name);
    }

    public function get_order()
    {
        return $this->order;
    }

    public function set_order($order)
    {
        $this->order = $order;
    }

    public function incremente_order()
    {
        $this->order++;
    }

    public function has_special_authorizations()
    {
        return $this->special_authorizations;
    }

    public function set_special_authorizations($special_authorizations)
    {
        $this->special_authorizations = (bool)$special_authorizations;
    }

    public function get_authorizations()
    {
        return $this->auth;
    }

    public function set_authorizations(array $auth)
    {
        $this->auth = $auth;
    }

    public function auth_is_empty()
    {
        return empty($this->auth);
    }

    public function auth_is_equals(Array $auth)
    {
        return $this->auth === $auth;
    }

    public function get_id_parent()
    {
        return $this->id_parent;
    }

    public function set_id_parent($id_parent)
    {
        $this->id_parent = $id_parent;
    }

    public function get_elements_number()
    {
        return $this->elements_number;
    }

    public function set_elements_number($elements_number)
    {
        $this->elements_number = $elements_number;
    }

    public function is_allowed_to_have_childs()
    {
        return $this->allowed_to_have_childs;
    }

    public function check_auth($bit)
    {
        return AppContext::get_current_user()->check_auth($this->auth, $bit);
    }

    public function get_properties()
    {
        return array(
            'id' => $this->get_id(),
            'name' => TextHelper::htmlspecialchars($this->get_name()),
            'rewrited_name' => TextHelper::htmlspecialchars($this->get_rewrited_name()),
            'c_order' => $this->get_order(),
            'special_authorizations' => (int)$this->has_special_authorizations(),
            'auth' => !$this->auth_is_empty() ? TextHelper::serialize($this->get_authorizations()) : '',
            'id_parent' => $this->get_id_parent()
        );
    }

    public function set_properties(array $properties)
    {
        $this->set_id($properties['id']);
        $this->set_name($properties['name']);
        $this->set_rewrited_name($properties['rewrited_name']);
        $this->set_order($properties['c_order']);
        $this->set_special_authorizations($properties['special_authorizations']);
        $this->set_authorizations(!empty($properties['auth']) ? TextHelper::unserialize($properties['auth']) : array());
        $this->set_id_parent($properties['id_parent']);
    }

    public static function create_categories_table($table_name)
    {
        $fields = array(
            'id' => array('type' => 'integer', 'length' => 11, 'autoincrement' => true, 'notnull' => 1),
            'name' => array('type' => 'string', 'length' => 255, 'notnull' => 1, 'default' => "''"),
            'rewrited_name' => array('type' => 'string', 'length' => 250, 'default' => "''"),
            'c_order' => array('type' => 'integer', 'length' => 11, 'unsigned' => 1, 'notnull' => 1, 'default' => 0),
            'special_authorizations' => array('type' => 'boolean', 'notnull' => 1, 'default' => 0),
            'auth' => array('type' => 'text', 'length' => 65000),
            'id_parent' => array('type' => 'integer', 'length' => 11, 'notnull' => 1, 'default' => 0),
        );

        $options = array(
            'primary' => array('id')
        );
        PersistenceContext::get_dbms_utils()->create_table($table_name, $fields, $options);
    }
}
?>
Annonces