[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 24/27: Code rewriting
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 24/27: Code rewriting |
Date: |
Sun, 02 Nov 2014 11:08:52 +0000 |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 1bcf0cbc9e538c7093c8c60d834109e8090715e9
Author: Dany De Bontridder <address@hidden>
Date: Sun Nov 2 11:54:54 2014 +0100
Code rewriting
---
include/class_menu_ref_sql.php | 271 +++++++---------------------------------
1 files changed, 44 insertions(+), 227 deletions(-)
diff --git a/include/class_menu_ref_sql.php b/include/class_menu_ref_sql.php
index cf3eaf1..b002d10 100644
--- a/include/class_menu_ref_sql.php
+++ b/include/class_menu_ref_sql.php
@@ -26,237 +26,54 @@
*/
require_once('class_database.php');
require_once('ac_common.php');
+require_once('class_noalyss_sql.php');
/**
* @brief Manage the table public.menu_ref
*/
-class Menu_Ref_sql
+class Menu_Ref_SQL extends Noalyss_SQL
{
- /* example private
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
*/
-
- protected $variable = array(
- "me_code" => "me_code"
- , "me_menu" => "me_menu"
- , "me_file" => "me_file"
- , "me_url" => "me_url"
- , "me_description" => "me_description"
- , "me_parameter" => "me_parameter"
- , "me_javascript" => "me_javascript"
- , "me_type" => "me_type"
- );
-
- function __construct(& $p_cn, $p_id=-1)
- {
- $this->cn = $p_cn;
- $this->me_code = $p_id;
-
- if ($p_id == -1)
- {
- /* Initialize an empty object */
- foreach ($this->variable as $key => $value)
- $this->$value = null;
- $this->me_code = $p_id;
- }
- else
- {
- /* load it */
-
- $this->load();
- }
- }
-
- public function get_parameter($p_string)
- {
- if (array_key_exists($p_string, $this->variable))
- {
- $idx = $this->variable[$p_string];
- return $this->$idx;
- }
- else
- throw new Exception(__FILE__ . ":" . __LINE__ .
$p_string . 'Erreur attribut inexistant');
- }
-
- public function set_parameter($p_string, $p_value)
- {
- if (array_key_exists($p_string, $this->variable))
- {
- $idx = $this->variable[$p_string];
- $this->$idx = $p_value;
- }
- else
- throw new Exception(__FILE__ . ":" . __LINE__ .
$p_string . 'Erreur attribut inexistant');
- }
-
- public function get_info()
- {
- return var_export($this, true);
- }
-
- public function verify()
- {
- // Verify that the elt we want to add is correct
- /* verify only the datatype */
- if (trim($this->me_menu) == '')
- $this->me_menu = null;
- if (trim($this->me_file) == '')
- $this->me_file = null;
- if (trim($this->me_url) == '')
- $this->me_url = null;
- if (trim($this->me_description) == '')
- $this->me_description = null;
- if (trim($this->me_parameter) == '')
- $this->me_parameter = null;
- if (trim($this->me_javascript) == '')
- $this->me_javascript = null;
- if (trim($this->me_type) == '')
- $this->me_type = null;
- }
-
- /**
- * @brief retrieve array of object thanks a condition
- * @param $cond condition (where clause) (optional by default all the
rows are fetched)
- * you can use this parameter for the order or subselect
- * @param $p_array array for the SQL stmt
- * @see Database::exec_sql get_object Database::num_row
- * @return the return value of exec_sql
- */
- public function seek($cond='', $p_array=null)
- {
- $sql = "select * from public.menu_ref $cond";
- $aobj = array();
- $ret = $this->cn->exec_sql($sql, $p_array);
- return $ret;
- }
-
- /**
- * get_seek return the next object, the return of the query must have
all the column
- * of the object
- * @param $p_ret is the return value of an exec_sql
- * @param $idx is the index
- * @see seek
- * @return object
- */
- public function get_object($p_ret, $idx)
- {
- // map each row in a object
- $oobj = new Menu_Ref_sql($this->cn);
- $array = Database::fetch_array($p_ret, $idx);
- foreach ($array as $idx => $value)
- {
- $oobj->$idx = $value;
- }
- return $oobj;
- }
-
- public function insert()
- {
- if ($this->verify() != 0)
- return;
-
- $sql = "insert into public.menu_ref(me_menu
- ,me_file
- ,me_url
- ,me_description
- ,me_parameter
- ,me_javascript
- ,me_type
- ,me_code) values ($1
- ,$2
- ,$3
- ,$4
- ,$5
- ,$6
- ,$7
- ,$8
- ) returning me_code";
-
- $this->me_code = $this->cn->get_value(
- $sql, array($this->me_menu
- , $this->me_file
- , $this->me_url
- , $this->me_description
- , $this->me_parameter
- , $this->me_javascript
- , $this->me_type
- , $this->me_code)
- );
-
- }
-
- public function update()
- {
- if ($this->verify() != 0)
- return;
- /* please adapt */
- $sql = " update public.menu_ref set me_menu = $1
- ,me_file = $2
- ,me_url = $3
- ,me_description = $4
- ,me_parameter = $5
- ,me_javascript = $6
- ,me_type = $7
- where me_code= $8";
- $res = $this->cn->exec_sql(
- $sql, array($this->me_menu
- , $this->me_file
- , $this->me_url
- , $this->me_description
- , $this->me_parameter
- , $this->me_javascript
- , $this->me_type
- , $this->me_code)
- );
- }
-
- /**
- * @brief load a object
- * @return 0 on success -1 the object is not found
- */
- public function load()
- {
-
- $sql = "select me_menu
- ,me_file
- ,me_url
- ,me_description
- ,me_parameter
- ,me_javascript
- ,me_type
- from public.menu_ref where
me_code=$1";
- /* please adapt */
- $res = $this->cn->get_array(
- $sql, array($this->me_code)
- );
-
- if (count($res) == 0)
- {
- /* Initialize an empty object */
- foreach ($this->variable as $key => $value)
- $this->$key = '';
-
- return -1;
- }
- foreach ($res[0] as $idx => $value)
- {
- $this->$idx = $value;
- }
- return 0;
- }
-
- public function delete()
- {
- $sql = "delete from public.menu_ref where me_code=$1";
- $res = $this->cn->exec_sql($sql, array($this->me_code));
- }
-
- /**
- * Unit test for the class
- */
- static function test_me()
- {
- }
-
+ protected $table="public.menu_ref";
+ protected $primary_key="me_code";
+ protected $name = array(
+ "me_code" => "me_code"
+ , "me_menu" => "me_menu"
+ , "me_file" => "me_file"
+ , "me_url" => "me_url"
+ , "me_description" => "me_description"
+ , "me_parameter" => "me_parameter"
+ , "me_javascript" => "me_javascript"
+ , "me_type" => "me_type"
+ );
+ protected $type=array(
+ "me_code" => "text"
+ , "me_menu" => "text"
+ , "me_file" => "text"
+ , "me_url" => "text"
+ , "me_description" => "text"
+ , "me_parameter" => "text"
+ , "me_javascript" => "text"
+ , "me_type" => "text"
+ );
+ function __construct($p_id=null)
+ {
+ global $cn;
+ parent::__construct($cn,$p_id);
+ }
+ static function test_me()
+ {
+ $a=new Menu_Ref_sql();
+ $a->setp('me_code','test');
+ $a->insert();
+ $a->setp('me_menu','update');
+ $a->update();
+ $a->delete();
+ $b=$a->collect_objects(' where me_type = $1',array('PR'));
+ echo "size ".count($b);
+ $a->verify();
+ $a->setp('me_code','ACH');
+ $a->load();
+ echo $a->get_info();
+ }
}
-
-// Menu_Ref_sql::test_me();
?>
- [Noalyss-commit] [noalyss] 11/27: Button_image Add button with icon, (continued)
- [Noalyss-commit] [noalyss] 11/27: Button_image Add button with icon, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 13/27: Cosmetique icon, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 12/27: resize icon, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 14/27: Cosmetique remove border, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 10/27: Correct mes Task #1038 - Recherche de fiche par poste comptable, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 17/27: Traduction, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 19/27: Last version of prototype + patch, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 23/27: Documentation, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 18/27: Documentation, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 22/27: Documentation, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 24/27: Code rewriting,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 16/27: Search by accounting Task #1038 - Recherche de fiche par poste comptable, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 25/27: Code rewriting : accept table with a text PK, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 26/27: Code rewriting : change due to change of menu_ref_sql, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 15/27: Button_image for search card, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 21/27: New functionnal test, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 27/27: Test unitaire avec PHPUNIT, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 20/27: Translation progress, Dany De Bontridder, 2014/11/02
- [Noalyss-commit] [noalyss] 05/27: Mise a jour traduction, Dany De Bontridder, 2014/11/02