noalyss  Version-9
Public Member Functions | Static Public Member Functions
Fiche_Attr Class Reference

Manage the table attr_def. More...

+ Inheritance diagram for Fiche_Attr:
+ Collaboration diagram for Fiche_Attr:

Public Member Functions

 __construct ($p_cn, $p_id=0)
 
 delete ()
 
 get_parameter ($p_string)
 
 save ()
 Insert or update : if the row already exists, update otherwise insert. More...
 
 set_parameter ($p_string, $p_value)
 
 to_array ($prefix="")
 Turn an object (row) into an array, and the key could be prefixed with $prefix. More...
 
 update ()
 
 verify ()
 
- Public Member Functions inherited from Attr_def_SQL
 __construct (DatabaseCore $p_cn, $p_id=-1)
 
- Public Member Functions inherited from Table_Data_SQL
 build_query ()
 Build the SQL select statement for querying the object and returns it. More...
 
 count ($p_where="", $p_array=null)
 return the number of count in the table corresponding to the where condition More...
 
 exist ()
 Count the number of record with the id ,. More...
 
 get_all_to_array ($p_key_col, $p_cond="", $p_array=NULL)
 Get all the row and use the p_key_code are the key value of array. More...
 
 insert ()
 
 load ()
 
 seek ($cond='', $p_array=null)
 retrieve array of object thanks a condition More...
 
- Public Member Functions inherited from Data_SQL
 collect_objects ($cond='', $p_array=null)
 return an array of objects. More...
 
 from_array ($p_array)
 Transform an array into object. More...
 
 get ($p_string)
 get the value thanks the colum name and not the alias (name). More...
 
 get_cn ()
 
 get_info ()
 
 get_name ()
 
 get_object ($p_ret, $idx)
 
 get_pk_value ()
 
 get_primary_key ()
 
 get_type ()
 
 getp ($p_string)
 set the value thanks the alias name instead of the colum name More...
 
 next ($ret, $i)
 get_seek return the next object, the return of the query must have all the column of the object More...
 
 set ($p_string, $p_value)
 set the value thanks the colum name and not the alias (name) More...
 
 set_cn ($cn)
 
 set_name ($name)
 
 set_pk_value ($p_value)
 
 set_primary_key ($primary_key)
 
 set_type ($type)
 
 setp ($p_string, $p_value)
 set the value thanks the alias name instead of the colum name More...
 

Static Public Member Functions

static sort_by_id ($o1, $o2)
 

Additional Inherited Members

- Data Fields inherited from Data_SQL
 $cn
 
 $date_format
 Type of the data. More...
 
 $default
 defaullt date format More...
 
 $name
 Database connection. More...
 
 $primary_key
 Array of logical and real name. More...
 
 $type
 Column name of the primary key. More...
 

Detailed Description

Manage the table attr_def.

Definition at line 13 of file fiche_attr.class.php.

Constructor & Destructor Documentation

◆ __construct()

Fiche_Attr::__construct (   $p_cn,
  $p_id = 0 
)

Reimplemented from Table_Data_SQL.

Definition at line 17 of file fiche_attr.class.php.

18  {
19  parent::__construct($p_cn, $p_id);
20  }

References $p_id.

Member Function Documentation

◆ delete()

Fiche_Attr::delete ( )

Reimplemented from Table_Data_SQL.

Definition at line 107 of file fiche_attr.class.php.

108  {
109  if ($this->ad_id<9000)
110  return;
111  $sql=$this->cn->exec_sql("delete from fiche_detail where ad_id=$1 ", array($this->ad_id));
112 
113  $sql="delete from jnt_fic_attr where ad_id=$1";
114  $res=$this->cn->exec_sql($sql, array($this->ad_id));
115 
116  $sql="delete from attr_def where ad_id=$1";
117  $res=$this->cn->exec_sql($sql, array($this->ad_id));
118  }

References $res, $sql, and cn.

◆ get_parameter()

Fiche_Attr::get_parameter (   $p_string)

Definition at line 22 of file fiche_attr.class.php.

23  {
24  return $this->getp($p_string);
25  }

References Data_SQL\getp().

+ Here is the call graph for this function:

◆ save()

Fiche_Attr::save ( )

Insert or update : if the row already exists, update otherwise insert.

Reimplemented from Data_SQL.

Definition at line 133 of file fiche_attr.class.php.

134  {
135 
136  /* please adapt */
137  if ($this->ad_id < 1)
138  {
139  $this->ad_id=-1;
140  $this->insert();
141  }
142  else
143  $this->update();
144  }

References Table_Data_SQL\insert(), and update().

+ Here is the call graph for this function:

◆ set_parameter()

Fiche_Attr::set_parameter (   $p_string,
  $p_value 
)

Definition at line 27 of file fiche_attr.class.php.

28  {
29  $this->setp($p_string, $p_value);
30  }

References Data_SQL\setp().

+ Here is the call graph for this function:

◆ sort_by_id()

static Fiche_Attr::sort_by_id (   $o1,
  $o2 
)
static

