当前位置: 首页>>代码示例>>PHP>>正文


PHP eZContentObject::currentVersion方法代码示例

本文整理汇总了PHP中eZContentObject::currentVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP eZContentObject::currentVersion方法的具体用法?PHP eZContentObject::currentVersion怎么用?PHP eZContentObject::currentVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZContentObject的用法示例。


在下文中一共展示了eZContentObject::currentVersion方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: modify

 public function modify(eZContentObject $contentObject, &$docList)
 {
     $isEvent = $from = $to = false;
     $attributes = $contentObject->fetchAttributesByIdentifier(array('from_time', 'to_time'));
     if (empty($attributes)) {
         return false;
     }
     foreach ($attributes as $attribute) {
         if ($attribute instanceof eZContentObjectAttribute) {
             if ($attribute->attribute('contentclass_attribute_identifier') == 'from_time' && $attribute->hasContent()) {
                 $from = $attribute->toString();
             }
             if ($attribute->attribute('contentclass_attribute_identifier') == 'to_time' && $attribute->hasContent()) {
                 $to = $attribute->toString();
             }
         }
     }
     if ($from && $to) {
         $isEvent = true;
     }
     if ($isEvent) {
         $duration = $to - $from;
         $version = $contentObject->currentVersion();
         if ($version === false) {
             return;
         }
         $availableLanguages = $version->translationList(false, false);
         foreach ($availableLanguages as $languageCode) {
             if ($docList[$languageCode] instanceof eZSolrDoc) {
                 if ($docList[$languageCode]->Doc instanceof DOMDocument) {
                     $xpath = new DomXpath($docList[$languageCode]->Doc);
                     if ($xpath->evaluate('//field[@name="extra_event_duration_s"]')->length == 0) {
                         $docList[$languageCode]->addField('extra_event_duration_s', $duration);
                         $docList[$languageCode]->addField('extra_event_duration_si', intval($duration));
                     }
                 } elseif (is_array($docList[$languageCode]->Doc) && !isset($docList[$languageCode]->Doc['extra_event_duration_s'])) {
                     $docList[$languageCode]->addField('extra_event_duration_s', $duration);
                     $docList[$languageCode]->addField('extra_event_duration_si', intval($duration));
                 }
             }
         }
     }
 }
开发者ID:OpencontentCoop,项目名称:ocsearchtools,代码行数:43,代码来源:ezfindexeventduration.php

示例2: restoreXmlRelations

/**
 * Parses the XML for the attributes in $classAttributeIdentifiers, and fixes the relations for $object
 * @param eZContentObject $object
 * @param array $classAttributeIdentifiers
 * @return int The number of created relations
 */
function restoreXmlRelations(eZContentObject $object, array $classAttributeIdentifiers)
{
    $currentVersion = $object->currentVersion();
    $langMask = $currentVersion->attribute('language_mask');
    $languageList = eZContentLanguage::decodeLanguageMask($langMask, true);
    $languageList = $languageList['language_list'];
    // nothing to do if the object isn't translated
    if (count($languageList) < 2) {
        return 0;
    }
    $attributeArray = $object->fetchAttributesByIdentifier($classAttributeIdentifiers, $currentVersion->attribute('version'), $languageList);
    $embedRelationsCount = $object->relatedContentObjectCount(false, 0, array('AllRelations' => eZContentObject::RELATION_EMBED));
    $linkRelationsCount = $object->relatedContentObjectCount(false, 0, array('AllRelations' => eZContentObject::RELATION_LINK));
    $embeddedObjectIdArray = $linkedObjectIdArray = array();
    foreach ($attributeArray as $attribute) {
        $xmlText = eZXMLTextType::rawXMLText($attribute);
        $dom = new DOMDocument('1.0', 'utf-8');
        if (!$dom->loadXML($xmlText)) {
            continue;
        }
        // linked objects
        $linkedObjectIdArray = array_merge($linkedObjectIdArray, getRelatedObjectList($dom->getElementsByTagName('link')));
        // embedded objects
        $embeddedObjectIdArray = array_merge($embeddedObjectIdArray, getRelatedObjectList($dom->getElementsByTagName('embed')), getRelatedObjectList($dom->getElementsByTagName('embed-inline')));
    }
    $doCommit = false;
    $restoredRelations = 0;
    if (!empty($embeddedObjectIdArray)) {
        $object->appendInputRelationList($embeddedObjectIdArray, eZContentObject::RELATION_EMBED);
        $restoredRelations += count($embeddedObjectIdArray) - $embedRelationsCount;
        $doCommit = true;
    }
    if (!empty($linkedObjectIdArray)) {
        $object->appendInputRelationList($linkedObjectIdArray, eZContentObject::RELATION_LINK);
        $restoredRelations += count($linkedObjectIdArray) - $linkRelationsCount;
        $doCommit = true;
    }
    if ($doCommit) {
        $object->commitInputRelations($currentVersion->attribute('version'));
    }
    return $restoredRelations;
}
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:48,代码来源:restorexmlrelations.php

