Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
616eac7e | 19 | * CiviCRM Dashboard. |
6a488035 TO |
20 | */ |
21 | class CRM_Contact_Page_DashBoard extends CRM_Core_Page { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Run dashboard. |
6a488035 | 25 | */ |
00be9182 | 26 | public function run() { |
6a488035 | 27 | CRM_Utils_System::setTitle(ts('CiviCRM Home')); |
3bdcd4ec | 28 | $contactID = CRM_Core_Session::getLoggedInContactID(); |
6a488035 | 29 | |
6a488035 TO |
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 | ||
eaa5a171 | 39 | $this->assign('communityMessages', $this->getCommunityMessageOutput()); |
9d9fa5bc | 40 | |
b1510da4 CW |
41 | $loader = Civi::service('angularjs.loader'); |
42 | $loader->addModules('crmDashboard'); | |
f263929f CW |
43 | $loader->setPageName('civicrm/dashboard'); |
44 | ||
45 | // For each dashlet that requires an angular directive, load the angular module which provides that directive | |
f263929f CW |
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']])) { | |
b1510da4 | 50 | $loader->addModules($name); |
f263929f CW |
51 | continue; |
52 | } | |
53 | } | |
54 | } | |
55 | } | |
f263929f | 56 | |
6a488035 TO |
57 | return parent::run(); |
58 | } | |
96025800 | 59 | |
f263929f CW |
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'])) { | |
a9cf6070 CW |
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>"; | |
f263929f CW |
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 | ||
eaa5a171 EM |
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 | ||
6a488035 | 108 | } |