Merge pull request #18745 from seamuslee001/backdrop_session
[civicrm-core.git] / CRM / Contact / BAO / Query / Hook.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Delegate query functions based on hook system.
20 */
21 class CRM_Contact_BAO_Query_Hook {
22
23 /**
24 * Query objects.
25 *
26 * @var CRM_Contact_BAO_Query_Interface[]
27 */
28 protected $_queryObjects = NULL;
29
30 /**
31 * Singleton function used to manage this object.
32 *
33 * @return object
34 */
35 public static function singleton() {
36 static $singleton = NULL;
37 if (!$singleton) {
38 $singleton = new CRM_Contact_BAO_Query_Hook();
39 }
40 return $singleton;
41 }
42
43 /**
44 * Get or build the list of search objects (via hook).
45 *
46 * @return array
47 * Array of CRM_Contact_BAO_Query_Interface objects
48 */
49 public function getSearchQueryObjects() {
50 if ($this->_queryObjects === NULL) {
51 $this->_queryObjects = [];
52 CRM_Utils_Hook::queryObjects($this->_queryObjects, 'Contact');
53 }
54 return $this->_queryObjects;
55 }
56
57 /**
58 * @return array
59 */
60 public function &getFields() {
61 $extFields = [];
62 foreach (self::getSearchQueryObjects() as $obj) {
63 $flds = $obj->getFields();
64 $extFields = array_merge($extFields, $flds);
65 }
66 return $extFields;
67 }
68
69 /**
70 * @param $apiEntities
71 * @param $fieldOptions
72 */
73 public function alterSearchBuilderOptions(&$apiEntities, &$fieldOptions) {
74 foreach (self::getSearchQueryObjects() as $obj) {
75 $obj->alterSearchBuilderOptions($apiEntities, $fieldOptions);
76 }
77 }
78
79 /**
80 * Alter search query.
81 *
82 * @param string $query
83 * @param string $fnName
84 */
85 public function alterSearchQuery(&$query, $fnName) {
86 foreach (self::getSearchQueryObjects() as $obj) {
87 $obj->$fnName($query);
88 }
89 }
90
91 /**
92 * @param string $fieldName
93 * @param $mode
94 * @param $side
95 *
96 * @return string
97 */
98 public function buildSearchfrom($fieldName, $mode, $side) {
99 $from = '';
100 foreach (self::getSearchQueryObjects() as $obj) {
101 $from .= $obj->from($fieldName, $mode, $side);
102 }
103 return $from;
104 }
105
106 /**
107 * @param $tables
108 */
109 public function setTableDependency(&$tables) {
110 foreach (self::getSearchQueryObjects() as $obj) {
111 $obj->setTableDependency($tables);
112 }
113 }
114
115 /**
116 * @param $panes
117 */
118 public function registerAdvancedSearchPane(&$panes) {
119 foreach (self::getSearchQueryObjects() as $obj) {
120 $obj->registerAdvancedSearchPane($panes);
121 }
122 }
123
124 /**
125 * @param $panes
126 */
127 public function getPanesMapper(&$panes) {
128 foreach (self::getSearchQueryObjects() as $obj) {
129 $obj->getPanesMapper($panes);
130 }
131 }
132
133 /**
134 * @param CRM_Core_Form $form
135 * @param $type
136 */
137 public function buildAdvancedSearchPaneForm(&$form, $type) {
138 foreach (self::getSearchQueryObjects() as $obj) {
139 $obj->buildAdvancedSearchPaneForm($form, $type);
140 }
141 }
142
143 /**
144 * @param $paneTemplatePathArray
145 * @param $type
146 */
147 public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) {
148 foreach (self::getSearchQueryObjects() as $obj) {
149 $obj->setAdvancedSearchPaneTemplatePath($paneTemplatePathArray, $type);
150 }
151 }
152
153 }