Hazırlamış olduğum sınıfın kodu şöyle:
/**
* This class is used to represent a ADV Template to provide required fileld and values along
* the reqistration process of the advertisement.
* This class uses Domdocument object library to load xml schema file.
*
* @author Behçet MUTLU
* @copyright 2009 Adres Gezgini
*/
class ADVTemplate {
private $name;
private $author;
private $datecreated;
private $copyright;
private $website;
private $schema;
private $isReady;
private $xml;
private $fields;
private $values;
/**
* This is the general constructor of the ADV Template class that used to initialize the
* ADV Template itself with given arguments.
*/
public function __construct($schema = "", $values = array())
{
$this->schema = $schema;
$this->isReady = false;
if($this->schema != "")
$this->load();
if(sizeof($values) > 0)
$this->setValues($values);
}
/**
* This method is used to initialize the Template from the schema file and set the values
*/
private function initialize()
{
$this->name = $this->xml["template"]["info"]["name"];
$this->author = $this->xml["template"]["info"]["author"];
$this->datecreated = $this->xml["template"]["info"]["datecreated"];
$this->copyright = $this->xml["template"]["info"]["copyright"];
$this->website = $this->xml["template"]["info"]["website"];
$this->fields = $this->xml["template"]["fields"];
foreach($this->fields as $fieldType)
{
if($fieldType != 0)
foreach($fieldType as $field)
{
if($field != 0)
$this->values[$field["@id"]] = isset($field["default"]) ? $field["default"] : "";
}
}
}
/**
* This method is used to initialize the Template from the schema file and set the values
*/
public function load()
{
$xml = new CArray2xml2array();
if($xml->setXMLFile($this->schema))
{
$this->xml = $xml->toArray();
$this->isReady = true;
$this->initialize();
debug("XML file, \"" . $xml->getXMLFile() . "\" loaded successfully.","pre");
}
else
{
$this->isReady = false;
debug("Error: XML file could not be loaded!");
}
}
/**
* This method is used to learn if the xml file is ready or not
*/
public function ready()
{
return $this->isReady;
}
/**
* This method is used to set value of the class
*/
public function setName($value) { $this->name = $value; }
public function setAuthor($value) { $this->name = $value; }
public function setWebsite($value) { $this->website = $value; }
public function setDatecreated($value) { $this->datecreated = $value; }
public function setCopyright($value) { $this->copyright = $value; }
public function setSchema($value) { $this->schema = $value; }
public function setFields($value) { $this->fields = $value; }
public function setXml($value) { $this->xml = $value; }
/**
* This method is used to get value of the class
*/
public function getName() { return $this->name; }
public function getAuthor() { return $this->author; }
public function getWebsite() { return $this->website; }
public function getDatecreated() { return $this->datecreated; }
public function getCopyright() { return $this->copyright; }
public function getSchema() { return $this->schema; }
public function getFields() { return $this->fields; }
public function getXml() { return $this->xml; }
/**
* This method is used to set value of the class
*/
public function setValueOf($id, $value)
{
$this->values[$id] = $value;
}
/**
* This method is used to set values of the class
* The spacial thing here is setting only given indexes but keeping the rest of
* the values remain same.
*/
public function setValues($values)
{
foreach($values as $id=>$value)
$this->setValueOf($id,$value);
}
/**
* This method is used to get a string output of this object.
*/
public function toString()
{
print_r($this);
}
}
0 yorum:
Yorum Gönder