QueryBuilder.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\DoctrineORMAdminBundle\Tests\Filter;
  11. use Sonata\DoctrineORMAdminBundle\Filter\Filter;
  12. class QueryBuilder
  13. {
  14. public $parameters = array();
  15. public $query = array();
  16. /**
  17. * @param string $name
  18. * @param mixed $value
  19. */
  20. public function setParameter($name, $value)
  21. {
  22. $this->parameters[$name] = $value;
  23. }
  24. /**
  25. * @param string $query
  26. */
  27. public function andWhere($query)
  28. {
  29. $this->query[] = $query;
  30. }
  31. /**
  32. * @return QueryBuilder
  33. */
  34. public function expr()
  35. {
  36. return $this;
  37. }
  38. /**
  39. * @param string $name
  40. * @param string $value
  41. * @return string
  42. */
  43. public function in($name, $value)
  44. {
  45. $this->query[] = 'in_'.$name;
  46. if (is_array($value)) {
  47. return sprintf('%s IN ("%s")', $name, implode(',', $value));
  48. }
  49. return sprintf('%s IN %s', 'in_'.$name, $value);
  50. }
  51. /**
  52. * @return string
  53. */
  54. public function getRootAlias()
  55. {
  56. return 'o';
  57. }
  58. /**
  59. * @param string $parameter
  60. * @param string $alias
  61. */
  62. public function leftJoin($parameter, $alias)
  63. {
  64. $this->query[] = $parameter;
  65. }
  66. }