From 1b166ea8cb5131eaa6ca3b248c8caf1268836ba9 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 15 Jan 2023 22:24:54 +0100 Subject: [PATCH] Documentation --- include/lib/data_sql.class.php | 53 +++++++++++++++++++++++++- include/lib/manage_table_sql.class.php | 3 +- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/include/lib/data_sql.class.php b/include/lib/data_sql.class.php index 37b0bc1f5..55d0353d3 100644 --- a/include/lib/data_sql.class.php +++ b/include/lib/data_sql.class.php @@ -38,7 +38,31 @@ * - type = array , match between column and type of data * - default = array of column with a default value * - date_format = format of the date - * + * + * if you give a SQL or a View you have to give a primary key, usually , the best is to use a key composed of + * different PK of the tables + * Example : in this SQL (or view) the PK is id and it is composed with the PK f_id and sg_id , remember that the + * pk cannot be null and must be unique ! For SQL , the value is computed , so you need a subselect like this + @code + select + ssw.sg_id::text||'-'||vfp.f_id::text id, + vfp.f_id,vfp.f_enable,vfp.person_name ,vfp.person_fname ,vfp.person_qcode ,ssw.sg_id + from rash.vw_fiche_person vfp + join rash.security_social_worker ssw using(f_id) ; + @endcode + * + * For SQL , the value is computed , so you need a subselect like this +@code + select * from ( + select + ssw.sg_id::text||'-'||vfp.f_id::text id, + vfp.f_id,vfp.f_enable,vfp.person_name ,vfp.person_fname ,vfp.person_qcode ,ssw.sg_id + from rash.vw_fiche_person vfp + join rash.security_social_worker ssw using(f_id))sub1 +@encode + * + * + * * After you call the parent constructor * @note the view or the table must include an unique key, otherwise the load * doesn't work. @@ -199,6 +223,33 @@ abstract class Data_SQL return $this->$pk; } + /** + * @brief Load the current row return false if not found + * @code + $pk=$this->primary_key; + if ( $this->get_limit_fiche_qcode() != 0 ) + { + $sql=sprintf($this->sql," limit ".$this->get_limit_fiche_qcode()); + } else + { + $sql=sprintf($this->sql," "); + } + $result=$this->cn->get_array($sql. " where id=$1",array ($this->$pk)); + if ($this->cn->count()==0) + { + $this->$pk=-1; + return false; + } + + foreach ($result[0] as $key=> $value) + { + $this->$key=$value; + } + return true; + * + * @endcode + * @return bool + */ abstract function load():bool; public function get_info() diff --git a/include/lib/manage_table_sql.class.php b/include/lib/manage_table_sql.class.php index ba52307db..45cffff6f 100644 --- a/include/lib/manage_table_sql.class.php +++ b/include/lib/manage_table_sql.class.php @@ -31,7 +31,7 @@ \code $objet->set_pk($p_id); // It is very important to set the name of the javascript variable - // Contained in the http_input variable "ctl" + // Contained in the http_input variable "ctl" , without this the list cannot be updated $objet->set_object_name($objet_name); // Set the ajax to call @@ -51,6 +51,7 @@ $json=json_encode($aJson); $objet->param_set($json); + // Display the box header('Content-type: text/xml; charset=UTF-8'); $xml=$objet->ajax_input();