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