a51bbf3efe04c5997f51254cbf9bf7490fdaac7c
[org.fsf.memberdashboard.git] / CRM / Memberdashboard / Page / MemberDashboard.php
1 <?php
2 /**
3 * FSF Member Dashboard
4 * Copyright © 2014 Free Software Foundation, Inc.
5 *
6 * This file is a part of FSF Member Dashboard.
7 *
8 * FSF Member Dashboard is free software; you can copy, modify, and
9 * distribute it under the terms of the GNU Affero General Public
10 * License Version 3, 19 November 2007 and the CiviCRM Licensing
11 * Exception.
12 *
13 * FSF Member Dashboard is distributed in the hope that it will be
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with FSF Member Dashboard. If not, see
20 * <http://www.gnu.org/licenses/>.
21 */
22
23 require_once 'CRM/Core/Page.php';
24
25 class CRM_Memberdashboard_Page_MemberDashboard extends CRM_Memberdashboard_Page {
26 /**
27 * Return the personalized title for the page.
28 *
29 * @return Title string
30 */
31 function pageTitle() {
32 return ts('Welcome, ') . $this->contact['first_name'] . '!';
33 }
34
35 /**
36 * There isn't a function that does this simple task in the PCP BAO,
37 * surprisingly.
38 */
39 function campaignPages() {
40 $dao = CRM_Core_DAO::executeQuery(
41 'SELECT id, title, is_active, is_honor_roll FROM civicrm_pcp WHERE contact_id=%1',
42 array( 1 => array($this->contact['id'], 'Integer') )
43 );
44
45 $pages = array();
46
47 while($dao->fetch()) {
48 $pages[] = array(
49 'id' => $dao->id,
50 'title' => $dao->title,
51 'is_active' => $dao->is_active,
52 'is_honor_roll' => $dao->is_honor_roll
53 );
54 }
55
56 $dao->free();
57
58 return $pages;
59 }
60
61 function makeChecksum() {
62 return CRM_Contact_BAO_Contact_Utils::generateChecksum($this->contact['id']);
63 }
64
65 function run() {
66 $helper = new CRM_Memberdashboard_Page_ComponentHelper(array(
67 'CiviMember',
68 'CiviContribute'
69 ));
70 $helper->run();
71
72 $this->assign('dashboardElements', $helper->buildDashboardElements());
73 $this->assign('campaignPages', $this->campaignPages());
74 // Checksum for editing recurring contributions.
75 $this->assign('contributionChecksum', $this->makeChecksum());
76 $this->assign('contactId', $this->contact['id']);
77
78 parent::run();
79
80 CRM_Utils_System::setTitle($this->pageTitle());
81 }
82 }