static function descriptionFromSerializedString($serializedDescriptionList) { return eZSerializedObjectNameList::nameFromSerializedString($serializedNameList); }
function install($package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData) { $serializedNameListNode = $content->getElementsByTagName('serialized-name-list')->item(0); $serializedNameList = $serializedNameListNode ? $serializedNameListNode->textContent : false; $classNameList = new eZContentClassNameList($serializedNameList); if ($classNameList->isEmpty()) { $classNameList->initFromString($content->getElementsByTagName('name')->item(0)->textContent); // for backward compatibility( <= 3.8 ) } $classNameList->validate(); $serializedDescriptionListNode = $content->getElementsByTagName('serialized-description-list')->item(0); $serializedDescriptionList = $serializedDescriptionListNode ? $serializedDescriptionListNode->textContent : false; $classDescriptionList = new eZSerializedObjectNameList($serializedDescriptionList); $classIdentifier = $content->getElementsByTagName('identifier')->item(0)->textContent; $classRemoteID = $content->getElementsByTagName('remote-id')->item(0)->textContent; $classObjectNamePattern = $content->getElementsByTagName('object-name-pattern')->item(0)->textContent; $classURLAliasPattern = is_object($content->getElementsByTagName('url-alias-pattern')->item(0)) ? $content->getElementsByTagName('url-alias-pattern')->item(0)->textContent : null; $classIsContainer = $content->getAttribute('is-container'); if ($classIsContainer !== false) { $classIsContainer = $classIsContainer == 'true' ? 1 : 0; } $classRemoteNode = $content->getElementsByTagName('remote')->item(0); $classID = $classRemoteNode->getElementsByTagName('id')->item(0)->textContent; $classGroupsNode = $classRemoteNode->getElementsByTagName('groups')->item(0); $classCreated = $classRemoteNode->getElementsByTagName('created')->item(0)->textContent; $classModified = $classRemoteNode->getElementsByTagName('modified')->item(0)->textContent; $classCreatorNode = $classRemoteNode->getElementsByTagName('creator')->item(0); $classModifierNode = $classRemoteNode->getElementsByTagName('modifier')->item(0); $classAttributesNode = $content->getElementsByTagName('attributes')->item(0); $dateTime = time(); $classCreated = $dateTime; $classModified = $dateTime; $userID = false; if (isset($installParameters['user_id'])) { $userID = $installParameters['user_id']; } $class = eZContentClass::fetchByRemoteID($classRemoteID); if ($class) { $className = $class->name(); $description = ezpI18n::tr('kernel/package', "Class '%classname' already exists.", false, array('%classname' => $className)); $choosenAction = $this->errorChoosenAction(self::ERROR_EXISTS, $installParameters, $description, $this->HandlerType); switch ($choosenAction) { case eZPackage::NON_INTERACTIVE: case self::ACTION_REPLACE: if (eZContentClassOperations::remove($class->attribute('id')) == false) { eZDebug::writeWarning("Unable to remove class '{$className}'."); return true; } eZDebug::writeNotice("Class '{$className}' will be replaced.", 'eZContentClassPackageHandler'); break; case self::ACTION_SKIP: return true; case self::ACTION_NEW: $class->setAttribute('remote_id', eZRemoteIdUtility::generate('class')); $class->store(); $classNameList->appendGroupName(" (imported)"); break; default: $installParameters['error'] = array('error_code' => self::ERROR_EXISTS, 'element_id' => $classRemoteID, 'description' => $description, 'actions' => array()); if ($class->isRemovable()) { $errorMsg = ezpI18n::tr('kernel/package', "Replace existing class"); $objectsCount = eZContentObject::fetchSameClassListCount($class->attribute('id')); if ($objectsCount) { $errorMsg .= ' ' . ezpI18n::tr('kernel/package', "(Warning! {$objectsCount} content object(s) and their sub-items will be removed)"); } $installParameters['error']['actions'][self::ACTION_REPLACE] = $errorMsg; } $installParameters['error']['actions'][self::ACTION_SKIP] = ezpI18n::tr('kernel/package', 'Skip installing this class'); $installParameters['error']['actions'][self::ACTION_NEW] = ezpI18n::tr('kernel/package', 'Keep existing and create a new one'); return false; } } unset($class); // Try to create a unique class identifier $currentClassIdentifier = $classIdentifier; $unique = false; while (!$unique) { $classList = eZContentClass::fetchByIdentifier($currentClassIdentifier); if ($classList) { // "increment" class identifier if (preg_match('/^(.*)_(\\d+)$/', $currentClassIdentifier, $matches)) { $currentClassIdentifier = $matches[1] . '_' . ($matches[2] + 1); } else { $currentClassIdentifier = $currentClassIdentifier . '_1'; } } else { $unique = true; } unset($classList); } $classIdentifier = $currentClassIdentifier; $values = array('version' => 0, 'serialized_name_list' => $classNameList->serializeNames(), 'serialized_description_list' => $classDescriptionList->serializeNames(), 'create_lang_if_not_exist' => true, 'identifier' => $classIdentifier, 'remote_id' => $classRemoteID, 'contentobject_name' => $classObjectNamePattern, 'url_alias_name' => $classURLAliasPattern, 'is_container' => $classIsContainer, 'created' => $classCreated, 'modified' => $classModified); if ($content->hasAttribute('sort-field')) { $values['sort_field'] = eZContentObjectTreeNode::sortFieldID($content->getAttribute('sort-field')); } else { eZDebug::writeNotice('The sort field was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__); } if ($content->hasAttribute('sort-order')) { $values['sort_order'] = $content->getAttribute('sort-order'); } else { eZDebug::writeNotice('The sort order was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__); } if ($content->hasAttribute('always-available')) { $values['always_available'] = $content->getAttribute('always-available') === 'true' ? 1 : 0; } else { eZDebug::writeNotice('The default object availability was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__); } // create class $class = eZContentClass::create($userID, $values); $class->store(); $classID = $class->attribute('id'); if (!isset($installData['classid_list'])) { $installData['classid_list'] = array(); } if (!isset($installData['classid_map'])) { $installData['classid_map'] = array(); } $installData['classid_list'][] = $class->attribute('id'); $installData['classid_map'][$classID] = $class->attribute('id'); // create class attributes $classAttributeList = $classAttributesNode->getElementsByTagName('attribute'); foreach ($classAttributeList as $classAttributeNode) { $isNotSupported = strtolower($classAttributeNode->getAttribute('unsupported')) == 'true'; if ($isNotSupported) { continue; } $attributeDatatype = $classAttributeNode->getAttribute('datatype'); $attributeIsRequired = strtolower($classAttributeNode->getAttribute('required')) == 'true'; $attributeIsSearchable = strtolower($classAttributeNode->getAttribute('searchable')) == 'true'; $attributeIsInformationCollector = strtolower($classAttributeNode->getAttribute('information-collector')) == 'true'; $attributeIsTranslatable = strtolower($classAttributeNode->getAttribute('translatable')) == 'true'; $attributeSerializedNameListNode = $classAttributeNode->getElementsByTagName('serialized-name-list')->item(0); $attributeSerializedNameListContent = $attributeSerializedNameListNode ? $attributeSerializedNameListNode->textContent : false; $attributeSerializedNameList = new eZSerializedObjectNameList($attributeSerializedNameListContent); if ($attributeSerializedNameList->isEmpty()) { $attributeSerializedNameList->initFromString($classAttributeNode->getElementsByTagName('name')->item(0)->textContent); } // for backward compatibility( <= 3.8 ) $attributeSerializedNameList->validate(); $attributeSerializedDescriptionListNode = $classAttributeNode->getElementsByTagName('serialized-description-list')->item(0); $attributeSerializedDescriptionListContent = $attributeSerializedDescriptionListNode ? $attributeSerializedDescriptionListNode->textContent : false; $attributeSerializedDescriptionList = new eZSerializedObjectNameList($attributeSerializedDescriptionListContent); $attributeCategoryNode = $classAttributeNode->getElementsByTagName('category')->item(0); $attributeCategory = $attributeCategoryNode ? $attributeCategoryNode->textContent : ''; $attributeSerializedDataTextNode = $classAttributeNode->getElementsByTagName('serialized-description-text')->item(0); $attributeSerializedDataTextContent = $attributeSerializedDataTextNode ? $attributeSerializedDataTextNode->textContent : false; $attributeSerializedDataText = new eZSerializedObjectNameList($attributeSerializedDataTextContent); $attributeIdentifier = $classAttributeNode->getElementsByTagName('identifier')->item(0)->textContent; $attributePlacement = $classAttributeNode->getElementsByTagName('placement')->item(0)->textContent; $attributeDatatypeParameterNode = $classAttributeNode->getElementsByTagName('datatype-parameters')->item(0); $classAttribute = $class->fetchAttributeByIdentifier($attributeIdentifier); if (!$classAttribute) { $classAttribute = eZContentClassAttribute::create($class->attribute('id'), $attributeDatatype, array('version' => 0, 'identifier' => $attributeIdentifier, 'serialized_name_list' => $attributeSerializedNameList->serializeNames(), 'serialized_description_list' => $attributeSerializedDescriptionList->serializeNames(), 'category' => $attributeCategory, 'serialized_data_text' => $attributeSerializedDataText->serializeNames(), 'is_required' => $attributeIsRequired, 'is_searchable' => $attributeIsSearchable, 'is_information_collector' => $attributeIsInformationCollector, 'can_translate' => $attributeIsTranslatable, 'placement' => $attributePlacement)); $dataType = $classAttribute->dataType(); $classAttribute->store(); $dataType->unserializeContentClassAttribute($classAttribute, $classAttributeNode, $attributeDatatypeParameterNode); $classAttribute->sync(); } } // add class to a class group $classGroupsList = $classGroupsNode->getElementsByTagName('group'); foreach ($classGroupsList as $classGroupNode) { $classGroupName = $classGroupNode->getAttribute('name'); $classGroup = eZContentClassGroup::fetchByName($classGroupName); if (!$classGroup) { $classGroup = eZContentClassGroup::create(); $classGroup->setAttribute('name', $classGroupName); $classGroup->store(); } $classGroup->appendClass($class); } return true; }
function eZContentClassNameList($serializedNameList = false) { eZSerializedObjectNameList::eZSerializedObjectNameList($serializedNameList); }
function contentClassAttributeName() { $db = eZDB::instance(); $nameArray = $db->arrayQuery( "SELECT serialized_name_list FROM ezcontentclass_attribute WHERE id='$this->ContentClassAttributeID'" ); return eZSerializedObjectNameList::nameFromSerializedString( $nameArray[0]['serialized_name_list'] ); }
/** * Returns name from serialized string, can be used for serialized description and data_text as well. * * @param string $serializedNameList * @param string|false $languageLocale Uses AlwaysAvailable language if false * @return string */ static function nameFromSerializedString( $serializedNameList, $languageLocale = false ) { return eZSerializedObjectNameList::nameFromSerializedString( $serializedNameList, $languageLocale ); }
/** * Create NameList element. * * @param DOMDocument Owner DOMDocument * @param eZSerializedObjectNameList eZSerializedObjectNameList object. * * @return DOMElement NameList DOMDocument, example: * * <NameList> * <Name locale="eng-GB">eZ Publish rocks</Name> * </NameList> */ protected function createNameListDOMElement(DOMDocument $domDocument, eZSerializedObjectNameList $nameList) { $languageListElement = $domDocument->createElement('NameList'); // Add language names. foreach ($nameList->languageLocaleList() as $locale) { $languageElement = $domDocument->createElement('Name'); $languageElement->setAttribute('locale', $locale); $languageElement->appendChild($domDocument->createTextNode($nameList->nameByLanguageLocale($locale))); $languageListElement->appendChild($languageElement); } return $languageListElement; }
static function nameFromSerializedString($serializedNames, $languageLocale = false) { $nameList = new eZSerializedObjectNameList($serializedNames); return $nameList->name($languageLocale); }
function serializeNames($selectSQL, $storeToTable) { $db = eZDB::instance(); $limit = 100; $offset = 0; //$selectSQL .= "\nLIMIT $limit"; while ($result = $db->arrayQuery($selectSQL, array('limit' => $limit, 'offset' => $offset))) { // since name data is splitted between rows, // need to adjust selected data: // exclude the last id/version and process it during next 'select' iteration // 1. get last id/version pair $lastIdx = count($result) - 1; if ($lastIdx > 0) { $lastID = $result[$lastIdx]['id']; $lastVersion = $result[$lastIdx]['version']; // 2. check remained data for ($lastIdx = $lastIdx - 1; $lastIdx >= 0; $lastIdx--) { $row = $result[$lastIdx]; if ($lastID != $row['id'] || $lastVersion != $row['version']) { break; } } // 3. check whether $lastIdx is valid if ($lastIdx < 0) { // all selected data belongs to the same id/version $lastIdx = count($result) - 1; } } // 4. adjust offset to include excluded data to the next 'select' $offset += $lastIdx + 1; // process selected data $serializedName = false; $prevId = false; $prevVersion = false; for ($idx = 0; $idx <= $lastIdx; $idx++) { if (!isset($result[$idx])) { continue; } $row = $result[$idx]; // check whether serialized name is completely assembled if ($prevId != $row['id'] || $prevVersion != $row['version']) { if ($serializedName !== false) { // store serialized name storeSerializedName($serializedName, $prevId, $prevVersion, $storeToTable); } // create new $serializedName to collect data $serializedName = new eZSerializedObjectNameList(); $serializedName->resetNameList(); } $prevId = $row['id']; $prevVersion = $row['version']; $serializedName->setNameByLanguageLocale($row['name'], $row['language_locale']); if ($row['is_always_available'] & 1) { $serializedName->setAlwaysAvailableLanguage($row['language_locale']); } if ($idx == $lastIdx) { // no more date => store serialized name storeSerializedName($serializedName, $prevId, $prevVersion, $storeToTable); } } } }
protected function syncAttribute($originalAttribute, $localeAttribute) { if ($localeAttribute instanceof eZContentClassAttribute) { if (array_key_exists($originalAttribute->Identifier, $this->notifications[self::ERROR])) { return $localeAttribute; } $isModified = false; ezpEvent::getInstance()->notify('classtools/pre_sync_class_attribute', array($localeAttribute, $originalAttribute)); foreach ($this->fields as $localeIdentifier => $remoteProperty) { if ($localeAttribute->attribute($localeIdentifier) != $originalAttribute->{$remoteProperty}) { $localeAttribute->setAttribute($localeIdentifier, $originalAttribute->{$remoteProperty}); if ($localeIdentifier == 'serialized_name_list') { $nameList = new eZSerializedObjectNameList(); $nameList->initFromSerializedList($originalAttribute->SerializedNameList); $localeAttribute->NameList = $nameList; } elseif ($localeIdentifier == 'serialized_description_list') { $descriptionList = new eZSerializedObjectNameList(); $descriptionList->initFromSerializedList($originalAttribute->SerializedDescriptionList); $localeAttribute->DescriptionList = $descriptionList; } $isModified = true; } } $localeAttribute->store(); ezpEvent::getInstance()->notify('classtools/post_sync_class_attribute', array($localeAttribute, $originalAttribute, $isModified)); return $localeAttribute; } return false; }
function __construct($serializedNameList = false) { parent::__construct($serializedNameList); }
public static function parseClassesDefinition(DOMDocument $dom, array $options = null) { $classes = array(); $classNodes = $dom->getElementsByTagName('content-class'); foreach ($classNodes as $classNode) { $serializedNameListNode = $classNode->getElementsByTagName('serialized-name-list')->item(0); $serializedNameList = $serializedNameListNode ? $serializedNameListNode->textContent : false; $classNameList = new eZContentClassNameList($serializedNameList); $classNameList->validate(); $class = array('name' => $classNameList->name(), 'identifier' => $classNode->getElementsByTagName('identifier')->item(0)->textContent, 'object_name_patter' => is_object($classNode->getElementsByTagName('object-name-pattern')->item(0)) ? $classNode->getElementsByTagName('object-name-pattern')->item(0)->textContent : null, 'is_container' => $classNode->getAttribute('is-container') == 'true', 'attributes' => array()); $classAttributesNode = $classNode->getElementsByTagName('attributes')->item(0); $classAttributeList = $classAttributesNode->getElementsByTagName('attribute'); foreach ($classAttributeList as $classAttributeNode) { $attributeSerializedNameListNode = $classAttributeNode->getElementsByTagName('serialized-name-list')->item(0); $attributeSerializedNameListContent = $attributeSerializedNameListNode ? $attributeSerializedNameListNode->textContent : false; $attributeSerializedNameList = new eZSerializedObjectNameList($attributeSerializedNameListContent); $attributeSerializedNameList->validate(); $datatypeParameters = array(); $datatypeParameterNodes = $classAttributeNode->getElementsByTagName('datatype-parameters')->item(0)->childNodes; if ($datatypeParameterNodes->length > 0) { // set default value for default-placement parameter for object relation list datatype if ($classAttributeNode->getAttribute('datatype') == 'ezobjectrelationlist') { $datatypeParameters['default-placement'] = ''; } foreach ($datatypeParameterNodes as $datatypeParameterNode) { if ($datatypeParameterNode instanceof DOMText) { $value = trim($datatypeParameterNode->textContent); if (strlen($value) > 0) { $datatypeParameters[] = $datatypeParameterNode->textContent; } } else { if ($datatypeParameterNode->tagName == 'class-constraints') { $tmp = array(); $classIdentifiers = $classAttributeNode->getElementsByTagName('class-constraint'); foreach ($classIdentifiers as $classIdentifier) { if ($classIdentifier->hasAttribute('class-identifier')) { $tmp[] = $classIdentifier->getAttribute('class-identifier'); } } asort($tmp); $value = implode(',', $tmp); } elseif ($datatypeParameterNode->tagName == 'options') { $tmp = array(); $optionValues = $classAttributeNode->getElementsByTagName('option'); foreach ($optionValues as $option) { if ($option->hasAttribute('id')) { $tmp[] = $option->getAttribute('id') . ':' . $option->getAttribute('name'); } } asort($tmp); $value = implode(',', $tmp); } else { $value = trim($datatypeParameterNode->textContent); } $datatypeParameters[$datatypeParameterNode->tagName] = $value; } } } $attribute = array('name' => $attributeSerializedNameList->name(), 'identifier' => $classAttributeNode->getElementsByTagName('identifier')->item(0)->textContent, 'placement' => $classAttributeNode->getElementsByTagName('placement')->item(0)->textContent, 'datatype' => $classAttributeNode->getAttribute('datatype'), 'required' => strtolower($classAttributeNode->getAttribute('required')) == 'true', 'searchable' => strtolower($classAttributeNode->getAttribute('searchable')) == 'true', 'information_collector' => strtolower($classAttributeNode->getAttribute('information-collector')) == 'true', 'translatable' => strtolower($classAttributeNode->getAttribute('translatable')) == 'true', 'datatype_parameters' => $datatypeParameters); if (is_array($options) && count($options) > 0) { foreach ($attribute as $key => $value) { if ($key == 'identifier') { continue; } if (isset($options[$key]) === false) { unset($attribute[$key]); } } } $class['attributes'][$attribute['identifier']] = $attribute; } ksort($class['attributes']); $classes[$class['identifier']] = $class; } return $classes; }