Commit | Line | Data |
---|---|---|
99e9587a DS |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | /** | |
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 of CRM_Contact_BAO_Query_Interface objects | |
65 | */ | |
66 | public function getSearchQueryObjects() { | |
67 | if ($this->_queryObjects === NULL) { | |
68 | $this->_queryObjects = array(); | |
c3e3dd65 | 69 | CRM_Utils_Hook::queryObjects($this->_queryObjects, 'Contact'); |
99e9587a DS |
70 | } |
71 | return $this->_queryObjects; | |
72 | } | |
2efcf0c2 | 73 | |
99e9587a DS |
74 | public function &getFields() { |
75 | $extFields = array(); | |
76 | foreach (self::getSearchQueryObjects() as $obj) { | |
77 | $flds = $obj->getFields(); | |
78 | $extFields = array_merge($extFields, $flds); | |
79 | } | |
80 | return $extFields; | |
81 | } | |
2efcf0c2 | 82 | |
6a5f199e TO |
83 | public function alterSearchBuilderOptions(&$apiEntities, &$fieldOptions) { |
84 | foreach (self::getSearchQueryObjects() as $obj) { | |
85 | $obj->alterSearchBuilderOptions($apiEntities, $fieldOptions); | |
86 | } | |
87 | } | |
88 | ||
99e9587a DS |
89 | public function alterSearchQuery(&$query, $fnName) { |
90 | foreach (self::getSearchQueryObjects() as $obj) { | |
91 | $obj->$fnName($query); | |
92 | } | |
93 | } | |
2efcf0c2 | 94 | |
99e9587a DS |
95 | public function buildSearchfrom($fieldName, $mode, $side) { |
96 | $from = ''; | |
97 | foreach (self::getSearchQueryObjects() as $obj) { | |
98 | $from .= $obj->from($fieldName, $mode, $side); | |
99 | } | |
100 | return $from; | |
101 | } | |
efa3a566 DS |
102 | |
103 | public function setTableDependency(&$tables) { | |
104 | foreach (self::getSearchQueryObjects() as $obj) { | |
105 | $obj->setTableDependency($tables); | |
106 | } | |
107 | } | |
108 | ||
109 | public function registerAdvancedSearchPane(&$panes) { | |
110 | foreach (self::getSearchQueryObjects() as $obj) { | |
111 | $obj->registerAdvancedSearchPane($panes); | |
112 | } | |
113 | } | |
114 | ||
066b4d4a DS |
115 | public function getPanesMapper(&$panes) { |
116 | foreach (self::getSearchQueryObjects() as $obj) { | |
117 | $obj->getPanesMapper($panes); | |
118 | } | |
119 | } | |
120 | ||
efa3a566 DS |
121 | public function buildAdvancedSearchPaneForm(&$form, $type) { |
122 | foreach (self::getSearchQueryObjects() as $obj) { | |
123 | $obj->buildAdvancedSearchPaneForm($form, $type); | |
124 | } | |
125 | } | |
126 | ||
127 | public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) { | |
128 | foreach (self::getSearchQueryObjects() as $obj) { | |
129 | $obj->setAdvancedSearchPaneTemplatePath($paneTemplatePathArray, $type); | |
130 | } | |
131 | } | |
232624b1 | 132 | } |