Merge pull request #23707 from eileenmcnaughton/import_activity
[civicrm-core.git] / CRM / Contact / Page / DashBoard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * CiviCRM Dashboard.
20 */
21 class CRM_Contact_Page_DashBoard extends CRM_Core_Page {
22
23 /**
24 * Run dashboard.
25 */
26 public function run() {
27 CRM_Utils_System::setTitle(ts('CiviCRM Home'));
28 $contactID = CRM_Core_Session::getLoggedInContactID();
29
30 // call hook to get html from other modules
31 // ignored but needed to prevent warnings
32 $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW;
33 $html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement);
34 if (is_array($html)) {
35 $this->assign_by_ref('hookContent', $html);
36 $this->assign('hookContentPlacement', $contentPlacement);
37 }
38
39 $this->assign('communityMessages', $this->getCommunityMessageOutput());
40
41 $loader = Civi::service('angularjs.loader');
42 $loader->addModules('crmDashboard');
43 $loader->setPageName('civicrm/dashboard');
44
45 // For each dashlet that requires an angular directive, load the angular module which provides that directive
46 foreach (CRM_Core_BAO_Dashboard::getContactDashlets() as $dashlet) {
47 if (!empty($dashlet['directive'])) {
48 foreach ($loader->getAngular()->getModules() as $name => $module) {
49 if (!empty($module['exports'][$dashlet['directive']])) {
50 $loader->addModules($name);
51 continue;
52 }
53 }
54 }
55 }
56
57 return parent::run();
58 }
59
60 /**
61 * partialsCallback from crmDashboard.ang.php
62 *
63 * Generates an html template for each angular-based dashlet.
64 *
65 * @param $moduleName
66 * @param $module
67 * @return array
68 */
69 public static function angularPartials($moduleName, $module) {
70 $partials = [];
71 foreach (CRM_Core_BAO_Dashboard::getContactDashlets() as $dashlet) {
72 if (!empty($dashlet['directive'])) {
73 // FIXME: Wrapping each directive in <div id='bootstrap-theme'> produces invalid html (duplicate ids in the dom)
74 // but it's the only practical way to selectively apply boostrap3 theming to specific dashlets
75 $partials["~/$moduleName/directives/{$dashlet['directive']}.html"] = "<div id='bootstrap-theme'><{$dashlet['directive']}></{$dashlet['directive']}></div>";
76 }
77 }
78 return $partials;
79 }
80
81 /**
82 * settingsFactory from crmDashboard.ang.php
83 *
84 * @return array
85 */
86 public static function angularSettings() {
87 return [
88 'dashlets' => CRM_Core_BAO_Dashboard::getContactDashlets(),
89 ];
90 }
91
92 /**
93 * Get community message output.
94 *
95 * @return string
96 */
97 protected function getCommunityMessageOutput(): string {
98 $communityMessages = CRM_Core_CommunityMessages::create();
99 if ($communityMessages->isEnabled()) {
100 $message = $communityMessages->pick();
101 if ($message) {
102 return $communityMessages->evalMarkup($message['markup']);
103 }
104 }
105 return '';
106 }
107
108 }