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