![]() |
- Developper API
2.0.5
|
00001 <?php 00017 require_once("Property.php"); 00018 abstract class AbstractDataObject 00019 { 00020 private $id; 00021 private $type; 00022 private $language; 00023 00024 protected $xmlObject; 00025 00026 public static $TYPE=array( 00027 "WINERY"=>0,"WINE"=>1,"RANGE"=>2,"OWNER"=>3 00028 ); 00029 00030 private final static function typeIndexToName($index) 00031 { 00032 foreach(AbstractDataObject::$TYPE as $key=>$value) 00033 { 00034 if($index == $value) 00035 return $key; 00036 } 00037 } 00038 00047 protected function __construct($id,$type,$xmlObject,$language) 00048 { 00049 $this->id = $id; 00050 $this->type = $type; 00051 $this->xmlObject = $xmlObject; 00052 $this->language = $language; 00053 } 00054 00059 public final function getType() 00060 { 00061 return (!empty($this->type)) ? AbstractDataObject::typeIndexToName($this->type) : false; 00062 } 00063 00068 public final function getId() 00069 { 00070 return (!empty($this->id)) ? $this->id : false; 00071 } 00072 00077 public final function getLanguage() 00078 { 00079 return (!empty($this->language)) ? $this->language : false; 00080 } 00081 00086 public final function hasProperty($propertyName) 00087 { 00088 $propertiesElementArray = getSXMLElementWithNameSpace($this->xmlObject,"property",true); 00089 00090 foreach($propertiesElementArray as $propertyElement) 00091 { 00092 $property = Property::getPropertyFromSXMLElement($propertyElement); 00093 if($property->getName() == $propertyName) 00094 return true; 00095 } 00096 00097 return false; 00098 } 00099 00104 public final function getProperties() 00105 { 00106 $propertiesArray = array(); 00107 $propertiesElementArray = getSXMLElementWithNameSpace($this->xmlObject,"property",true); 00108 00109 foreach($propertiesElementArray as $propertyElement) 00110 { 00111 $property = Property::getPropertyFromSXMLElement($propertyElement); 00112 if($property) 00113 { 00114 array_push($propertiesArray,$property ); 00115 } 00116 } 00117 00118 return $propertiesArray; 00119 } 00120 00125 abstract protected function isCustomProperties($label); 00126 00131 public final function getCustomProperties() 00132 { 00133 $properties = $this->getProperties(); 00134 $finalArray = array(); 00135 foreach($properties as $property) 00136 { 00137 if($this->isCustomProperties($property->getName())) 00138 array_push($finalArray, $property); 00139 } 00140 00141 return $finalArray; 00142 } 00143 00148 public final function getNonCustomProperties() 00149 { 00150 $properties = $this->getProperties(); 00151 $finalArray = array(); 00152 foreach($properties as $property) 00153 { 00154 if(!$this->isCustomProperties($property->getName())) 00155 array_push($finalArray, $property); 00156 } 00157 00158 return $finalArray; 00159 } 00160 00166 public final function getProperty($propertyName) 00167 { 00168 $propertiesElementArray = getSXMLElementWithNameSpace($this->xmlObject,"property",true); 00169 $finalPropertyArray = array(); 00170 foreach($propertiesElementArray as $propertyElement) 00171 { 00172 $property = Property::getPropertyFromSXMLElement($propertyElement); 00173 00174 if($property->getName() == $propertyName) 00175 { 00176 array_push($finalPropertyArray,$property); 00177 } 00178 } 00179 00180 return $finalPropertyArray; 00181 } 00182 00187 public final function addSimpleProperty($property) 00188 { 00189 $this->xmlObject->addChild($property->getName(),$property->getValue()); 00190 } 00191 00196 public final function addProperty($property) 00197 { 00198 $name = $property->getName(); 00199 $label = $property->getLabel(); 00200 $value = $property->getValue(); 00201 00202 $child = $this->xmlObject->addChild($name); 00203 $label = $property->getLabel(); 00204 $value = $property->getValue(); 00205 $language = $property->getLanguage(); 00206 00207 if(!empty($label)) 00208 $child->addChild("label",$label); 00209 00210 $child->addChild("value",$value); 00211 00212 if(!empty($language)) 00213 $child->addChild("language",$language); 00214 } 00215 } 00216 ?>