示例3: addObject

 /**
  * Adds object $contentObject to the search database.
  *
  * @param eZContentObject $contentObject Object to add to search engine
  * @param bool $commit Whether to commit after adding the object
  * @return bool True if the operation succeed.
  */
 public function addObject($contentObject, $commit = true)
 {
     $contentObjectID = $contentObject->attribute('id');
     $currentVersion = $contentObject->currentVersion();
     if (!$currentVersion) {
         $errCurrentVersion = $contentObject->attribute('current_version');
         eZDebug::writeError("Failed to fetch \"current version\" ({$errCurrentVersion})" . " of content object (ID: {$contentObjectID})", 'eZSearchEngine');
         return false;
     }
     $indexArray = array();
     $indexArrayOnlyWords = array();
     $wordCount = 0;
     $placement = 0;
     $previousWord = '';
     eZContentObject::recursionProtectionStart();
     foreach ($currentVersion->contentObjectAttributes() as $attribute) {
         $metaData = array();
         $classAttribute = $attribute->contentClassAttribute();
         if ($classAttribute->attribute("is_searchable") == 1) {
             // Fetch attribute translations
             $attributeTranslations = $attribute->fetchAttributeTranslations();
             foreach ($attributeTranslations as $translation) {
                 $tmpMetaData = $translation->metaData();
                 if (!is_array($tmpMetaData)) {
                     $tmpMetaData = array(array('id' => $attribute->attribute('contentclass_attribute_identifier'), 'text' => $tmpMetaData));
                 }
                 $metaData = array_merge($metaData, $tmpMetaData);
             }
             foreach ($metaData as $metaDataPart) {
                 $text = eZSearchEngine::normalizeText(htmlspecialchars($metaDataPart['text'], ENT_NOQUOTES, 'UTF-8'), true);
                 // Split text on whitespace
                 if (is_numeric(trim($text))) {
                     $integerValue = (int) $text;
                 } else {
                     $integerValue = 0;
                 }
                 $wordArray = explode(' ', $text);
                 foreach ($wordArray as $word) {
                     if (trim($word) != "") {
                         // words stored in search index are limited to 150 characters
                         if (strlen($word) > 150) {
                             $word = substr($word, 0, 150);
                         }
                         $indexArray[] = array('Word' => $word, 'ContentClassAttributeID' => $attribute->attribute('contentclassattribute_id'), 'identifier' => $metaDataPart['id'], 'integer_value' => $integerValue);
                         $indexArrayOnlyWords[$word] = 1;
                         $wordCount++;
                         //if we have "www." before word than
                         //treat it as url and add additional entry to the index
                         if (substr(strtolower($word), 0, 4) == 'www.') {
                             $additionalUrlWord = substr($word, 4);
                             $indexArray[] = array('Word' => $additionalUrlWord, 'ContentClassAttributeID' => $attribute->attribute('contentclassattribute_id'), 'identifier' => $metaDataPart['id'], 'integer_value' => $integerValue);
                             $indexArrayOnlyWords[$additionalUrlWord] = 1;
                             $wordCount++;
                         }
                     }
                 }
             }
         }
     }
     eZContentObject::recursionProtectionEnd();
     $wordIDArray = $this->buildWordIDArray(array_keys($indexArrayOnlyWords));
     $db = eZDB::instance();
     $db->begin();
     for ($arrayCount = 0; $arrayCount < $wordCount; $arrayCount += 1000) {
         $placement = $this->indexWords($contentObject, array_slice($indexArray, $arrayCount, 1000), $wordIDArray, $placement);
     }
     $db->commit();
     return true;
 }
