CompositeExpression.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\DB\QueryBuilder;
  23. use OCP\DB\QueryBuilder\ICompositeExpression;
  24. class CompositeExpression implements ICompositeExpression, \Countable {
  25. /** @var \Doctrine\DBAL\Query\Expression\CompositeExpression */
  26. protected $compositeExpression;
  27. /**
  28. * Constructor.
  29. *
  30. * @param \Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression
  31. */
  32. public function __construct(\Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression) {
  33. $this->compositeExpression = $compositeExpression;
  34. }
  35. /**
  36. * Adds multiple parts to composite expression.
  37. *
  38. * @param array $parts
  39. *
  40. * @return \OCP\DB\QueryBuilder\ICompositeExpression
  41. */
  42. public function addMultiple(array $parts = array()) {
  43. $this->compositeExpression->addMultiple($parts);
  44. return $this;
  45. }
  46. /**
  47. * Adds an expression to composite expression.
  48. *
  49. * @param mixed $part
  50. *
  51. * @return \OCP\DB\QueryBuilder\ICompositeExpression
  52. */
  53. public function add($part) {
  54. $this->compositeExpression->add($part);
  55. return $this;
  56. }
  57. /**
  58. * Retrieves the amount of expressions on composite expression.
  59. *
  60. * @return integer
  61. */
  62. public function count() {
  63. return $this->compositeExpression->count();
  64. }
  65. /**
  66. * Returns the type of this composite expression (AND/OR).
  67. *
  68. * @return string
  69. */
  70. public function getType() {
  71. return $this->compositeExpression->getType();
  72. }
  73. /**
  74. * Retrieves the string representation of this composite expression.
  75. *
  76. * @return string
  77. */
  78. public function __toString()
  79. {
  80. return (string) $this->compositeExpression;
  81. }
  82. }