Commit | Line | Data |
---|---|---|
99e9587a DS |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
99e9587a | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
99e9587a DS |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
99e9587a DS |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Delegate query functions based on hook system | |
38 | */ | |
39 | class CRM_Contact_BAO_Query_Hook { | |
2efcf0c2 | 40 | |
99e9587a DS |
41 | /** |
42 | * @var array of CRM_Contact_BAO_Query_Interface objects | |
43 | */ | |
44 | protected $_queryObjects = NULL; | |
45 | ||
46 | /** | |
100fef9d | 47 | * Singleton function used to manage this object |
99e9587a DS |
48 | * |
49 | * @return object | |
99e9587a DS |
50 | */ |
51 | public static function singleton() { | |
52 | static $singleton = NULL; | |
53 | if (!$singleton) { | |
54 | $singleton = new CRM_Contact_BAO_Query_Hook(); | |
55 | } | |
56 | return $singleton; | |
57 | } | |
58 | ||
353ffa53 TO |
59 | /** |
60 | * Get or build the list of search objects (via hook) | |
61 | * | |
62 | * @return array | |
16b10e64 | 63 | * Array of CRM_Contact_BAO_Query_Interface objects |
353ffa53 | 64 | */ |
99e9587a DS |
65 | public function getSearchQueryObjects() { |
66 | if ($this->_queryObjects === NULL) { | |
67 | $this->_queryObjects = array(); | |
c3e3dd65 | 68 | CRM_Utils_Hook::queryObjects($this->_queryObjects, 'Contact'); |
99e9587a DS |
69 | } |
70 | return $this->_queryObjects; | |
71 | } | |
2efcf0c2 | 72 | |
86538308 EM |
73 | /** |
74 | * @return array | |
75 | */ | |
99e9587a DS |
76 | public function &getFields() { |
77 | $extFields = array(); | |
78 | foreach (self::getSearchQueryObjects() as $obj) { | |
79 | $flds = $obj->getFields(); | |
80 | $extFields = array_merge($extFields, $flds); | |
81 | } | |
82 | return $extFields; | |
83 | } | |
2efcf0c2 | 84 | |
86538308 EM |
85 | /** |
86 | * @param $apiEntities | |
87 | * @param $fieldOptions | |
88 | */ | |
6a5f199e TO |
89 | public function alterSearchBuilderOptions(&$apiEntities, &$fieldOptions) { |
90 | foreach (self::getSearchQueryObjects() as $obj) { | |
91 | $obj->alterSearchBuilderOptions($apiEntities, $fieldOptions); | |
92 | } | |
93 | } | |
94 | ||
86538308 EM |
95 | /** |
96 | * @param $query | |
100fef9d | 97 | * @param string $fnName |
86538308 | 98 | */ |
99e9587a DS |
99 | public function alterSearchQuery(&$query, $fnName) { |
100 | foreach (self::getSearchQueryObjects() as $obj) { | |
101 | $obj->$fnName($query); | |
102 | } | |
103 | } | |
2efcf0c2 | 104 | |
86538308 | 105 | /** |
100fef9d | 106 | * @param string $fieldName |
86538308 EM |
107 | * @param $mode |
108 | * @param $side | |
109 | * | |
110 | * @return string | |
111 | */ | |
99e9587a DS |
112 | public function buildSearchfrom($fieldName, $mode, $side) { |
113 | $from = ''; | |
114 | foreach (self::getSearchQueryObjects() as $obj) { | |
115 | $from .= $obj->from($fieldName, $mode, $side); | |
116 | } | |
117 | return $from; | |
118 | } | |
efa3a566 | 119 | |
86538308 EM |
120 | /** |
121 | * @param $tables | |
122 | */ | |
efa3a566 DS |
123 | public function setTableDependency(&$tables) { |
124 | foreach (self::getSearchQueryObjects() as $obj) { | |
125 | $obj->setTableDependency($tables); | |
126 | } | |
127 | } | |
128 | ||
86538308 EM |
129 | /** |
130 | * @param $panes | |
131 | */ | |
efa3a566 DS |
132 | public function registerAdvancedSearchPane(&$panes) { |
133 | foreach (self::getSearchQueryObjects() as $obj) { | |
134 | $obj->registerAdvancedSearchPane($panes); | |
135 | } | |
136 | } | |
137 | ||
86538308 EM |
138 | /** |
139 | * @param $panes | |
140 | */ | |
066b4d4a DS |
141 | public function getPanesMapper(&$panes) { |
142 | foreach (self::getSearchQueryObjects() as $obj) { | |
143 | $obj->getPanesMapper($panes); | |
144 | } | |
145 | } | |
146 | ||
86538308 | 147 | /** |
c490a46a | 148 | * @param CRM_Core_Form $form |
86538308 EM |
149 | * @param $type |
150 | */ | |
efa3a566 DS |
151 | public function buildAdvancedSearchPaneForm(&$form, $type) { |
152 | foreach (self::getSearchQueryObjects() as $obj) { | |
153 | $obj->buildAdvancedSearchPaneForm($form, $type); | |
154 | } | |
155 | } | |
156 | ||
86538308 EM |
157 | /** |
158 | * @param $paneTemplatePathArray | |
159 | * @param $type | |
160 | */ | |
efa3a566 DS |
161 | public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) { |
162 | foreach (self::getSearchQueryObjects() as $obj) { | |
163 | $obj->setAdvancedSearchPaneTemplatePath($paneTemplatePathArray, $type); | |
164 | } | |
165 | } | |
232624b1 | 166 | } |