[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 07/16: Code rewrite
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 07/16: Code rewrite |
Date: |
Tue, 18 Nov 2014 01:09:03 +0000 |
sparkyx pushed a commit to branch master
in repository noalyss.
commit a03efcba36f613d9d49575c3b0c6e624c4b2b4b1
Author: Dany De Bontridder <address@hidden>
Date: Tue Nov 18 01:27:23 2014 +0100
Code rewrite
---
include/class_profile_menu_sql.php | 284 +++++-------------------------------
1 files changed, 36 insertions(+), 248 deletions(-)
diff --git a/include/class_profile_menu_sql.php
b/include/class_profile_menu_sql.php
index 0190e3f..6d0c118 100644
--- a/include/class_profile_menu_sql.php
+++ b/include/class_profile_menu_sql.php
@@ -1,4 +1,5 @@
<?php
+
/*
* This file is part of NOALYSS.
*
@@ -18,269 +19,56 @@
*/
// Copyright Author Dany De Bontridder address@hidden
/**
- address@hidden
- address@hidden Manage the table public.profile_menu
+ * @file
+ * @brief Manage the table public.profile_menu
*
*
-Example
address@hidden
+ Example
+ @code
address@hidden
+ @endcode
*/
require_once('class_database.php');
require_once('ac_common.php');
-
+require_once 'class_noalyss_sql.php';
/**
- address@hidden Manage the table public.profile_menu
-*/
-class Profile_Menu_sql
+ * @brief Manage the table public.profile_menu
+ */
+class Profile_Menu_sql extends Noalyss_SQL
{
- /* example private
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
*/
-
- protected $variable=array("pm_id"=>"pm_id","me_code"=>"me_code"
-,"me_code_dep"=>"me_code_dep"
-,"p_id"=>"p_id"
-,"p_order"=>"p_order"
-,"p_type_display"=>"p_type_display"
-,"pm_default"=>"pm_default"
-);
- function __construct ( & $p_cn,$p_id=-1) {
- $this->cn=$p_cn;
- $this->pm_id=$p_id;
-
- if ( $p_id == -1 ) {
- /* Initialize an empty object */
- foreach ($this->variable as $key=>$value) $this->$value=null;
- $this->pm_id=$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_code) == '') $this->me_code=null;
- if ( trim($this->me_code_dep) == '') $this->me_code_dep=null;
- if ( trim($this->p_id) == '') $this->p_id=null;
-if ( $this->p_id!== null && settype($this->p_id,'float') == false )
- throw new Exception('DATATYPE p_id $this->p_id non numerique');
- if ( trim($this->p_order) == '') $this->p_order=null;
-if ( $this->p_order!== null && settype($this->p_order,'float') == false )
- throw new Exception('DATATYPE p_order $this->p_order non
numerique');
- if ( trim($this->p_type_display) == '') $this->p_type_display=null;
- if ( trim($this->pm_default) == '') $this->pm_default=null;
-if ( $this->pm_default!== null && settype($this->pm_default,'float') == false )
- throw new Exception('DATATYPE pm_default $this->pm_default non
numerique');
-
- }
- public function save() {
- /* please adapt */
- if ( $this->pm_id == -1 )
- $this->insert();
- else
- $this->update();
- }
- /**
- address@hidden retrieve array of object thanks a condition
- address@hidden $cond condition (where clause) (optional by default all the
rows are fetched)
- * you can use this parameter for the order or subselect
- address@hidden $p_array array for the SQL stmt
- address@hidden Database::exec_sql get_object Database::num_row
- address@hidden the return value of exec_sql
- */
- public function seek($cond='',$p_array=null)
- {
- $sql="select * from public.profile_menu $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
- address@hidden $p_ret is the return value of an exec_sql
- address@hidden $idx is the index
- address@hidden seek
- address@hidden object
- */
- public function get_object($p_ret,$idx)
+ function __construct(&$p_cn,$p_id=-1)
{
- // map each row in a object
- $oobj=new Profile_Menu_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;
- if( $this->pm_id==-1 ){
- /* please adapt */
- $sql="insert into public.profile_menu(me_code
-,me_code_dep
-,p_id
-,p_order
-,p_type_display
-,pm_default
-) values ($1
-,$2
-,$3
-,$4
-,$5
-,$6
-) returning pm_id";
-
- $this->pm_id=$this->cn->get_value(
- $sql,
- array( $this->me_code
-,$this->me_code_dep
-,$this->p_id
-,$this->p_order
-,$this->p_type_display
-,$this->pm_default
-)
- );
- } else {
- $sql="insert into public.profile_menu(me_code
-,me_code_dep
-,p_id
-,p_order
-,p_type_display
-,pm_default
-,pm_id) values ($1
-,$2
-,$3
-,$4
-,$5
-,$6
-,$7
-) returning pm_id";
-
- $this->pm_id=$this->cn->get_value(
- $sql,
- array( $this->me_code
-,$this->me_code_dep
-,$this->p_id
-,$this->p_order
-,$this->p_type_display
-,$this->pm_default
-,$this->pm_id)
- );
+ $this->table="public.profile_menu";
+ $this->primary_key="pm_id";
- }
-
- }
+ $this->name=array(
+ "pm_id"=>"pm_id", "me_code"=>"me_code"
+ , "me_code_dep"=>"me_code_dep"
+ , "p_id"=>"p_id"
+ , "p_order"=>"p_order"
+ , "p_type_display"=>"p_type_display"
+ , "pm_default"=>"pm_default"
+ );
- public function update() {
- if ( $this->verify() != 0 ) return;
- /* please adapt */
- $sql=" update public.profile_menu set me_code = $1
-,me_code_dep = $2
-,p_id = $3
-,p_order = $4
-,p_type_display = $5
-,pm_default = $6
- where pm_id= $7";
- $res=$this->cn->exec_sql(
- $sql,
- array($this->me_code
-,$this->me_code_dep
-,$this->p_id
-,$this->p_order
-,$this->p_type_display
-,$this->pm_default
-,$this->pm_id)
- );
-
- }
-/**
- address@hidden load a object
- address@hidden 0 on success -1 the object is not found
- */
- public function load() {
+ $this->type=array(
+ "pm_id"=>"number",
+ "me_code"=>"text"
+ , "me_code_dep"=>"text"
+ , "p_id"=>"number"
+ , "p_order"=>"number"
+ , "p_type_display"=>"text"
+ , "pm_default"=>"text"
+ );
- $sql="select me_code
-,me_code_dep
-,p_id
-,p_order
-,p_type_display
-,pm_default
- from public.profile_menu where pm_id=$1";
- /* please adapt */
- $res=$this->cn->get_array(
- $sql,
- array($this->pm_id)
- );
-
- if ( count($res) == 0 ) {
- /* Initialize an empty object */
- foreach ($this->variable as $key=>$value) $this->$key='';
+ $this->default=array(
+ "pm_id"=>"auto"
+ );
- return -1;
- }
- foreach ($res[0] as $idx=>$value) { $this->$idx=$value; }
- return 0;
- }
-
- public function delete() {
- $sql="delete from public.profile_menu where pm_id=$1";
- $res=$this->cn->exec_sql($sql,array($this->pm_id));
- }
- /**
- * Unit test for the class
- */
- static function test_me() {
- $cn=new Database(25);
-$cn->start();
- echo h2info('Test object vide');
- $obj=new Profile_Menu_sql($cn);
- var_dump($obj);
-
- echo h2info('Test object NON vide');
- $obj->set_parameter('j_id',3);
- $obj->load();
- var_dump($obj);
-
- echo h2info('Update');
- $obj->set_parameter('j_qcode','NOUVEAU CODE');
- $obj->save();
- $obj->load();
- var_dump($obj);
-
- echo h2info('Insert');
- $obj->set_parameter('j_id',0);
- $obj->save();
- $obj->load();
- var_dump($obj);
-
- echo h2info('Delete');
- $obj->delete();
- echo (($obj->load()==0)?'Trouve':'non trouve');
- var_dump($obj);
-$cn->rollback();
+ parent::__construct($p_cn, $p_id);
+ }
- }
-
}
-// Profile_Menu_sql::test_me();
+
?>
- [Noalyss-commit] [noalyss] 04/16: Task #1045 - Amélioration apparence : Placement Box menu, (continued)
- [Noalyss-commit] [noalyss] 04/16: Task #1045 - Amélioration apparence : Placement Box menu, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 02/16: Task #1045 - Amélioration apparence : Configuration Menu : ajout des tabs, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 05/16: Remove global, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 09/16: Task #1045 - Amélioration apparence : Improve window detail op, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 06/16: Adapt change for class_extension.php, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 08/16: Adapt change for class_extension.php, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 11/16: Task #1045 - Amélioration apparence : Improve apparence profie, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 12/16: profile_menu Extends profile_menu_sql, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 10/16: Task #1045 - Amélioration apparence :, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 13/16: class_menu_ref_sql add column me_description_etendue, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 07/16: Code rewrite,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 14/16: Fix SQL bug in restore, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 16/16: Task #1045 - Amélioration apparence : Amélioration detail operation, Dany De Bontridder, 2014/11/17
- [Noalyss-commit] [noalyss] 15/16: Task #1052 - Automatic integration of plugin Plugin management, Dany De Bontridder, 2014/11/17