Esempio n. 1
0
 static function addAttributeToClass($contentClass, $newAttributeXPath)
 {
     $classID = $contentClass->attribute("id");
     // extracting from the xml, it's gross, but it's better than from an assoc array
     $xmlValues = array("identifier" => trim($newAttributeXPath->query("//newattribute/identifier")->item(0)->nodeValue), "display_name" => trim($newAttributeXPath->query("//newattribute/displayname")->item(0)->nodeValue), "description" => trim($newAttributeXPath->query("//newattribute/description")->item(0)->nodeValue), "language" => trim($newAttributeXPath->query("//newattribute/language")->item(0)->nodeValue), "can_translate" => trim($newAttributeXPath->query("//newattribute/can_translate")->item(0)->nodeValue), "is_required" => trim($newAttributeXPath->query("//newattribute/is_required")->item(0)->nodeValue), "is_searchable" => trim($newAttributeXPath->query("//newattribute/is_searchable")->item(0)->nodeValue), "is_information_collector" => trim($newAttributeXPath->query("//newattribute/is_information_collector")->item(0)->nodeValue), "datatypestring" => trim($newAttributeXPath->query("//newattribute/datatypestring")->item(0)->nodeValue), "content" => trim($newAttributeXPath->query("//newattribute/content")->item(0)->nodeValue));
     // create new attribute
     $attributeCreationInfo = array("identifier" => $xmlValues["identifier"], "serialized_name_list" => serialize(array($xmlValues["language"] => $xmlValues["display_name"], "always-available" => $xmlValues["language"])), "description" => $xmlValues["description"], "can_translate" => $xmlValues["can_translate"], "is_required" => $xmlValues["is_required"], "is_searchable" => $xmlValues["is_searchable"], "is_information_collector" => $xmlValues["is_information_collector"]);
     $newAttribute = eZContentClassAttribute::create($classID, $xmlValues["datatypestring"], $attributeCreationInfo);
     $dataType = $newAttribute->dataType();
     if (!$dataType) {
         throw new Exception("Unknown datatype: [ " . $datatype . " ]");
     }
     $dataType->initializeClassAttribute($newAttribute);
     $newAttribute->store();
     AttributeFunctions::updateParameters($newAttribute, $newAttributeXPath);
     $newAttribute->sync();
     $content = $xmlValues["content"];
     if ("eep-no-content" != $content) {
         $newAttribute->setContent($content);
     }
     // store attribute, update placement, etc...
     $allAttributesList = $contentClass->fetchAttributes();
     $allAttributesList[] = $newAttribute;
     // remove temporary version
     if ($newAttribute->attribute("id") !== null) {
         $newAttribute->remove();
     }
     $newAttribute->setAttribute("version", eZContentClass::VERSION_STATUS_DEFINED);
     $newAttribute->setAttribute("placement", count($allAttributesList));
     $contentClass->adjustAttributePlacements($allAttributesList);
     foreach ($allAttributesList as $attribute) {
         $attribute->storeDefined();
     }
     $classAttributeID = $newAttribute->attribute("id");
     echo "\n\nAttribute with ID " . $classAttributeID . " added\n\n";
     return $classAttributeID;
 }