<commit_before><?php

    namespace thebuggenie\core\entities;

    use thebuggenie\core\framework;

    /**
     * @Table(name="\thebuggenie\core\entities\tables\CustomFields")
     */
    class CustomDatatype extends DatatypeBase
    {

        const DROPDOWN_CHOICE_TEXT = 1;
        const INPUT_TEXT = 2;
        const INPUT_TEXTAREA_MAIN = 3;
        const INPUT_TEXTAREA_SMALL = 4;
        const RADIO_CHOICE = 5;
        const RELEASES_CHOICE = 8;
        const COMPONENTS_CHOICE = 10;
        const EDITIONS_CHOICE = 12;
        const STATUS_CHOICE = 13;
        const USER_CHOICE = 14;
        const TEAM_CHOICE = 15;
        const CALCULATED_FIELD = 18;
        const DATE_PICKER = 19;
        const MILESTONE_CHOICE = 20;
        const CLIENT_CHOICE = 21;

        protected static $_types = null;

        /**
         * This custom types options (if any)
         *
         * @var array
         * @Relates(class="\thebuggenie\core\entities\CustomDatatypeOption", collection=true, foreign_column="customfield_id", orderby="sort_order")
         */
        protected $_options = null;

        /**
         * The custom types description
         *
         * @var string
         * @Column(type="string", length=200)
         */
        protected $_description = null;

        /**
         * The custom types instructions
         *
         * @var string
         * @Column(type="text")
         */
        protected $_instructions = null;

        /**
         * Returns all custom types available
         *
         * @return array
         */
        public static function getAll()
        {
            if (self::$_types === null)
            {
                self::$_types = tables\CustomFields::getTable()->getAll();
            }
            return self::$_types;
        }

        public static function getByFieldType($type)
        {
            $return_fields = array();
            foreach (self::getAll() as $field)
            {
                if ($field->getType() == $type) $return_fields[$field->getID()] = $field;
            }

            return $return_fields;
        }

        public static function getAllExceptTypes($types)
        {
            $return_fields = array();
            foreach (self::getAll() as $field)
            {
                if (!in_array($field->getType(), $types)) $return_fields[$field->getID()] = $field;
            }

            return $return_fields;
        }

        public static function getFieldTypes()
        {
            $i18n = framework\Context::getI18n();
            $types = array();
            $types[self::DROPDOWN_CHOICE_TEXT] = $i18n->__('Dropdown list with custom text choices');
            $types[self::INPUT_TEXT] = $i18n->__('Single line text input');
            $types[self::INPUT_TEXTAREA_MAIN] = $i18n->__('Textarea in issue main area');
            $types[self::INPUT_TEXTAREA_SMALL] = $i18n->__('Textarea (small) in issue details list');
            $types[self::RADIO_CHOICE] = $i18n->__('Radio choices');
            $types[self::RELEASES_CHOICE] = $i18n->__('Dropdown list of available releases');
            $types[self::COMPONENTS_CHOICE] = $i18n->__('Dropdown list of available components');
            $types[self::EDITIONS_CHOICE] = $i18n->__('Dropdown list of available editions');
            $types[self::MILESTONE_CHOICE] = $i18n->__('Dropdown list of available milestones');
            $types[self::STATUS_CHOICE] = $i18n->__('Dropdown list of all statuses');
            $types[self::CALCULATED_FIELD] = $i18n->__('Calculated field');
            $types[self::DATE_PICKER] = $i18n->__('Date picker');
            $types[self::USER_CHOICE] = $i18n->__('Find and pick a user');
            $types[self::TEAM_CHOICE] = $i18n->__('Find and pick a team');
            $types[self::CLIENT_CHOICE] = $i18n->__('Find and pick a client');

            return $types;

        }

        protected function _preSave($is_new)
        {
            parent::_preSave($is_new);
            if ($is_new)
            {
                $this->_generateKey();
                if (array_key_exists($this->_key, self::getAll()))
                {
                    throw new \Exception(framework\Context::getI18n()->__('This field key already exists'));
                }
            }
        }

        /**
         * Delete a custom type by id
         *
         * @param integer $id
         */
        protected function _preDelete()
        {
            tables\CustomFieldOptions::getTable()->deleteCustomFieldOptions($this->getID());
            tables\IssueFields::getTable()->deleteByIssueFieldKey($this->getKey());
        }

        public static function doesKeyExist($key)
        {
            return array_key_exists($key, self::getAll());
        }

        /**
         * Get a custom type by its key
         *
         * @param string $key
         *
         * @return \thebuggenie\core\entities\CustomDatatype
         */
        public static function getByKey($key)
        {
            foreach (self::getAll() as $field)
            {
                if ($field->getKey() == $key) return $field;
            }
            return null;
        }

        public static function getCustomChoiceFieldsAsArray()
        {<commit_msg>remove incorrect docblock in CustomDatatype::_preDelete()<commit_after><?php

    namespace thebuggenie\core\entities;

    use thebuggenie\core\framework;

    /**
     * @Table(name="\thebuggenie\core\entities\tables\CustomFields")
     */
    class CustomDatatype extends DatatypeBase
    {

        const DROPDOWN_CHOICE_TEXT = 1;
        const INPUT_TEXT = 2;
        const INPUT_TEXTAREA_MAIN = 3;
        const INPUT_TEXTAREA_SMALL = 4;
        const RADIO_CHOICE = 5;
        const RELEASES_CHOICE = 8;
        const COMPONENTS_CHOICE = 10;
        const EDITIONS_CHOICE = 12;
        const STATUS_CHOICE = 13;
        const USER_CHOICE = 14;
        const TEAM_CHOICE = 15;
        const CALCULATED_FIELD = 18;
        const DATE_PICKER = 19;
        const MILESTONE_CHOICE = 20;
        const CLIENT_CHOICE = 21;

        protected static $_types = null;

        /**
         * This custom types options (if any)
         *
         * @var array
         * @Relates(class="\thebuggenie\core\entities\CustomDatatypeOption", collection=true, foreign_column="customfield_id", orderby="sort_order")
         */
        protected $_options = null;

        /**
         * The custom types description
         *
         * @var string
         * @Column(type="string", length=200)
         */
        protected $_description = null;

        /**
         * The custom types instructions
         *
         * @var string
         * @Column(type="text")
         */
        protected $_instructions = null;

        /**
         * Returns all custom types available
         *
         * @return array
         */
        public static function getAll()
        {
            if (self::$_types === null)
            {
                self::$_types = tables\CustomFields::getTable()->getAll();
            }
            return self::$_types;
        }

        public static function getByFieldType($type)
        {
            $return_fields = array();
            foreach (self::getAll() as $field)
            {
                if ($field->getType() == $type) $return_fields[$field->getID()] = $field;
            }

            return $return_fields;
        }

        public static function getAllExceptTypes($types)
        {
            $return_fields = array();
            foreach (self::getAll() as $field)
            {
                if (!in_array($field->getType(), $types)) $return_fields[$field->getID()] = $field;
            }

            return $return_fields;
        }

        public static function getFieldTypes()
        {
            $i18n = framework\Context::getI18n();
            $types = array();
            $types[self::DROPDOWN_CHOICE_TEXT] = $i18n->__('Dropdown list with custom text choices');
            $types[self::INPUT_TEXT] = $i18n->__('Single line text input');
            $types[self::INPUT_TEXTAREA_MAIN] = $i18n->__('Textarea in issue main area');
            $types[self::INPUT_TEXTAREA_SMALL] = $i18n->__('Textarea (small) in issue details list');
            $types[self::RADIO_CHOICE] = $i18n->__('Radio choices');
            $types[self::RELEASES_CHOICE] = $i18n->__('Dropdown list of available releases');
            $types[self::COMPONENTS_CHOICE] = $i18n->__('Dropdown list of available components');
            $types[self::EDITIONS_CHOICE] = $i18n->__('Dropdown list of available editions');
            $types[self::MILESTONE_CHOICE] = $i18n->__('Dropdown list of available milestones');
            $types[self::STATUS_CHOICE] = $i18n->__('Dropdown list of all statuses');
            $types[self::CALCULATED_FIELD] = $i18n->__('Calculated field');
            $types[self::DATE_PICKER] = $i18n->__('Date picker');
            $types[self::USER_CHOICE] = $i18n->__('Find and pick a user');
            $types[self::TEAM_CHOICE] = $i18n->__('Find and pick a team');
            $types[self::CLIENT_CHOICE] = $i18n->__('Find and pick a client');

            return $types;

        }

        protected function _preSave($is_new)
        {
            parent::_preSave($is_new);
            if ($is_new)
            {
                $this->_generateKey();
                if (array_key_exists($this->_key, self::getAll()))
                {
                    throw new \Exception(framework\Context::getI18n()->__('This field key already exists'));
                }
            }
        }

        protected function _preDelete()
        {
            tables\CustomFieldOptions::getTable()->deleteCustomFieldOptions($this->getID());
            tables\IssueFields::getTable()->deleteByIssueFieldKey($this->getKey());
        }

        public static function doesKeyExist($key)
        {
            return array_key_exists($key, self::getAll());
        }

        /**
         * Get a custom type by its key
         *
         * @param string $key
         *
         * @return \thebuggenie\core\entities\CustomDatatype
         */
        public static function getByKey($key)
        {
            foreach (self::getAll() as $field)
            {
                if ($field->getKey() == $key) return $field;
            }
            return null;
        }

        public static function getCustomChoiceFieldsAsArray()
        {
{'fraction_non_alphanumeric': 0.1237704135230637, 'fraction_numerical': 0.012033234648075637, 'mean_word_length': 1.8448791089377887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5427522', 'n_tokens_mistral': 3138, 'n_tokens_neox': 2950, 'n_words': 611}