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


PHP Wrapper\AbstractWrapper类代码示例

本文整理汇总了PHP中Gedmo\Tool\Wrapper\AbstractWrapper的典型用法代码示例。如果您正苦于以下问题:PHP AbstractWrapper类的具体用法?PHP AbstractWrapper怎么用?PHP AbstractWrapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getLogsByObject

 public function getLogsByObject($object, $searchChild = true, $searchOnlyChild = false)
 {
     $wrapped = AbstractWrapper::wrap($object, $this->getEntityManager());
     $id = $wrapped->getIdentifier();
     $class = $wrapped->getRootObjectName();
     return $this->getLogsByClassId($class, $id, $searchChild, $searchOnlyChild);
 }
开发者ID:fcpauldiaz,项目名称:IbrowsLoggableBundle,代码行数:7,代码来源:LogMany2ManyRepository.php

示例2: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $em = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $em);
     $qb = $em->createQueryBuilder();
     $qb->select('rec.' . $config['slug'])->from($config['useObjectClass'], 'rec')->where($qb->expr()->like('rec.' . $config['slug'], ':slug'));
     $qb->setParameter('slug', $slug . '%');
     // use the unique_base to restrict the uniqueness check
     if ($config['unique'] && isset($config['unique_base'])) {
         if (($ubase = $wrapped->getPropertyValue($config['unique_base'])) && !array_key_exists($config['unique_base'], $wrapped->getMetadata()->getAssociationMappings())) {
             $qb->andWhere('rec.' . $config['unique_base'] . ' = :unique_base');
             $qb->setParameter(':unique_base', $ubase);
         } elseif (array_key_exists($config['unique_base'], $wrapped->getMetadata()->getAssociationMappings())) {
             $associationMappings = $wrapped->getMetadata()->getAssociationMappings();
             $qb->join($associationMappings[$config['unique_base']]['targetEntity'], 'unique_' . $config['unique_base']);
         } else {
             $qb->andWhere($qb->expr()->isNull('rec.' . $config['unique_base']));
         }
     }
     // include identifiers
     foreach ((array) $wrapped->getIdentifier(false) as $id => $value) {
         if (!$meta->isIdentifier($config['slug'])) {
             $qb->andWhere($qb->expr()->neq('rec.' . $id, ':' . $id));
             $qb->setParameter($id, $value);
         }
     }
     $q = $qb->getQuery();
     $q->setHydrationMode(Query::HYDRATE_ARRAY);
     return $q->execute();
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:33,代码来源:ORM.php

示例3: getClassAndId

 protected function getClassAndId($object)
 {
     $wrapped = AbstractWrapper::wrap($object, $this->getEntityManager());
     $id = $wrapped->getIdentifier();
     $class = $wrapped->getRootObjectName();
     return array('id' => $id, 'class' => $class);
 }
开发者ID:fcpauldiaz,项目名称:IbrowsLoggableBundle,代码行数:7,代码来源:LogRepository.php

