From 2fabfc160c76fd639806e369000bd8c1a0e1da85 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 1 Oct 2014 10:14:31 -0400 Subject: [PATCH] Display CiviMember and CiviContribute dashboard elements. * CRM/Memberdashboard/Page/MemberDashboard.php (__construct): Assign the result of 'loadContact'. (loadContact): Return the contact rather than assigning it to a variable. (buildDashboard): Return an array with CiviMember and CiviContribute dashboard elements. (pageTitle): New method. (run): Use 'pageTitle' method. Assign dashboard elements for rendering. * templates/CRM/Memberdashboard/Page/DashboardElement.tpl: New file. * templates/CRM/Memberdashboard/Page/MemberDashboard.tpl: Render CiviMember and CiviContribute elements. --- CRM/Memberdashboard/Page/MemberDashboard.php | 55 ++++++++++++------- .../Memberdashboard/Page/DashboardElement.tpl | 4 ++ .../Memberdashboard/Page/MemberDashboard.tpl | 11 ++-- 3 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 templates/CRM/Memberdashboard/Page/DashboardElement.tpl diff --git a/CRM/Memberdashboard/Page/MemberDashboard.php b/CRM/Memberdashboard/Page/MemberDashboard.php index f25a94e..9551cd4 100644 --- a/CRM/Memberdashboard/Page/MemberDashboard.php +++ b/CRM/Memberdashboard/Page/MemberDashboard.php @@ -8,39 +8,56 @@ class CRM_Memberdashboard_Page_MemberDashboard extends CRM_Core_Page { function __construct() { parent::__construct(); - $this->loadContact(); + $this->contact = $this->loadContact(); } + /** + * Return a contact object for the current user. + * + * @return CRM_Contact + */ function loadContact() { $session = CRM_Core_Session::singleton(); $params = array('contact_id' => $session->get('userID')); $defaults = array(); - $this->contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); + return CRM_Contact_BAO_Contact::retrieve($params, $defaults); } + /** + * Build user CiviMember and CiviContribute dashboard elements. + * + * @return Array of dashboard elements + */ function buildDashboard() { - $components = CRM_Core_Component::getEnabledComponents(); - - // Use the CiviMember component dashboard. - $memberComponent = $components['CiviMember']; - $elem = $memberComponent->getUserDashboardElement(); - $userDashboard = $memberComponent->getUserDashboardObject(); - $userDashboard->run(); - $dashboardElement = array( - 'class' => 'crm-dashboard-' . strtolower($memberComponent->name), - 'sectionTitle' => $elem['title'], - 'templatePath' => $userDashboard->getTemplateFileName(), - 'weight' => $elem['weight'], - ); - $this->assign('element', $dashboardElement); + return array_map(function($component) { + $elem = $component->getUserDashboardElement(); + $userDashboard = $component->getUserDashboardObject(); + $userDashboard->run(); + return array( + 'class' => 'crm-dashboard-' . strtolower($component->name), + 'sectionTitle' => $elem['title'], + 'templatePath' => $userDashboard->getTemplateFileName(), + 'weight' => $elem['weight'], + ); + }, array_filter(CRM_Core_Component::getEnabledComponents(), function($component) { + return in_array($component->info['name'], array('CiviMember', 'CiviContribute')); + })); + } + + /** + * Return the personalized title for the page. + * + * @return Title string + */ + function pageTitle() { + return ts('Welcome, ') . $this->contact->first_name . '!'; } function run() { - CRM_Utils_System::setTitle(ts('Welcome, ') . $this->contact->first_name . '!'); + CRM_Utils_System::setTitle($this->pageTitle()); $this->assign('contact', $this->contact); - - $this->buildDashboard(); + $this->assign('dashboardElements', $this->buildDashboard()); parent::run(); } diff --git a/templates/CRM/Memberdashboard/Page/DashboardElement.tpl b/templates/CRM/Memberdashboard/Page/DashboardElement.tpl new file mode 100644 index 0000000..90469e5 --- /dev/null +++ b/templates/CRM/Memberdashboard/Page/DashboardElement.tpl @@ -0,0 +1,4 @@ + +
{$element.sectionTitle}
+ {include file=$element.templatePath} + diff --git a/templates/CRM/Memberdashboard/Page/MemberDashboard.tpl b/templates/CRM/Memberdashboard/Page/MemberDashboard.tpl index 8d51908..2bf88a2 100644 --- a/templates/CRM/Memberdashboard/Page/MemberDashboard.tpl +++ b/templates/CRM/Memberdashboard/Page/MemberDashboard.tpl @@ -3,9 +3,8 @@

Your display name is {$contact->display_name}

Your contact ID is #{$contact->id}

- - -
{$element.sectionTitle}
- {include file=$element.templatePath} - - +{include file="CRM/Memberdashboard/Page/DashboardElement.tpl" + element=$dashboardElements.CiviMember } + +{include file="CRM/Memberdashboard/Page/DashboardElement.tpl" + element=$dashboardElements.CiviContribute } -- 2.25.1