本文整理汇总了PHP中eZContentClass::create方法的典型用法代码示例。如果您正苦于以下问题:PHP eZContentClass::create方法的具体用法?PHP eZContentClass::create怎么用?PHP eZContentClass::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZContentClass
的用法示例。
在下文中一共展示了eZContentClass::create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMultipleCallsToCalculatedPrice
/**
* 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);
}
示例2: __construct
/**
* 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();
}
示例3: install
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 {
//.........这里部分代码省略.........
示例4: array
}
} 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);
示例5: execute
//.........这里部分代码省略.........
}
$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;
}
}
}
示例6: createClass
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();
}
示例7: createNew
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;
}