<commit_before><?php
/**
 * WebEnq4
 *
 *  LICENSE
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    Webenq_Questionnaires_Manage
 * @copyright  Copyright (c) 2012 Nivocer B.V. (http://www.nivocer.com)
 * @license    http://www.gnu.org/licenses/agpl.html
 */

/**
 * Subform to edit answer domain information within the context of editing a
 * question in a questionnaire.
 *
 * @package    Webenq_Questionnaires_Manage
 * @author     <NAME> <<EMAIL>>
 */
class Webenq_Form_AnswerDomain_Items extends WebEnq4_Form
{
    /**
     * List of fields to show for items
     */
    private $_fields = array(
        'value' => array(
            'label' => 'Value',
            'description' => "The value stored\nin the database",
            'type' => 'string'
        ),
        'label' => array(
            'label' => 'Label',
            'description' => "How the value is presented\nin forms and reports",
            'type' => 'i18n'
        ),
        'isNullValue' => array(
            'label' => 'Null value?',
            'description' => "Should this be considered\nas \"non-response\"?",
            'type' => 'boolean'
        ),
        'isActive' => array(
            'label' => 'Active?',
            'description' => "Is this item in use?",
            'type' => 'boolean'
        ),
        'isHidden' => array(
            'label' => 'Hidden?',
            'description' => "Should this item be shown in lists?",
            'type' => 'boolean'
        ),
    );

    /**
     * Load the default decorators
     *
     * @return Webenq_Form_AnswerDomain_Items
     */
    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return $this;
        }

        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->addDecorator('FormElements')
            ->addDecorator('HtmlTag', array('tag' => 'table'));
        }
        return $this;
    }

    /**
     * Subform to ask answer domain properties when editing a question
     *
     * @return void
     * @see Zend_Form::init()
     */
    public function init()
    {
        $id = new Zend_Form_Element_Hidden('id');
        $id->setBelongsTo($this->getName());
        $id->removeDecorator('DtDdWrapper');
        $id->removeDecorator('Label');
        $id->setBelongsTo('items');
        $this->addElement($id);

        // add the table headers
        $header = array();
        foreach ($this->_fields as $fieldname => $fieldinfo) {
            $cell = new WebEnq4_Form_Element_Note('th_'.$fieldname);
            $cell->setValue($fieldinfo['label']);
            $id->setBelongsTo('items');
            $this->decorateAsTableCell($cell, true);
            $this->addElement($cell);
            $header[] = $cell->getName();
        }
        $this->addDisplayGroup($header, 'header', array());
        $this->decorateAsTableRow($this->getDisplayGroup('header'));
    }

    /**
     * Set defaults, in our case: add some form elements
     */
    public function setDefaults(array $defaults)
    {
        if (isset($defaults['id'])) {
            if (!isset($defaults['item'])) {
                $defaults['item'] = array();
            }
            $defaults['items']['id'] = $defaults['id'];

            $tree = Doctrine_Core::getTable('Webenq_Model_AnswerDomainItem')->getTree();
            $domainitems = $tree->fetchTree(array('root_id' => $defaults['id']));<commit_msg>Quick&dirty 'add item row ' option<commit_after><?php
/**
 * WebEnq4
 *
 *  LICENSE
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    Webenq_Questionnaires_Manage
 * @copyright  Copyright (c) 2012 Nivocer B.V. (http://www.nivocer.com)
 * @license    http://www.gnu.org/licenses/agpl.html
 */

/**
 * Subform to edit answer domain information within the context of editing a
 * question in a questionnaire.
 *
 * @package    Webenq_Questionnaires_Manage
 * @author     <NAME> <<EMAIL>>
 */
class Webenq_Form_AnswerDomain_Items extends WebEnq4_Form
{
    /**
     * List of fields to show for items
     */
    private $_fields = array(
        'value' => array(
            'label' => 'Value',
            'description' => "The value stored\nin the database",
            'type' => 'string'
        ),
        'label' => array(
            'label' => 'Label',
            'description' => "How the value is presented\nin forms and reports",
            'type' => 'i18n'
        ),
        'isNullValue' => array(
            'label' => 'Null value?',
            'description' => "Should this be considered\nas \"non-response\"?",
            'type' => 'boolean'
        ),
        'isActive' => array(
            'label' => 'Active?',
            'description' => "Is this item in use?",
            'type' => 'boolean'
        ),
        'isHidden' => array(
            'label' => 'Hidden?',
            'description' => "Should this item be shown in lists?",
            'type' => 'boolean'
        ),
    );

    /**
     * Load the default decorators
     *
     * @return Webenq_Form_AnswerDomain_Items
     */
    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return $this;
        }

        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->addDecorator('FormElements')
            ->addDecorator('HtmlTag', array('tag' => 'table'));
        }
        return $this;
    }

    /**
     * Subform to ask answer domain properties when editing a question
     *
     * @return void
     * @see Zend_Form::init()
     */
    public function init()
    {
        $id = new Zend_Form_Element_Hidden('id');
        $id->setBelongsTo($this->getName());
        $id->removeDecorator('DtDdWrapper');
        $id->removeDecorator('Label');
        $id->setBelongsTo('items');
        $this->addElement($id);

        // add the table headers
        $header = array();
        foreach ($this->_fields as $fieldname => $fieldinfo) {
            $cell = new WebEnq4_Form_Element_Note('th_'.$fieldname);
            $cell->setValue($fieldinfo['label']);
            $id->setBelongsTo('items');
            $this->decorateAsTableCell($cell, true);
            $this->addElement($cell);
            $header[] = $cell->getName();
        }
        $this->addDisplayGroup($header, 'header', array());
        $this->decorateAsTableRow($this->getDisplayGroup('header'));

        // add the table headers
        $cell = new WebEnq4_Form_Element_Note('addItemRow');
        $cell->setValue('<a class="add with_icon" href="#">' . t('Add an item') . '</a>');
        $this->decorateAsTableCell($cell);
        $this->addElement($cell);
        $this->addDisplayGroup(array('addItemRow'), 'footer', array('order' => '999'));
        $this->decorateAsTableRow($this->getDisplayGroup('footer'));
    }

    /**
     * Set defaults, in our case: add some form elements
     */
    public function setDefaults(array $defaults)
    {
        if (isset($defaults['id'])) {
            if (!isset($defaults['item'])) {
                $defaults['item'] = array();
            }
            $defaults['items']['id'] = $defaults['id'];

            $tree = Doctrine_Core::getTable('Webenq_Model_AnswerDomainItem')->getTree();
            $domainitems = $tree->fetchTree(array('root_id' => $defaults['id']));
{'fraction_non_alphanumeric': 0.14331983805668017, 'fraction_numerical': 0.002776171197223829, 'mean_word_length': 2.2937142857142856, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2965142', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2463, 'n_words': 657}