Classes

File content/category/RichCategory.class.php

File content/category/RichCategory.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: 
<?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 24
 * @since       PHPBoost 4.0 - 2013 01 29
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class RichCategory extends Category
{
    protected $description;
    protected $image;

    public function set_description($description)
    {
        $this->description = $description;
    }

    public function get_description()
    {
        return $this->description;
    }

    public function set_image(Url $image)
    {
        $this->image = $image;
    }

    public function get_image()
    {
        if (!$this->image instanceof Url)
            return new Url('/' . Environment::get_running_module_name() . '/' . Environment::get_running_module_name() . '.png');

        return $this->image;
    }

    public function get_properties()
    {
        return array_merge(parent::get_properties(), array(
            'description' => $this->get_description(),
            'image' => $this->get_image()->relative()
        ));
    }

    public function set_properties(array $properties)
    {
        parent::set_properties($properties);
        $this->set_description($properties['description']);
        $this->set_image(new Url($properties['image']));
    }

    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' => "''"),
            'description' => array('type' => 'text', 'length' => 65000),
            '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),
            'image' => array('type' => 'string', 'length' => 255, 'notnull' => 1, 'default' => "''"),
            '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);
    }
}
?>