开发者ID:EVE-Corp-Center,项目名称:ECC-Website,代码行数:76,代码来源:ezsearchengine.php

示例4: onPublish

 /**
  * Method triggered on publish for xml text datatype
  *
  * This method makes sure that links from all translations of an xml text
  * are registered in the ezurl_object_link table, and thus retained, if
  * previous versions of an object are removed.
  *
  * It also checks for embedded objects in other languages xml, and makes
  * sure the matching object relations are stored for the publish version.
  *
  * @param eZContentObjectAttribute $contentObjectAttribute
  * @param eZContentObject $object
  * @param array $publishedNodes
  * @return boolean
  */
 function onPublish($contentObjectAttribute, $object, $publishedNodes)
 {
     $currentVersion = $object->currentVersion();
     $langMask = $currentVersion->attribute('language_mask');
     // We find all translations present in the current version. We calculate
     // this from the language mask already present in the fetched version,
     // so no further round-trip to the DB is required.
     $languageList = eZContentLanguage::decodeLanguageMask($langMask, true);
     $languageList = $languageList['language_list'];
     // We want to have the class attribute identifier of the attribute
     // containing the current ezxmltext, as we then can use the more efficient
     // eZContentObject->fetchAttributesByIdentifier() to get the data
     $identifier = $contentObjectAttribute->attribute('contentclass_attribute_identifier');
     $attributeArray = $object->fetchAttributesByIdentifier(array($identifier), $currentVersion->attribute('version'), $languageList);
     foreach ($attributeArray as $attribute) {
         $xmlText = eZXMLTextType::rawXMLText($attribute);
         $dom = new DOMDocument('1.0', 'utf-8');
         if (!$dom->loadXML($xmlText)) {
             continue;
         }
         // urls
         $urlIdArray = array();
         foreach ($dom->getElementsByTagName('link') as $link) {
             // We are looking for external 'http://'-style links, not the internal
             // object or node links.
             if ($link->hasAttribute('url_id')) {
                 $urlIdArray[] = $link->getAttribute('url_id');
             }
         }
         if (count($urlIdArray) > 0) {
             eZSimplifiedXMLInput::updateUrlObjectLinks($attribute, $urlIdArray);
         }
         // linked objects
         $linkedObjectIdArray = $this->getRelatedObjectList($dom->getElementsByTagName('link'));
         // embedded objects
         $embeddedObjectIdArray = array_merge($this->getRelatedObjectList($dom->getElementsByTagName('embed')), $this->getRelatedObjectList($dom->getElementsByTagName('embed-inline')));
         if (!empty($embeddedObjectIdArray)) {
             $object->appendInputRelationList($embeddedObjectIdArray, eZContentObject::RELATION_EMBED);
         }
         if (!empty($linkedObjectIdArray)) {
             $object->appendInputRelationList($linkedObjectIdArray, eZContentObject::RELATION_LINK);
         }
         if (!empty($linkedObjectIdArray) || !empty($embeddedObjectIdArray)) {
             $object->commitInputRelations($currentVersion->attribute('version'));
         }
     }
 }
开发者ID:nlescure,项目名称:ezpublish,代码行数:62,代码来源:ezxmltexttype.php

