Merge pull request #19296 from eileenmcnaughton/fbool
[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 = new Civi\Angular\AngularLoader();
48 $loader->setPageName('civicrm/dashboard');
49
50 // For each dashlet that requires an angular directive, load the angular module which provides that directive
51 $modules = [];
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 $modules[] = $name;
57 continue;
58 }
59 }
60 }
61 }
62 $loader->setModules($modules);
63
64 $loader->load();
65
66 return parent::run();
67 }
68
69 /**
70 * partialsCallback from crmDashboard.ang.php
71 *
72 * Generates an html template for each angular-based dashlet.
73 *
74 * @param $moduleName
75 * @param $module
76 * @return array
77 */
78 public static function angularPartials($moduleName, $module) {
79 $partials = [];
80 foreach (CRM_Core_BAO_Dashboard::getContactDashlets() as $dashlet) {
81 if (!empty($dashlet['directive'])) {
82 $partials["~/$moduleName/directives/{$dashlet['directive']}.html"] = "<{$dashlet['directive']}></{$dashlet['directive']}>";
83 }
84 }
85 return $partials;
86 }
87
88 /**
89 * settingsFactory from crmDashboard.ang.php
90 *
91 * @return array
92 */
93 public static function angularSettings() {
94 return [
95 'dashlets' => CRM_Core_BAO_Dashboard::getContactDashlets(),
96 ];
97 }
98
99 }