<commit_before><?php
/*"******************************************************************************************************
*   (c) 2007-2015 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
********************************************************************************************************/

/**
 * A formelement rendering an array of checkboxes.
 * Requires both, a set of possible options and the set of options currently selected.
 *
 * @author <EMAIL>
 * @since 4.8
 * @package module_formgenerator
 */
class class_formentry_checkboxarray extends class_formentry_base implements interface_formentry_printable {

    const TYPE_CHECKBOX = 1;
    const TYPE_RADIO = 2;

    private $intType = 1;
    private $bitInline = false;
    private $arrKeyValues = array();
    private $arrSelected;

    public function __construct($strFormName, $strSourceProperty, $objSourceObject = null) {
        parent::__construct($strFormName, $strSourceProperty, $objSourceObject);

        //set the default validator
        $this->setObjValidator(new class_dummy_validator());
    }

    public function setIntType($intType)
    {
        $this->intType = $intType;

        return $this;
    }

    public function setBitInline($bitInline)
    {
        $this->bitInline = $bitInline;

        return $this;
    }

    /**
     * Renders the field itself.
     * In most cases, based on the current toolkit.
     *
     * @return string
     */
    public function renderField() {
        $objToolkit = class_carrier::getInstance()->getObjToolkit("admin");
        $strReturn = "";
        if($this->getStrHint() != null)
            $strReturn .= $objToolkit->formTextRow($this->getStrHint());

        $arrSelected = $this->arrSelected !== null ? $this->arrSelected : $this->getStrValue();
        $strReturn .= $objToolkit->formInputCheckboxArray($this->getStrEntryName(), $this->getStrLabel(), $this->intType, $this->arrKeyValues, $arrSelected, $this->bitInline, $this->getBitReadonly());

        return $strReturn;
    }

    /**
     * @param $strValue
     * @return class_formentry_base
     */
    public function setStrValue($strValue) {
        $arrTargetValues = array();

        if((is_array($strValue) || $strValue instanceof ArrayObject) && count($strValue) > 0) {

            foreach($strValue as $strKey => $strSingleValue) {
                //DB vals
                if(is_object($strSingleValue)) {
                    $arrTargetValues[] = $strSingleValue->getSystemid();
                }

                //POST vals
                else if($strSingleValue == "checked") {
                    $arrTargetValues[] = $strKey;
                }
            }
        }

        return parent::setStrValue($arrTargetValues);
    }



    /**
     * @return array
     */
    public function getArrKeyValues() {
        return $this->arrKeyValues;
    }

    /**
     * @param array $arrKeyValues
     */
    public function setArrKeyValues($arrKeyValues) {
        $this->arrKeyValues = $arrKeyValues;

        return $this;
    }

    /**
     * @param array $arrSelected
     */
    public function setArrSelected($arrSelected) {
        $this->arrSelected = $arrSelected;

        return $this;
    }

    /**
     * Returns a textual representation of the formentries' value.
     * May contain html, but should be stripped down to text-only.
     *<commit_msg>UPDATE: module_system | class_formentry_checkboxarray > remove array selected property<commit_after><?php
/*"******************************************************************************************************
*   (c) 2007-2015 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
********************************************************************************************************/

/**
 * A formelement rendering an array of checkboxes.
 * Requires both, a set of possible options and the set of options currently selected.
 *
 * @author <EMAIL>
 * @since 4.8
 * @package module_formgenerator
 */
class class_formentry_checkboxarray extends class_formentry_base implements interface_formentry_printable {

    const TYPE_CHECKBOX = 1;
    const TYPE_RADIO = 2;

    private $intType = 1;
    private $bitInline = false;
    private $arrKeyValues = array();

    public function __construct($strFormName, $strSourceProperty, $objSourceObject = null) {
        parent::__construct($strFormName, $strSourceProperty, $objSourceObject);

        //set the default validator
        $this->setObjValidator(new class_dummy_validator());
    }

    public function setIntType($intType)
    {
        $this->intType = $intType;

        return $this;
    }

    public function setBitInline($bitInline)
    {
        $this->bitInline = $bitInline;

        return $this;
    }

    /**
     * Renders the field itself.
     * In most cases, based on the current toolkit.
     *
     * @return string
     */
    public function renderField() {
        $objToolkit = class_carrier::getInstance()->getObjToolkit("admin");
        $strReturn = "";
        if($this->getStrHint() != null)
            $strReturn .= $objToolkit->formTextRow($this->getStrHint());

        $strReturn .= $objToolkit->formInputCheckboxArray($this->getStrEntryName(), $this->getStrLabel(), $this->intType, $this->arrKeyValues, $this->getStrValue(), $this->bitInline, $this->getBitReadonly());

        return $strReturn;
    }

    /**
     * @param $strValue
     * @return class_formentry_base
     */
    public function setStrValue($strValue) {
        $arrTargetValues = array();

        if((is_array($strValue) || $strValue instanceof ArrayObject) && count($strValue) > 0) {

            foreach($strValue as $strKey => $strSingleValue) {
                //DB vals
                if(is_object($strSingleValue)) {
                    $arrTargetValues[] = $strSingleValue->getSystemid();
                }

                //POST vals
                else if($strSingleValue == "checked") {
                    $arrTargetValues[] = $strKey;
                }
            }
        }

        return parent::setStrValue($arrTargetValues);
    }



    /**
     * @return array
     */
    public function getArrKeyValues() {
        return $this->arrKeyValues;
    }

    /**
     * @param array $arrKeyValues
     */
    public function setArrKeyValues($arrKeyValues) {
        $this->arrKeyValues = $arrKeyValues;

        return $this;
    }

    /**
     * Returns a textual representation of the formentries' value.
     * May contain html, but should be stripped down to text-only.
     *
{'fraction_non_alphanumeric': 0.17027185033615902, 'fraction_numerical': 0.00467699503069278, 'mean_word_length': 2.3994038748137108, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7150525', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1803, 'n_words': 409}