config=$config;
$this->data=$data;
$this->index=$index;
$this->skip=false;
$this->userdata=false;
}
//set userdata for the item
function set_userdata($name, $value){
if ($this->userdata === false)
$this->userdata = array();
$this->userdata[$name]=$value;
}
/*! get named value
@param name
name or alias of field
@return
value from field with provided name or alias
*/
public function get_value($name){
return $this->data[$name];
}
/*! set named value
@param name
name or alias of field
@param value
value for field with provided name or alias
*/
public function set_value($name,$value){
return $this->data[$name]=$value;
}
/*! get id of element
@return
id of element
*/
public function get_id(){
$id = $this->config->id["name"];
if (array_key_exists($id,$this->data))
return $this->data[$id];
return false;
}
/*! change id of element
@param value
new id value
*/
public function set_id($value){
$this->data[$this->config->id["name"]]=$value;
}
/*! get index of element
@return
index of element
*/
public function get_index(){
return $this->index;
}
/*! mark element for skiping ( such element will not be rendered )
*/
public function skip(){
$this->skip=true;
}
/*! return self as XML string
*/
public function to_xml(){
return $this->to_xml_start().$this->to_xml_end();
}
/*! replace xml unsafe characters
@param string
string to be escaped
@return
escaped string
*/
public function xmlentities($string) {
return str_replace( array( '&', '"', "'", '<', '>', '’' ), array( '&' , '"', ''' , '<' , '>', ''' ), $string);
}
/*! return starting tag for self as XML string
*/
public function to_xml_start(){
$str="- config->data); $i++){
$name=$this->config->data[$i]["name"];
$db_name=$this->config->data[$i]["db_name"];
$str.=" ".$name."='".$this->xmlentities($this->data[$name])."'";
}
//output custom data
if ($this->userdata !== false)
foreach ($this->userdata as $key => $value){
$str.=" ".$key."='".$this->xmlentities($value)."'";
}
return $str.">";
}
/*! return ending tag for XML string
*/
public function to_xml_end(){
return "
";
}
}