/** * Test scenario for issue #13712: Multiprice datatype shows wrong price after multiple calls in template * * Test Outline * ------------ * 1. Create a euro currency * 2. Create a VAT type of 10 % * 3. Create a content class with an attribute of the datatype ezmultiprice * 4. Create a content object of this content class and set a custom price ex. VAT with the VAT type of 10% that we created * 5. Subsequently retrieve the attribute 'inc_vat_price_list' * * @result: the returned eZMultiPriceData instances differ on each call, their values are increased each time with VAT * @expected: the returned eZMultiPriceData instances are equal * @link http://issues.ez.no/13712 * @group issue_13712 */ public function testMultipleCallsToCalculatedPrice() { $currencyCode = 'EUR'; // create currency $currencyParams = array('code' => $currencyCode, 'symbol' => false, 'locale' => 'eng-GB', 'custom_rate_value' => 0, 'rate_factor' => 1); $currency = eZCurrencyData::create($currencyCode, '€', 'eng-GB', 0, 0, 1); $currency->store(); $currencyID = $currency->attribute('id'); $this->assertInternalType('integer', $currencyID); // create VAT type $row = array('name' => 'Test', 'percentage' => 10.0); $vatType = new eZVatType($row); $vatType->store(); $vatTypeID = $vatType->attribute('id'); $this->assertInternalType('integer', $vatTypeID); $class = eZContentClass::create(false, array('name' => 'eZMultiPrice::testMultipleCallsToCalculatedPrice', 'identifier' => 'ezmultiprice_test')); $class->store(); $classID = $class->attribute('id'); $this->assertInternalType('integer', $classID); $attributes = $class->fetchAttributes(); // add class attributes $newAttribute = eZContentClassAttribute::create($classID, 'ezmultiprice', array('name' => 'Test', 'identifier' => 'test')); $dataType = $newAttribute->dataType(); $dataType->initializeClassAttribute($newAttribute); $newAttribute->setAttribute(eZMultiPriceType::DEFAULT_CURRENCY_CODE_FIELD, $currencyCode); $newAttribute->setAttribute(eZMultiPriceType::VAT_ID_FIELD, $vatTypeID); $newAttribute->store(); $attributes[] = $newAttribute; $class->storeDefined($attributes); $contentObject = $class->instantiate(); $version = $contentObject->currentVersion(); $dataMap = $version->dataMap(); $multiPrice = $dataMap['test']->content(); $multiPrice->setAttribute('selected_vat_type', $vatTypeID); $multiPrice->setAttribute('is_vat_included', eZMultiPriceType::EXCLUDED_VAT); $multiPrice->setCustomPrice($currencyCode, 100); $multiPrice->updateAutoPriceList(); $dataMap['test']->setContent($multiPrice); $dataMap['test']->setAttribute('data_text', $vatTypeID . ',' . eZMultiPriceType::EXCLUDED_VAT); $dataMap['test']->store(); // test values $firstIncVatPriceList = $multiPrice->attribute('inc_vat_price_list'); $this->assertArrayHasKey('EUR', $firstIncVatPriceList); $firstCallValue = $firstIncVatPriceList['EUR']->attribute('value'); $secondIncVatPriceList = $multiPrice->attribute('inc_vat_price_list'); $this->assertArrayHasKey('EUR', $secondIncVatPriceList); $secondCallValue = $secondIncVatPriceList['EUR']->attribute('value'); $this->assertEquals($firstCallValue, $secondCallValue); $thirdIncVatPriceList = $multiPrice->attribute('inc_vat_price_list'); $this->assertArrayHasKey('EUR', $thirdIncVatPriceList); $thirdCallValue = $thirdIncVatPriceList['EUR']->attribute('value'); $this->assertEquals($firstCallValue, $thirdCallValue); }
/** * Initialize ezpClass object * * @param string $name * @param string $identifier * @param string $contentObjectName * @param int $creatorID * @param string $language * @param int $groupID * @param string $groupName */ public function __construct($name = 'Test class', $identifier = 'test_class', $contentObjectName = '<test_attribute>', $creatorID = 14, $language = 'eng-GB', $groupID = 1, $groupName = 'Content') { if (eZContentLanguage::fetchByLocale($language) === false) { $topPriorityLanguage = eZContentLanguage::topPriorityLanguage(); if ($topPriorityLanguage) { $language = $topPriorityLanguage->attribute('locale'); } } $this->language = $language; $this->class = eZContentClass::create($creatorID, array(), $this->language); $this->class->setName($name, $this->language); $this->class->setAttribute('contentobject_name', $contentObjectName); $this->class->setAttribute('identifier', $identifier); $this->class->store(); $languageID = eZContentLanguage::idByLocale($this->language); $this->class->setAlwaysAvailableLanguageID($languageID); $this->classGroup = eZContentClassClassGroup::create($this->id, $this->version, $groupID, $groupName); $this->classGroup->store(); }
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; }
} } else { if (!$EditLanguage) { $language = eZContentLanguage::topPriorityLanguage(); if ($language) { $EditLanguage = $language->attribute('locale'); } else { eZDebug::writeError('Undefined default language', 'class/edit.php'); $Module->setExitStatus(eZModule::STATUS_FAILED); return; } } if (is_numeric($GroupID) and is_string($GroupName) and $GroupName != '') { $user = eZUser::currentUser(); $user_id = $user->attribute('contentobject_id'); $class = eZContentClass::create($user_id, array(), $EditLanguage); $class->setName(ezpI18n::tr('kernel/class/edit', 'New Class'), $EditLanguage); $class->store(); $editLanguageID = eZContentLanguage::idByLocale($EditLanguage); $class->setAlwaysAvailableLanguageID($editLanguageID); $ClassID = $class->attribute('id'); $ClassVersion = $class->attribute('version'); $ingroup = eZContentClassClassGroup::create($ClassID, $ClassVersion, $GroupID, $GroupName); $ingroup->store(); $Module->redirectTo($Module->functionURI('edit') . '/' . $ClassID . '/(language)/' . $EditLanguage); return; } else { $errorResponseGroupName = $GroupName == '' ? '<Empty name>' : $GroupName; $errorResponseGroupID = !is_numeric($GroupID) ? '<Empty ID>' : $GroupID; eZDebug::writeError("Unknown class group: {$errorResponseGroupName} (ID: {$errorResponseGroupID})", 'Kernel - Class - Edit'); $Module->setExitStatus(eZModule::STATUS_FAILED);
function execute($xml) { $classList = $xml->getElementsByTagName('ContentClass'); $refArray = array(); $availableLanguageList = eZContentLanguage::fetchLocaleList(); foreach ($classList as $class) { $this->adjustAttributesPlacement = false; $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); $classIdentifier = $class->getAttribute('identifier'); $classRemoteID = $class->getAttribute('remoteID'); $classObjectNamePattern = $class->getAttribute('objectNamePattern'); $classExistAction = $class->getAttribute('classExistAction'); $referenceID = $class->getAttribute('referenceID'); $this->writeMessage("\tClass '{$classIdentifier}' will be updated.", 'notice'); $classURLAliasPattern = $class->getAttribute('urlAliasPattern') ? $class->getAttribute('urlAliasPattern') : null; $classIsContainer = $class->getAttribute('isContainer'); if ($classIsContainer !== false) { $classIsContainer = $classIsContainer == 'true' ? 1 : 0; } $classGroupsNode = $class->getElementsByTagName('Groups')->item(0); $classAttributesNode = $class->getElementsByTagName('Attributes')->item(0); $nameList = array(); $nameListObject = $class->getElementsByTagName('Names')->item(0); if ($nameListObject && $nameListObject->parentNode === $class && $nameListObject->hasAttributes()) { $attributes = $nameListObject->attributes; if (!is_null($attributes)) { foreach ($attributes as $index => $attr) { if (in_array($attr->name, $availableLanguageList)) { $nameList[$attr->name] = $attr->value; } } } } if (!empty($nameList)) { $classNameList = new eZContentClassNameList(serialize($nameList)); $classNameList->validate(); } else { $classNameList = null; } $dateTime = time(); $classCreated = $dateTime; $classModified = $dateTime; $class = eZContentClass::fetchByRemoteID($classRemoteID); if (!$class) { $class = eZContentClass::fetchByIdentifier($classIdentifier); } if ($class) { $className = $class->name(); switch ($classExistAction) { case 'replace': $this->writeMessage("\t\tClass '{$classIdentifier}' will be replaced.", 'notice'); foreach ($nameList as $lang => $name) { if (in_array($lang, $availableLanguageList)) { $class->setName($name, $lang); } } $class->setAttribute('contentobject_name', $classObjectNamePattern); $class->setAttribute('identifier', $classIdentifier); $class->setAttribute('is_container', $classIsContainer); $class->setAttribute('url_alias_name', $classURLAliasPattern); $class->store(); $class->removeAttributes(); break; case 'new': unset($class); $class = false; break; break; case 'extend': $this->writeMessage("\t\tClass '{$classIdentifier}' will be extended.", 'notice'); foreach ($nameList as $lang => $name) { if (in_array($lang, $availableLanguageList)) { $class->setName($name, $lang); } } $class->setAttribute('contentobject_name', $classObjectNamePattern); $class->setAttribute('identifier', $classIdentifier); $class->setAttribute('is_container', $classIsContainer); $class->setAttribute('url_alias_name', $classURLAliasPattern); $class->store(); break; case 'skip': default: continue; break; } } if (!$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; // create class $class = eZContentClass::create($userID, array('version' => 1, 'serialized_name_list' => $classNameList->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)); $class->store(); $attributes = $class->fetchAttributes(); $class->storeDefined($attributes); $classID = $class->attribute('id'); $this->writeMessage("\t\tClass '{$classIdentifier}' will be newly created.", 'notice'); } // create class attributes $classAttributeList = $classAttributesNode->getElementsByTagName('Attribute'); $classDataMap = $class->attribute('data_map'); $updateAttributeList = array(); if ($classDataMap == NULL) { $classDataMap = array(); } foreach ($classAttributeList as $classAttributeNode) { $attributeDatatype = $classAttributeNode->getAttribute('datatype'); $attributeIsRequired = strtolower($classAttributeNode->getAttribute('required')) == 'true'; $attributeIsSearchable = strtolower($classAttributeNode->getAttribute('searchable')) == 'true'; $attributeIsInformationCollector = strtolower($classAttributeNode->getAttribute('informationCollector')) == 'true'; $attributeIsTranslatable = strtolower($classAttributeNode->getAttribute('translatable')) == 'false' ? 0 : 1; $attributeIdentifier = $classAttributeNode->getAttribute('identifier'); $attributePlacement = $classAttributeNode->getAttribute('placement'); $attributeNameListObject = $classAttributeNode->getElementsByTagName('Names')->item(0); if ($attributeNameListObject->hasAttributes()) { if ($attributeNameListObject->hasAttributes()) { $attributes = $attributeNameListObject->attributes; if (!is_null($attributes)) { $attributeNameList = array(); foreach ($attributes as $index => $attr) { $attributeNameList[$attr->name] = $attr->value; } } } } $classAttributeNameList = new eZContentClassNameList(serialize($attributeNameList)); $classAttributeNameList->validate(); $attributeDatatypeParameterNode = $classAttributeNode->getElementsByTagName('DatatypeParameters')->item(0); $classAttribute = $class->fetchAttributeByIdentifier($attributeIdentifier); $params = array(); $params['identifier'] = $attributeIdentifier; $params['name_list'] = $classAttributeNameList; $params['data_type_string'] = $attributeDatatype; $params['default_value'] = ''; $params['can_translate'] = $attributeIsTranslatable; $params['is_required'] = $attributeIsRequired; $params['is_searchable'] = $attributeIsSearchable; $params['content'] = ''; $params['placement'] = $attributePlacement; $params['is_information_collector'] = $attributeIsInformationCollector; $params['datatype-parameter'] = $this->parseAndReplaceNodeStringReferences($attributeDatatypeParameterNode); $params['attribute-node'] = $classAttributeNode; if (!array_key_exists($attributeIdentifier, $classDataMap)) { $this->writeMessage("\t\tClass '{$classIdentifier}' will get new Attribute '{$attributeIdentifier}'.", 'notice'); $updateAttributeList[] = $this->addClassAttribute($class, $params); } else { $this->writeMessage("\t\tClass '{$classIdentifier}' will get updated Attribute '{$attributeIdentifier}'.", 'notice'); $this->updateClassAttribute($class, $params); } } if ($this->adjustAttributesPlacement) { //once every attribute has been processed, we may reset placement $this->writeMessage("\t\tAdjusting attributes placement.", 'notice'); $this->adjustClassAttributesPlacement($class); } if (count($updateAttributeList)) { $this->writeMessage("\t\tUpdating content object attributes.", 'notice'); $classID = $class->attribute('id'); // update object attributes $objects = eZContentObject::fetchSameClassList($classID, false); foreach ($objects as $objectID) { $object = eZContentObject::fetch($objectID['id']); if ($object) { $contentobjectID = $object->attribute('id'); $objectVersions = $object->versions(); foreach ($objectVersions as $objectVersion) { $translations = $objectVersion->translations(false); $version = $objectVersion->attribute('version'); foreach ($translations as $translation) { foreach ($updateAttributeList as $classAttributeID) { $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentobjectID, $version); $objectAttribute->setAttribute('language_code', $translation); $objectAttribute->initialize(); $objectAttribute->store(); $objectAttribute->postInitialize(); } } } } unset($object); } } if ($classNameList) { $classNameList->store($class); } // 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); } if ($referenceID) { $refArray[$referenceID] = $class->attribute('id'); } } $this->addReference($refArray); eZContentCacheManager::clearAllContentCache(); }
private function createClass($displayName, $classIdentifier, $groupIdentifier, $groupId) { $adminUserObject = eZUser::fetchByName("admin"); $adminUserObject->loginCurrent(); $adminUserId = $adminUserObject->attribute('contentobject_id'); $language = eZContentLanguage::topPriorityLanguage(); $editLanguage = $language->attribute('locale'); $class = eZContentClass::create($adminUserId, array(), $editLanguage); // this is the display name, ez automatically creates the content-class-identifier from it $class->setName($displayName, $editLanguage); $class->setAttribute("identifier", $classIdentifier); // default naming for objects - content classes should update this value once they have attributes added $class->setAttribute('contentobject_name', 'eep-created-content-class'); $class->store(); $editLanguageID = eZContentLanguage::idByLocale($editLanguage); $class->setAlwaysAvailableLanguageID($editLanguageID); $ClassID = $class->attribute('id'); $ClassVersion = $class->attribute('version'); $ingroup = eZContentClassClassGroup::create($ClassID, $ClassVersion, $groupId, $groupIdentifier); $ingroup->store(); // clean up the content class status $class->storeDefined(array()); $adminUserObject->logoutCurrent(); }
protected function createNew($identifier) { $remote = self::fetchRemoteByIdentifier($identifier); if ($remote === null) { throw new Exception("Classe remota non trovata"); } $this->syncAllGroups($remote); $classGroup = false; foreach ($remote->InGroups as $group) { $classGroup = eZContentClassGroup::fetchByName($group->GroupName); if ($classGroup instanceof eZContentClassGroup) { break; } } if (!$classGroup instanceof eZContentClassGroup) { throw new Exception('Errore creando la nuova classe'); } $db = eZDB::instance(); $db->begin(); $options = array('serialized_name_list' => $remote->SerializedNameList, 'serialized_description_list' => $remote->SerializedDescriptionList); $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); $class = eZContentClass::create($userID, $options, $this->EditLanguage); $class->setName('New automatic', $this->EditLanguage); $class->store(); $editLanguageID = eZContentLanguage::idByLocale($this->EditLanguage); $class->setAlwaysAvailableLanguageID($editLanguageID); $ClassID = $class->attribute('id'); $ClassVersion = $class->attribute('version'); $ingroup = eZContentClassClassGroup::create($ClassID, $ClassVersion, $classGroup->attribute('id'), $classGroup->attribute('name')); $ingroup->store(); $class->setAttribute('identifier', $identifier); foreach ($this->properties as $identifier => $remoteProperty) { $class->setAttribute($identifier, $remote->{$remoteProperty}); } $class->storeVersioned(array(), eZContentClass::VERSION_STATUS_DEFINED); $db->commit(); return $class; }