Bitrix-D7  20.5.0
operator.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage main
6  * @copyright 2001-2016 Bitrix
7  */
8 
11 
12 /**
13  * SQL operators handler.
14  * @package bitrix
15  * @subpackage main
16  */
17 class Operator
18 {
19  /**
20  * Available operators.
21  * @var array
22  */
23  protected static $operators = array(
24  '=' => 'eq',
25  '<>' => 'neq',
26  '!=' => 'neq',
27  '<' => 'lt',
28  '<=' => 'lte',
29  '>' => 'gt',
30  '>=' => 'gte',
31  'in' => 'in',
32  'between' => 'between',
33  'like' => 'like',
34  'exists' => 'exists',
35  'match' => 'match'
36  );
37 
38  /**
39  * List of available operators `code => method`.
40  *
41  * @return array
42  */
43  public static function get()
44  {
45  return static::$operators;
46  }
47 
48  public static function eq($columnSql, $valueSql)
49  {
50  if ($valueSql instanceof NullExpression)
51  {
52  return "{$columnSql} IS NULL";
53  }
54  return "{$columnSql} = {$valueSql}";
55  }
56 
57  public static function neq($columnSql, $valueSql)
58  {
59  if ($valueSql instanceof NullExpression)
60  {
61  return "{$columnSql} IS NOT NULL";
62  }
63  return "{$columnSql} <> {$valueSql}";
64  }
65 
66  public static function lt($columnSql, $valueSql)
67  {
68  return "{$columnSql} < {$valueSql}";
69  }
70 
71  public static function lte($columnSql, $valueSql)
72  {
73  return "{$columnSql} <= {$valueSql}";
74  }
75 
76  public static function gt($columnSql, $valueSql)
77  {
78  return "{$columnSql} > {$valueSql}";
79  }
80 
81  public static function gte($columnSql, $valueSql)
82  {
83  return "{$columnSql} >= {$valueSql}";
84  }
85 
86  public static function in($columnSql, $valueSql)
87  {
88  return "{$columnSql} IN (".join(', ', (array) $valueSql).")";
89  }
90 
91  public static function between($columnSql, $valueSql)
92  {
93  return "{$columnSql} BETWEEN {$valueSql[0]} AND {$valueSql[1]}";
94  }
95 
96  public static function like($columnSql, $valueSql)
97  {
98  return "{$columnSql} LIKE {$valueSql}";
99  }
100 
101  public static function exists(/** @noinspection PhpUnusedParameterInspection */ $columnSql, $valueSql)
102  {
103  return "EXISTS ({$valueSql})";
104  }
105 
106  public static function match($columnSql, $valueSql)
107  {
108  return "MATCH ({$columnSql}) AGAINST ({$valueSql} IN BOOLEAN MODE)";
109  }
110 }
static lt($columnSql, $valueSql)
Definition: operator.php:66
static eq($columnSql, $valueSql)
Definition: operator.php:48
static gte($columnSql, $valueSql)
Definition: operator.php:81
static match($columnSql, $valueSql)
Definition: operator.php:106
static between($columnSql, $valueSql)
Definition: operator.php:91
static in($columnSql, $valueSql)
Definition: operator.php:86
static lte($columnSql, $valueSql)
Definition: operator.php:71
static gt($columnSql, $valueSql)
Definition: operator.php:76
static neq($columnSql, $valueSql)
Definition: operator.php:57
static exists( $columnSql, $valueSql)
Definition: operator.php:101
static like($columnSql, $valueSql)
Definition: operator.php:96