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


PHP NodeInterface::getIndex方法代码示例

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


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

示例1: setNewIndex

 /**
  * Assigns an index to the given node which reflects the specified position.
  * If the position is "before" or "after", an index will be chosen which makes
  * the given node the previous or next node of the given reference node.
  * If the position "last" is specified, an index higher than any existing index
  * will be chosen.
  *
  * If no free index is available between two nodes (for "before" and "after"),
  * the whole index of the current node level will be renumbered.
  *
  * @param NodeData $node The node to set the new index for
  * @param integer $position The position the new index should reflect, must be one of the POSITION_* constants
  * @param NodeInterface $referenceNode The reference node. Mandatory for POSITION_BEFORE and POSITION_AFTER
  * @return void
  * @throws \InvalidArgumentException
  */
 public function setNewIndex(NodeData $node, $position, NodeInterface $referenceNode = null)
 {
     $parentPath = $node->getParentPath();
     switch ($position) {
         case self::POSITION_BEFORE:
             if ($referenceNode === null) {
                 throw new \InvalidArgumentException('The reference node must be specified for POSITION_BEFORE.', 1317198857);
             }
             $referenceIndex = $referenceNode->getIndex();
             $nextLowerIndex = $this->findNextLowerIndex($parentPath, $referenceIndex);
             if ($nextLowerIndex === null) {
                 // FIXME: $nextLowerIndex returns 0 and not NULL in case no lower index is found. So this case seems to be
                 // never executed. We need to check that again!
                 $newIndex = (int) round($referenceIndex / 2);
             } elseif ($nextLowerIndex < $referenceIndex - 1) {
                 // there is free space left between $referenceNode and preceding sibling.
                 $newIndex = (int) round($nextLowerIndex + ($referenceIndex - $nextLowerIndex) / 2);
             } else {
                 // there is no free space left between $referenceNode and following sibling -> we need to re-number!
                 $this->renumberIndexesInLevel($parentPath);
                 $referenceIndex = $referenceNode->getIndex();
                 $nextLowerIndex = $this->findNextLowerIndex($parentPath, $referenceIndex);
                 if ($nextLowerIndex === null) {
                     $newIndex = (int) round($referenceIndex / 2);
                 } else {
                     $newIndex = (int) round($nextLowerIndex + ($referenceIndex - $nextLowerIndex) / 2);
                 }
             }
             break;
         case self::POSITION_AFTER:
             if ($referenceNode === null) {
                 throw new \InvalidArgumentException('The reference node must be specified for POSITION_AFTER.', 1317198858);
             }
             $referenceIndex = $referenceNode->getIndex();
             $nextHigherIndex = $this->findNextHigherIndex($parentPath, $referenceIndex);
             if ($nextHigherIndex === null) {
                 // $referenceNode is last node, so we can safely add an index at the end by incrementing the reference index.
                 $newIndex = $referenceIndex + 100;
                 $this->setHighestIndexInParentPath($parentPath, $newIndex);
             } elseif ($nextHigherIndex > $referenceIndex + 1) {
                 // $referenceNode is not last node, but there is free space left between $referenceNode and following sibling.
                 $newIndex = (int) round($referenceIndex + ($nextHigherIndex - $referenceIndex) / 2);
             } else {
                 // $referenceNode is not last node, and no free space is left -> we need to re-number!
                 $this->renumberIndexesInLevel($parentPath);
                 $referenceIndex = $referenceNode->getIndex();
                 $nextHigherIndex = $this->findNextHigherIndex($parentPath, $referenceIndex);
                 if ($nextHigherIndex === null) {
                     $newIndex = $referenceIndex + 100;
                     $this->setHighestIndexInParentPath($parentPath, $newIndex);
                 } else {
                     $newIndex = (int) round($referenceIndex + ($nextHigherIndex - $referenceIndex) / 2);
                 }
             }
             break;
         case self::POSITION_LAST:
             $nextFreeIndex = $this->findNextFreeIndexInParentPath($parentPath);
             $newIndex = $nextFreeIndex;
             break;
         default:
             throw new \InvalidArgumentException('Invalid position for new node index given.', 1329729088);
     }
     $node->setIndex($newIndex);
 }
开发者ID:testbird,项目名称:neos-development-collection,代码行数:80,代码来源:NodeDataRepository.php


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