Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\search;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Database\Query\Condition;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Extends the core SearchQuery to be able to gets its protected values.
|
Chris@0
|
9 */
|
Chris@0
|
10 class ViewsSearchQuery extends SearchQuery {
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Returns the conditions property.
|
Chris@0
|
14 *
|
Chris@0
|
15 * @return array
|
Chris@0
|
16 * The query conditions.
|
Chris@0
|
17 */
|
Chris@0
|
18 public function &conditions() {
|
Chris@0
|
19 return $this->conditions;
|
Chris@0
|
20 }
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Returns the words property.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @return array
|
Chris@0
|
26 * The positive search keywords.
|
Chris@0
|
27 */
|
Chris@0
|
28 public function words() {
|
Chris@0
|
29 return $this->words;
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Returns the simple property.
|
Chris@0
|
34 *
|
Chris@0
|
35 * @return bool
|
Chris@0
|
36 * TRUE if it is a simple query, and FALSE if it is complicated (phrases
|
Chris@0
|
37 * or LIKE).
|
Chris@0
|
38 */
|
Chris@0
|
39 public function simple() {
|
Chris@0
|
40 return $this->simple;
|
Chris@0
|
41 }
|
Chris@0
|
42
|
Chris@0
|
43 /**
|
Chris@0
|
44 * Returns the matches property.
|
Chris@0
|
45 *
|
Chris@0
|
46 * @return int
|
Chris@0
|
47 * The number of matches needed.
|
Chris@0
|
48 */
|
Chris@0
|
49 public function matches() {
|
Chris@0
|
50 return $this->matches;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * Executes and returns the protected parseSearchExpression method.
|
Chris@0
|
55 */
|
Chris@0
|
56 public function publicParseSearchExpression() {
|
Chris@0
|
57 return $this->parseSearchExpression();
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 /**
|
Chris@0
|
61 * Replaces the original condition with a custom one from views recursively.
|
Chris@0
|
62 *
|
Chris@0
|
63 * @param string $search
|
Chris@0
|
64 * The searched value.
|
Chris@0
|
65 * @param string $replace
|
Chris@0
|
66 * The value which replaces the search value.
|
Chris@0
|
67 * @param array $condition
|
Chris@0
|
68 * The query conditions array in which the string is replaced. This is an
|
Chris@0
|
69 * item from a \Drupal\Core\Database\Query\Condition::conditions array,
|
Chris@0
|
70 * which must have a 'field' element.
|
Chris@0
|
71 */
|
Chris@0
|
72 public function conditionReplaceString($search, $replace, &$condition) {
|
Chris@0
|
73 if ($condition['field'] instanceof Condition) {
|
Chris@0
|
74 $conditions =& $condition['field']->conditions();
|
Chris@0
|
75 foreach ($conditions as $key => &$subcondition) {
|
Chris@0
|
76 if (is_numeric($key)) {
|
Chris@0
|
77 // As conditions can be nested, the function has to be called
|
Chris@0
|
78 // recursively.
|
Chris@0
|
79 $this->conditionReplaceString($search, $replace, $subcondition);
|
Chris@0
|
80 }
|
Chris@0
|
81 }
|
Chris@0
|
82 }
|
Chris@0
|
83 else {
|
Chris@0
|
84 $condition['field'] = str_replace($search, $replace, $condition['field']);
|
Chris@0
|
85 }
|
Chris@0
|
86 }
|
Chris@0
|
87
|
Chris@0
|
88 }
|