<?php
require_once "IppPhone.php";

/**
 * 
 * This is an representation of a basic XML Element including some render functions
 * 
 * @author sebastiankauder
 *
 */
abstract class SiemensXMLElement {

	private $uiElements = array();
// 	protected $attributes = array();
	public $attributes = array();
	private $title = null;
	private $text  = null;
	private $url = null;
	private $label = null;
//	private $image = null;
	private $number = null;
	private $screenID = null;
	private $ippPhoneNumber = null;
	private $hiddenValue = null;
	
	public function __construct($attributes = array()) {
	
		$this->attributes = $attributes;
		
	}
	
	public function setTitle($title) {
		$this->title = $title;
	}
	
	public function setText(Text $text) {
		$this->text = $text;
	}
	
	public function setUrl($url) {
		$this->url = $url;
	}
	
	public function setLabel($label) {
		$this->label = $label;
	}
/*	
	public function setImage(Image $image) {
		$this->image = $image;
	}
*/	
	public function setNumber($number) {
		$this->number = $number;
	}
	
	public function setIppPhoneNumber(IppPhoneNumber $ippPhoneNumber) {
		$this->ippPhoneNumber = $ippPhoneNumber;
	}
	
	public function setScreenID($screenID) {
		$this->screenID = $screenID;
	}
	
	public function setHiddenValue($hiddenValue) {
		$this->hiddenValue = $hiddenValue;
	}
	
	
	public function renderXML(xmlWriter &$xw) {

		$xw->startElement($this->name());
		
		// write uiElement attributes
		foreach ($this->attributes as $key => $value) {
			$xw->writeAttribute($key, $value);
		}
		
		if ($this->title != null) {
			$xw->startElement("Title");
			$xw->text($this->title);
			$xw->endElement();
		}

		if ($this->url != null) {
			$xw->startElement("Url");
			$xw->text($this->url);
			$xw->endElement();
		}
		
		if ($this->label != null) {
			$xw->startElement("Label");
			$xw->text($this->label);
			$xw->endElement();
		}
		
		if ($this->number != null) {
			$xw->startElement("Number");
			$xw->text($this->number);
			$xw->endElement();
		}
		
		if ($this->screenID != null) {
			$xw->startElement("ScreenID");
			$xw->text($this->screenID);
			$xw->endElement();
		}
/*		
		if ($this->image != null) {
			$xw->startElement("Image");
			$xw->text($this->image);
			$xw->endElement();
		}
/*		
		if ($this->ippPhoneNumber != null) {
			$xw->startElement("IppPhoneNumber");
			$xw->text($this->ippPhoneNumber);
			$xw->endElement();
		}
*/		
		if ($this->hiddenValue != null) {
			$xw->startElement("Value");
			$xw->text($this->hiddenValue);
			$xw->endElement();
		}
		
		if ($this->text != null) {
			$this->text->renderXML($xw);
		}
				
		$this->renderXMLBeforeChildsHook($xw);
		
		foreach ($this->uiElements as $uiElement) {
 			$uiElement->renderXML($xw);
 		}
 		
 		$xw->endElement();
 		
	}
	
	public function renderXMLBeforeChildsHook(xmlWriter &$xw) {
		// does nothing.
	}
	
	
	public function addUIElement(SiemensXMLElement $element) {
	
		$this->uiElements[] = $element;
	
	}
	
	protected function name() {
		return "INVALID";		
	}
	
	
}