<?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/Field.php
*/
abstract class Plugg_User_Model_Base_Field extends Sabai_Model_Entity
{
    public function __construct(Sabai_Model $model)
    {
        parent::__construct('Field', $model);
        $this->_vars = array('field_id' => 0, 'field_created' => 0, 'field_updated' => 0, 'field_name' => null, 'field_title' => null, 'field_plugin' => null, 'field_order' => 0, 'field_active' => 0, 'field_type' => 0, 'field_registerable' => 0, 'field_editable' => 0, 'field_viewable' => 0, 'field_configurable' => 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['field_' . $name];
    }

    protected function _setVar($name, $value)
    {
        switch ($name) {
        case 'id':
            $this->_vars['field_id'] = $value;
            break;
        case 'name':
            $this->_vars['field_name'] = trim($value);
            break;
        case 'title':
            $this->_vars['field_title'] = trim($value);
            break;
        case 'plugin':
            $this->_vars['field_plugin'] = trim($value);
            break;
        case 'order':
            $this->_vars['field_order'] = $value;
            break;
        case 'active':
            $this->_vars['field_active'] = $value;
            break;
        case 'type':
            $this->_vars['field_type'] = $value;
            break;
        case 'registerable':
            $this->_vars['field_registerable'] = $value;
            break;
        case 'editable':
            $this->_vars['field_editable'] = $value;
            break;
        case 'viewable':
            $this->_vars['field_viewable'] = $value;
            break;
        case 'configurable':
            $this->_vars['field_configurable'] = $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 'registerable':
            return $this->getVar('registerable');
        case 'editable':
            return $this->getVar('editable');
        case 'viewable':
            return $this->getVar('viewable');
        case 'configurable':
            return $this->getVar('configurable');
        }
    }

    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 'registerable':
            $this->setVar('registerable', $value);
            break;
        case 'editable':
            $this->setVar('editable', $value);
            break;
        case 'viewable':
            $this->setVar('viewable', $value);
            break;
        case 'configurable':
            $this->setVar('configurable', $value);
            break;
        }
    }

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

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

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

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

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

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

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