INFRA-132 - Fix spacing of @return tag in comments
[civicrm-core.git] / CRM / Contact / BAO / Query / Hook.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * Delegate query functions based on hook system
38 */
39 class CRM_Contact_BAO_Query_Hook {
40
41 /**
42 * @var array of CRM_Contact_BAO_Query_Interface objects
43 */
44 protected $_queryObjects = NULL;
45
46 /**
47 * Singleton function used to manage this object
48 *
49 * @return object
50 * @static
51 *
52 */
53 public static function singleton() {
54 static $singleton = NULL;
55 if (!$singleton) {
56 $singleton = new CRM_Contact_BAO_Query_Hook();
57 }
58 return $singleton;
59 }
60
61 /**
62 * Get or build the list of search objects (via hook)
63 *
64 * @return array
65 * of CRM_Contact_BAO_Query_Interface objects
66 */
67 public function getSearchQueryObjects() {
68 if ($this->_queryObjects === NULL) {
69 $this->_queryObjects = array();
70 CRM_Utils_Hook::queryObjects($this->_queryObjects, 'Contact');
71 }
72 return $this->_queryObjects;
73 }
74
75 /**
76 * @return array
77 */
78 public function &getFields() {
79 $extFields = array();
80 foreach (self::getSearchQueryObjects() as $obj) {
81 $flds = $obj->getFields();
82 $extFields = array_merge($extFields, $flds);
83 }
84 return $extFields;
85 }
86
87 /**
88 * @param $apiEntities
89 * @param $fieldOptions
90 */
91 public function alterSearchBuilderOptions(&$apiEntities, &$fieldOptions) {
92 foreach (self::getSearchQueryObjects() as $obj) {
93 $obj->alterSearchBuilderOptions($apiEntities, $fieldOptions);
94 }
95 }
96
97 /**
98 * @param $query
99 * @param string $fnName
100 */
101 public function alterSearchQuery(&$query, $fnName) {
102 foreach (self::getSearchQueryObjects() as $obj) {
103 $obj->$fnName($query);
104 }
105 }
106
107 /**
108 * @param string $fieldName
109 * @param $mode
110 * @param $side
111 *
112 * @return string
113 */
114 public function buildSearchfrom($fieldName, $mode, $side) {
115 $from = '';
116 foreach (self::getSearchQueryObjects() as $obj) {
117 $from .= $obj->from($fieldName, $mode, $side);
118 }
119 return $from;
120 }
121
122 /**
123 * @param $tables
124 */
125 public function setTableDependency(&$tables) {
126 foreach (self::getSearchQueryObjects() as $obj) {
127 $obj->setTableDependency($tables);
128 }
129 }
130
131 /**
132 * @param $panes
133 */
134 public function registerAdvancedSearchPane(&$panes) {
135 foreach (self::getSearchQueryObjects() as $obj) {
136 $obj->registerAdvancedSearchPane($panes);
137 }
138 }
139
140 /**
141 * @param $panes
142 */
143 public function getPanesMapper(&$panes) {
144 foreach (self::getSearchQueryObjects() as $obj) {
145 $obj->getPanesMapper($panes);
146 }
147 }
148
149 /**
150 * @param CRM_Core_Form $form
151 * @param $type
152 */
153 public function buildAdvancedSearchPaneForm(&$form, $type) {
154 foreach (self::getSearchQueryObjects() as $obj) {
155 $obj->buildAdvancedSearchPaneForm($form, $type);
156 }
157 }
158
159 /**
160 * @param $paneTemplatePathArray
161 * @param $type
162 */
163 public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) {
164 foreach (self::getSearchQueryObjects() as $obj) {
165 $obj->setAdvancedSearchPaneTemplatePath($paneTemplatePathArray, $type);
166 }
167 }
168 }