NotConditionBuilder.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\conditions;
  8. use yii\db\ExpressionBuilderInterface;
  9. use yii\db\ExpressionBuilderTrait;
  10. use yii\db\ExpressionInterface;
  11. /**
  12. * Class NotConditionBuilder builds objects of [[NotCondition]]
  13. *
  14. * @author Dmytro Naumenko <d.naumenko.a@gmail.com>
  15. * @since 2.0.14
  16. */
  17. class NotConditionBuilder implements ExpressionBuilderInterface
  18. {
  19. use ExpressionBuilderTrait;
  20. /**
  21. * Method builds the raw SQL from the $expression that will not be additionally
  22. * escaped or quoted.
  23. *
  24. * @param ExpressionInterface|NotCondition $expression the expression to be built.
  25. * @param array $params the binding parameters.
  26. * @return string the raw SQL that will not be additionally escaped or quoted.
  27. */
  28. public function build(ExpressionInterface $expression, array &$params = [])
  29. {
  30. $operand = $expression->getCondition();
  31. if ($operand === '') {
  32. return '';
  33. }
  34. $expession = $this->queryBuilder->buildCondition($operand, $params);
  35. return "{$this->getNegationOperator()} ($expession)";
  36. }
  37. /**
  38. * @return string
  39. */
  40. protected function getNegationOperator()
  41. {
  42. return 'NOT';
  43. }
  44. }