[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 26/26: Code cleaning : remove Fic_Attr , repl
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 26/26: Code cleaning : remove Fic_Attr , replace by Attr_Def_SQL |
Date: |
Wed, 11 Aug 2021 11:08:18 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 07fedf51784c0ef696b86b3016635bcc3b538065
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Aug 11 17:07:56 2021 +0200
Code cleaning : remove Fic_Attr , replace by Attr_Def_SQL
---
include/ajax/ajax_card_attribute.php | 4 +-
include/card_attr.inc.php | 2 +-
include/class/card_attribut_mtable.class.php | 54 +++++++--
include/class/card_property.class.php | 3 +-
include/class/document.class.php | 6 +-
include/class/fiche_attr.class.php | 162 -------------------------
include/constant.php | 1 -
include/database/attr_def_sql.class.php | 12 +-
unit-test/include/class/card_property.Test.php | 1 -
unit-test/include/class/document.Test.php | 12 +-
10 files changed, 68 insertions(+), 189 deletions(-)
diff --git a/include/ajax/ajax_card_attribute.php
b/include/ajax/ajax_card_attribute.php
index b0bd02e..4f32622 100644
--- a/include/ajax/ajax_card_attribute.php
+++ b/include/ajax/ajax_card_attribute.php
@@ -65,14 +65,14 @@ if ($action=="enable_search")
}
else
{
- $obj=new Fiche_Attr($cn);
+ $obj=new Attr_Def_SQL($cn);
$mtable=new Card_Attribut_MTable($obj);
$mtable->add_json_param("op", "card");
$mtable->add_json_param("op2", "attribute");
$mtable->set_callback("ajax_misc.php");
$mtable->set_object_name($http->request("ctl"));
$ad_id=$http->request("p_id");
- $mtable->get_table()->set_parameter("id", $ad_id);
+ $mtable->get_table()->setp("ad_id", $ad_id);
switch ($action)
{
case "input":
diff --git a/include/card_attr.inc.php b/include/card_attr.inc.php
index b4176d2..2ddf491 100644
--- a/include/card_attr.inc.php
+++ b/include/card_attr.inc.php
@@ -24,7 +24,7 @@
*/
if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-$obj=new Fiche_Attr($cn);
+$obj=new Attr_Def_SQL($cn);
$mtable=new Card_Attribut_MTable($obj);
$mtable->add_json_param("op", "card");
$mtable->add_json_param("op2", "attribute");
diff --git a/include/class/card_attribut_mtable.class.php
b/include/class/card_attribut_mtable.class.php
index 8f052a8..c731b5a 100644
--- a/include/class/card_attribut_mtable.class.php
+++ b/include/class/card_attribut_mtable.class.php
@@ -148,13 +148,11 @@ class Card_Attribut_MTable extends Manage_Table_SQL
function check()
{
- $nb_error=0;
$object_sql=$this->get_table();
if ($object_sql->get("ad_id")<9000 && $object_sql->get("ad_id")!=-1)
{
$this->set_error("ad_id",_("Bloqué"));
- return false;
}
// Duplicate
@@ -168,30 +166,70 @@ class Card_Attribut_MTable extends Manage_Table_SQL
if ($count_duplicate>0)
{
$this->set_error("ad_text", _("Doublon"));
- $nb_error++;
}
+ // type
+ if (in_array($object_sql->get("ad_type"),
+ array('date', 'text', 'numeric', 'zone', 'poste', 'card',
'select','check'))==false)
+ {
+ $this->set_error("ad_type", _("Type invalide"));
+ }
// Name empty
if (trim($object_sql->ad_text)=="")
{
$this->set_error("ad_text", _("Description ne peut pas être
vide"));
- $nb_error++;
}
// select protect
+ if ( $object_sql->ad_size=="") {
+ $object_sql->ad_size=22;
+ }
+ if ($object_sql->ad_type=='numeric')
+ {
+
$object_sql->ad_extra=(trim($object_sql->ad_extra)=='')?'2':$object_sql->ad_extra;
+ if (isNumber($object_sql->ad_extra)==0)
+ {
+ $this->set_error("ad_text",_("La précision doit être un
chiffre"));
+ }
+ }
+
+ if ($object_sql->ad_type=='select')
+ {
+ if (trim($object_sql->ad_extra)=="") {
+
+ $this->set_error("ad_extra",_("La requête SQL est vide "));
+ }
+ if (preg_match('/^\h*select/i', $object_sql->ad_extra)==0)
+ {
+ $this->set_error("ad_extra",_("La requête SQL doit commencer
par SELECT "));
+ }
-
- if ($nb_error>0)
+ }
+ if ($this->count_error()>0) {
return false;
+ }
return true;
}
function delete() {
$object_sql=$this->get_table();
+
+ if ( $object_sql->getp("ad_id") < 9000 ) {
+ throw new Exception (_("Effacement bloqué"));
+ }
+
$db=$object_sql->cn;
try {
$db->start();
- $object_sql=$this->get_table()->delete();
- $db->commit();
+ $sql=$db->exec_sql("delete from fiche_detail where ad_id=$1 ",
array($object_sql->ad_id));
+
+ $sql="delete from jnt_fic_attr where ad_id=$1";
+ $res=$db->exec_sql($sql, array($object_sql->ad_id));
+
+ $sql="delete from attr_def where ad_id=$1";
+ $res=$db->exec_sql($sql, array($object_sql->ad_id));
+
+ $object_sql=$this->get_table()->delete();
+ $db->commit();
} catch (Exception $ex) {
$db->rollback();
throw new Exception (_("Effacement bloqué : attribut utilisé"));
diff --git a/include/class/card_property.class.php
b/include/class/card_property.class.php
index f99b081..6e3cdb8 100644
--- a/include/class/card_property.class.php
+++ b/include/class/card_property.class.php
@@ -146,7 +146,8 @@ class Card_Property
return;
} elseif ($fiche->id==0 && $fiche->fiche_def ==0 )
{
- throw new Exception("CP147. Card category cannot be empty
(fiche->set_fiche_def)",EXC_PARAM_VALUE);
+ return;
+// throw new Exception("CP147. Card category cannot be empty
(fiche->set_fiche_def)",EXC_PARAM_VALUE);
}
$sql="select *
from
diff --git a/include/class/document.class.php b/include/class/document.class.php
index 136ae70..190d596 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -244,7 +244,7 @@ class Document
{
if (mkdir($temp_dir)==false)
{
- $msg=sprintf(_("Ne peut pas créer le répertoire %s",
$temp_dir));
+ $msg=sprintf("D221."._("Ne peut pas créer le répertoire %s",
$temp_dir));
record_log("D221".$msg);
throw new Exception($msg);
}
@@ -255,13 +255,13 @@ class Document
// check if the opening is sucessfull
if ($h===false)
{
- $msg=sprintf(_("Ne peut pas ouvrir [%s] [%s]"), $p_dir, $p_file);
+ $msg=sprintf("D232"._("Ne peut pas ouvrir [%s] [%s]"), $p_dir,
$p_file);
record_log("D232".$msg);
throw new Exception($msg);
}
if ($output_file==false)
{
- $msg=sprintf(_("Ne peut pas ouvrir [%s] [%s]"), $p_dir,
$output_name);
+ $msg=sprintf("D264."._("Ne peut pas ouvrir [%s] [%s]"), $p_dir,
$output_name);
record_log($msg);
throw new Exception($msg);
}
diff --git a/include/class/fiche_attr.class.php
b/include/class/fiche_attr.class.php
deleted file mode 100644
index c424e38..0000000
--- a/include/class/fiche_attr.class.php
+++ /dev/null
@@ -1,162 +0,0 @@
-<?php
-
-//This file is part of NOALYSS and is under GPL
-//see licence.txt
-/**
- * @brief Manage the table attr_def
- *
- *
- */
-require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE."/database/attr_def_sql.class.php";
-
-class Fiche_Attr extends Attr_Def_SQL
-{
- /* example private
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
*/
-
- function __construct($p_cn, $p_id=0)
- {
- parent::__construct($p_cn, $p_id);
- }
-
- public function get_parameter($p_string)
- {
- return $this->getp($p_string);
- }
-
- public function set_parameter($p_string, $p_value)
- {
- $this->setp($p_string, $p_value);
- }
-
- public function verify()
- {
- // Verify that the elt we want to add is correct
- /* verify only the datatype */
- if (strlen(trim($this->ad_text))==0)
- throw new Exception('La description ne peut pas être vide', 1);
- if (strlen(trim($this->ad_type))==0)
- throw new Exception('Le type ne peut pas être vide', 1);
- $this->ad_type=strtolower($this->ad_type);
- if (in_array($this->ad_type, array('date', 'text', 'numeric', 'zone',
'poste', 'card', 'select','check'))==false)
- throw new Exception('Le type doit être text, numeric,poste, card,
select ou date', 1);
- if
(trim($this->ad_size)==''||isNumber($this->ad_size)==0||$this->ad_size>22)
- {
- switch ($this->ad_type)
- {
- case 'text':
- $this->ad_size=22;
- break;
- case 'numeric':
- $this->ad_size=9;
- break;
- case 'date':
- $this->ad_size=8;
- break;
- case 'zone':
- $this->ad_size=22;
- break;
-
- default:
- $this->ad_size=22;
- }
- }
- if ($this->ad_type=='numeric')
- {
- $this->ad_extra=(trim($this->ad_extra)=='')?'2':$this->ad_extra;
- if (isNumber($this->ad_extra)==0)
- throw new Exception("La précision doit être un chiffre");
- }
- if ($this->ad_type=='select')
- {
- if (trim($this->ad_extra)=="")
- throw new Exception("La requête SQL est vide ");
- if (preg_match('/^\h*select/i', $this->ad_extra)==0)
- throw new Exception("La requête SQL doit commencer par SELECT
");
- try
- {
-
- $this->cn->exec_sql($this->ad_extra);
- }
- catch (Exception $e)
- {
- record_log($e);
- throw new Exception("La requête SQL ".h($this->ad_extra)." est
invalide ");
- }
- }
- }
-
-
- public function update()
- {
- try
- {
- $this->verify();
- if ($this->ad_id<9000)
- return;
- /* please adapt */
- parent::update();
- }
- catch (Exception $e)
- {
- record_log($e);
- throw $e;
- }
- }
-
- public function delete()
- {
- if ($this->ad_id<9000)
- return;
- $sql=$this->cn->exec_sql("delete from fiche_detail where ad_id=$1 ",
array($this->ad_id));
-
- $sql="delete from jnt_fic_attr where ad_id=$1";
- $res=$this->cn->exec_sql($sql, array($this->ad_id));
-
- $sql="delete from attr_def where ad_id=$1";
- $res=$this->cn->exec_sql($sql, array($this->ad_id));
- }
-
- /* !
- * @brief used with a usort function, to sort an array of Attribut on the
attribut_id (ad_id)
- */
-
- static function sort_by_id($o1, $o2)
- {
- if ($o1->ad_id>$o2->ad_id)
- return 1;
- if ($o1->ad_id==$o2->ad_id)
- return 0;
- return -1;
- }
-
- public function save()
- {
-
- /* please adapt */
- if ($this->ad_id < 1)
- {
- $this->ad_id=-1;
- $this->insert();
- }
- else
- $this->update();
- }
- public function to_array($prefix="")
- {
-
- $array=array();
- foreach ($this->name as $key=> $value)
- {
- $nkey=$prefix.$value;
- $array[$nkey]=$this->$value;
-//
- }
- return $array;
- }
-}
-
-//Fiche_Attr::test_me();
-
-
-
diff --git a/include/constant.php b/include/constant.php
index 179779e..07c9dd9 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -437,7 +437,6 @@ function noalyss_class_autoloader($class) {
"dossier" => "class/dossier.class.php",
"exercice" => "class/exercice.class.php",
"extension" => "class/extension.class.php",
- "fiche_attr" => "class/fiche_attr.class.php",
"fiche" => "class/fiche.class.php",
"fiche_def" => "class/fiche_def.class.php",
"fiche_def_ref" => "class/fiche_def_ref.class.php",
diff --git a/include/database/attr_def_sql.class.php
b/include/database/attr_def_sql.class.php
index 758f537..94cd45e 100644
--- a/include/database/attr_def_sql.class.php
+++ b/include/database/attr_def_sql.class.php
@@ -40,12 +40,12 @@ class Attr_Def_SQL extends Table_Data_SQL
* List of columns
*/
$this->name=array(
- "id"=>"ad_id"
- , "desc"=>"ad_text"
- , "type"=>"ad_type"
- , "size"=>"ad_size"
- , "extra"=>"ad_extra"
- , "search_followup"=>"ad_search_followup"
+ "ad_id"=>"ad_id"
+ , "ad_text"=>"ad_text"
+ , "ad_type"=>"ad_type"
+ , "ad_size"=>"ad_size"
+ , "ad_extra"=>"ad_extra"
+ , "ad_search_followup"=>"ad_search_followup"
);
/*
* Type of columns
diff --git a/unit-test/include/class/card_property.Test.php
b/unit-test/include/class/card_property.Test.php
index 61a0610..449fffd 100644
--- a/unit-test/include/class/card_property.Test.php
+++ b/unit-test/include/class/card_property.Test.php
@@ -88,7 +88,6 @@ class Card_PropertyTest extends TestCase
public static function tearDownAfterClass()
{
- return;
require_once 'global.php';
global $g_connection;
$g_connection=Dossier::connect();
diff --git a/unit-test/include/class/document.Test.php
b/unit-test/include/class/document.Test.php
index cb5b7ba..9015d15 100644
--- a/unit-test/include/class/document.Test.php
+++ b/unit-test/include/class/document.Test.php
@@ -121,7 +121,7 @@ class DocumentTest extends TestCase
$this->assertTrue ( $document->replace('CUST_NAME',$array) == 'Client
1','CUST_NAME');
}
/**
- * @testdox Document::generate(),
Document::parseDocument(),Document::replace(); require unoconv -l in another
session
+ * @testdox Generate Document::generate(),
Document::parseDocument(),Document::replace(); require unoconv -l in another
session
* @covers Document::generate(),
Document::parseDocument(),Document::replace();
*/
function testGenerate()
@@ -136,12 +136,12 @@ class DocumentTest extends TestCase
$document->md_id=$md_id;
$cnt_before=$cn->get_value("select count(*) from document");
$document->generate($array);
+ var_dump($document);
$this->assertEquals($document->d_filename ,'all-tags.odt','Generated
File ');
$cnt_after=$cn->get_value("select count(*) from document");
$this->assertTrue ($cnt_after == $cnt_before+1,"One file generated");
-
-
}
+
/**
* @testdox test $_ENV['TMP']
*/
@@ -155,11 +155,15 @@ class DocumentTest extends TestCase
$document->ag_id=2;
$document->md_id=$md_id;
$cnt_before=$cn->get_value("select count(*) from document");
+ $tEnv=$_ENV['TMP'];
$_ENV['TMP']='/not.exist';
$this->assertContains ('échoué',$document->generate($array));
+ $_ENV['TMP']= $tEnv;
}
+
+
/**
- * @testdox export PDF tests Document::export_pdf,
Document::transform2pdf()
+ * @testdox ExtractPdf export PDF tests Document::export_pdf,
Document::transform2pdf()
*
*/
function testExtractPdf()
- [Noalyss-commit] [noalyss] 19/26: cosmetic : fix icon in followup for the trash can, (continued)
- [Noalyss-commit] [noalyss] 19/26: cosmetic : fix icon in followup for the trash can, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 16/26: cosmetic : flashing color for h2.error, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 24/26: Code cleaning Improve doc and test, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 15/26: Bug in print_ledger_purchase for company w/o vat, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 14/26: Code cleaning : extra information are now a fonction, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 25/26: Improve code : Card_Property is separated from Card (Fiche) , add more phpunit tests, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 18/26: Task #0002046: Improve COMPTA/MENUACH/ACH, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 20/26: Code cleaning : remove useless class gestion_sold gestion_purchase and gestion_table, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 21/26: Merge branch 'master' of gitlab.noalyss.eu:noalyss/noalyss, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 23/26: translate, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 26/26: Code cleaning : remove Fic_Attr , replace by Attr_Def_SQL,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 17/26: Bug #0002048: PRINTJRN : export CSV et PDF cosmetic : remove currency data if the currency is EUR, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 13/26: Translation, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 22/26: code cleaning rename class Acc_Ledger_Sold to Acc_Ledger_Sale , improve doc , improve phpunit test, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 09/26: Documentation, Dany De Bontridder, 2021/08/11
- [Noalyss-commit] [noalyss] 11/26: Task #0002050: stay in mobile menu, Dany De Bontridder, 2021/08/11