/**
  * #15898: Cannot translate a user content object
  * Make sure datatype translation flag is honored.
  *
  * @link http://issues.ez.no/15898
  */
 public function testAttributeIsTranslatable()
 {
     $stringAttribute = eZContentClassAttribute::create(0, 'ezstring');
     $this->assertEquals(1, $stringAttribute->attribute('can_translate'), 'ezstring class attribute should have been translatable by default');
     $stringAttribute = eZContentClassAttribute::create(0, 'ezuser');
     $this->assertEquals(0, $stringAttribute->attribute('can_translate'), 'ezuser class attribute should NOT have been translatable by default');
 }
Ejemplo n.º 2
0
 /**
  * Adds new content class attribute to initialized class.
  *
  * @param string $name
  * @param string $identifier
  * @param string $type
  * @return eZContentClassAttribute
  */
 public function add($name = 'Test attribute', $identifer = 'test_attribute', $type = 'ezstring')
 {
     $classAttribute = eZContentClassAttribute::create($this->id, $type, array(), $this->language);
     $classAttribute->setName($name, $this->language);
     $dataType = $classAttribute->dataType();
     $dataType->initializeClassAttribute($classAttribute);
     $classAttribute->setAttribute('identifier', $identifer);
     $classAttribute->store();
     return $classAttribute;
 }
 /**
  * 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);
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
    function addClassAttributes( $params )
    {
        $classInfo = $params['class'];
        $attributesInfo = $params['attributes'];

        $classID = isset( $classInfo['id'] ) ? $classInfo['id'] : false;
        if( $classID )
        {
            $class = eZContentClass::fetch( $classID );
        }
        else
        {
            if( isset( $classInfo['identifier'] ) )
            {
                $class = eZSiteInstaller::classByIdentifier( $classInfo );
            }
            else
            {
                $this->reportError( "neither 'id' nor 'identifier' is set for content class" ,
                                    'eZSiteInstaller::addClassAttribute' );
            }
        }

        if( !is_object( $class ) )
        {
            $this->reportError( "Can't fetch content class" ,
                                'eZSiteInstaller::addClassAttribute' );
            return;
        }

        $classID = $class->attribute( 'id' );

        foreach( $attributesInfo as $attributeInfo )
        {
            $classAttributeIdentifier = $attributeInfo['identifier'];
            $classAttributeName = $attributeInfo['name'];
            $datatype = $attributeInfo['data_type_string'];
            $defaultValue = isset( $attributeInfo['default_value'] ) ? $attributeInfo['default_value'] : false;
            $canTranslate = isset( $attributeInfo['can_translate'] ) ? $attributeInfo['can_translate'] : 1;
            $isRequired   = isset( $attributeInfo['is_required']   ) ? $attributeInfo['is_required'] : 0;
            $isSearchable = isset( $attributeInfo['is_searchable'] ) ? $attributeInfo['is_searchable'] : 0;
            $attrContent  = isset( $attributeInfo['content'] ) ? $attributeInfo['content'] : false;

            $attrCreateInfo = array( 'identifier' => $classAttributeIdentifier,
                                     'name' => $classAttributeName,
                                     'can_translate' => $canTranslate,
                                     'is_required' => $isRequired,
                                     'is_searchable' => $isSearchable );
            $newAttribute = eZContentClassAttribute::create( $classID, $datatype, $attrCreateInfo  );

            $dataType = $newAttribute->dataType();
            $dataType->initializeClassAttribute( $newAttribute );

            // not all datatype can have 'default_value'. do check here.
            if( $defaultValue !== false  )
            {
                switch( $datatype )
                {
                    case 'ezboolean':
                    {
                        $newAttribute->setAttribute( 'data_int3', $defaultValue );
                    }
                    break;

                    default:
                        break;
                }
            }

            if( $attrContent )
                $newAttribute->setContent( $attrContent );

            // store attribute, update placement, etc...
            $attributes = $class->fetchAttributes();
            $attributes[] = $newAttribute;

            // remove temporary version
            if ( $newAttribute->attribute( 'id' ) !== null )
            {
                $newAttribute->remove();
            }

            $newAttribute->setAttribute( 'version', eZContentClass::VERSION_STATUS_DEFINED );
            $newAttribute->setAttribute( 'placement', count( $attributes ) );

            $class->adjustAttributePlacements( $attributes );
            foreach( $attributes as $attribute )
            {
                $attribute->storeDefined();
            }

            // update objects
            $classAttributeID = $newAttribute->attribute( 'id' );
            $objects = eZContentObject::fetchSameClassList( $classID );
            foreach( $objects as $object )
            {
                $contentobjectID = $object->attribute( 'id' );
                $objectVersions = $object->versions();
                foreach( $objectVersions as $objectVersion )
                {
                    $translations = $objectVersion->translations( false );
                    $version = $objectVersion->attribute( 'version' );
                    foreach( $translations as $translation )
                    {
                        $objectAttribute = eZContentObjectAttribute::create( $classAttributeID, $contentobjectID, $version );
                        $objectAttribute->setAttribute( 'language_code', $translation );
                        $objectAttribute->initialize();
                        $objectAttribute->store();
                        $objectAttribute->postInitialize();
                    }
                }
            }
        }
    }
Ejemplo n.º 6
0
        } else {
            $unorderedParameters['ScheduledScriptID'] = 0;
            $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED);
        }
        $db->commit();
        $http->removeSessionVariable('ClassCanStoreTicket');
        ezpEvent::getInstance()->notify('content/class/cache', array($ClassID));
        return $Module->redirectToView('view', array($ClassID), $unorderedParameters);
    }
}
// Store changes
if ($canStore) {
    $class->store($attributes);
}
if ($http->hasPostVariable('NewButton')) {
    $newAttribute = eZContentClassAttribute::create($ClassID, $cur_datatype, array(), $EditLanguage);
    $attrcnt = count($attributes) + 1;
    $newAttribute->setName(ezpI18n::tr('kernel/class/edit', 'new attribute') . $attrcnt, $EditLanguage);
    $dataType = $newAttribute->dataType();
    $dataType->initializeClassAttribute($newAttribute);
    $newAttribute->store();
    $attributes[] = $newAttribute;
    $lastChangedID = $newAttribute->attribute('id');
} else {
    if ($http->hasPostVariable('MoveUp')) {
        $attribute = eZContentClassAttribute::fetch($http->postVariable('MoveUp'), true, eZContentClass::VERSION_STATUS_TEMPORARY, array('contentclass_id', 'version', 'placement'));
        $attribute->move(false);
        $Module->redirectTo($Module->functionURI('edit') . '/' . $ClassID . '/(language)/' . $EditLanguage);
        return;
    } else {
        if ($http->hasPostVariable('MoveDown')) {
Ejemplo n.º 7
0
 function addClassAttribute($class, $params)
 {
     $classID = $class->attribute('id');
     $classAttributeIdentifier = $params['identifier'];
     $classAttributeNameList = $params['name_list'];
     $datatype = $params['data_type_string'];
     $defaultValue = isset($params['default_value']) ? $params['default_value'] : false;
     $canTranslate = isset($params['can_translate']) ? $params['can_translate'] : 0;
     $isRequired = isset($params['is_required']) ? $params['is_required'] : 0;
     $isSearchable = isset($params['is_searchable']) ? $params['is_searchable'] : 0;
     $isCollector = isset($params['is_information_collector']) ? $params['is_information_collector'] : false;
     $attrContent = isset($params['content']) ? $params['content'] : false;
     $attrCreateInfo = array('identifier' => $classAttributeIdentifier, 'serialized_name_list' => $classAttributeNameList->serializeNames(), 'can_translate' => $canTranslate, 'is_required' => $isRequired, 'is_searchable' => $isSearchable, 'is_information_collector' => $isCollector);
     $newAttribute = eZContentClassAttribute::create($classID, $datatype, $attrCreateInfo);
     $dataType = $newAttribute->dataType();
     if (!$dataType) {
         $this->writeMessage("\t\tUnknown datatype: '{$datatype}'", 'error');
         return false;
     }
     $dataType->initializeClassAttribute($newAttribute);
     $newAttribute->store();
     $dataType->unserializeContentClassAttribute($newAttribute, $params['attribute-node'], $params['datatype-parameter']);
     $newAttribute->sync();
     if ($attrContent) {
         $newAttribute->setContent($attrContent);
     }
     // store attribute, update placement, etc...
     $attributes = $class->fetchAttributes();
     $attributes[] = $newAttribute;
     // remove temporary version
     if ($newAttribute->attribute('id') !== null) {
         $newAttribute->remove();
     }
     $newAttribute->setAttribute('version', eZContentClass::VERSION_STATUS_DEFINED);
     $placement = $params['placement'] ? intval($params['placement']) : count($attributes);
     $newAttribute->setAttribute('placement', $placement);
     $this->adjustAttributesPlacement = true;
     $newAttribute->storeDefined();
     $classAttributeID = $newAttribute->attribute('id');
     return $classAttributeID;
 }
Ejemplo n.º 8
0
 protected function addAttribute($originalAttribute)
 {
     $class = $this->currentClass;
     $localeAttributes = $class->fetchAttributes();
     $placement = count($localeAttributes);
     $allowedTypes = eZDataType::allowedTypes();
     if (!$class->fetchAttributeByIdentifier($originalAttribute->Identifier) && in_array($originalAttribute->DataTypeString, $allowedTypes)) {
         /** @var eZContentClassAttribute $localeAttribute */
         $localeAttribute = eZContentClassAttribute::create($class->attribute('id'), $originalAttribute->DataTypeString, array('version' => eZContentClass::VERSION_STATUS_TEMPORARY, 'identifier' => $originalAttribute->Identifier, 'serialized_name_list' => $originalAttribute->SerializedNameList, 'serialized_description_list' => $originalAttribute->SerializedDescriptionList, 'category' => $originalAttribute->Category, 'serialized_data_text' => $originalAttribute->SerializedDataText, 'is_required' => $originalAttribute->IsRequired, 'is_searchable' => $originalAttribute->IsSearchable, 'is_information_collector' => $originalAttribute->IsInformationCollector, 'can_translate' => $originalAttribute->CanTranslate, 'placement' => ++$placement), $this->EditLanguage);
         foreach ($this->fields as $localeIdentifier => $remoteProperty) {
             $localeAttribute->setAttribute($localeIdentifier, $originalAttribute->{$remoteProperty});
         }
         $localeAttribute->store();
         return $localeAttribute;
     }
     return false;
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 public static function addClassAttributes($class_identifier, $attributesInfo)
 {
     if (isset($class_identifier)) {
         $class = eZContentClass::fetchByIdentifier($class_identifier);
     }
     if (!is_object($class)) {
         return;
     }
     $classID = $class->attribute('id');
     foreach ($attributesInfo as $attributeInfo) {
         $classAttributeIdentifier = $attributeInfo['identifier'];
         $classAttributeName = $attributeInfo['name'];
         $datatype = $attributeInfo['data_type_string'];
         $defaultValue = isset($attributeInfo['default_value']) ? $attributeInfo['default_value'] : false;
         $canTranslate = isset($attributeInfo['can_translate']) ? $attributeInfo['can_translate'] : 1;
         $isRequired = isset($attributeInfo['is_required']) ? $attributeInfo['is_required'] : 0;
         $isSearchable = isset($attributeInfo['is_searchable']) ? $attributeInfo['is_searchable'] : 1;
         $attrContent = isset($attributeInfo['content']) ? $attributeInfo['content'] : false;
         $attrCreateInfo = array('identifier' => $classAttributeIdentifier, 'name' => $classAttributeName, 'can_translate' => $canTranslate, 'is_required' => $isRequired, 'is_searchable' => $isSearchable);
         $newAttribute = eZContentClassAttribute::create($classID, $datatype, $attrCreateInfo);
         $dataType = $newAttribute->dataType();
         $dataType->initializeClassAttribute($newAttribute);
         // not all datatype can have 'default_value'. do check here.
         if ($defaultValue !== false) {
             switch ($datatype) {
                 case 'ezboolean':
                     $newAttribute->setAttribute('data_int3', $defaultValue);
                     break;
                 default:
                     break;
             }
         }
         if ($attrContent) {
             $newAttribute->setContent($attrContent);
         }
         // store attribute, update placement, etc...
         $attributes = $class->fetchAttributes();
         $attributes[] = $newAttribute;
         // remove temporary version
         if ($newAttribute->attribute('id') !== null) {
             $newAttribute->remove();
         }
         $newAttribute->setAttribute('version', eZContentClass::VERSION_STATUS_DEFINED);
         $newAttribute->setAttribute('placement', count($attributes));
         $class->adjustAttributePlacements($attributes);
         foreach ($attributes as $attribute) {
             $attribute->storeDefined();
         }
         // update objects
         $classAttributeID = $newAttribute->attribute('id');
         $count = eZContentObject::fetchSameClassListCount($class->ID);
         $output = new ezcConsoleOutput();
         $bar = new ezcConsoleProgressbar($output, (int) $count);
         $offset = 0;
         $limit = 50;
         while (true) {
             if ($offset > $count) {
                 break;
             }
             $objects = eZContentObject::fetchSameClassList($classID, true, $offset, $limit);
             foreach ($objects as $object) {
                 $contentobjectID = $object->attribute('id');
                 $objectVersions = $object->versions();
                 foreach ($objectVersions as $objectVersion) {
                     $translations = $objectVersion->translations(false);
                     $version = $objectVersion->attribute('version');
                     foreach ($translations as $translation) {
                         $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentobjectID, $version);
                         $objectAttribute->setAttribute('language_code', $translation);
                         $objectAttribute->initialize();
                         $objectAttribute->store();
                         $objectAttribute->postInitialize();
                     }
                 }
                 $bar->advance();
             }
             eZContentObject::clearCache();
             $offset += $limit;
         }
         $bar->finish();
     }
 }