|
noalyss
Version-6.7.2
|
Manage the table attr_def. More...
Public Member Functions | |
| __construct ($p_cn, $p_id=0) | |
| delete () | |
| get_info () | |
| get_parameter ($p_string) | |
| insert () | |
| load () | |
| load a object | |
| save () | |
| seek ($cond='', $p_array=null) | |
| retrieve array of object thanks a condition | |
| set_parameter ($p_string, $p_value) | |
| update () | |
| verify () | |
Static Public Member Functions | |
| static | sort_by_id ($o1, $o2) |
| used with a usort function, to sort an array of Attribut on the attribut_id (ad_id) | |
| static | test_me () |
| Unit test for the class. | |
Protected Attributes | |
| $variable = array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size","extra"=>"ad_extra") | |
Manage the table attr_def.
Definition at line 12 of file class_fiche_attr.php.
| Fiche_Attr::__construct | ( | $ | p_cn, |
| $ | p_id = 0 |
||
| ) |
Definition at line 221 of file class_fiche_attr.php.
References $res, $sql, and cn.
{
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));
}
Definition at line 52 of file class_fiche_attr.php.
{
return var_export($this,true);
}
| Fiche_Attr::get_parameter | ( | $ | p_string | ) |
Definition at line 32 of file class_fiche_attr.php.
References $idx.
| Fiche_Attr::load | ( | ) |
load a object
Definition at line 195 of file class_fiche_attr.php.
References $idx, $res, $sql, $value, and cn.
Referenced by __construct().
{
$sql="select ad_text
,ad_type,ad_size,ad_extra
from attr_def where ad_id=$1";
/* please adapt */
$res=$this->cn->get_array(
$sql,
array($this->ad_id)
);
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;
}
| Fiche_Attr::save | ( | ) |
| Fiche_Attr::seek | ( | $ | cond = '', |
| $ | p_array = null |
||
| ) |
retrieve array of object thanks a condition
| $cond | condition (where clause) |
| $p_array | array for the SQL stmt |
Definition at line 122 of file class_fiche_attr.php.
References $array, $idx, $p_array, $size, $sql, $value, and cn.
{
if ( $cond != '')
$sql="select * from attr_def where $cond order by ad_text";
else
$sql="select * from attr_def order by ad_text";
$aobj=array();
$array= $this->cn->get_array($sql,$p_array);
// map each row in a object
$size=$this->cn->count();
if ( $size == 0 ) return $aobj;
for ($i=0;$i<$size;$i++)
{
$oobj=new Fiche_Attr ($this->cn);
foreach ($array[$i] as $idx=>$value)
{
$oobj->$idx=$value;
}
$aobj[]=clone $oobj;
}
return $aobj;
}
| Fiche_Attr::set_parameter | ( | $ | p_string, |
| $ | p_value | ||
| ) |
Definition at line 42 of file class_fiche_attr.php.
References $idx.
| static Fiche_Attr::sort_by_id | ( | $ | o1, |
| $ | o2 | ||
| ) | [static] |
used with a usort function, to sort an array of Attribut on the attribut_id (ad_id)
Definition at line 272 of file class_fiche_attr.php.
{
if ( $o1->ad_id > $o2->ad_id ) return 1;
if ( $o1->ad_id == $o2->ad_id ) return 0;
return -1;
}
| static Fiche_Attr::test_me | ( | ) | [static] |
Unit test for the class.
Definition at line 237 of file class_fiche_attr.php.
References $cn, $obj, echo, and h2info().
{
$cn=new Database(25);
$cn->start();
echo h2info('Test object vide');
$obj=new Fiche_Attr($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();
}
Definition at line 168 of file class_fiche_attr.php.
References $e, $res, $sql, cn, and verify().
Referenced by save().
{
try
{
$this->verify();
if ( $this->ad_id < 9000) return;
/* please adapt */
$sql=" update attr_def set ad_text = $1
,ad_type = $2,ad_size=$4,ad_extra=$5
where ad_id= $3";
$res=$this->cn->exec_sql(
$sql,
array($this->ad_text
,$this->ad_type
,$this->ad_id,$this->ad_size,$this->ad_extra)
);
}catch (Exception $e)
{
throw $e;
}
}
Definition at line 56 of file class_fiche_attr.php.
References $e, cn, h(), isNumber(), and trim().
Referenced by insert(), and update().
{
// 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'))==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)
{
throw new Exception ("La requête SQL ".h($this->ad_extra)." est invalide ");
}
}
}
Fiche_Attr::$variable = array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size","extra"=>"ad_extra") [protected] |
Definition at line 16 of file class_fiche_attr.php.