. */ require_once 'CRM/Core/Page.php'; class CRM_Memberdashboard_Page_MemberDashboard extends CRM_Core_Page { public $contact = NULL; function __construct() { parent::__construct(); $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(); return CRM_Contact_BAO_Contact::retrieve($params, $defaults); } /** * Build user CiviMember and CiviContribute dashboard elements. * * @return Array of dashboard elements */ function buildDashboard() { 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() { $this->assign('contact', $this->contact); $this->assign('dashboardElements', $this->buildDashboard()); parent::run(); CRM_Utils_System::setTitle($this->pageTitle()); } }