<?php
//$Id$ 
//gen openMairie le 14/12/2020 11:49

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

class task_gen extends om_dbform {

    protected $_absolute_class_name = "task";

    var $table = "task";
    var $clePrimaire = "task";
    var $typeCle = "N";
    var $required_field = array(
        "task",
        "type"
    );
    
    var $foreign_keys_extended = array(
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("type");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "task",
            "type",
            "timestamp_log",
            "state",
            "object_id",
            "dossier",
            "json_payload",
            "stream",
        );
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['task'])) {
            $this->valF['task'] = ""; // -> requis
        } else {
            $this->valF['task'] = $val['task'];
        }
        $this->valF['type'] = $val['type'];
            $this->valF['timestamp_log'] = $val['timestamp_log'];
        if ($val['state'] == "") {
            $this->valF['state'] = ""; // -> default
        } else {
            $this->valF['state'] = $val['state'];
        }
        if ($val['object_id'] == "") {
            $this->valF['object_id'] = NULL;
        } else {
            $this->valF['object_id'] = $val['object_id'];
        }
        if ($val['dossier'] == "") {
            $this->valF['dossier'] = NULL;
        } else {
            $this->valF['dossier'] = $val['dossier'];
        }
            $this->valF['json_payload'] = $val['json_payload'];
        if ($val['stream'] == "") {
            $this->valF['stream'] = NULL;
        } else {
            $this->valF['stream'] = $val['stream'];
        }
    }

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

    function setId(&$dnu1 = null) {
    //numero automatique
        $this->valF[$this->clePrimaire] = $this->f->db->nextId(DB_PREFIXE.$this->table);
    }

    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("task", "hidden");
            $form->setType("type", "text");
            $form->setType("timestamp_log", "textarea");
            $form->setType("state", "text");
            $form->setType("object_id", "text");
            $form->setType("dossier", "text");
            $form->setType("json_payload", "textarea");
            $form->setType("stream", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("task", "hiddenstatic");
            $form->setType("type", "text");
            $form->setType("timestamp_log", "textarea");
            $form->setType("state", "text");
            $form->setType("object_id", "text");
            $form->setType("dossier", "text");
            $form->setType("json_payload", "textarea");
            $form->setType("stream", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("task", "hiddenstatic");
            $form->setType("type", "hiddenstatic");
            $form->setType("timestamp_log", "hiddenstatic");
            $form->setType("state", "hiddenstatic");
            $form->setType("object_id", "hiddenstatic");
            $form->setType("dossier", "hiddenstatic");
            $form->setType("json_payload", "hiddenstatic");
            $form->setType("stream", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("task", "static");
            $form->setType("type", "static");
            $form->setType("timestamp_log", "textareastatic");
            $form->setType("state", "static");
            $form->setType("object_id", "static");
            $form->setType("dossier", "static");
            $form->setType("json_payload", "textareastatic");
            $form->setType("stream", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('task','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("task", 11);
        $form->setTaille("type", 30);
        $form->setTaille("timestamp_log", 80);
        $form->setTaille("state", 20);
        $form->setTaille("object_id", 30);
        $form->setTaille("dossier", 30);
        $form->setTaille("json_payload", 80);
        $form->setTaille("stream", 10);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("task", 11);
        $form->setMax("type", 30);
        $form->setMax("timestamp_log", 6);
        $form->setMax("state", 20);
        $form->setMax("object_id", 30);
        $form->setMax("dossier", 30);
        $form->setMax("json_payload", 6);
        $form->setMax("stream", -5);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('task', __('task'));
        $form->setLib('type', __('type'));
        $form->setLib('timestamp_log', __('timestamp_log'));
        $form->setLib('state', __('state'));
        $form->setLib('object_id', __('object_id'));
        $form->setLib('dossier', __('dossier'));
        $form->setLib('json_payload', __('json_payload'));
        $form->setLib('stream', __('stream'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

    }


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

    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        $this->retourformulaire = $retourformulaire;
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

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

}