Definition at line 124 of file fiche_attr.class.php.

125  {
126  if ($o1->ad_id>$o2->ad_id)
127  return 1;
128  if ($o1->ad_id==$o2->ad_id)
129  return 0;
130  return -1;
131  }

◆ to_array()

Fiche_Attr::to_array (   $prefix = "")

Turn an object (row) into an array, and the key could be prefixed with $prefix.

Parameters
string$prefixbefore the key
Returns
array

Reimplemented from Data_SQL.

Definition at line 145 of file fiche_attr.class.php.

146  {
147 
148  $array=array();
149  foreach ($this->name as $key=> $value)
150  {
151  $nkey=$prefix.$value;
152  $array[$nkey]=$this->$value;
153 // $nkey=$prefix.$key;
154 // $array[$nkey]=$this->$value;
155 //
156  }
157  tracedebug("card_attribute.log",$array);
158  return $array;
159  }

References $array, $prefix, $value, and name.

◆ update()

Fiche_Attr::update ( )

Reimplemented from Table_Data_SQL.

Definition at line 90 of file fiche_attr.class.php.

91  {
92  try
93  {
94  $this->verify();
95  if ($this->ad_id<9000)
96  return;
97  /* please adapt */
98  parent::update();
99  }
100  catch (Exception $e)
101  {
102  record_log($e);
103  throw $e;
104  }
105  }

References $e, record_log(), and verify().

Referenced by save().

+ Here is the call graph for this function:

◆ verify()

Fiche_Attr::verify ( )
Todo:
ajout vérification type (date, text ou numeric)
Returns
int

Reimplemented from Data_SQL.

Definition at line 32 of file fiche_attr.class.php.

33  {
34  // Verify that the elt we want to add is correct
35  /* verify only the datatype */
36  if (strlen(trim($this->ad_text))==0)
37  throw new Exception('La description ne peut pas être vide', 1);
38  if (strlen(trim($this->ad_type))==0)
39  throw new Exception('Le type ne peut pas être vide', 1);
40  $this->ad_type=strtolower($this->ad_type);
41  if (in_array($this->ad_type, array('date', 'text', 'numeric', 'zone', 'poste', 'card', 'select','check'))==false)
42  throw new Exception('Le type doit être text, numeric,poste, card, select ou date', 1);
43  if (trim($this->ad_size)==''||isNumber($this->ad_size)==0||$this->ad_size>22)
44  {
45  switch ($this->ad_type)
46  {
47  case 'text':
48  $this->ad_size=22;
49  break;
50  case 'numeric':
51  $this->ad_size=9;
52  break;
53  case 'date':
54  $this->ad_size=8;
55  break;
56  case 'zone':
57  $this->ad_size=22;
58  break;
59 
60  default:
61  $this->ad_size=22;
62  }
63  }
64  if ($this->ad_type=='numeric')
65  {
66  $this->ad_extra=(trim($this->ad_extra)=='')?'2':$this->ad_extra;
67  if (isNumber($this->ad_extra)==0)
68  throw new Exception("La précision doit être un chiffre");
69  }
70  if ($this->ad_type=='select')
71  {
72  if (trim($this->ad_extra)=="")
73  throw new Exception("La requête SQL est vide ");
74  if (preg_match('/^\h*select/i', $this->ad_extra)==0)
75  throw new Exception("La requête SQL doit commencer par SELECT ");
76  try
77  {
78 
79  $this->cn->exec_sql($this->ad_extra);
80  }
81  catch (Exception $e)
82  {
83  record_log($e);
84  throw new Exception("La requête SQL ".h($this->ad_extra)." est invalide ");
85  }
86  }
87  }

References $e, cn, h, isNumber(), and record_log().

Referenced by update().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file:
$prefix
$prefix
Definition: ajax_search_display_tag.php:30
h
h( $row[ 'oa_description'])
Definition: ajax_anc_detail_operation.php:46
$e
$e
Definition: result_cat_card_summary.php:26
cn
$input_from cn
Definition: balance.inc.php:66
Data_SQL\setp
setp($p_string, $p_value)
set the value thanks the alias name instead of the colum name
Definition: data_sql.class.php:159
Table_Data_SQL\insert
insert()
Definition: table_data_sql.class.php:100
$sql
$sql
Definition: ajax_add_concerned_card.php:100
$array
$array
Definition: ajax_add_concerned_card.php:115
name
$from_poste name
Definition: balance.inc.php:159
$value
$value
Definition: export_document.php:41
isNumber
isNumber($p_int)
Definition: ac_common.php:218
Fiche_Attr\verify
verify()
Definition: fiche_attr.class.php:32
Fiche_Attr\update
update()
Definition: fiche_attr.class.php:90
$p_id
$p_id
Definition: ajax_accounting.php:33
$res
$res
Definition: ajax_preference.php:49
record_log
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1400
Data_SQL\getp
getp($p_string)
set the value thanks the alias name instead of the colum name
Definition: data_sql.class.php:145