Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | * This interface defines methods that need to be implemented | |
30 | * for a component to introduce itself to the system. | |
31 | * | |
32 | * @package CRM | |
33 | * @copyright CiviCRM LLC (c) 2004-2013 | |
34 | * $Id$ | |
35 | * | |
36 | */ | |
37 | ||
38 | abstract class CRM_Core_Component_Info { | |
39 | ||
40 | /* | |
cbb7c7e0 | 41 | * Name of the class (minus component namespace path) |
42 | * of the component invocation class'es name. | |
6a488035 TO |
43 | */ |
44 | CONST COMPONENT_INVOKE_CLASS = 'Invoke'; | |
45 | ||
46 | /* | |
cbb7c7e0 | 47 | * Name of the class (minus component namespace path) |
6a488035 TO |
48 | * of the component configuration class'es name. |
49 | */ | |
50 | CONST COMPONENT_CONFIG_CLASS = 'Config'; | |
51 | ||
52 | /* | |
cbb7c7e0 | 53 | * Name of the class (minus component namespace path) |
6a488035 TO |
54 | * of the component BAO Query class'es name. |
55 | */ | |
56 | CONST COMPONENT_BAO_QUERY_CLASS = 'BAO_Query'; | |
57 | ||
58 | /* | |
cbb7c7e0 | 59 | * Name of the class (minus component namespace path) |
6a488035 TO |
60 | * of the component user dashboard plugin. |
61 | */ | |
62 | CONST COMPONENT_USERDASHBOARD_CLASS = 'Page_UserDashboard'; | |
63 | ||
64 | /* | |
cbb7c7e0 | 65 | * Name of the class (minus component namespace path) |
6a488035 TO |
66 | * of the component tab offered to contact record view. |
67 | */ | |
68 | CONST COMPONENT_TAB_CLASS = 'Page_Tab'; | |
69 | ||
70 | /* | |
cbb7c7e0 | 71 | * Name of the class (minus component namespace path) |
6a488035 TO |
72 | * of the component tab offered to contact record view. |
73 | */ | |
74 | CONST COMPONENT_ADVSEARCHPANE_CLASS = 'Form_Search_AdvancedSearchPane'; | |
75 | ||
76 | /* | |
cbb7c7e0 | 77 | * Name of the directory (assumed in component directory) |
6a488035 TO |
78 | * where xml resources used by this component live. |
79 | */ | |
80 | CONST COMPONENT_XML_RESOURCES = 'xml'; | |
81 | ||
82 | /* | |
cbb7c7e0 | 83 | * Name of the directory (assumed in xml resources path) |
6a488035 TO |
84 | * containing component menu definition XML file names. |
85 | */ | |
86 | CONST COMPONENT_MENU_XML = 'Menu'; | |
87 | ||
88 | /* | |
89 | * Stores component information. | |
90 | * @var array component settings as key/value pairs | |
91 | */ | |
92 | public $info; | |
93 | ||
94 | /* | |
95 | * Stores component keyword | |
96 | * @var string name of component keyword | |
97 | */ | |
98 | protected $keyword; | |
99 | ||
100 | /* | |
101 | * Class constructor, sets name and namespace (those are stored | |
102 | * in the component registry (database) and no need to duplicate | |
103 | * them here, as well as populates the info variable. | |
cbb7c7e0 | 104 | * |
6a488035 TO |
105 | * @param string $name name of the component |
106 | * @param string $namespace namespace prefix for component's files | |
107 | * @access public | |
cbb7c7e0 | 108 | * |
6a488035 TO |
109 | */ |
110 | public function __construct($name, $namespace, $componentID) { | |
111 | $this->name = $name; | |
112 | $this->namespace = $namespace; | |
113 | $this->componentID = $componentID; | |
114 | $this->info = $this->getInfo(); | |
115 | $this->info['url'] = $this->getKeyword(); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Provides base information about the component. | |
120 | * Needs to be implemented in component's information | |
121 | * class. | |
122 | * | |
123 | * @return array collection of required component settings | |
124 | * @access public | |
125 | * | |
126 | */ | |
127 | abstract public function getInfo(); | |
128 | ||
3bd831aa TO |
129 | /** |
130 | * Get a list of entities to register via API | |
131 | * | |
132 | * @return array list of entities; same format as CRM_Utils_Hook::managedEntities(&$entities) | |
133 | * @see CRM_Utils_Hook::managedEntities | |
134 | */ | |
135 | public function getManagedEntities() { | |
136 | return array(); | |
137 | } | |
138 | ||
6a488035 TO |
139 | /** |
140 | * Provides permissions that are used by component. | |
141 | * Needs to be implemented in component's information | |
142 | * class. | |
143 | * | |
33777e4a PJ |
144 | * NOTE: if using conditionally permission return, |
145 | * implementation of $getAllUnconditionally is required. | |
6a488035 TO |
146 | * @return array|null collection of permissions, null if none |
147 | * @access public | |
148 | * | |
149 | */ | |
33777e4a | 150 | abstract public function getPermissions($getAllUnconditionally = FALSE); |
6a488035 TO |
151 | |
152 | /** | |
153 | * Provides information about user dashboard element | |
154 | * offered by this component. | |
155 | * | |
156 | * @return array|null collection of required dashboard settings, | |
157 | * null if no element offered | |
158 | * @access public | |
159 | * | |
160 | */ | |
161 | abstract public function getUserDashboardElement(); | |
162 | ||
163 | /** | |
164 | * Provides information about user dashboard element | |
165 | * offered by this component. | |
166 | * | |
167 | * @return array|null collection of required dashboard settings, | |
168 | * null if no element offered | |
169 | * @access public | |
170 | * | |
171 | */ | |
172 | abstract public function registerTab(); | |
173 | ||
174 | /** | |
175 | * Provides information about advanced search pane | |
176 | * offered by this component. | |
177 | * | |
178 | * @return array|null collection of required pane settings, | |
179 | * null if no element offered | |
180 | * @access public | |
181 | * | |
182 | */ | |
183 | abstract public function registerAdvancedSearchPane(); | |
184 | ||
185 | /** | |
186 | * Provides potential activity types that this | |
187 | * component might want to register in activity history. | |
188 | * Needs to be implemented in component's information | |
189 | * class. | |
190 | * | |
191 | * @return array|null collection of activity types | |
192 | * @access public | |
193 | * | |
194 | */ | |
195 | abstract public function getActivityTypes(); | |
196 | ||
197 | /** | |
198 | * Provides information whether given component is currently | |
199 | * marked as enabled in configuration. | |
200 | * | |
201 | * @return boolean true if component is enabled, false if not | |
202 | * @access public | |
203 | * | |
204 | */ | |
205 | public function isEnabled() { | |
206 | $config = CRM_Core_Config::singleton(); | |
207 | if (in_array($this->info['name'], $config->enableComponents)) { | |
208 | return TRUE; | |
209 | } | |
210 | return FALSE; | |
211 | } | |
212 | ||
213 | /** | |
214 | * Provides component's configuration object. | |
215 | * | |
216 | * @return mixed component's configuration object | |
217 | * @access public | |
218 | * | |
219 | */ | |
220 | public function getConfigObject() { | |
221 | return $this->_instantiate(self::COMPONENT_CONFIG_CLASS); | |
222 | } | |
223 | ||
224 | /** | |
225 | * Provides component's menu definition object. | |
226 | * | |
227 | * @return mixed component's menu definition object | |
228 | * @access public | |
229 | * | |
230 | */ | |
231 | public function getMenuObject() { | |
232 | return $this->_instantiate(self::COMPONENT_MENU_CLASS); | |
233 | } | |
234 | ||
235 | /** | |
236 | * Provides component's invocation object. | |
237 | * | |
238 | * @return mixed component's invocation object | |
239 | * @access public | |
240 | * | |
241 | */ | |
242 | public function getInvokeObject() { | |
243 | return $this->_instantiate(self::COMPONENT_INVOKE_CLASS); | |
244 | } | |
245 | ||
246 | /** | |
247 | * Provides component's BAO Query object. | |
248 | * | |
249 | * @return mixed component's BAO Query object | |
250 | * @access public | |
251 | * | |
252 | */ | |
253 | public function getBAOQueryObject() { | |
254 | return $this->_instantiate(self::COMPONENT_BAO_QUERY_CLASS); | |
255 | } | |
256 | ||
257 | /** | |
258 | * Builds advanced search form's component specific pane. | |
259 | * | |
260 | * @access public | |
261 | * | |
262 | */ | |
263 | public function buildAdvancedSearchPaneForm(&$form) { | |
264 | $bao = $this->getBAOQueryObject(); | |
265 | $bao->buildSearchForm($form); | |
266 | } | |
267 | ||
268 | /** | |
269 | * Provides component's user dashboard page object. | |
270 | * | |
271 | * @return mixed component's User Dashboard applet object | |
272 | * @access public | |
273 | * | |
274 | */ | |
275 | public function getUserDashboardObject() { | |
276 | return $this->_instantiate(self::COMPONENT_USERDASHBOARD_CLASS); | |
277 | } | |
278 | ||
279 | /** | |
280 | * Provides component's contact record tab object. | |
281 | * | |
282 | * @return mixed component's contact record tab object | |
283 | * @access public | |
284 | * | |
285 | */ | |
286 | public function getTabObject() { | |
287 | return $this->_instantiate(self::COMPONENT_TAB_CLASS); | |
288 | } | |
289 | ||
290 | /** | |
291 | * Provides component's advanced search pane's template path. | |
292 | * | |
293 | * @return string component's advanced search pane's template path | |
294 | * @access public | |
295 | * | |
296 | */ | |
297 | public function getAdvancedSearchPaneTemplatePath() { | |
298 | $fullpath = $this->namespace . '_' . self::COMPONENT_ADVSEARCHPANE_CLASS; | |
299 | return str_replace('_', DIRECTORY_SEPARATOR, $fullpath . '.tpl'); | |
300 | } | |
301 | ||
302 | /** | |
303 | * Provides information whether given component uses system wide search. | |
304 | * | |
305 | * @return boolean true if component needs search integration | |
306 | * @access public | |
307 | * | |
308 | */ | |
309 | public function usesSearch() { | |
310 | return $this->info['search'] ? TRUE : FALSE; | |
311 | } | |
312 | ||
313 | /** | |
314 | * Provides the xml menu files | |
315 | * | |
316 | * @return array array of menu files | |
317 | * @access public | |
318 | * | |
319 | */ | |
320 | public function menuFiles() { | |
321 | return CRM_Utils_File::getFilesByExtension($this->_getMenuXMLPath(), 'xml'); | |
322 | } | |
323 | ||
324 | /** | |
325 | * Simple "keyword" getter. | |
326 | * FIXME: It should be protected so the keyword is not | |
327 | * FIXME: accessed from beyond component infrastructure. | |
328 | * | |
329 | * @return string component keyword | |
330 | * @access public | |
331 | * | |
332 | */ | |
333 | public function getKeyword() { | |
334 | return $this->keyword; | |
335 | } | |
336 | ||
337 | /** | |
338 | * Helper for figuring out menu XML file location. | |
339 | * | |
340 | * @return mixed component's element as class instance | |
341 | * @access private | |
342 | * | |
343 | */ | |
344 | private function _getMenuXMLPath() { | |
345 | global $civicrm_root; | |
346 | $fullpath = $this->namespace . '_' . self::COMPONENT_XML_RESOURCES . '_' . self::COMPONENT_MENU_XML; | |
347 | return CRM_Utils_File::addTrailingSlash($civicrm_root . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $fullpath)); | |
348 | } | |
349 | ||
350 | /** | |
351 | * Helper for instantiating component's elements. | |
352 | * | |
353 | * @return mixed component's element as class instance | |
354 | * @access private | |
355 | * | |
356 | */ | |
357 | private function _instantiate($cl) { | |
358 | $className = $this->namespace . '_' . $cl; | |
359 | require_once (str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'); | |
360 | return new $className(); | |
361 | } | |
362 | } | |
363 |