Exemplo n.º 1
0
 /**
  * Generate result data for a node view
  *
  * @param eZTemplate $tpl
  * @param eZContentObjectTreeNode $node
  * @param eZContentObject $object
  * @param bool|string $languageCode
  * @param string $viewMode
  * @param int $offset
  * @param array $viewParameters
  * @param bool|array $collectionAttributes
  * @param bool $validation
  * @return array Result array for view
  */
 static function generateNodeViewData(eZTemplate $tpl, eZContentObjectTreeNode $node, eZContentObject $object, $languageCode, $viewMode, $offset, array $viewParameters = array('offset' => 0, 'year' => false, 'month' => false, 'day' => false), $collectionAttributes = false, $validation = false)
 {
     $section = eZSection::fetch($object->attribute('section_id'));
     if ($section) {
         $navigationPartIdentifier = $section->attribute('navigation_part_identifier');
         $sectionIdentifier = $section->attribute('identifier');
     } else {
         $navigationPartIdentifier = null;
         $sectionIdentifier = null;
     }
     $keyArray = array(array('object', $object->attribute('id')), array('node', $node->attribute('node_id')), array('parent_node', $node->attribute('parent_node_id')), array('class', $object->attribute('contentclass_id')), array('class_identifier', $node->attribute('class_identifier')), array('view_offset', $offset), array('viewmode', $viewMode), array('remote_id', $object->attribute('remote_id')), array('node_remote_id', $node->attribute('remote_id')), array('navigation_part_identifier', $navigationPartIdentifier), array('depth', $node->attribute('depth')), array('url_alias', $node->attribute('url_alias')), array('class_group', $object->attribute('match_ingroup_id_list')), array('state', $object->attribute('state_id_array')), array('state_identifier', $object->attribute('state_identifier_array')), array('section', $object->attribute('section_id')), array('section_identifier', $sectionIdentifier));
     $parentClassID = false;
     $parentClassIdentifier = false;
     $parentNodeRemoteID = false;
     $parentObjectRemoteID = false;
     $parentNode = $node->attribute('parent');
     if (is_object($parentNode)) {
         $parentNodeRemoteID = $parentNode->attribute('remote_id');
         $keyArray[] = array('parent_node_remote_id', $parentNodeRemoteID);
         $parentObject = $parentNode->attribute('object');
         if (is_object($parentObject)) {
             $parentObjectRemoteID = $parentObject->attribute('remote_id');
             $keyArray[] = array('parent_object_remote_id', $parentObjectRemoteID);
             $parentClass = $parentObject->contentClass();
             if (is_object($parentClass)) {
                 $parentClassID = $parentClass->attribute('id');
                 $parentClassIdentifier = $parentClass->attribute('identifier');
                 $keyArray[] = array('parent_class', $parentClassID);
                 $keyArray[] = array('parent_class_identifier', $parentClassIdentifier);
             }
         }
     }
     $res = eZTemplateDesignResource::instance();
     $res->setKeys($keyArray);
     if ($languageCode) {
         $oldLanguageCode = $node->currentLanguage();
         $node->setCurrentLanguage($languageCode);
     }
     $tpl->setVariable('node', $node);
     $tpl->setVariable('viewmode', $viewMode);
     $tpl->setVariable('language_code', $languageCode);
     if (isset($viewParameters['_custom'])) {
         foreach ($viewParameters['_custom'] as $customVarName => $customValue) {
             $tpl->setVariable($customVarName, $customValue);
         }
         unset($viewParameters['_custom']);
     }
     $tpl->setVariable('view_parameters', $viewParameters);
     $tpl->setVariable('collection_attributes', $collectionAttributes);
     $tpl->setVariable('validation', $validation);
     $tpl->setVariable('persistent_variable', false);
     $parents = $node->attribute('path');
     $path = array();
     $titlePath = array();
     foreach ($parents as $parent) {
         $path[] = array('text' => $parent->attribute('name'), 'url' => '/content/view/full/' . $parent->attribute('node_id'), 'url_alias' => $parent->attribute('url_alias'), 'node_id' => $parent->attribute('node_id'));
     }
     $titlePath = $path;
     $path[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false, 'node_id' => $node->attribute('node_id'));
     $titlePath[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false);
     $tpl->setVariable('node_path', $path);
     $event = ezpEvent::getInstance();
     $event->notify('content/pre_rendering', array($node, $tpl, $viewMode));
     $Result = array();
     $Result['content'] = $tpl->fetch('design:node/view/' . $viewMode . '.tpl');
     $Result['view_parameters'] = $viewParameters;
     $Result['path'] = $path;
     $Result['title_path'] = $titlePath;
     $Result['section_id'] = $object->attribute('section_id');
     $Result['node_id'] = $node->attribute('node_id');
     $Result['navigation_part'] = $navigationPartIdentifier;
     $contentInfoArray = array();
     $contentInfoArray['object_id'] = $object->attribute('id');
     $contentInfoArray['node_id'] = $node->attribute('node_id');
     $contentInfoArray['parent_node_id'] = $node->attribute('parent_node_id');
     $contentInfoArray['class_id'] = $object->attribute('contentclass_id');
     $contentInfoArray['class_identifier'] = $node->attribute('class_identifier');
     $contentInfoArray['remote_id'] = $object->attribute('remote_id');
     $contentInfoArray['node_remote_id'] = $node->attribute('remote_id');
     $contentInfoArray['offset'] = $offset;
     $contentInfoArray['viewmode'] = $viewMode;
     $contentInfoArray['navigation_part_identifier'] = $navigationPartIdentifier;
     $contentInfoArray['node_depth'] = $node->attribute('depth');
     $contentInfoArray['url_alias'] = $node->attribute('url_alias');
     $contentInfoArray['current_language'] = $object->attribute('current_language');
     $contentInfoArray['language_mask'] = $object->attribute('language_mask');
     $contentInfoArray['main_node_id'] = $node->attribute('main_node_id');
     $contentInfoArray['main_node_url_alias'] = false;
     // Add url alias for main node if it is not current node and user has access to it
     if (!$node->isMain()) {
         $mainNode = $object->mainNode();
         if ($mainNode->canRead()) {
             $contentInfoArray['main_node_url_alias'] = $mainNode->attribute('url_alias');
         }
     }
     $contentInfoArray['persistent_variable'] = false;
     if ($tpl->variable('persistent_variable') !== false) {
         $contentInfoArray['persistent_variable'] = $tpl->variable('persistent_variable');
         $keyArray[] = array('persistent_variable', $contentInfoArray['persistent_variable']);
         $res->setKeys($keyArray);
     }
     $contentInfoArray['class_group'] = $object->attribute('match_ingroup_id_list');
     $contentInfoArray['state'] = $object->attribute('state_id_array');
     $contentInfoArray['state_identifier'] = $object->attribute('state_identifier_array');
     $contentInfoArray['parent_class_id'] = $parentClassID;
     $contentInfoArray['parent_class_identifier'] = $parentClassIdentifier;
     $contentInfoArray['parent_node_remote_id'] = $parentNodeRemoteID;
     $contentInfoArray['parent_object_remote_id'] = $parentObjectRemoteID;
     $Result['content_info'] = $contentInfoArray;
     // Store which templates were used to make this cache.
     $Result['template_list'] = $tpl->templateFetchList();
     // Check if time to live is set in template
     if ($tpl->hasVariable('cache_ttl')) {
         $cacheTTL = $tpl->variable('cache_ttl');
     }
     if (!isset($cacheTTL)) {
         $cacheTTL = -1;
     }
     $Result['cache_ttl'] = $cacheTTL;
     // if cache_ttl is set to 0 from the template, we need to add a no-cache advice
     // to the node's data. That way, the retrieve callback on the next calls
     // will be able to determine earlier that no cache generation should be started
     // for this node
     if ($cacheTTL == 0) {
         $Result['no_cache'] = true;
     }
     if ($languageCode) {
         $node->setCurrentLanguage($oldLanguageCode);
     }
     return $Result;
 }
    /**
     * @param string $applicationName Compatibility with other getNodeUrl operators
     * @param eZContentObjectTreeNode $node
     * @param boolean $languageCode
     * @return string
     */
    public static function getMerckManualNodeUrl($applicationName, $node, $languageCode = false)
    {
        if( $languageCode )
            $node->setCurrentLanguage($languageCode);

        /* @type $dataMap eZContentObjectAttribute[] */
        $chapterNode = ( $node->attribute( 'depth' ) > 4 ) ? $node->fetchParent() : $node;
        $topicNode   = ( $node->attribute( 'depth' ) > 4 ) ? $node : null;
        $linkType    = is_null( $topicNode ) ? 'chapter' : 'topic';
        $dataMap     = $chapterNode->dataMap();

        if ( !$dataMap || !isset($dataMap['serialized_taxonomies']) || !$dataMap['serialized_taxonomies']->hasContent() )
            return "";

        $serial        = $dataMap['serialized_taxonomies']->content();
        $sectionRemote = null;

        if( isset($serial['section']) && is_array($serial['section']) )
            $sectionRemote = $serial['section'][0];

        $fetchResult = MerckManualFunctionCollection::fetchUnifiedUrl($sectionRemote, $chapterNode, $topicNode, $linkType);

        return $fetchResult['result'];
    }