noalyss-commit
[Top][All Lists]
Advanced

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

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


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 10/13: - Override the function __toString to comply with xdebug - Correct bug in input_switch.class.php when there is several input_switch - FicheDef the insertAttribut can have an order, usefull when installing new category + attribute
Date: Sun, 16 Oct 2022 17:26:15 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 570e3c53a1c589b90107656c4ed3024434316083
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Oct 16 23:13:10 2022 +0200

    - Override the function __toString to comply with xdebug
    - Correct bug in input_switch.class.php when there is several input_switch
    - FicheDef the insertAttribut can have an order, usefull when installing 
new category + attribute
---
 include/class/fiche_def.class.php                | 24 ++++++++++++++----
 include/class/noalyss_parameter_folder.class.php | 31 ++++++++++++++++++++++++
 include/class/user.class.php                     |  4 +++
 include/lib/http_input.class.php                 |  4 +++
 include/lib/input_switch.class.php               |  9 ++++---
 unit-test/include/class/Fiche_DefTest.php        |  2 +-
 6 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/include/class/fiche_def.class.php 
b/include/class/fiche_def.class.php
index f087bc505..53e008fdf 100644
--- a/include/class/fiche_def.class.php
+++ b/include/class/fiche_def.class.php
@@ -44,6 +44,12 @@ class Fiche_Def
         
         
     }
+
+    public function __toString(): string
+    {
+        return "fiche_def".print_r($this,true);
+    }
+
     /*!\brief show the content of the form to create  a new Fiche_Def_Ref
     */
     function input ()
@@ -258,7 +264,7 @@ $order
             $sql="insert into 
fiche_def(fd_label,fd_class_base,frd_id,fd_create_account,fd_description)
                  values ($1,$2,$3,$4,$5) returning fd_id";
 
-            
$fd_id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_fiche_def,$p_create,$p_fd_description));
+            
$this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_fiche_def,$p_create,$p_fd_description));
 
             // p_class must be added to tmp_pcmn if it is a single accounting
             if ( strpos(',',$p_class_base) ==0)
@@ -621,24 +627,32 @@ $order
 
     /*!\brief insert a new attribut for this fiche_def
      * \param $p_ad_id id of the attribut
+     * \param int $p_order order of the attribut if  -1 then computed
      */
-    function InsertAttribut($p_ad_id)
+    function insertAttribut($p_ad_id,$p_order=-1)
     {
         if ( $this->id == 0 ) return;
         /* ORDER */
         $this->GetAttribut();
-        $max=sizeof($this->attribut)*15;
+        $order=$p_order;
+        if ( $p_order == -1 ) {
+            $order = $this->cn->get_value("select ad_default_order from 
attr_def where ad_id=$1",[$p_ad_id]);
+            if ( $order == 0 || empty($order)) {
+                $max=$this->get_value("select count(*) from jnt_fic_attr where 
fd_id=$1",[$this->id]);
+                $order=$max*15;
+            }
+        }
         // Insert a new attribute for the model
         // it means insert a row in jnt_fic_attr
         $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values 
(%d,%d,%d)",
-                     $this->id,$p_ad_id,$max);
+                     $this->id,$p_ad_id,$order);
         $Res=$this->cn->exec_sql($sql);
     }
     /*!\brief remove an attribut for this fiche_def
      * \param array of ad_id to remove
      * \remark you can't remove the attribut defined in attr_min
      */
-    function RemoveAttribut($array)
+    function removeAttribut($array)
     {
         foreach ($array as $ch)
         {
diff --git a/include/class/noalyss_parameter_folder.class.php 
b/include/class/noalyss_parameter_folder.class.php
index 345184c2f..e346ba829 100644
--- a/include/class/noalyss_parameter_folder.class.php
+++ b/include/class/noalyss_parameter_folder.class.php
@@ -66,6 +66,37 @@ class Noalyss_Parameter_Folder
         }
 
     }
