Beispiel #1
0
 /**
  * Finds an attribute by its name
  * @param $name String - attribute key name
  * @param $language Language - Optional, if not given, the main language is used
  * @return ObjectAttribute - ObjectAttribute or null, if it couldn't be found
  */
 function findAttributeByName($name, $language = null)
 {
     if (is_null($language)) {
         $languageMapper = new LanguageMapper();
         $language = $languageMapper->getMain();
     }
     $objectAttributeArray = $this->getAttributes();
     foreach ($objectAttributeArray as $objectAttribute) {
         /* @var $objectAttribute ObjectAttribute */
         $classAttribute = $objectAttribute->getClassAttribute();
         /* @var $classAttribute ClassAttribute */
         if ($objectAttribute->getLanguageID() == $language->getId() && $classAttribute->getName() == $name) {
             return $objectAttribute;
         }
     }
     // Couldn't find it
     return null;
 }
Beispiel #2
0
 /**
  * Gets the ClassAttribute objects assigned in the descriptor as fields. If there is no description, TITLE is looked up
  * @return Array - array of ClassAttribute objects
  */
 function getTitleClassAttributes()
 {
     $languageMapper = new LanguageMapper();
     $language = $languageMapper->getMain();
     $classAttributeArray = $this->getAttributesForLanguage($language);
     // If it has no descriptor, search for a TITLE attribute
     if ($this->getDescriptor() == null || $this->getDescriptor() == "") {
         foreach ($classAttributeArray as $classAttribute) {
             /* @var $classAttribute ClassAttribute */
             if ($classAttribute->getName() == "TITLE") {
                 return $classAttribute;
             }
         }
         trigger_error("Class has no descriptor defined and no TITLE attribute: " . $this->getTitle());
     }
     // Has a descriptor, get its title properties
     $descriptor = $this->getDescriptor();
     $titleArray = array();
     while (ereg("<[A-Z]*>", $descriptor, $tempTitleArray) != false) {
         array_push($titleArray, $tempTitleArray[0]);
         $descriptor = str_replace($tempTitleArray[0], "", $descriptor);
     }
     if ($titleArray == null || count($titleArray) == 0) {
         trigger_error("Class do not has a valid title defined: " . $this->getDescriptor());
     }
     $titleClassAttributeArray = array();
     foreach ($titleArray as $title) {
         $titleNoTags = str_replace(">", "", str_replace("<", "", $title));
         $found = false;
         foreach ($classAttributeArray as $classAttribute) {
             if ($classAttribute->getName() == $titleNoTags) {
                 array_push($titleClassAttributeArray, $classAttribute);
                 $found = true;
                 break;
             }
         }
         if ($found == false) {
             trigger_error("Could not found ClassAttribute " . $titleNoTags);
         }
     }
     return $titleClassAttributeArray;
 }