noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 11/13: - Override the function __toString to


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 11/13: - Override the function __toString to comply with xdebug - function Card_Property::input ; the build of the HtmlInput is done is a separated function Card_Property::build_input to ease the override of the input function
Date: Sun, 16 Oct 2022 17:26:15 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 840cd82f3b7f575fab9212871e6a00138719a8c1
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Oct 16 23:15:12 2022 +0200

    - Override the function __toString to comply with xdebug
    - function Card_Property::input ; the build of the HtmlInput is done is a 
separated function Card_Property::build_input to ease the override of the input 
function
---
 include/class/card_property.class.php | 292 +++++++++++++++++++---------------
 1 file changed, 160 insertions(+), 132 deletions(-)

diff --git a/include/class/card_property.class.php 
b/include/class/card_property.class.php
index acb748b3d..2fb1f883c 100644
--- a/include/class/card_property.class.php
+++ b/include/class/card_property.class.php
@@ -56,6 +56,10 @@ class Card_Property
         $this->ad_id=0;
         $this->display_mode='window';
     }
+    public function __toString(): string
+    {
+        return "card_property".var_export($this,true);
+    }
     public function setDisplayMode($p_mode)
     {
         if ( ! in_array($p_mode,array("window","large"))) {
@@ -139,6 +143,143 @@ class Card_Property
         $this->jnt_order=$jnt_order;
     }
 
+    /**
+     * @brief build the needed elements to display
+     * @param Object Fiche_Def $p_fiche_def
+     * @return array
+     *               - $result['msg'] message to display,
+     *               - $result['label'] label of the CardProperty (ad_text),
+    *                - $result['input' is the HtmlInput object
+     *               - $result['class'] is the CSS class to use
+     *               - $result['bulle'] is the infobulle
+     */
+    public function build_input($p_fiche_def=null)
+    {
+        $result = ['msg' => '', 'input' => null, 'label' => '', 'class' => 
'input_text','bulle'=>''];
+        if ($this->ad_id == ATTR_DEF_NAME || $this->ad_id == 
ATTR_DEF_QUICKCODE) {
+            $result['class'] = " input_text highlight info";
+        }
+        if ($this->ad_id == ATTR_DEF_ACCOUNT) {
+            if ( $p_fiche_def == null ) {
+                throw new \Exception ("CP162.p_fiche_def is null");
+            }
+            $result['input'] = new IPoste("av_text" . $this->ad_id);
+            $result['input']->id = uniqid('accounting');
+            $result['input']->set_attribute('ipopup', 'ipop_account');
+            $result['input']->set_attribute('jrn', '0');
+            $result['input']->set_attribute('account', "av_text" . 
$this->ad_id);
+            $result['input']->dbl_click_history();
+            $result['input']->value = $this->av_text;
+            //  account created automatically
+            $sql = "select account_auto($p_fiche_def->id)";
+            $ret_sql = $this->cn->exec_sql($sql);
+            $a = Database::fetch_array($ret_sql, 0);
+            $result['label'] = new ISpan();
+            $result['label']->name = "av_text" . $this->ad_id . "_label";
+            $p_fiche_def->load();
+            if ($a['account_auto'] == 't') {
+                $result['msg'] .= $result['label']->input() . " <span 
style=\"color:red\">" .
+                    _("Rappel: Poste créé automatiquement à partir de ")
+                    . $p_fiche_def->class_base . " </span> ";
+            } else {
+                // if there is a class base in fiche_def_ref, this account 
will be the
+                // the default one
+                if (strlen(trim($p_fiche_def->class_base)) != 0) {
+                    $result['msg'] .= " <span style=\"color:red\">" . 
_("Rappel: Poste par défaut sera ") .
+                        $p_fiche_def->class_base .
+                        " !</span> ";
+                    $result['input']->value = $p_fiche_def->class_base;
+                }
+            }
+            $result['label']=_("Poste comptable");
+            $result['class']=" highlight input_text";
+            return $result;
+        } elseif ($this->ad_id == ATTR_DEF_TVA) {
+            $result['input'] = new ITva_Popup('popup_tva');
+            $result['input']->table = 1;
+            $result['input']->value = $this->av_text;
+            $result['label']=$this->ad_text;
+        } else {
+            switch ($this->ad_type) {
+                case 'text':
+                    $result['input'] = new IText();
+                    $result['input']->css_size = "100%";
+                    $result['input']->value = $this->av_text;
+                    break;
+                case 'numeric':
+                    $result['input'] = new INum();
+                    $result['input']->prec = ($this->ad_extra == "") ? 2 : 
$this->ad_extra;
+                    $result['input']->size = $this->ad_size;
+                    $result['input']->value = $this->av_text;
+                    break;
+                case 'date':
+                    $result['input'] = new IDate();
+                    $result['input']->value = $this->av_text;
+                    break;
+                case 'zone':
+                    $result['input'] = new ITextArea();
+                    $result['input']->style = ' class="itextarea" 
style="margin:0px;width:100%"';
+                    $result['input']->value = $this->av_text;
+                    break;
+                case 'poste':
+                    $result['input'] = new IPoste("av_text" . $this->ad_id);
+                    $result['input']->set_attribute('ipopup', 'ipop_account');
+                    $result['input']->set_attribute('account', "av_text" . 
$this->ad_id);
+                    $result['input']->table = 1;
+                    $bulle = Icon_Action::infobulle(14);
+                    $result['input']->value = $this->av_text;
+                    break;
+                case 'check':
+                    $result['input'] = new InputSwitch("av_text" . 
$this->ad_id);
+                    $result['input']->value = (empty($this->av_text) ) ? 0 : 1;
+                    break;
+                case 'select':
+                    $result['input'] = new ISelect("av_text" . $this->ad_id);
+                    $result['input']->value = 
$this->cn->make_array($this->ad_extra);
+                    $result['input']->style = 'style="width:100%"';
+                    $result['input']->selected = $this->av_text;
+                    break;
+                case 'card':
+                    $result['input'] = new ICard("av_text" . $this->ad_id);
+                    // filter on frd_id
+                    $result['input']->extra = $this->ad_extra;
+                    $result['input']->extra2 = 0;
+                    $result['input']->id = uniqid();
+                    $result['label'] = new ISpan();
+                    $filter = $this->ad_extra;
+                    $result['input']->width = $this->ad_size;
+                    $result['input']->extra = $filter;
+                    $result['input']->extra2 = 0;
+                    $result['input']->limit = 6;
+                    $result['label']->name = "av_text" . $this->ad_id . 
$result['input']->id . "_label";
+                    $result['input']->set_attribute('ipopup', 'ipopcard');
+                    $result['input']->set_attribute('typecard', 
$this->ad_extra);
+                    $result['input']->set_attribute('inp', 
$result['input']->id);
+                    $result['input']->set_attribute('label', "av_text" . 
$this->ad_id . $result['input']->id . "_label");
+                    $result['input']->autocomplete = 1;
+                    $result['input']->dblclick = "fill_ipopcard(this);";
+                    $result['msg'] = $result['input']->search();
+                    $result['msg'] .= $result['label']->input();
+                    $result['input']->value = $this->av_text;
+                    break;
+            }
+            $result['input']->table = 0;
+            $result['label']=$this->ad_text;
+        }
+
+        $result['input']->label = $this->ad_text;
+        $result['input']->name = "av_text" . $this->ad_id;
+        if ($this->ad_id == 21 || $this->ad_id == 22 || $this->ad_id == 20 || 
$this->ad_id == 31) {
+            $result['bulle'] = Icon_Action::infobulle(21);
+        }
+
+        // Warning length quickcode
+        if ($this->ad_id == ATTR_DEF_QUICKCODE) {
+            $result['bulle'] = Icon_Action::warnbulle(76);
+        }
+
+        return $result;
+    }
     /**
      * @brief Load all the attribute of a card , it modifies the parameter 
$fiche. Usually called from fiche::insert 
      * and fiche::update . In the same time, it will synchronize the 
attributes which the database. 
@@ -231,142 +372,15 @@ class Card_Property
      */
     function input($p_fiche_def=null)
     {
-        $bulle=""; $msg="";
-        $r="";
-        if ($this->ad_id==ATTR_DEF_ACCOUNT)
-        {
-            $w=new IPoste("av_text".$this->ad_id);
-            $w->id=uniqid('accounting');
-            $w->set_attribute('ipopup', 'ipop_account');
-            $w->set_attribute('jrn', '0');
-            $w->set_attribute('account', "av_text".$this->ad_id);
-            $w->dbl_click_history();
-            $w->value=$this->av_text;
-            //  account created automatically
-            $sql="select account_auto($p_fiche_def->id)";
-            $ret_sql=$this->cn->exec_sql($sql);
-            $a=Database::fetch_array($ret_sql, 0);
-            $label=new ISpan();
-            $label->name="av_text".$this->ad_id."_label";
 
-            if ($a['account_auto']=='t')
-            {
-                $msg.=$label->input()." <span style=\"color:red\">".
-                        _("Rappel: Poste créé automatiquement à partir de ")
-                        .$p_fiche_def->class_base." </span> ";
-            }
-            else
-            {
-                // if there is a class base in fiche_def_ref, this account 
will be the
-                // the default one
-                if (strlen(trim($p_fiche_def->class_base))!=0)
-                {
-                    $msg.="<TD>".$label->input()." <span 
style=\"color:red\">"._("Rappel: Poste par défaut sera ").
-                            $p_fiche_def->class_base.
-                            " !</span> ";
-                    $w->value=$p_fiche_def->class_base;
-                }
-            }
-            $r.="<TR>".td(_("Poste Comptable"), ' class="highlight input_text" 
').td($w->input().$msg)."</TR>";
-            return $r;
-        }
-        elseif ($this->ad_id==ATTR_DEF_TVA)
-        {
-            $w=new ITva_Popup('popup_tva');
-            $w->table=1;
-            $w->value=$this->av_text;
-        }
-        else
-        {
-            switch ($this->ad_type)
-            {
-                case 'text':
-                    $w=new IText();
-                    $w->css_size="100%";
-                    $w->value=$this->av_text;
-                    break;
-                case 'numeric':
-                    $w=new INum();
-                    $w->prec=($this->ad_extra=="")?2:$this->ad_extra;
-                    $w->size=$this->ad_size;
-                    $w->value=$this->av_text;
-                    break;
-                case 'date':
-                    $w=new IDate();
-                    $w->value=$this->av_text;
-                    break;
-                case 'zone':
-                    $w=new ITextArea();
-                    $w->style=' class="itextarea" 
style="margin:0px;width:100%"';
-                    $w->value=$this->av_text;
-                    break;
-                case 'poste':
-                    $w=new IPoste("av_text".$this->ad_id);
-                    $w->set_attribute('ipopup', 'ipop_account');
-                    $w->set_attribute('account', "av_text".$this->ad_id);
-                    $w->table=1;
-                    $bulle=Icon_Action::infobulle(14);
-                    $w->value=$this->av_text;
-                    break;
-                case 'check':
-                    $w=new InputSwitch("av_text".$this->ad_id);
-                    $w->value=(trim($w->value)=="")?1:$w->value;
-                    break;
-                case 'select':
-                    $w=new ISelect("av_text".$this->ad_id);
-                    $w->value=$this->cn->make_array($this->ad_extra);
-                    $w->style='style="width:100%"';
-                    $w->selected=$this->av_text;
-                    break;
-                case 'card':
-                    $w=new ICard("av_text".$this->ad_id);
-                    // filter on frd_id
-                    $w->extra=$this->ad_extra;
-                    $w->extra2=0;
-                    $w->id=uniqid();
-                    $label=new ISpan();
-                    $filter=$this->ad_extra;
-                    $w->width=$this->ad_size;
-                    $w->extra=$filter;
-                    $w->extra2=0;
-                    $w->limit=6;
-                    $label->name="av_text".$this->ad_id.$w->id."_label";
-                    $w->set_attribute('ipopup', 'ipopcard');
-                    $w->set_attribute('typecard', $this->ad_extra);
-                    $w->set_attribute('inp', $w->id);
-                    $w->set_attribute('label', 
"av_text".$this->ad_id.$w->id."_label");
-                    $w->autocomplete=1;
-                    $w->dblclick="fill_ipopcard(this);";
-                    $msg=$w->search();
-                    $msg.=$label->input();
-                    $w->value=$this->av_text;
-                    break;
-            }
-            $w->table=0;
-        }
+        $result=$this->build_input($p_fiche_def);
 
-        $w->label=$this->ad_text;
-        $w->name="av_text".$this->ad_id;
-        if 
($this->ad_id==21||$this->ad_id==22||$this->ad_id==20||$this->ad_id==31)
-        {
-            $bulle=Icon_Action::infobulle(21);
-        }
 
-        // Warning length quickcode
-        if ($this->ad_id==ATTR_DEF_QUICKCODE)
-        {
-            $bulle=Icon_Action::warnbulle(76);
-        }
-        if ($this->ad_id==ATTR_DEF_NAME||$this->ad_id==ATTR_DEF_QUICKCODE)
-        {
-            $class=" input_text highlight info";
-        }
-        else
-        {
-            $class="input_text";
-        }
         $url='<td>'.$this->add_link($this->ad_id,$this->av_text).'</td>';
-        $r.="<TR>".td(_($w->label)." $bulle", ' class="'.$class.'" 
').td($w->input()." $msg").
+        $r="<TR>".
+             td(_($result["label"]). $result['bulle'],
+            ' class="'.$result['class'].'" ').
+            td($result["input"]->input().$result["msg"]).
             $url.
             " </TR>";
         return $r;
@@ -653,4 +667,18 @@ class Card_Property
         return $url;
     }
 
+    /**
+     * @brief return the Property of an array of property with the right ad_id
+     * @param int $attr_def_id the search attr_def_id
+     * @param array $a_property array of Card_Property
+     * @return mixed|null
+     */
+    static function findProperty($attr_def_id, $a_property)
+    {
+        $nb = count($a_property);
+        for ($i = 0; $i < $nb; $i++) {
+            if ($a_property[$i]->get_ad_id() == $attr_def_id) return 
$a_property[$i];
+        }
+        return null;
+    }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]