MaterializedPath.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Gedmo\Tree\Strategy\ODM\MongoDB;
  3. use Gedmo\Tree\Strategy\AbstractMaterializedPath;
  4. /**
  5. * This strategy makes tree using materialized path strategy
  6. *
  7. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  8. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  9. * @package Gedmo.Tree.Strategy.ODM.MongoDB
  10. * @subpackage MaterializedPath
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class MaterializedPath extends AbstractMaterializedPath
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function removeNode($om, $meta, $config, $node)
  20. {
  21. $pathProp = $meta->getReflectionProperty($config['path']);
  22. $pathProp->setAccessible(true);
  23. // Remove node and its children
  24. $om->createQueryBuilder()
  25. ->remove($meta->name)
  26. ->field($config['path'])->equals(new \MongoRegex('/^'.preg_quote($pathProp->getValue($node)).'.?+/'))
  27. ->getQuery()
  28. ->execute();
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function getChildren($om, $meta, $config, $originalPath)
  34. {
  35. return $om->createQueryBuilder()
  36. ->find($meta->name)
  37. ->field($config['path'])->equals(new \MongoRegex('/^'.preg_quote($originalPath).'.+/'))
  38. ->sort($config['path'], 'asc') // This may save some calls to updateNode
  39. ->getQuery()
  40. ->execute();
  41. }
  42. }