<?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:
pluginsy/System/Model/PluginHTMLQuickForm.php
*/
abstract class Plugg_System_Model_Base_PluginHTMLQuickForm extends Sabai_Model_EntityHTMLQuickForm
{
    public function onInit(array $params)
    {
        $this->addElement('text', 'name', $this->_model->_('Name'), array('size' => 80, 'maxlength' => 255));
        $this->setRequired('name', $this->_model->_('Name is required'));
        $this->addElement('text', 'nicename', $this->_model->_('Nicename'), array('size' => 80, 'maxlength' => 255));
        $this->setRequired('nicename', $this->_model->_('Nicename is required'));
        $this->addElement('altselect', 'active', $this->_model->_('Active'), array(
            1 => $this->_model->_('Yes'),
            0 => $this->_model->_('No'),
        ))->setDelimiter('&nbsp;');
        $this->addElement('altselect', 'locked', $this->_model->_('Locked'), array(
            1 => $this->_model->_('Yes'),
            0 => $this->_model->_('No'),
        ))->setDelimiter('&nbsp;');
        $this->_onInit($params);
    }

    public function onEntity(Sabai_Model_Entity $entity)
    {
        $defaults = array();
        foreach (array('name', 'nicename', 'active', 'locked') as $key) {
            if ($this->elementExists($key) || $this->isInGroup($key)) {
                $defaults[$key] = $entity->getVar($key);
            }
        }
        if (!empty($defaults)) $this->setDefaults($defaults);
        $this->_onEntity($entity);
    }

    public function onFillEntity(Sabai_Model_Entity $entity)
    {
        $vars = array();
        foreach (array('name' => 'name', 'nicename' => 'nicename', 'active' => 'active', 'locked' => 'locked') as $var_name => $form_name) {
            if ($this->elementExists($form_name) || $this->isInGroup($form_name)) {
                if ($this->getElementType($form_name) == 'static') continue;

                $value = $this->getSubmitValue($form_name);
                $vars[$var_name] = is_array($value) ? array_shift($value) : $value;
            }
        }
        $entity->setVars($vars);
        $this->_onFillEntity($entity);
    }

    abstract protected function _onInit(array $params);
    abstract protected function _onEntity(Sabai_Model_Entity $entity);
    abstract protected function _onFillEntity(Sabai_Model_Entity $entity);
}