+
+    public function __toString(): string
+    {
+        $r = <<<EOF
+MY_TVA = [     {$this->MY_TVA }]
+MY_STREET = [  {$this->MY_STREET }]
+MY_NUMBER= [   {$this->MY_NUMBER }]
+MY_CP= [       {$this->MY_CP }]
+MY_TEL= [      {$this->MY_TEL }]
+MY_PAYS= [     {$this->MY_PAYS }]
+MY_COMMUNE= [  {$this->MY_COMMUNE }]
+MY_FAX= [      {$this->MY_FAX }]
+MY_ANALYTIC= [ {$this->MY_ANALYTIC }]
+MY_STRICT= [   {$this->MY_STRICT }]
+MY_TVA_USE= [  {$this->MY_TVA_USE }]
+MY_PJ_SUGGEST= [       {$this->MY_PJ_SUGGEST }]
+MY_CHECK_PERIODE= [    {$this->MY_CHECK_PERIODE }]
+MY_DATE_SUGGEST= [     {$this->MY_DATE_SUGGEST }]
+MY_ALPHANUM= [ {$this->MY_ALPHANUM }]
+MY_UPDLAB= [   {$this->MY_UPDLAB }]
+MY_STOCK= [    {$this->MY_STOCK }]
+MY_DEFAULT_ROUND_ERROR_DEB= [  {$this->MY_DEFAULT_ROUND_ERROR_DEB }]
+MY_DEFAULT_ROUND_ERROR_CRED= [ {$this->MY_DEFAULT_ROUND_ERROR_CRED }]
+MY_ANC_FILTER= [       {$this->MY_ANC_FILTER }]
+MY_CURRENCY= [ {$this->MY_CURRENCY }]
+
+
+EOF;
+        return $r;
+    }
+
     function check_anc_filter($p_value)
     {
         $tmp_value=$p_value;
diff --git a/include/class/user.class.php b/include/class/user.class.php
index dee3e115b..05161b8d1 100644
--- a/include/class/user.class.php
+++ b/include/class/user.class.php
@@ -60,6 +60,10 @@ class User
             $this->load();
         }
     }
+    public function __toString(): string
+    {
+        return "User ".print_r($this,true);
+    }
     /**
      * @brief check the password and user
      */
diff --git a/include/lib/http_input.class.php b/include/lib/http_input.class.php
index 02976d7ee..7525a4894 100644
--- a/include/lib/http_input.class.php
+++ b/include/lib/http_input.class.php
@@ -45,6 +45,10 @@ class HttpInput
         $this->array=null;
         $this->empty="";
     }
+    public function __toString(): string
+    {
+        return "http_input".print_r($this,true);
+    }
     public function get_array()
     {
         return $this->array;
diff --git a/include/lib/input_switch.class.php 
b/include/lib/input_switch.class.php
index 19d0990be..7fe7c6c4e 100644
--- a/include/lib/input_switch.class.php
+++ b/include/lib/input_switch.class.php
@@ -40,7 +40,8 @@ class InputSwitch extends HtmlInput
 
     function __construct($name='', $value='', $p_id="")
     {
-        $this->value_container=$name;
+        $this->name=$name;
+        $this->value_container=uniqid();
         $this->value=$value;
         $this->icon=$p_id;
         $this->javascript="";
@@ -50,8 +51,8 @@ class InputSwitch extends HtmlInput
     {
         $r="";
         if ($p_name!=NULL)
-            $this->value_container=$p_name;
-        if ($p_value!==NULL)
+            $this->name=$p_name;
+        if ($p_value!=NULL)
             $this->value=$p_value;
 
         if ( $this->icon=="") $this->icon=uniqid ("inputSwitch");
@@ -62,7 +63,7 @@ class InputSwitch extends HtmlInput
         if ($this->readOnly == TRUE) {
             return $this->display();
         }
-        $r.= HtmlInput::hidden($this->value_container, $this->value);
+        $r.= HtmlInput::hidden($this->name, 
$this->value,$this->value_container);
         
         
$this->javascript=sprintf('toggle_onoff(\'%s\',\'%s\');%s;',$this->icon,$this->value_container,$this->javascript);
         
diff --git a/unit-test/include/class/Fiche_DefTest.php 
b/unit-test/include/class/Fiche_DefTest.php
index 0751becdb..c7e95939f 100644
--- a/unit-test/include/class/Fiche_DefTest.php
+++ b/unit-test/include/class/Fiche_DefTest.php
@@ -182,7 +182,7 @@ class Fiche_DefTest extends Testcase
        
         // percent deductible
         $fiche_def->InsertAttribut(20);
-        $fiche_def->InsertAttribut(21);
+        $fiche_def->InsertAttribut(21,120);
         $fiche_def->InsertAttribut(22);
 
         // accouting for not deductible



reply via email to

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