preliminary whitespace cleanup
[civicrm-core.git] / CRM / Core / Component / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 /*
41 * Name of the class (minus component namespace path)
42 * of the component invocation class'es name.
43 */
44 CONST COMPONENT_INVOKE_CLASS = 'Invoke';
45
46 /*
47 * Name of the class (minus component namespace path)
48 * of the component configuration class'es name.
49 */
50 CONST COMPONENT_CONFIG_CLASS = 'Config';
51
52 /*
53 * Name of the class (minus component namespace path)
54 * of the component BAO Query class'es name.
55 */
56 CONST COMPONENT_BAO_QUERY_CLASS = 'BAO_Query';
57
58 /*
59 * Name of the class (minus component namespace path)
60 * of the component user dashboard plugin.
61 */
62 CONST COMPONENT_USERDASHBOARD_CLASS = 'Page_UserDashboard';
63
64 /*
65 * Name of the class (minus component namespace path)
66 * of the component tab offered to contact record view.
67 */
68 CONST COMPONENT_TAB_CLASS = 'Page_Tab';
69
70 /*
71 * Name of the class (minus component namespace path)
72 * of the component tab offered to contact record view.
73 */
74 CONST COMPONENT_ADVSEARCHPANE_CLASS = 'Form_Search_AdvancedSearchPane';
75
76 /*
77 * Name of the directory (assumed in component directory)
78 * where xml resources used by this component live.
79 */
80 CONST COMPONENT_XML_RESOURCES = 'xml';
81
82 /*
83 * Name of the directory (assumed in xml resources path)
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.
104 *
105 * @param string $name name of the component
106 * @param string $namespace namespace prefix for component's files
107 * @access public
108 *
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
129 /**
130 * Provides permissions that are used by component.
131 * Needs to be implemented in component's information
132 * class.
133 *
134 * NOTE: if using conditionally permission return,
135 * implementation of $getAllUnconditionally is required.
136 * @return array|null collection of permissions, null if none
137 * @access public
138 *
139 */
140 abstract public function getPermissions($getAllUnconditionally = FALSE);
141
142 /**
143 * Provides information about user dashboard element
144 * offered by this component.
145 *
146 * @return array|null collection of required dashboard settings,
147 * null if no element offered
148 * @access public
149 *
150 */
151 abstract public function getUserDashboardElement();
152
153 /**
154 * Provides information about user dashboard element
155 * offered by this component.
156 *
157 * @return array|null collection of required dashboard settings,
158 * null if no element offered
159 * @access public
160 *
161 */
162 abstract public function registerTab();
163
164 /**
165 * Provides information about advanced search pane
166 * offered by this component.
167 *
168 * @return array|null collection of required pane settings,
169 * null if no element offered
170 * @access public
171 *
172 */
173 abstract public function registerAdvancedSearchPane();
174
175 /**
176 * Provides potential activity types that this
177 * component might want to register in activity history.
178 * Needs to be implemented in component's information
179 * class.
180 *
181 * @return array|null collection of activity types
182 * @access public
183 *
184 */
185 abstract public function getActivityTypes();
186
187 /**
188 * Provides information whether given component is currently
189 * marked as enabled in configuration.
190 *
191 * @return boolean true if component is enabled, false if not
192 * @access public
193 *
194 */
195 public function isEnabled() {
196 $config = CRM_Core_Config::singleton();
197 if (in_array($this->info['name'], $config->enableComponents)) {
198 return TRUE;
199 }
200 return FALSE;
201 }
202
203 /**
204 * Provides component's configuration object.
205 *
206 * @return mixed component's configuration object
207 * @access public
208 *
209 */
210 public function getConfigObject() {
211 return $this->_instantiate(self::COMPONENT_CONFIG_CLASS);
212 }
213
214 /**
215 * Provides component's menu definition object.
216 *
217 * @return mixed component's menu definition object
218 * @access public
219 *
220 */
221 public function getMenuObject() {
222 return $this->_instantiate(self::COMPONENT_MENU_CLASS);
223 }
224
225 /**
226 * Provides component's invocation object.
227 *
228 * @return mixed component's invocation object
229 * @access public
230 *
231 */
232 public function getInvokeObject() {
233 return $this->_instantiate(self::COMPONENT_INVOKE_CLASS);
234 }
235
236 /**
237 * Provides component's BAO Query object.
238 *
239 * @return mixed component's BAO Query object
240 * @access public
241 *
242 */
243 public function getBAOQueryObject() {
244 return $this->_instantiate(self::COMPONENT_BAO_QUERY_CLASS);
245 }
246
247 /**
248 * Builds advanced search form's component specific pane.
249 *
250 * @access public
251 *
252 */
253 public function buildAdvancedSearchPaneForm(&$form) {
254 $bao = $this->getBAOQueryObject();
255 $bao->buildSearchForm($form);
256 }
257
258 /**
259 * Provides component's user dashboard page object.
260 *
261 * @return mixed component's User Dashboard applet object
262 * @access public
263 *
264 */
265 public function getUserDashboardObject() {
266 return $this->_instantiate(self::COMPONENT_USERDASHBOARD_CLASS);
267 }
268
269 /**
270 * Provides component's contact record tab object.
271 *
272 * @return mixed component's contact record tab object
273 * @access public
274 *
275 */
276 public function getTabObject() {
277 return $this->_instantiate(self::COMPONENT_TAB_CLASS);
278 }
279
280 /**
281 * Provides component's advanced search pane's template path.
282 *
283 * @return string component's advanced search pane's template path
284 * @access public
285 *
286 */
287 public function getAdvancedSearchPaneTemplatePath() {
288 $fullpath = $this->namespace . '_' . self::COMPONENT_ADVSEARCHPANE_CLASS;
289 return str_replace('_', DIRECTORY_SEPARATOR, $fullpath . '.tpl');
290 }
291
292 /**
293 * Provides information whether given component uses system wide search.
294 *
295 * @return boolean true if component needs search integration
296 * @access public
297 *
298 */
299 public function usesSearch() {
300 return $this->info['search'] ? TRUE : FALSE;
301 }
302
303 /**
304 * Provides the xml menu files
305 *
306 * @return array array of menu files
307 * @access public
308 *
309 */
310 public function menuFiles() {
311 return CRM_Utils_File::getFilesByExtension($this->_getMenuXMLPath(), 'xml');
312 }
313
314 /**
315 * Simple "keyword" getter.
316 * FIXME: It should be protected so the keyword is not
317 * FIXME: accessed from beyond component infrastructure.
318 *
319 * @return string component keyword
320 * @access public
321 *
322 */
323 public function getKeyword() {
324 return $this->keyword;
325 }
326
327 /**
328 * Helper for figuring out menu XML file location.
329 *
330 * @return mixed component's element as class instance
331 * @access private
332 *
333 */
334 private function _getMenuXMLPath() {
335 global $civicrm_root;
336 $fullpath = $this->namespace . '_' . self::COMPONENT_XML_RESOURCES . '_' . self::COMPONENT_MENU_XML;
337 return CRM_Utils_File::addTrailingSlash($civicrm_root . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $fullpath));
338 }
339
340 /**
341 * Helper for instantiating component's elements.
342 *
343 * @return mixed component's element as class instance
344 * @access private
345 *
346 */
347 private function _instantiate($cl) {
348 $className = $this->namespace . '_' . $cl;
349 require_once (str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php');
350 return new $className();
351 }
352 }
353