Merge pull request #20239 from eileenmcnaughton/act
[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 $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
47 $loader = Civi::service('angularjs.loader');
48 $loader->addModules('crmDashboard');
49 $loader->setPageName('civicrm/dashboard');
50
51 // For each dashlet that requires an angular directive, load the angular module which provides that directive
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']])) {
56 $loader->addModules($name);
57 continue;
58 }
59 }
60 }
61 }
62
63 return parent::run();
64 }
65
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'])) {
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>";
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
98 }