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 | ||
9d9fa5bc TO |
39 | $communityMessages = CRM_Core_CommunityMessages::create(); |
40 | if ($communityMessages->isEnabled()) { | |
41 | $message = $communityMessages->pick(); | |
42 | if ($message) { | |
43 | $this->assign('communityMessages', $communityMessages->evalMarkup($message['markup'])); | |
44 | } | |
45 | } | |
46 | ||
b1510da4 CW |
47 | $loader = Civi::service('angularjs.loader'); |
48 | $loader->addModules('crmDashboard'); | |
f263929f CW |
49 | $loader->setPageName('civicrm/dashboard'); |
50 | ||
51 | // For each dashlet that requires an angular directive, load the angular module which provides that directive | |
f263929f CW |
52 | foreach (CRM_Core_BAO_Dashboard::getContactDashlets() as $dashlet) { |
53 | if (!empty($dashlet['directive'])) { | |
54 | foreach ($loader->getAngular()->getModules() as $name => $module) { | |
55 | if (!empty($module['exports'][$dashlet['directive']])) { | |
b1510da4 | 56 | $loader->addModules($name); |
f263929f CW |
57 | continue; |
58 | } | |
59 | } | |
60 | } | |
61 | } | |
f263929f | 62 | |
6a488035 TO |
63 | return parent::run(); |
64 | } | |
96025800 | 65 | |
f263929f CW |
66 | /** |
67 | * partialsCallback from crmDashboard.ang.php | |
68 | * | |
69 | * Generates an html template for each angular-based dashlet. | |
70 | * | |
71 | * @param $moduleName | |
72 | * @param $module | |
73 | * @return array | |
74 | */ | |
75 | public static function angularPartials($moduleName, $module) { | |
76 | $partials = []; | |
77 | foreach (CRM_Core_BAO_Dashboard::getContactDashlets() as $dashlet) { | |
78 | if (!empty($dashlet['directive'])) { | |
a9cf6070 CW |
79 | // FIXME: Wrapping each directive in <div id='bootstrap-theme'> produces invalid html (duplicate ids in the dom) |
80 | // but it's the only practical way to selectively apply boostrap3 theming to specific dashlets | |
81 | $partials["~/$moduleName/directives/{$dashlet['directive']}.html"] = "<div id='bootstrap-theme'><{$dashlet['directive']}></{$dashlet['directive']}></div>"; | |
f263929f CW |
82 | } |
83 | } | |
84 | return $partials; | |
85 | } | |
86 | ||
87 | /** | |
88 | * settingsFactory from crmDashboard.ang.php | |
89 | * | |
90 | * @return array | |
91 | */ | |
92 | public static function angularSettings() { | |
93 | return [ | |
94 | 'dashlets' => CRM_Core_BAO_Dashboard::getContactDashlets(), | |
95 | ]; | |
96 | } | |
97 | ||
6a488035 | 98 | } |