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