Пример #1
0
 static function create($userID = false, $optionalValues = array(), $languageLocale = false)
 {
     $dateTime = time();
     if (!$userID) {
         $userID = eZUser::currentUserID();
     }
     $nameList = new eZContentClassNameList();
     if (isset($optionalValues['serialized_name_list'])) {
         $nameList->initFromSerializedList($optionalValues['serialized_name_list']);
     } else {
         if (isset($optionalValues['name'])) {
             $nameList->initFromString($optionalValues['name'], $languageLocale);
         } else {
             $nameList->initFromString('', $languageLocale);
         }
     }
     $descriptionList = new eZSerializedObjectNameList();
     if (isset($optionalValues['serialized_description_list'])) {
         $descriptionList->initFromSerializedList($optionalValues['serialized_description_list']);
     } else {
         if (isset($optionalValues['description'])) {
             $descriptionList->initFromString($optionalValues['description'], $languageLocale);
         } else {
             $descriptionList->initFromString('', $languageLocale);
         }
     }
     $languageMask = $nameList->languageMask();
     $initialLanguageID = $nameList->alwaysAvailableLanguageID();
     $contentClassDefinition = eZContentClass::definition();
     $row = array("id" => null, "version" => 1, "serialized_name_list" => $nameList->serializeNames(), 'serialized_description_list' => $descriptionList->serializeNames(), "identifier" => "", "contentobject_name" => "", "creator_id" => $userID, "modifier_id" => $userID, "created" => $dateTime, 'remote_id' => eZRemoteIdUtility::generate('class'), "modified" => $dateTime, "is_container" => $contentClassDefinition['fields']['is_container']['default'], "always_available" => $contentClassDefinition['fields']['always_available']['default'], 'language_mask' => $languageMask, 'initial_language_id' => $initialLanguageID, "sort_field" => $contentClassDefinition['fields']['sort_field']['default'], "sort_order" => $contentClassDefinition['fields']['sort_order']['default']);
     $row = array_merge($row, $optionalValues);
     $contentClass = new eZContentClass($row);
     // setting 'dirtyData' to make sure the 'NameList' will be stored into db.
     $contentClass->NameList->setHasDirtyData(true);
     return $contentClass;
 }
Пример #2
0
function unserializeContentClassAttributeNames()
{
    $db = eZDB::instance();
    $attributeName = new eZSerializedObjectNameList();
    $limit = 100;
    $offset = 0;
    $selectSQL = "SELECT id, version, serialized_name_list FROM ezcontentclass_attribute ORDER BY id, version";
    while ($result = $db->arrayQuery($selectSQL, array('limit' => $limit, 'offset' => $offset))) {
        foreach ($result as $row) {
            //showMessage3( "id: '" . $row['id'] . "' version: '" . $row['version'] . "'" );
            $attributeName->initFromSerializedList($row['serialized_name_list']);
            $nameList = $attributeName->cleanNameList();
            $alwaysAvailableLocale = $attributeName->alwaysAvailableLanguageLocale();
            $insertSQL = 'INSERT INTO ' . EZ_CONTENTCLASS_ATTRIBUTE_TMP_TABLE_NAME . '(id, version, is_always_available, language_locale, name) VALUES (' . "{$row['id']}, {$row['version']}";
            foreach ($nameList as $locale => $name) {
                $isAlwaysAvailable = $locale == $alwaysAvailableLocale ? 1 : 0;
                $sql = $insertSQL . ", {$isAlwaysAvailable}, '" . $db->escapeString($locale) . "', '" . $db->escapeString($name) . "')";
                $db->query($sql);
            }
        }
        $offset += $limit;
    }
}
Пример #3
0
    static function create( $class_id, $data_type_string, $optionalValues = array(), $languageLocale = false )
    {
        $nameList = new eZSerializedObjectNameList();
        if ( isset( $optionalValues['serialized_name_list'] ) )
            $nameList->initFromSerializedList( $optionalValues['serialized_name_list'] );
        else if ( isset( $optionalValues['name'] ) )
            $nameList->initFromString( $optionalValues['name'], $languageLocale );
        else
            $nameList->initFromString( '', $languageLocale );

        $descriptionList = new eZSerializedObjectNameList();
        if ( isset( $optionalValues['serialized_description_list'] ) )
            $descriptionList->initFromSerializedList( $optionalValues['serialized_description_list'] );
        else if ( isset( $optionalValues['description'] ) )
            $descriptionList->initFromString( $optionalValues['description'], $languageLocale );
        else
            $descriptionList->initFromString( '', $languageLocale );

        if ( isset( $optionalValues['data_text_i18n'] ) )
        {
            $dataTextI18nList = new eZSerializedObjectNameList( $optionalValues['data_text_i18n'] );
            $optionalValues['serialized_data_text'] = $dataTextI18nList->serializeNames();
        }

        $row = array(
            'id' => null,
            'version' => eZContentClass::VERSION_STATUS_TEMPORARY,
            'contentclass_id' => $class_id,
            'identifier' => '',
            'serialized_name_list' => $nameList->serializeNames(),
            'serialized_description_list' => $descriptionList->serializeNames(),
            'is_searchable' => 1,
            'is_required' => 0,
            'can_translate' => 1,
            'is_information_collector' => 0,
            'data_type_string' => $data_type_string,
            'placement' => eZPersistentObject::newObjectOrder( eZContentClassAttribute::definition(),
                                                               'placement',
                                                               array( 'version' => 1,
                                                                      'contentclass_id' => $class_id ) ) );
        $row = array_merge( $row, $optionalValues );
        $attribute = new eZContentClassAttribute( $row );

        return $attribute;
    }
 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;
 }