示例5: optimize

    /**
     * Adds object $contentObject to the search database.
     *
     * @param eZContentObject $contentObject Object to add to search engine
     * @param bool $commit Whether to commit after adding the object.
              If set, run optimize() as well every 1000nd time this function is run.
     * @return bool True if the operation succeed.
     */
    function addObject( $contentObject, $commit = true )
    {
        // Add all translations to the document list
        $docList = array();

        // Check if we need to index this object after all
        // Exclude if class identifier is in the exclude list for classes
        $excludeClasses = $this->FindINI->variable( 'IndexExclude', 'ClassIdentifierList' );
        if ( $excludeClasses && in_array( $contentObject->attribute( 'class_identifier' ), $excludeClasses ) )
        {
            return true;
        }
        // Get global object values
        $mainNode = $contentObject->attribute( 'main_node' );
        if ( !$mainNode )
        {
            eZDebug::writeError( 'Unable to fetch main node for object: ' . $contentObject->attribute( 'id' ), __METHOD__ );
            return false;
        }

        $mainNodePathArray = $mainNode->attribute( 'path_array' );
        $mainNodeID = $mainNode->attribute( 'node_id' );
        // initialize array of parent node path ids, needed for multivalued path field and subtree filters
        $nodePathArray = array();

        //included in $nodePathArray
        //$pathArray = $mainNode->attribute( 'path_array' );
        $currentVersion = $contentObject->currentVersion();

        // Get object meta attributes.
        $metaAttributeValues = self::getMetaAttributesForObject( $contentObject );

        // Get node attributes.
        $nodeAttributeValues = array();
        foreach ( $contentObject->attribute( 'assigned_nodes' ) as $contentNode )
        {
            $nodeID = $contentNode->attribute( 'node_id' );
            foreach ( eZSolr::nodeAttributes() as $attributeName => $fieldType )
            {
                $nodeAttributeValues[$nodeID][] = array( 'name' => $attributeName,
                                                'value' => $contentNode->attribute( $attributeName ),
                                                'fieldType' => $fieldType );
            }
            $nodePathArray[] = $contentNode->attribute( 'path_array' );

        }

        // Check anonymous user access.
        if ( $this->FindINI->variable( 'SiteSettings', 'IndexPubliclyAvailable' ) == 'enabled' )
        {
            $anonymousUserID = $this->SiteINI->variable( 'UserSettings', 'AnonymousUserID' );
            $currentUserID = eZUser::currentUserID();
            $user = eZUser::instance( $anonymousUserID );
            eZUser::setCurrentlyLoggedInUser( $user, $anonymousUserID );
            $anonymousAccess = $contentObject->attribute( 'can_read' );
            $user = eZUser::instance( $currentUserID );
            eZUser::setCurrentlyLoggedInUser( $user, $currentUserID );
            $anonymousAccess = $anonymousAccess ? 'true' : 'false';
        }
        else
        {
            $anonymousAccess = 'false';
        }

        // Load index time boost factors if any
        //$boostMetaFields = $this->FindINI->variable( "IndexBoost", "MetaField" );
        $boostClasses = $this->FindINI->variable( 'IndexBoost', 'Class' );
        $boostAttributes = $this->FindINI->variable( 'IndexBoost', 'Attribute' );
        $boostDatatypes = $this->FindINI->variable( 'IndexBoost', 'Datatype' );
        $reverseRelatedScale = $this->FindINI->variable( 'IndexBoost', 'ReverseRelatedScale' );

        // Initialise default doc boost
        $docBoost = 1.0;
        $contentClassIdentifier = $contentObject->attribute( 'class_identifier' );
        // Just test if the boost factor is defined by checking if it has a numeric value
        if ( isset( $boostClasses[$contentClassIdentifier] ) && is_numeric( $boostClasses[$contentClassIdentifier] ) )
        {
            $docBoost += $boostClasses[$contentClassIdentifier];
        }
        // Google like boosting, using eZ Publish reverseRelatedObjectCount
        $reverseRelatedObjectCount = $contentObject->reverseRelatedObjectCount();
        $docBoost += $reverseRelatedScale * $reverseRelatedObjectCount;

        //  Create the list of available languages for this version :
        $availableLanguages = $currentVersion->translationList( false, false );

        // Loop over each language version and create an eZSolrDoc for it
        foreach ( $availableLanguages as $languageCode )
        {
            $doc = new eZSolrDoc( $docBoost );
            // Set global unique object ID
            $doc->addField( ezfSolrDocumentFieldBase::generateMetaFieldName( 'guid' ), $this->guid( $contentObject, $languageCode ) );
//.........这里部分代码省略.........
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:101,代码来源:ezsolr.php


注:本文中的eZContentObject::currentVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。