12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace Gedmo\Tree\Strategy\ORM;
- use Gedmo\Tree\Strategy\AbstractMaterializedPath;
- use Doctrine\Common\Persistence\ObjectManager;
- use Gedmo\Mapping\Event\AdapterInterface;
- /**
- * This strategy makes tree using materialized path strategy
- *
- * @author Gustavo Falco <comfortablynumb84@gmail.com>
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- class MaterializedPath extends AbstractMaterializedPath
- {
- /**
- * {@inheritdoc}
- */
- public function removeNode($om, $meta, $config, $node)
- {
- $uow = $om->getUnitOfWork();
- $pathProp = $meta->getReflectionProperty($config['path']);
- $pathProp->setAccessible(true);
- $path = addcslashes($pathProp->getValue($node), '%');
- // 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);
- }
- }
- /**
- * {@inheritdoc}
- */
- public function getChildren($om, $meta, $config, $path)
- {
- $path = addcslashes($path, '%');
- $qb = $om->createQueryBuilder($config['useObjectClass']);
- $qb->select('e')
- ->from($config['useObjectClass'], 'e')
- ->where($qb->expr()->like('e.'.$config['path'], $qb->expr()->literal($path.'%')))
- ->andWhere('e.'.$config['path'].' != :path')
- ->orderBy('e.'.$config['path'], 'asc'); // This may save some calls to updateNode
- $qb->setParameter('path', $path);
- return $qb->getQuery()
- ->execute();
- }
- }
|