コード例 #1
0
    /**
     * @param string $path
     * @param MerckManualSection $app
     * @return eZContentObjectTreeNode
     */
    public static function findNodeFromPath( $path, $app )
    {
        if( preg_match('#^/\d+/(?P<section>.*?)[/\?]?#', $path, $match) )
        {
            foreach ( array('url', 'remote', 'name') as $attribute )
            {
                $section = MerckManualFunctionCollection::fetchSection( $attribute, $match['section'] );
                if ( $section )
                {
                    $app->section = $section;
                    break;
                }
            }

            return eZContentObjectTreeNode::fetch(MerckManualShowcase::rootNodeId());
        }
        else
            return false;
    }
コード例 #2
0
    /**
     * @param string $path
     * @param MerckManualShowcase $app
     * @return bool|eZContentObjectTreeNode
     */
    public static function findNodeFromPath( $path, &$app )
    {
        /* We remove the publisher folder id at the beginning of the url as we already have it */
        $path                  = preg_replace('#^/\d+/#', '/', $path );

        $manualAppNode         = eZContentObjectTreeNode::fetch( self::rootNodeId() );
        $manualAppNodePathName = $manualAppNode->pathWithNames();
        $tabNodePath           = explode('/', substr($path, 1));
        $remoteId              = end($tabNodePath);

        if(preg_match('/^[a-f0-9]{32}$/', $remoteId))
        {
            $nodeRemote = eZContentObjectTreeNode::fetchByRemoteID($remoteId);

            if($nodeRemote instanceof eZContentObjectTreeNode)
            {
                $app->fullContext = 'topic';
                return $nodeRemote;
            }
        }

        $pathParts = explode('/', substr($path, 1));

        if ( $pathParts[0] == 'table' )
        {
            $app->fullContext = 'table';
            return eZContentObjectTreeNode::fetch($pathParts[1]);
        }

        // Url with topic
        list($sectionName, $chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts;

        // Url without topic
        $matches = array();

        if ( preg_match('/media-([a-z]+)/', $topicName, $matches) )
        {
            list($sectionName, $chapterName, $mediaType, $mediaName, $other) = $pathParts;
            $topicName = null;
        }

        // Full section
        if ( $sectionName != null && is_null( $chapterName ) && is_null( $topicName ) )
        {
            $app->fullContext = 'section';
            $app->section = MerckManualFunctionCollection::fetchSection('url', $sectionName);
            return eZContentObjectTreeNode::fetch(MerckManualShowcase::rootNodeId());
        }
        if ( $sectionName == 'about-us' )
        {
            list($chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts;
        }

        $path = $manualAppNodePathName;
        // Full of chapter
        if ( $chapterName )
        {
            $app->fullContext = 'chapter';
            $path .= '/' . $chapterName;
        }

        // Full of topic
        if ( $topicName )
        {
            $app->fullContext = 'topic';
            $path .= '/' . $topicName;
        }

        $nodeId = eZURLAliasML::fetchNodeIDByPath($path);

        if ( $nodeId )
        {
            if ( $mediaName )
            {
                $mediaType = str_replace('media-', '', $mediaType);

                // Get media node
                // Full of html table image
                // /topic_name/(media-image-file)/oscar2/filename
                if ( $mediaType == 'image-file' )
                {
                    $app->fullContext = $mediaType;
                    $app->oscarFolder = $mediaName;
                    $app->mediaName = $other;
                }

                // Full of inline audio, video, image
                elseif ( $mediaType )
                {
                    // Construct the remote_id of the media folder
                    /* @type $dataMap eZContentObjectAttribute[] */
                    $contentObject        = eZContentObject::fetchByNodeID($nodeId);
                    $dataMap              = $contentObject->dataMap();
                    $publisherAttrContent = $dataMap['publisher']->content();

                    if ( isset($publisherAttrContent['relation_list'][0]['contentobject_remote_id']) )
                    {
                        // Get media folder
                        $mediaFolderRemoteId = sprintf('%s_media_%s', $publisherAttrContent['relation_list'][0]['contentobject_remote_id'], $mediaType);
                        $mediaFolder = eZContentObject::fetchByRemoteID($mediaFolderRemoteId);

                        if ( $mediaFolder )
                        {
                            // Get media
                            $mediaFolderPathName = $mediaFolder->mainNode()->pathWithNames();
                            $nodeId = eZURLAliasML::fetchNodeIDByPath($mediaFolderPathName . '/' . $mediaName);
                            $app->fullContext = $mediaType;
                        }
                    }
                }
            }
        }

        if ( $nodeId )
        {
            // Full of chapter must not be accessible, show first topic
            if ( $app->fullContext == 'chapter' )
            {
                $params = array(
                    'Depth'         => 1,
                    'DepthOperator' => 'eq',
                    'SortBy'        => array(array('priority', 'asc')),
                    'Limit'         => 1
                );
                $children = eZContentObjectTreeNode::subTreeByNodeID($params, $nodeId);

                if ( isset($children[0]) && $children[0] instanceof eZContentObjectTreeNode )
                {
                    $node = $children[0];
                    $app->fullContext = 'topic';
                }
                else
                    $node = null;
            }
            else
            {
                $node = eZContentObjectTreeNode::fetch($nodeId);
            }

            return $node;
        }

        return false;
    }
コード例 #3
0
    /**
     * @param eZContentObjectTreeNode $mediaNode
     * @return array
     */
    public static function fetchMediaRelatedData( $mediaNode )
    {
        $result       = array();
        $relatedNodes = array();
        $parameters   = array(
            'object_id'     => $mediaNode->attribute('contentobject_id'),
            'all_relations' => true,
        );

        /* @type $relatedObjects eZContentObject[] */
        $relatedObjects  = eZFunctionHandler::execute( 'content', 'reverse_related_objects', $parameters );
        $publisherNodeId = MerckManualShowcase::rootNodeId();

        foreach( $relatedObjects as $o )
        {
            $an = $o->assignedNodes();
            foreach( $an as $n )
            {
                if( strpos( $n->attribute('path_string'), '/' . $publisherNodeId . '/' ) != false )
                    $relatedNodes[] = $n;
            }
        }

        foreach( $relatedNodes as $relatedNode )
        {
            /* @type $parentNode eZContentObjectTreeNode */
            $parentNode = eZFunctionHandler::execute( 'content', 'node', array(
                'node_id' => $relatedNode->NodeID,
            ) );

            if( $parentNode->attribute('parent_node_id') == $publisherNodeId )
            {
                $section = self::fetchChapterSection( $relatedNode );
                $section = $section['result'];
                $sectionTrigram = $section['trigram'];
                if( !array_key_exists( $sectionTrigram, $result ) )
                    $result[$sectionTrigram]['data'] = $section;

                $result[$sectionTrigram]['chapters'][$relatedNode->Name] = array(
                    'data' => $relatedNode,
                    'media' => $mediaNode
                );
            }
            else
            {
                /* @type $chapterNode eZContentObjectTreeNode */
                $chapterNode = $parentNode = eZFunctionHandler::execute( 'content', 'node', array(
                    'node_id' => $relatedNode->ParentNodeID,
                ) );
                $chapterName = $chapterNode->attribute('name');
                $section = self::fetchChapterSection( $chapterNode );
                $section = $section['result'];
                $sectionTrigram = $section['trigram'];
                if( !array_key_exists( $sectionTrigram, $result ) )
                {
                    $result[$sectionTrigram]['data'] = $section;
                }
                if( !array_key_exists( $chapterName, $result[$sectionTrigram]['chapters'] ) )
                {
                    $result[$sectionTrigram]['chapters'][$chapterName]['data'] = $chapterNode;
                }

                $result[$sectionTrigram]['chapters'][$chapterName]['topics'][$relatedNode->Name] = array(
                    'data' => $relatedNode,
                    'media' => $mediaNode
                );
            }
        }
        return array(
            'result' => $result
        );
    }
コード例 #4
0
    /**
     * @return int
     */
    public static function rootNodeId()
    {
        if (self::$rootNodeID == null)
        {
            $aboutChapterPublisherInternalID = self::iniMerck()->variable( 'MerckManualAboutSettings', 'PublisherInternalID' );

            $params = array(
                'ClassFilterType'  => 'include',
                'ClassFilterArray' => array('article'),
                'Limit'            => 1,
                'Offset'           => 0,
                'Depth'            => 1,
                'AttributeFilter'  => array(
                    array(
                        'article/publisher_internal_id',
                        'like',
                        strtolower($aboutChapterPublisherInternalID) . '*'
                    )
                ),
            );

            /* @type $nodes eZContentObjectTreeNode[] */
            $nodes = eZContentObjectTreeNode::subTreeByNodeID( $params, MerckManualShowcase::rootNodeId() );
            $node  = $nodes[0];

            if ( !empty( $nodes ) )
                self::$rootNodeID = $node->attribute('node_id');
        }

        return self::$rootNodeID;
    }