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


PHP NodeHelper::calculateOrderBefore方法代码示例

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


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

示例1: getOrderCommands

 /**
  * Returns the orderBefore commands to be applied to the childnodes
  * to get from the original order to the new one
  *
  * @return array of arrays with 2 fields: name of node to order before second name
  *
  * @private
  */
 public function getOrderCommands()
 {
     if (!$this->originalNodesOrder) {
         return array();
     }
     $reorders = NodeHelper::calculateOrderBefore($this->originalNodesOrder, $this->nodes);
     $this->originalNodesOrder = null;
     return $reorders;
 }
开发者ID:frogriotcom,项目名称:jackalope,代码行数:17,代码来源:Node.php

示例2: computeChildrenChanges

 /**
  * @param object $document
  * @param string $class
  * @param string $oid
  * @param boolean $isNew
  * @param array $changeSet
  * @throws Exception\RuntimeException
  * @throws PHPCRException
  */
 private function computeChildrenChanges($document, $class, $oid, $isNew, $changeSet)
 {
     $id = $this->getDocumentId($document, false);
     foreach ($class->childrenMappings as $fieldName) {
         if ($changeSet[$fieldName] instanceof PersistentCollection) {
             if (!$changeSet[$fieldName]->isInitialized()) {
                 continue;
             }
         } else {
             if (null === $changeSet[$fieldName]) {
                 $changeSet[$fieldName] = array();
             }
             if (!is_array($changeSet[$fieldName]) && !$changeSet[$fieldName] instanceof Collection) {
                 throw PHPCRException::childrenFieldNoArray(self::objToStr($document, $this->dm), $fieldName);
             }
             $filter = isset($mapping['filter']) ? $mapping['filter'] : null;
             $fetchDepth = isset($mapping['fetchDepth']) ? $mapping['fetchDepth'] : null;
             // convert to a PersistentCollection
             $changeSet[$fieldName] = ChildrenCollection::createFromCollection($this->dm, $document, $changeSet[$fieldName], $filter, $fetchDepth, !$isNew);
             $class->setFieldValue($document, $fieldName, $changeSet[$fieldName]);
             $this->originalData[$oid][$fieldName] = $changeSet[$fieldName];
         }
         $mapping = $class->mappings[$fieldName];
         $childNames = $movedChildNames = array();
         $coid = spl_object_hash($changeSet[$fieldName]);
         $this->visitedCollections[$coid] = $changeSet[$fieldName];
         foreach ($changeSet[$fieldName] as $originalNodename => $child) {
             if (!is_object($child)) {
                 throw PHPCRException::childrenContainsNonObject(self::objToStr($document, $this->dm), $fieldName, gettype($child));
             }
             $nodename = $this->getChildNodename($id, $originalNodename, $child, $document);
             $changeSet[$fieldName][$nodename] = $this->computeChildChanges($mapping, $child, $id, $nodename, $document);
             if (0 !== strcmp($originalNodename, $nodename)) {
                 unset($changeSet[$fieldName][$originalNodename]);
                 $movedChildNames[] = (string) $originalNodename;
             }
             $childNames[] = $nodename;
         }
         if ($isNew) {
             continue;
         }
         if (!$this->originalData[$oid][$fieldName] instanceof ChildrenCollection) {
             throw new RuntimeException("OriginalData for a children association contains something else than a ChildrenCollection.");
         }
         $this->originalData[$oid][$fieldName]->initialize();
         $originalNames = $this->originalData[$oid][$fieldName]->getOriginalNodenames();
         foreach ($originalNames as $key => $childName) {
             // check moved children to not accidentally remove a child that simply moved away.
             if (!(in_array($childName, $childNames) || in_array($childName, $movedChildNames))) {
                 $child = $this->getDocumentById($id . '/' . $childName);
                 $this->scheduleRemove($child);
                 unset($originalNames[$key]);
             }
         }
         if (!empty($childNames) && isset($originalNames)) {
             // reindex the arrays to avoid holes in the indexes
             $originalNames = array_values($originalNames);
             $originalNames = array_merge($originalNames, array_diff($childNames, $originalNames));
             if ($originalNames !== $childNames) {
                 $reordering = NodeHelper::calculateOrderBefore($originalNames, $childNames);
                 if (empty($this->documentChangesets[$oid])) {
                     $this->documentChangesets[$oid] = array('reorderings' => array($reordering));
                 } else {
                     $this->documentChangesets[$oid]['reorderings'][] = $reordering;
                 }
                 $this->scheduledUpdates[$oid] = $document;
             } elseif (empty($this->documentChangesets[$oid]['fields'])) {
                 unset($this->documentChangesets[$oid]);
                 unset($this->scheduledUpdates[$oid]);
             } else {
                 $this->documentChangesets[$oid]['reorderings'] = array();
             }
         }
     }
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:84,代码来源:UnitOfWork.php

示例3: testCalculateOrderBeforeDeleted

 public function testCalculateOrderBeforeDeleted()
 {
     $old = array('one', 'two', 'three', 'four');
     $new = array('one', 'three', 'two');
     $reorders = NodeHelper::calculateOrderBefore($old, $new);
     $expected = array('two' => null, 'one' => 'three');
     $this->assertEquals($expected, $reorders);
 }
开发者ID:frogriotcom,项目名称:phpcr-utils,代码行数:8,代码来源:NodeHelperTest.php


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