- Developper API  2.0.5
developerApi_2.0.5/Property.php
Go to the documentation of this file.
00001 <?php
00017 require_once("Utils.php");
00018 class Property
00019 {
00020         private $name;
00021         private $label;
00022         private $value;
00023         private $language;
00024 
00025         private static $xmlNodesName = array(
00026                 "label",
00027                 "value",
00028                 "language"
00029         );
00030     
00039         public function __construct($name,$label, $value,$language="")
00040         {
00041                 $this->name = $name;
00042                 $this->label = $label;
00043                 $this->value = $value;
00044                 $this->language = $language;
00045         }
00046 
00051         public final function getName()
00052         {
00053                 return (!empty($this->name)) ? $this->name : false;
00054         }
00055         
00060         public final function getLabel()
00061         {
00062                 return (!empty($this->label)) ? $this->label : false;
00063         }
00064 
00069         public final function getValue()
00070         {
00071                 return (!empty($this->value)) ? $this->value : false;
00072         }
00073 
00078         public final function getLanguage()
00079         {
00080                 return (!empty($this->language)) ? $this->language : false;
00081         }
00082 
00087         public function __toString()
00088         {
00089                 return "Label: ".$this->label."<br />Value: ".$this->value."<br />Lang: ".$this->language;
00090         }
00091 
00097      public final static function getPropertyFromSXMLElement($node)
00098         {
00099                 $label = "";
00100                 $value =  "";
00101                 $language = "";
00102 
00103                 if(!Property::isSXMLNodeProperty($node))
00104                 {
00105                         error("Property creation failed for element: ".$node->getName());
00106                         return false;
00107                 }                       
00108                 
00109                 if(!hasChildren($node))
00110                 {
00111                 $name = $node->getName();
00112                         $label = "";
00113                         $value = (string) $node;
00114                         $language = "";
00115                 }
00116                 else
00117                 {                       
00118                         $label = $node->xpath("label");
00119                         $value = $node->xpath("value");
00120                         $language = $node->xpath("language");
00121 
00122                         
00123                         //If label node not in property then the node name will be the label
00124                         if(count($label)==0)
00125                                 $label = "";
00126                         else
00127                                 $label = (string)$label[0];     
00128 
00129                         if(count($value)==0)
00130                                 $value="";
00131                         else
00132                                 $value = (string)$value[0];
00133 
00134                         if(count($language)>0)
00135                                 $language = (string)$language[0];
00136                         else
00137                                 $language = "";
00138 
00139                 }               
00140 
00141                 $property = new Property($node->getName(),$label,$value,$language);
00142                 return $property;
00143                         
00144         }
00145 
00151         public final static function isSXMLNodeProperty($node)
00152         {
00153                 if(!hasChildren($node))
00154                         return true;
00155                 else
00156                 {
00157                         foreach($node->children() as $child)
00158                         {
00159                                 $name = $child->getName();
00160 
00161                                 if(! in_array($name, Property::$xmlNodesName))
00162                                         return false;                           
00163                         }
00164 
00165                         return true;
00166                 }
00167         }
00168 }
00169 ?>