--- /dev/null
+<?php
+/**
+ * FSF Member Dashboard
+ * Copyright © 2014 Free Software Foundation, Inc.
+ *
+ * This file is a part of FSF Member Dashboard.
+ *
+ * FSF Member Dashboard is free software; you can copy, modify, and
+ * distribute it under the terms of the GNU Affero General Public
+ * License Version 3, 19 November 2007 and the CiviCRM Licensing
+ * Exception.
+ *
+ * FSF Member Dashboard is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FSF Member Dashboard. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+class CRM_Memberdashboard_Page_ComponentHelper {
+ public $componentNames = array();
+ public $components = array();
+
+ function __construct($componentNames) {
+ $this->componentNames = $componentNames;
+ $this->components = $this->loadComponents();
+ }
+
+ /**
+ * Return an array of components that will be rendered on the dashboard.
+ *
+ * @return Component array
+ */
+ function loadComponents() {
+ $allComponents = CRM_Core_Component::getEnabledComponents();
+ $names = $this->componentNames;
+
+ return array_filter($allComponents, function($component) use($names) {
+ return in_array($component->info['name'], $names);
+ });
+ }
+
+ /**
+ * Build user CiviMember and CiviContribute dashboard elements.
+ *
+ * @return Array of dashboard elements
+ */
+ function buildDashboardElements() {
+ return array_map(function($component) {
+ $elem = $component->getUserDashboardElement();
+ return array(
+ 'class' => 'crm-dashboard-' . strtolower($component->name),
+ 'sectionTitle' => $elem['title'],
+ 'templatePath' => 'CRM/Memberdashboard/Page/Element/' .
+ $component->name . '.tpl',
+ 'weight' => $elem['weight'],
+ );
+ }, $this->components);
+ }
+
+ function run() {
+ // Setup dashboard component state.
+ foreach ($this->components as $name => $component) {
+ $userDashboard = $component->getUserDashboardObject();
+ $userDashboard->run();
+ }
+ }
+}
class CRM_Memberdashboard_Page_MemberDashboard extends CRM_Core_Page {
public $contact = NULL;
- public $components = array();
function __construct() {
parent::__construct();
$this->contact = $this->loadContact();
- $this->components = $this->loadComponents();
}
/**
return CRM_Contact_BAO_Contact::retrieve($params, $defaults);
}
- /**
- * Return an array of components that will be rendered on the dashboard.
- *
- * @return Component array
- */
- function loadComponents() {
- return array_filter(CRM_Core_Component::getEnabledComponents(), function($component) {
- return in_array($component->info['name'], array('CiviMember', 'CiviContribute'));
- });
- }
-
- /**
- * Build user CiviMember and CiviContribute dashboard elements.
- *
- * @return Array of dashboard elements
- */
- function buildDashboardElements() {
- return array_map(function($component) {
- $elem = $component->getUserDashboardElement();
- return array(
- 'class' => 'crm-dashboard-' . strtolower($component->name),
- 'sectionTitle' => $elem['title'],
- 'templatePath' => 'CRM/Memberdashboard/Page/Element/' .
- $component->name . '.tpl',
- 'weight' => $elem['weight'],
- );
- }, $this->components);
- }
-
/**
* Return the personalized title for the page.
*
}
function run() {
- // Setup dashboard component state.
- foreach ($this->components as $name => $component) {
- $userDashboard = $component->getUserDashboardObject();
- $userDashboard->run();
- }
+ $helper = new CRM_Memberdashboard_Page_ComponentHelper(array(
+ 'CiviMember',
+ 'CiviContribute'
+ ));
+ $helper->run();
- $this->assign('contact', $this->contact);
- $this->assign('dashboardElements', $this->buildDashboardElements());
+ $this->assign('dashboardElements', $helper->buildDashboardElements());
parent::run();