3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Component stores all the static and dynamic information of the various
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Core_Component
{
40 * End part (filename) of the component information class'es name
41 * that needs to be present in components main directory.
43 CONST COMPONENT_INFO_CLASS
= 'Info';
45 private static $_info = NULL;
47 static $_contactSubTypes = NULL;
49 private static function &_info($force = FALSE) {
50 if (self
::$_info == NULL ||
$force) {
51 self
::$_info = array();
54 $config = CRM_Core_Config
::singleton();
55 $c = self
::getComponents();
57 foreach ($c as $name => $comp) {
58 if (in_array($name, $config->enableComponents
)) {
59 self
::$_info[$name] = $comp;
67 static function get($name, $attribute = NULL) {
68 $comp = CRM_Utils_Array
::value($name, self
::_info());
70 return CRM_Utils_Array
::value($attribute, $comp->info
);
75 public static function &getComponents($force = FALSE) {
76 static $_cache = NULL;
78 if (!$_cache ||
$force) {
81 $cr = new CRM_Core_DAO_Component();
83 while ($cr->fetch()) {
84 $infoClass = $cr->namespace . '_' . self
::COMPONENT_INFO_CLASS
;
85 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $infoClass) . '.php');
86 $infoObject = new $infoClass($cr->name
, $cr->namespace, $cr->id
);
87 if ($infoObject->info
['name'] !== $cr->name
) {
88 CRM_Core_Error
::fatal("There is a discrepancy between name in component registry and in info file ({$cr->name}).");
90 $_cache[$cr->name
] = $infoObject;
98 static public function &getEnabledComponents($force = FALSE) {
99 return self
::_info($force);
102 static public function flushEnabledComponents() {
103 self
::getEnabledComponents(TRUE);
106 public static function &getNames($translated = FALSE) {
107 $allComponents = self
::getComponents();
110 foreach ($allComponents as $name => $comp) {
112 $names[$comp->componentID
] = $comp->info
['translatedName'];
115 $names[$comp->componentID
] = $name;
121 static function invoke(&$args, $type) {
122 $info = self
::_info();
123 $config = CRM_Core_Config
::singleton();
125 $firstArg = CRM_Utils_Array
::value(1, $args, '');
126 $secondArg = CRM_Utils_Array
::value(2, $args, '');
127 foreach ($info as $name => $comp) {
128 if (in_array($name, $config->enableComponents
) &&
129 (($comp->info
['url'] === $firstArg && $type == 'main') ||
130 ($comp->info
['url'] === $secondArg && $type == 'admin')
133 if ($type == 'main') {
134 // also set the smarty variables to the current component
135 $template = CRM_Core_Smarty
::singleton();
136 $template->assign('activeComponent', $name);
137 if (CRM_Utils_Array
::value('formTpl', $comp->info
[$name])) {
138 $template->assign('formTpl', $comp->info
[$name]['formTpl']);
140 if (CRM_Utils_Array
::value('css', $comp->info
[$name])) {
141 $styleSheets = '<style type="text/css">@import url(' . "{$config->resourceBase}css/{$comp->info[$name]['css']});</style>";
142 CRM_Utils_System
::addHTMLHead($styleSheet);
145 $inv = $comp->getInvokeObject();
153 static function xmlMenu() {
155 // lets build the menu for all components
156 $info = self
::getComponents(TRUE);
159 foreach ($info as $name => $comp) {
160 $files = array_merge($files,
168 static function &menu() {
169 $info = self
::_info();
171 foreach ($info as $name => $comp) {
172 $mnu = $comp->getMenuObject();
174 $ret = $mnu->permissioned();
175 $items = array_merge($items, $ret);
177 $ret = $mnu->main($task);
178 $items = array_merge($items, $ret);
183 static function addConfig(&$config, $oldMode = FALSE) {
184 $info = self
::_info();
186 foreach ($info as $name => $comp) {
187 $cfg = $comp->getConfigObject();
188 $cfg->add($config, $oldMode);
193 static function getComponentID($componentName) {
194 $info = self
::_info();
196 return $info[$componentName]->componentID
;
199 static function getComponentName($componentID) {
200 $info = self
::_info();
202 $componentName = NULL;
203 foreach ($info as $compName => $component) {
204 if ($component->componentID
== $componentID) {
205 $componentName = $compName;
210 return $componentName;
213 static function &getQueryFields() {
214 $info = self
::_info();
216 foreach ($info as $name => $comp) {
217 if ($comp->usesSearch()) {
218 $bqr = $comp->getBAOQueryObject();
219 $flds = $bqr->getFields();
220 $fields = array_merge($fields, $flds);
226 static function alterQuery(&$query, $fnName) {
227 $info = self
::_info();
229 foreach ($info as $name => $comp) {
230 if ($comp->usesSearch()) {
231 $bqr = $comp->getBAOQueryObject();
232 $bqr->$fnName($query);
237 static function from($fieldName, $mode, $side) {
238 $info = self
::_info();
241 foreach ($info as $name => $comp) {
242 if ($comp->usesSearch()) {
243 $bqr = $comp->getBAOQueryObject();
244 $from = $bqr->from($fieldName, $mode, $side);
253 static function &defaultReturnProperties($mode,
254 $includeCustomFields = TRUE
256 $info = self
::_info();
259 foreach ($info as $name => $comp) {
260 if ($comp->usesSearch()) {
261 $bqr = $comp->getBAOQueryObject();
262 $properties = $bqr->defaultReturnProperties($mode, $includeCustomFields);
271 static function &buildSearchForm(&$form) {
272 $info = self
::_info();
274 foreach ($info as $name => $comp) {
275 if ($comp->usesSearch()) {
276 $bqr = $comp->getBAOQueryObject();
277 $bqr->buildSearchForm($form);
282 static function &addShowHide(&$showHide) {
283 $info = self
::_info();
285 foreach ($info as $name => $comp) {
286 if ($comp->usesSearch()) {
287 $bqr = $comp->getBAOQueryObject();
288 $bqr->addShowHide($showHide);
293 static function searchAction(&$row, $id) {
294 $info = self
::_info();
296 foreach ($info as $name => $comp) {
297 if ($comp->usesSearch()) {
298 $bqr = $comp->getBAOQueryObject();
299 $bqr->searchAction($row, $id);
304 static function &contactSubTypes() {
305 if (self
::$_contactSubTypes == NULL) {
306 self
::$_contactSubTypes = array();
308 return self
::$_contactSubTypes;
312 static function &contactSubTypeProperties($subType, $op) {
313 $properties = self
::contactSubTypes();
314 if (array_key_exists($subType, $properties) &&
315 array_key_exists($op, $properties[$subType])
317 return $properties[$subType][$op];
319 return CRM_Core_DAO
::$_nullObject;
322 static function &taskList() {
323 $info = self
::_info();
326 foreach ($info as $name => $value) {
327 if (CRM_Utils_Array
::value('task', $info[$name])) {
328 $tasks +
= $info[$name]['task'];
335 * Function to handle table dependencies of components
337 * @param array $tables array of tables
343 static function tableNames(&$tables) {
344 $info = self
::_info();
346 foreach ($info as $name => $comp) {
347 if ($comp->usesSearch()) {
348 $bqr = $comp->getBAOQueryObject();
349 $bqr->tableNames($tables);
355 * Function to get components info from info file
358 static function getComponentsFromFile($crmFolderDir) {
359 $components = array();
360 //traverse CRM folder and check for Info file
361 if (is_dir($crmFolderDir)) {
362 $dir = opendir($crmFolderDir);
363 while ($subDir = readdir($dir)) {
364 // skip the extensions diretory since it has an Info.php file also
365 if ($subDir == 'Extension') {
369 $infoFile = $crmFolderDir . "/{$subDir}/" . self
::COMPONENT_INFO_CLASS
. '.php';
370 if (file_exists($infoFile)) {
371 $infoClass = 'CRM_' . $subDir . '_' . self
::COMPONENT_INFO_CLASS
;
372 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $infoClass) . '.php');
373 $infoObject = new $infoClass(NULL, NULL, NULL);
374 $components[$infoObject->info
['name']] = $infoObject;