00001 <?php
00002
00008 class SDRMetadataObj extends SXMLModel {
00017 public function __construct($xml = null) {
00018 parent::__construct();
00019
00020 $this->registerNodeName('metadata');
00021
00022 if($xml)
00023 $this->setXML($xml);
00024 }
00025
00034 protected function setXMLImpl($xml) {
00035 $attrs = array();
00036
00037 foreach($xml->children() as $child) {
00038 $name = $child->getName();
00039 if(!$this->attributeExists($name)) {
00040 $this->addAttribute($name, array('type' => 'string', 'array' => true));
00041 $attrs[$name] = array( (string)$child );
00042 }
00043 else {
00044 $attrs[$name][] = (string)$child;
00045 }
00046 }
00047
00048 foreach($attrs as $a => $v) {
00049
00050 $this->set($a, array_unique($v));
00051 }
00052
00053 return true;
00054 }
00055
00066 public function addTag($name, $value, $reset = false) {
00067
00068
00069 if(!$this->attributeExists($name)) {
00070 $this->addAttribute($name, array('type' => 'string', 'array' => true));
00071 if(is_array($value))
00072 $this->set($name, $value);
00073 else
00074 $this->set($name, array($value));
00075 }
00076
00077
00078
00079 else {
00080 if($this->isAttributeArray($name)) {
00081 if($reset) {
00082 if(is_array($value))
00083 $attrs = $value;
00084 else
00085 $attrs = array((string)$value);
00086 }
00087 else {
00088 $attrs = $this->get($name);
00089 if(is_array($value))
00090 $attrs = array_merge($attrs, $value);
00091 else
00092 $attrs[]= (string)$value;
00093 $attrs = array_unique($attrs);
00094 }
00095 $this->set($name, $attrs);
00096 }
00097 else
00098 $this->set($name, $value);
00099 }
00100 }
00101
00111 public function removeTag($name, $value = null) {
00112
00113 if ($value == null) {
00114 $this->set($name, array());
00115 }
00116
00117 else {
00118 $attrs = $this->get($name);
00119 foreach ($attrs as $index => $attrVal) {
00120 if ($attrVal == $value) {
00121 unset($attrs[$index]);
00122 }
00123 }
00124 $this->set($name, $attrs);
00125 }
00126 }
00127 }
00128
00129 ?>