示例4: removeNode

 /**
  * {@inheritdoc}
  */
 public function removeNode($om, $meta, $config, $node)
 {
     $uow = $om->getUnitOfWork();
     $wrapped = AbstractWrapper::wrap($node, $om);
     // Remove node's children
     $results = $om->createQueryBuilder()->find($meta->name)->field($config['path'])->equals(new \MongoRegex('/^' . preg_quote($wrapped->getPropertyValue($config['path'])) . '.?+/'))->getQuery()->execute();
     foreach ($results as $node) {
         $uow->scheduleForDelete($node);
     }
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:13,代码来源:MaterializedPath.php

示例5: removeNode

 /**
  * {@inheritdoc}
  */
 public function removeNode($om, $meta, $config, $node)
 {
     $uow = $om->getUnitOfWork();
     $wrapped = AbstractWrapper::wrap($node, $om);
     $path = addcslashes($wrapped->getPropertyValue($config['path']), '%');
     // Remove node's children
     $qb = $om->createQueryBuilder();
     $qb->select('e')->from($config['useObjectClass'], 'e')->where($qb->expr()->like('e.' . $config['path'], $qb->expr()->literal($path . '%')));
     $results = $qb->getQuery()->execute();
     foreach ($results as $node) {
         $uow->scheduleForDelete($node);
     }
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:16,代码来源:MaterializedPath.php

示例6: replaceInverseRelative

 /**
  * This query can couse some data integrity failures since it does not
  * execute atomicaly
  *
  * {@inheritDoc}
  */
 public function replaceInverseRelative($object, array $config, $target, $replacement)
 {
     $dm = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrapp($object, $dm);
     $meta = $dm->getClassMetadata($config['useObjectClass']);
     $q = $dm->createQueryBuilder($config['useObjectClass'])->field($config['mappedBy'] . '.' . $meta->identifier)->equals($wrapped->getIdentifier())->getQuery();
     $q->setHydrate(false);
     $result = $q->execute();
     if ($result instanceof Cursor) {
         $result = $result->toArray();
         foreach ($result as $targetObject) {
             $slug = preg_replace("@^{$replacement}@smi", $target, $targetObject[$config['slug']]);
             $dm->createQueryBuilder()->update($config['useObjectClass'])->field($config['slug'])->set($slug)->field($meta->identifier)->equals($targetObject['_id'])->getQuery()->execute();
         }
     }
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:22,代码来源:ODM.php

示例7: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $em = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $em);
     $qb = $em->createQueryBuilder();
     $qb->select('rec.' . $config['slug'])->from($config['useObjectClass'], 'rec')->where($qb->expr()->like('rec.' . $config['slug'], $qb->expr()->literal($slug . '%')));
     // include identifiers
     foreach ((array) $wrapped->getIdentifier(false) as $id => $value) {
         if (!$meta->isIdentifier($config['slug'])) {
             $qb->andWhere($qb->expr()->neq('rec.' . $id, ':' . $id));
             $qb->setParameter($id, $value);
         }
     }
     $q = $qb->getQuery();
     $q->setHydrationMode(Query::HYDRATE_ARRAY);
     return $q->execute();
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:20,代码来源:ORM.php

示例8: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $dm = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $dm);
     $qb = $dm->createQueryBuilder($config['useObjectClass']);
     if (($identifier = $wrapped->getIdentifier()) && !$meta->isIdentifier($config['slug'])) {
         $qb->field($meta->identifier)->notEqual($identifier);
     }
     $qb->field($config['slug'])->equals(new \MongoRegex('/^' . preg_quote($slug, '/') . '/'));
     $q = $qb->getQuery();
     $q->setHydrate(false);
     $result = $q->execute();
     if ($result instanceof Cursor) {
         $result = $result->toArray();
     }
     return $result;
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:20,代码来源:ODM.php

示例9: prepareForDisplay

 /**
  * prepare object for display
  * 
  * 
  * @access public
  * @param array $objectsArray
  * @param mixed $sampleObject object used to get expected properties when $objectsArray is array of arrays not array of objects ,default is null
  * @param int $depthLevel ,default is 0
  * @param int $maxDepthLevel depth level including first object level ,default is 3
  * @return array objects prepared for display
  */
 public function prepareForDisplay($objectsArray, $sampleObject = null, $depthLevel = 0, $maxDepthLevel = 3)
 {
     $depthLevel++;
     foreach ($objectsArray as &$object) {
         $notObject = false;
         // support array of arrays instead of array of objects
         if (is_array($object)) {
             $object = (object) $object;
             $notObject = true;
         }
         $objectProperties = $this->prepareForStatusDisplay($object);
         if (($notObject === false || $notObject === true && !is_null($sampleObject)) && $depthLevel == 1) {
             if (is_null($sampleObject)) {
                 $sampleObjectForWrapper = $object;
             } else {
                 $sampleObjectForWrapper = $sampleObject;
             }
             $wrapped = AbstractWrapper::wrap($sampleObjectForWrapper, $this->query->entityManager);
             $meta = $wrapped->getMetadata();
         }
         foreach ($objectProperties as $objectPropertyName => $objectPropertyValue) {
             if (is_string($objectPropertyValue) && strlen($objectPropertyValue) <= 5) {
                 $textObjectPropertyName = $objectPropertyName . "Text";
                 if (array_key_exists($objectPropertyValue, $this->languages)) {
                     $object->{$textObjectPropertyName} = $this->languages[$objectPropertyValue];
                 } elseif (strlen($objectPropertyValue) == 2 && array_key_exists($objectPropertyValue, $this->countries)) {
                     $object->{$textObjectPropertyName} = $this->countries[$objectPropertyValue];
                 }
             } elseif ($objectPropertyValue instanceof \DateTime) {
                 $formattedString = $objectPropertyValue->format("D, d M Y");
                 if ($formattedString == Time::UNIX_DATE_STRING) {
                     $formattedString = $objectPropertyValue->format("H:i");
                 }
                 $object->{$objectPropertyName} = $formattedString;
             } elseif (is_object($objectPropertyValue) && $depthLevel != $maxDepthLevel) {
                 $objectsPropertyValue = $this->prepareForDisplay(array($objectPropertyValue), $sampleObject, $depthLevel, $maxDepthLevel);
                 $object->{$objectPropertyName} = reset($objectsPropertyValue);
             } elseif (is_array($objectPropertyValue) && array_key_exists("id", $objectPropertyValue) && isset($meta) && $meta->isSingleValuedAssociation($objectPropertyName)) {
                 $object->{$objectPropertyName} = $this->query->find($meta->getAssociationMapping($objectPropertyName)["targetEntity"], $objectPropertyValue["id"]);
             }
         }
     }
     return $objectsArray;
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:55,代码来源:Object.php

示例10: onSlugCompletion

 /**
  * {@inheritDoc}
  */
 public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug)
 {
     $this->om = $ea->getObjectManager();
     $isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
     if (!$isInsert) {
         $options = $config['handlers'][get_called_class()];
         $wrapped = AbstractWrapper::wrapp($object, $this->om);
         $oldSlug = $wrapped->getPropertyValue($config['slug']);
         $mappedByConfig = $this->sluggable->getConfiguration($this->om, $options['relationClass']);
         if ($mappedByConfig) {
             $meta = $this->om->getClassMetadata($options['relationClass']);
             if (!$meta->isSingleValuedAssociation($options['mappedBy'])) {
                 throw new InvalidMappingException("Unable to find " . $wrapped->getMetadata()->name . " relation - [{$options['mappedBy']}] in class - {$meta->name}");
             }
             if (!isset($mappedByConfig['slugs'][$options['inverseSlugField']])) {
                 throw new InvalidMappingException("Unable to find slug field - [{$options['inverseSlugField']}] in class - {$meta->name}");
             }
             $mappedByConfig['slug'] = $mappedByConfig['slugs'][$options['inverseSlugField']]['slug'];
             $mappedByConfig['mappedBy'] = $options['mappedBy'];
             $ea->replaceInverseRelative($object, $mappedByConfig, $slug, $oldSlug);
             $uow = $this->om->getUnitOfWork();
             // update in memory objects
             foreach ($uow->getIdentityMap() as $className => $objects) {
                 // for inheritance mapped classes, only root is always in the identity map
                 if ($className !== $mappedByConfig['useObjectClass']) {
                     continue;
                 }
                 foreach ($objects as $object) {
                     if (property_exists($object, '__isInitialized__') && !$object->__isInitialized__) {
                         continue;
                     }
                     $oid = spl_object_hash($object);
                     $objectSlug = $meta->getReflectionProperty($mappedByConfig['slug'])->getValue($object);
                     if (preg_match("@^{$oldSlug}@smi", $objectSlug)) {
                         $objectSlug = str_replace($oldSlug, $slug, $objectSlug);
                         $meta->getReflectionProperty($mappedByConfig['slug'])->setValue($object, $objectSlug);
                         $ea->setOriginalObjectProperty($uow, $oid, $mappedByConfig['slug'], $objectSlug);
                     }
                 }
             }
         }
     }
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:46,代码来源:InversedRelativeSlugHandler.php

示例11: getSimilarSlugs

 /**
  * {@inheritDoc}
  */
 public function getSimilarSlugs($object, $meta, array $config, $slug)
 {
     $em = $this->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $em);
     $qb = $em->createQueryBuilder();
     $qb->select('rec.' . $config['slug'])->from($config['useObjectClass'], 'rec')->where($qb->expr()->like('rec.' . $config['slug'], ':slug'));
     $qb->setParameter('slug', $slug . '%');
     // use the unique_base to restrict the uniqueness check
     if ($config['unique'] && isset($config['unique_base'])) {
         $ubase = $wrapped->getPropertyValue($config['unique_base']);
         if (array_key_exists($config['unique_base'], $wrapped->getMetadata()->getAssociationMappings())) {
             $mapping = $wrapped->getMetadata()->getAssociationMapping($config['unique_base']);
         } else {
             $mapping = false;
         }
         if ($ubase && !$mapping) {
             $qb->andWhere('rec.' . $config['unique_base'] . ' = :unique_base');
             $qb->setParameter(':unique_base', $ubase);
         } elseif ($ubase && $mapping && in_array($mapping['type'], array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE))) {
             $mappedAlias = 'mapped_' . $config['unique_base'];
             $wrappedUbase = AbstractWrapper::wrap($ubase, $em);
             $qb->innerJoin('rec.' . $config['unique_base'], $mappedAlias);
             foreach (array_keys($mapping['targetToSourceKeyColumns']) as $i => $mappedKey) {
                 $mappedProp = $wrappedUbase->getMetadata()->fieldNames[$mappedKey];
                 $qb->andWhere($qb->expr()->eq($mappedAlias . '.' . $mappedProp, ':assoc' . $i));
                 $qb->setParameter(':assoc' . $i, $wrappedUbase->getPropertyValue($mappedProp));
             }
         } else {
             $qb->andWhere($qb->expr()->isNull('rec.' . $config['unique_base']));
         }
     }
     // include identifiers
     foreach ((array) $wrapped->getIdentifier(false) as $id => $value) {
         if (!$meta->isIdentifier($config['slug'])) {
             $qb->andWhere($qb->expr()->neq('rec.' . $id, ':' . $id));
             $qb->setParameter($id, $value);
         }
     }
     $q = $qb->getQuery();
     $q->setHydrationMode(Query::HYDRATE_ARRAY);
     return $q->execute();
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:45,代码来源:ORM.php

示例12: createLogEntry

 /**
  * Create a new Log instance
  *
  * @param string $action
  * @param object $object
  * @param LoggableAdapter $ea
  * @return \Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry|null
  */
 protected function createLogEntry($action, $object, LoggableAdapter $ea)
 {
     $om = $ea->getObjectManager();
     $wrapped = AbstractWrapper::wrap($object, $om);
     $meta = $wrapped->getMetadata();
     if ($config = $this->getConfiguration($om, $meta->name)) {
         $logEntryClass = $this->getLogEntryClass($ea, $meta->name);
         $logEntryMeta = $om->getClassMetadata($logEntryClass);
         /** @var \Gedmo\Loggable\Entity\LogEntry $logEntry */
         $logEntry = $logEntryMeta->newInstance();
         $logEntry->setAction($action);
         $logEntry->setUsername($this->username);
         $logEntry->setObjectClass($meta->name);
         $logEntry->setLoggedAt();
         // check for the availability of the primary key
         $uow = $om->getUnitOfWork();
         if ($action === self::ACTION_CREATE && $ea->isPostInsertGenerator($meta)) {
             $this->pendingLogEntryInserts[spl_object_hash($object)] = $logEntry;
         } else {
             $logEntry->setObjectId($wrapped->getIdentifier());
         }
         $newValues = array();
         if ($action !== self::ACTION_REMOVE && isset($config['versioned'])) {
             foreach ($ea->getObjectChangeSet($uow, $object) as $field => $changes) {
                 if (!in_array($field, $config['versioned'])) {
                     continue;
                 }
                 $value = $changes[1];
                 if ($meta->isSingleValuedAssociation($field) && $value) {
                     $oid = spl_object_hash($value);
                     $wrappedAssoc = AbstractWrapper::wrap($value, $om);
                     $value = $wrappedAssoc->getIdentifier(false);
                     if (!is_array($value) && !$value) {
                         $this->pendingRelatedObjects[$oid][] = array('log' => $logEntry, 'field' => $field);
                     }
                 }
                 $newValues[$field] = $value;
             }
             $logEntry->setData($newValues);
         }
         if ($action === self::ACTION_UPDATE && 0 === count($newValues)) {
             return null;
         }
         $version = 1;
         if ($action !== self::ACTION_CREATE) {
             $version = $ea->getNewVersion($logEntryMeta, $object);
             if (empty($version)) {
                 // was versioned later
                 $version = 1;
             }
         }
         $logEntry->setVersion($version);
         $this->prePersistLogEntry($logEntry, $object);
         $om->persist($logEntry);
         $uow->computeChangeSet($logEntryMeta, $logEntry);
         return $logEntry;
     }
     return null;
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:67,代码来源:LoggableListener.php

示例13: updateNode

 /**
  * Update node and closures
  *
  * @param EntityManager $em
  * @param object $node
  * @param object $oldParent
  */
 public function updateNode(EntityManager $em, $node, $oldParent)
 {
     $wrapped = AbstractWrapper::wrap($node, $em);
     $meta = $wrapped->getMetadata();
     $config = $this->listener->getConfiguration($em, $meta->name);
     $closureMeta = $em->getClassMetadata($config['closure']);
     $nodeId = $wrapped->getIdentifier();
     $parent = $wrapped->getPropertyValue($config['parent']);
     $table = $closureMeta->getTableName();
     $conn = $em->getConnection();
     // ensure integrity
     if ($parent) {
         $dql = "SELECT COUNT(c) FROM {$closureMeta->name} c";
         $dql .= " WHERE c.ancestor = :node";
         $dql .= " AND c.descendant = :parent";
         $q = $em->createQuery($dql);
         $q->setParameters(compact('node', 'parent'));
         if ($q->getSingleScalarResult()) {
             throw new \Gedmo\Exception\UnexpectedValueException("Cannot set child as parent to node: {$nodeId}");
         }
     }
     if ($oldParent) {
         $subQuery = "SELECT c2.id FROM {$table} c1";
         $subQuery .= " JOIN {$table} c2 ON c1.descendant = c2.descendant";
         $subQuery .= " WHERE c1.ancestor = :nodeId AND c2.depth > c1.depth";
         $ids = $conn->fetchAll($subQuery, compact('nodeId'));
         if ($ids) {
             $ids = array_map(function ($el) {
                 return $el['id'];
             }, $ids);
         }
         // using subquery directly, sqlite acts unfriendly
         $query = "DELETE FROM {$table} WHERE id IN (" . implode(', ', $ids) . ")";
         if (!$conn->executeQuery($query)) {
             throw new RuntimeException('Failed to remove old closures');
         }
     }
     if ($parent) {
         $wrappedParent = AbstractWrapper::wrap($parent, $em);
         $parentId = $wrappedParent->getIdentifier();
         $query = "SELECT c1.ancestor, c2.descendant, (c1.depth + c2.depth + 1) AS depth";
         $query .= " FROM {$table} c1, {$table} c2";
         $query .= " WHERE c1.descendant = :parentId";
         $query .= " AND c2.ancestor = :nodeId";
         $closures = $conn->fetchAll($query, compact('nodeId', 'parentId'));
         foreach ($closures as $closure) {
             if (!$conn->insert($table, $closure)) {
                 throw new RuntimeException('Failed to insert new Closure record');
             }
         }
     }
     if (isset($config['level'])) {
         $this->pendingNodesLevelProcess[$nodeId] = $node;
     }
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:62,代码来源:Closure.php

示例14: updateNode

 /**
  * Update the $node with a diferent $parent
  * destination
  *
  * @param EntityManager $em
  * @param object        $node     - target node
  * @param object        $parent   - destination node
  * @param string        $position
  *
  * @throws \Gedmo\Exception\UnexpectedValueException
  */
 public function updateNode(EntityManager $em, $node, $parent, $position = 'FirstChild')
 {
     $wrapped = AbstractWrapper::wrap($node, $em);
     /** @var ClassMetadata $meta */
     $meta = $wrapped->getMetadata();
     $config = $this->listener->getConfiguration($em, $meta->name);
     $root = isset($config['root']) ? $wrapped->getPropertyValue($config['root']) : null;
     $identifierField = $meta->getSingleIdentifierFieldName();
     $nodeId = $wrapped->getIdentifier();
     $left = $wrapped->getPropertyValue($config['left']);
     $right = $wrapped->getPropertyValue($config['right']);
     $isNewNode = empty($left) && empty($right);
     if ($isNewNode) {
         $left = 1;
         $right = 2;
     }
     $oid = spl_object_hash($node);
     if (isset($this->nodePositions[$oid])) {
         $position = $this->nodePositions[$oid];
     }
     $level = 0;
     $treeSize = $right - $left + 1;
     $newRoot = null;
     if ($parent) {
         $wrappedParent = AbstractWrapper::wrap($parent, $em);
         $parentRoot = isset($config['root']) ? $wrappedParent->getPropertyValue($config['root']) : null;
         $parentOid = spl_object_hash($parent);
         $parentLeft = $wrappedParent->getPropertyValue($config['left']);
         $parentRight = $wrappedParent->getPropertyValue($config['right']);
         if (empty($parentLeft) && empty($parentRight)) {
             // parent node is a new node, but wasn't processed yet (due to Doctrine commit order calculator redordering)
             // We delay processing of node to the moment parent node will be processed
             if (!isset($this->delayedNodes[$parentOid])) {
                 $this->delayedNodes[$parentOid] = array();
             }
             $this->delayedNodes[$parentOid][] = array('node' => $node, 'position' => $position);
             return;
         }
         if (!$isNewNode && $root === $parentRoot && $parentLeft >= $left && $parentRight <= $right) {
             throw new UnexpectedValueException("Cannot set child as parent to node: {$nodeId}");
         }
         if (isset($config['level'])) {
             $level = $wrappedParent->getPropertyValue($config['level']);
         }
         switch ($position) {
             case self::PREV_SIBLING:
                 if (property_exists($node, 'sibling')) {
                     $wrappedSibling = AbstractWrapper::wrap($node->sibling, $em);
                     $start = $wrappedSibling->getPropertyValue($config['left']);
                     $level++;
                 } else {
                     $newParent = $wrappedParent->getPropertyValue($config['parent']);
                     if (is_null($newParent) && (isset($config['root']) || $isNewNode)) {
                         throw new UnexpectedValueException("Cannot persist sibling for a root node, tree operation is not possible");
                     }
                     $wrapped->setPropertyValue($config['parent'], $newParent);
                     $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
                     $start = $parentLeft;
                 }
                 break;
             case self::NEXT_SIBLING:
                 if (property_exists($node, 'sibling')) {
                     $wrappedSibling = AbstractWrapper::wrap($node->sibling, $em);
                     $start = $wrappedSibling->getPropertyValue($config['right']) + 1;
                     $level++;
                 } else {
                     $newParent = $wrappedParent->getPropertyValue($config['parent']);
                     if (is_null($newParent) && (isset($config['root']) || $isNewNode)) {
                         throw new UnexpectedValueException("Cannot persist sibling for a root node, tree operation is not possible");
                     }
                     $wrapped->setPropertyValue($config['parent'], $newParent);
                     $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
                     $start = $parentRight + 1;
                 }
                 break;
             case self::LAST_CHILD:
                 $start = $parentRight;
                 $level++;
                 break;
             case self::FIRST_CHILD:
             default:
                 $start = $parentLeft + 1;
                 $level++;
                 break;
         }
         $this->shiftRL($em, $config['useObjectClass'], $start, $treeSize, $parentRoot);
         if (!$isNewNode && $root === $parentRoot && $left >= $start) {
             $left += $treeSize;
             $wrapped->setPropertyValue($config['left'], $left);
//.........这里部分代码省略.........
开发者ID:7rin0,项目名称:SF3,代码行数:101,代码来源:Nested.php

示例15: updateNode

 /**
  * Update the $node with a diferent $parent
  * destination
  *
  * @param EntityManager $em
  * @param object $node - target node
  * @param object $parent - destination node
  * @param string $position
  * @throws Gedmo\Exception\UnexpectedValueException
  * @return void
  */
 public function updateNode(EntityManager $em, $node, $parent, $position = 'FirstChild')
 {
     $wrapped = AbstractWrapper::wrapp($node, $em);
     $meta = $wrapped->getMetadata();
     $config = $this->listener->getConfiguration($em, $meta->name);
     $rootId = isset($config['root']) ? $wrapped->getPropertyValue($config['root']) : null;
     $identifierField = $meta->getSingleIdentifierFieldName();
     $nodeId = $wrapped->getIdentifier();
     $left = $wrapped->getPropertyValue($config['left']);
     $right = $wrapped->getPropertyValue($config['right']);
     $isNewNode = empty($left) && empty($right);
     if ($isNewNode) {
         $left = 1;
         $right = 2;
     }
     $oid = spl_object_hash($node);
     if (isset($this->nodePositions[$oid])) {
         $position = $this->nodePositions[$oid];
     }
     $level = 0;
     $treeSize = $right - $left + 1;
     $newRootId = null;
     if ($parent) {
         $wrappedParent = AbstractWrapper::wrapp($parent, $em);
         $parentRootId = isset($config['root']) ? $wrappedParent->getPropertyValue($config['root']) : null;
         $parentLeft = $wrappedParent->getPropertyValue($config['left']);
         $parentRight = $wrappedParent->getPropertyValue($config['right']);
         if (!$isNewNode && $rootId === $parentRootId && $parentLeft >= $left && $parentRight <= $right) {
             throw new \Gedmo\Exception\UnexpectedValueException("Cannot set child as parent to node: {$nodeId}");
         }
         if (isset($config['level'])) {
             $level = $wrappedParent->getPropertyValue($config['level']);
         }
         switch ($position) {
             case self::PREV_SIBLING:
                 $newParent = $wrappedParent->getPropertyValue($config['parent']);
                 if (!$isNewNode) {
                     $wrapped->setPropertyValue($config['parent'], $newParent);
                     $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
                 }
                 $start = $parentLeft;
                 break;
             case self::NEXT_SIBLING:
                 $newParent = $wrappedParent->getPropertyValue($config['parent']);
                 if (!$isNewNode) {
                     $wrapped->setPropertyValue($config['parent'], $newParent);
                     $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
                 }
                 $start = $parentRight + 1;
                 break;
             case self::LAST_CHILD:
                 $start = $parentRight;
                 $level++;
                 break;
             case self::FIRST_CHILD:
             default:
                 $start = $parentLeft + 1;
                 $level++;
                 break;
         }
         $this->shiftRL($em, $config['useObjectClass'], $start, $treeSize, $parentRootId);
         if (!$isNewNode && $rootId === $parentRootId && $left >= $start) {
             $left += $treeSize;
             $wrapped->setPropertyValue($config['left'], $left);
         }
         if (!$isNewNode && $rootId === $parentRootId && $right >= $start) {
             $right += $treeSize;
             $wrapped->setPropertyValue($config['right'], $right);
         }
         $newRootId = $parentRootId;
     } elseif (!isset($config['root'])) {
         $start = isset($this->treeEdges[$meta->name]) ? $this->treeEdges[$meta->name] : $this->max($em, $config['useObjectClass']);
         $this->treeEdges[$meta->name] = $start + 2;
         $start++;
     } else {
         $start = 1;
         $newRootId = $nodeId;
     }
     $diff = $start - $left;
     if (!$isNewNode) {
         $levelDiff = isset($config['level']) ? $level - $wrapped->getPropertyValue($config['level']) : null;
         $this->shiftRangeRL($em, $config['useObjectClass'], $left, $right, $diff, $rootId, $newRootId, $levelDiff);
         $this->shiftRL($em, $config['useObjectClass'], $left, -$treeSize, $rootId);
     } else {
         $qb = $em->createQueryBuilder();
         $qb->update($config['useObjectClass'], 'node');
         if (isset($config['root'])) {
             $qb->set('node.' . $config['root'], $newRootId);
             $wrapped->setPropertyValue($config['root'], $newRootId);
//.........这里部分代码省略.........
开发者ID:rdohms,项目名称:DoctrineExtensions,代码行数:101,代码来源:Nested.php


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