<?php
//$Id$ 
//gen openMairie le 23/03/2026 15:39

require_once "../obj/om_dbform.class.php";

class extra_data_register_values_gen extends om_dbform {

    protected $_absolute_class_name = "extra_data_register_values";

    var $table = "extra_data_register_values";
    var $clePrimaire = "extra_data_register_values";
    var $typeCle = "N";
    var $required_field = array(
        "definition_ref",
        "extra_data_register_values"
    );
    var $unique_key = array(
      array("definition_ref","object_id"),
    );
    var $foreign_keys_extended = array(
        "extra_data_register_def" => array("extra_data_register_def", ),
    );
    /**
     * Retourne les métadonnées des colonnes de la table.
     *
     * @return array Tableau des métadonnées des colonnes
     */
    public static function get_columns_metadata() {
        return self::COLUMNS_METADATA;
    }

    /**
     * Métadonnées des colonnes de la table.
     * Utilisé pour optimiser les requêtes en évitant les appels à getColumnMeta()
     * ou tableInfo().
     */
    private const COLUMNS_METADATA = array(
        "extra_data_register_values" => array(
            "name" => "extra_data_register_values",
            "type" => "int4",
            "len" => 4,
            "flags" => array("not_null", "primary_key"),
        ),
        "definition_ref" => array(
            "name" => "definition_ref",
            "type" => "int4",
            "len" => 4,
            "flags" => array("not_null"),
        ),
        "object_id" => array(
            "name" => "object_id",
            "type" => "varchar",
            "len" => 255,
            "flags" => array(),
        ),
        "value_int" => array(
            "name" => "value_int",
            "type" => "int4",
            "len" => 4,
            "flags" => array(),
        ),
        "value_str" => array(
            "name" => "value_str",
            "type" => "varchar",
            "len" => 255,
            "flags" => array(),
        ),
        "value_text" => array(
            "name" => "value_text",
            "type" => "text",
            "len" => -1,
            "flags" => array(),
        ),
        "value_json" => array(
            "name" => "value_json",
            "type" => "jsonb",
            "len" => -1,
            "flags" => array(),
        ),
        "value_blob" => array(
            "name" => "value_blob",
            "type" => "bytea",
            "len" => -1,
            "flags" => array(),
        ),
        "value_timestamp" => array(
            "name" => "value_timestamp",
            "type" => "timestamp",
            "len" => 8,
            "flags" => array(),
        ),
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("definition_ref");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "extra_data_register_values",
            "definition_ref",
            "object_id",
            "value_int",
            "value_str",
            "value_text",
            "value_json",
            "value_blob",
            "value_timestamp",
        );
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_definition_ref() {
        return "SELECT extra_data_register_def.extra_data_register_def, extra_data_register_def.name FROM ".DB_PREFIXE."extra_data_register_def ORDER BY extra_data_register_def.name ASC";
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_definition_ref_by_id() {
        return "SELECT extra_data_register_def.extra_data_register_def, extra_data_register_def.name FROM ".DB_PREFIXE."extra_data_register_def WHERE extra_data_register_def = <idx>";
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['extra_data_register_values'])) {
            $this->valF['extra_data_register_values'] = ""; // -> requis
        } else {
            $this->valF['extra_data_register_values'] = $val['extra_data_register_values'];
        }
        if (!is_numeric($val['definition_ref'])) {
            $this->valF['definition_ref'] = ""; // -> requis
        } else {
            $this->valF['definition_ref'] = $val['definition_ref'];
        }
        if ($val['object_id'] == "") {
            $this->valF['object_id'] = NULL;
        } else {
            $this->valF['object_id'] = $val['object_id'];
        }
        if (!is_numeric($val['value_int'])) {
            $this->valF['value_int'] = NULL;
        } else {
            $this->valF['value_int'] = $val['value_int'];
        }
        if ($val['value_str'] == "") {
            $this->valF['value_str'] = NULL;
        } else {
            $this->valF['value_str'] = $val['value_str'];
        }
            $this->valF['value_text'] = $val['value_text'];
            $this->valF['value_json'] = $val['value_json'];
            $this->valF['value_blob'] = $val['value_blob'];
            $this->valF['value_timestamp'] = $val['value_timestamp'];
    }

    //=================================================
    //cle primaire automatique [automatic primary key]
    //==================================================

    function setId(&$dnu1 = null) {
    //numero automatique
        $qres = $this->f->get_next_id_from_db_sequence(DB_PREFIXE.$this->table, array("origin" => __METHOD__));
        $this->valF[$this->clePrimaire] = $qres['result'];
    }

    function setValFAjout($val = array()) {
    //numero automatique -> pas de controle ajout cle primaire
    }

    function verifierAjout($val = array(), &$dnu1 = null) {
    //numero automatique -> pas de verfication de cle primaire
    }

    //==========================
    // Formulaire  [form]
    //==========================
    /**
     *
     */
    function setType(&$form, $maj) {
        // Récupération du mode de l'action
        $crud = $this->get_action_crud($maj);

        // MODE AJOUTER
        if ($maj == 0 || $crud == 'create') {
            $form->setType("extra_data_register_values", "hidden");
            if ($this->is_in_context_of_foreign_key("extra_data_register_def", $this->retourformulaire)) {
                $form->setType("definition_ref", "selecthiddenstatic");
            } else {
                $form->setType("definition_ref", "select");
            }
            $form->setType("object_id", "text");
            $form->setType("value_int", "text");
            $form->setType("value_str", "text");
            $form->setType("value_text", "textarea");
            $form->setType("value_json", "text");
            $form->setType("value_blob", "text");
            $form->setType("value_timestamp", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("extra_data_register_values", "hiddenstatic");
            if ($this->is_in_context_of_foreign_key("extra_data_register_def", $this->retourformulaire)) {
                $form->setType("definition_ref", "selecthiddenstatic");
            } else {
                $form->setType("definition_ref", "select");
            }
            $form->setType("object_id", "text");
            $form->setType("value_int", "text");
            $form->setType("value_str", "text");
            $form->setType("value_text", "textarea");
            $form->setType("value_json", "text");
            $form->setType("value_blob", "text");
            $form->setType("value_timestamp", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("extra_data_register_values", "hiddenstatic");
            $form->setType("definition_ref", "selectstatic");
            $form->setType("object_id", "hiddenstatic");
            $form->setType("value_int", "hiddenstatic");
            $form->setType("value_str", "hiddenstatic");
            $form->setType("value_text", "hiddenstatic");
            $form->setType("value_json", "hiddenstatic");
            $form->setType("value_blob", "hiddenstatic");
            $form->setType("value_timestamp", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("extra_data_register_values", "static");
            $form->setType("definition_ref", "selectstatic");
            $form->setType("object_id", "static");
            $form->setType("value_int", "static");
            $form->setType("value_str", "static");
            $form->setType("value_text", "textareastatic");
            $form->setType("value_json", "static");
            $form->setType("value_blob", "static");
            $form->setType("value_timestamp", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('extra_data_register_values','VerifNum(this)');
        $form->setOnchange('definition_ref','VerifNum(this)');
        $form->setOnchange('value_int','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("extra_data_register_values", 11);
        $form->setTaille("definition_ref", 11);
        $form->setTaille("object_id", 30);
        $form->setTaille("value_int", 11);
        $form->setTaille("value_str", 30);
        $form->setTaille("value_text", 80);
        $form->setTaille("value_json", 10);
        $form->setTaille("value_blob", 10);
        $form->setTaille("value_timestamp", 8);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("extra_data_register_values", 11);
        $form->setMax("definition_ref", 11);
        $form->setMax("object_id", 255);
        $form->setMax("value_int", 11);
        $form->setMax("value_str", 255);
        $form->setMax("value_text", 6);
        $form->setMax("value_json", -5);
        $form->setMax("value_blob", -5);
        $form->setMax("value_timestamp", 8);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('extra_data_register_values', __('extra_data_register_values'));
        $form->setLib('definition_ref', __('definition_ref'));
        $form->setLib('object_id', __('object_id'));
        $form->setLib('value_int', __('value_int'));
        $form->setLib('value_str', __('value_str'));
        $form->setLib('value_text', __('value_text'));
        $form->setLib('value_json', __('value_json'));
        $form->setLib('value_blob', __('value_blob'));
        $form->setLib('value_timestamp', __('value_timestamp'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

        // definition_ref
        $this->init_select(
            $form, 
            $this->f->get_db_reference(),
            $maj,
            null,
            "definition_ref",
            $this->get_var_sql_forminc__sql("definition_ref"),
            $this->get_var_sql_forminc__sql("definition_ref_by_id"),
            false
        );
    }


    //==================================
    // sous Formulaire
    //==================================
    

    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            if($this->is_in_context_of_foreign_key('extra_data_register_def', $this->retourformulaire))
                $form->setVal('definition_ref', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

    //==================================
    // cle secondaire
    //==================================
    

}
