<?php
/*
This file has been generated by the Sabai scaffold script. Do not edit this file directly.
If you need to customize the class, use the following file:
plugins/User/Model/Widget.php
*/
abstract class Plugg_User_Model_Base_Widget extends Sabai_Model_Entity
{
    public function __construct(Sabai_Model $model)
    {
        parent::__construct('Widget', $model);
        $this->_vars = array('widget_id' => 0, 'widget_created' => 0, 'widget_updated' => 0, 'widget_name' => null, 'widget_title' => null, 'widget_plugin' => null, 'widget_order' => 0, 'widget_active' => 0, 'widget_type' => 0, 'widget_private' => 0, 'widget_mini' => 0);
    }

    public function getId()
    {
        return $this->getVar('id');
    }

    public function setId($value)
    {
        $this->setVar('id', $value);
    }

    public function getTimeCreated()
    {
        return $this->getVar('created');
    }

    public function getTimeUpdated()
    {
        return $this->getVar('updated');
    }

    public function getLabel()
    {
        return $this->getVar('title');
    }


    protected function _getVar($name)
    {
        return $this->_vars['widget_' . $name];
    }

    protected function _setVar($name, $value)
    {
        switch ($name) {
        case 'id':
            $this->_vars['widget_id'] = $value;
            break;
        case 'name':
            $this->_vars['widget_name'] = trim($value);
            break;
        case 'title':
            $this->_vars['widget_title'] = trim($value);
            break;
        case 'plugin':
            $this->_vars['widget_plugin'] = trim($value);
            break;
        case 'order':
            $this->_vars['widget_order'] = $value;
            break;
        case 'active':
            $this->_vars['widget_active'] = $value;
            break;
        case 'type':
            $this->_vars['widget_type'] = $value;
            break;
        case 'private':
            $this->_vars['widget_private'] = $value;
            break;
        case 'mini':
            $this->_vars['widget_mini'] = $value;
            break;
        default:
            trigger_error(sprintf('Error trying to set value for variable %s. This variable is either read-only or does not exist for this entity', $name), E_USER_WARNING);
            return false;
        }
        return true;
    }

    protected function _get($name, $sort, $order)
    {
        switch ($name) {
        case 'name':
            return $this->getVar('name');
        case 'title':
            return $this->getVar('title');
        case 'plugin':
            return $this->getVar('plugin');
        case 'order':
            return $this->getVar('order');
        case 'active':
            return $this->getVar('active');
        case 'type':
            return $this->getVar('type');
        case 'private':
            return $this->getVar('private');
        case 'mini':
            return $this->getVar('mini');
        }
    }

    public function __set($name, $value)
    {
        switch ($name) {
        case 'name':
            $this->setVar('name', $value);
            break;
        case 'title':
            $this->setVar('title', $value);
            break;
        case 'plugin':
            $this->setVar('plugin', $value);
            break;
        case 'order':
            $this->setVar('order', $value);
            break;
        case 'active':
            $this->setVar('active', $value);
            break;
        case 'type':
            $this->setVar('type', $value);
            break;
        case 'private':
            $this->setVar('private', $value);
            break;
        case 'mini':
            $this->setVar('mini', $value);
            break;
        }
    }

    public function initVar($name, $value)
    {
        switch ($name) {
        default:
            $this->_vars[$name] = $value;
            break;
        }
    }
}

abstract class Plugg_User_Model_Base_WidgetRepository extends Sabai_Model_EntityRepository
{
    public function __construct(Sabai_Model $model)
    {
        parent::__construct('Widget', $model);
    }

    protected function _getCollectionByRowset(Sabai_DB_Rowset $rs)
    {
        return new Plugg_User_Model_Base_WidgetsByRowset($rs, $this->_model->create('Widget'), $this->_model);
    }

    public function createCollection(array $entities = array())
    {
        return new Plugg_User_Model_Base_Widgets($this->_model, $entities);
    }
}

class Plugg_User_Model_Base_WidgetsByRowset extends Sabai_Model_EntityCollection_Rowset
{
    public function __construct(Sabai_DB_Rowset $rs, Sabai_Model_Entity $emptyEntity, Sabai_Model $model)
    {
        parent::__construct('Widgets', $rs, $emptyEntity, $model);
    }

    protected function _loadRow(Sabai_Model_Entity $entity, array $row)
    {
        $entity->initVars($row);
    }
}

class Plugg_User_Model_Base_Widgets extends Sabai_Model_EntityCollection_Array
{
    public function __construct(Sabai_Model $model, array $entities = array())
    {
        parent::__construct($model, 'Widgets', $entities);
    }
}