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();
}
<p>Your display name is {$contact->display_name}</p>
<p>Your contact ID is #{$contact->id}</p>
-<tr{if isset($element.class)} class="{$element.class}"{/if}>
- <td>
- <div class="header-dark">{$element.sectionTitle}</div>
- {include file=$element.templatePath}
- </td>
-</tr>
+{include file="CRM/Memberdashboard/Page/DashboardElement.tpl"
+ element=$dashboardElements.CiviMember }
+
+{include file="CRM/Memberdashboard/Page/DashboardElement.tpl"
+ element=$dashboardElements.CiviContribute }