Merge pull request #16008 from civicrm/5.20
[civicrm-core.git] / CRM / Member / Page / UserDashboard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * This class is for building membership block on user dashboard
22 */
23 class CRM_Member_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBoard {
24
25 /**
26 * List memberships for the UF user.
27 *
28 */
29 public function listMemberships() {
30 $membership = [];
31 $dao = new CRM_Member_DAO_Membership();
32 $dao->contact_id = $this->_contactId;
33 $dao->is_test = 0;
34 $dao->find();
35
36 while ($dao->fetch()) {
37 $membership[$dao->id] = [];
38 CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
39
40 //get the membership status and type values.
41 $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
42 foreach ([
43 'status',
44 'membership_type',
45 ] as $fld) {
46 $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
47 }
48 if (!empty($statusANDType[$dao->id]['is_current_member'])) {
49 $membership[$dao->id]['active'] = TRUE;
50 }
51
52 $membership[$dao->id]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($dao->id);
53 if (!$membership[$dao->id]['renewPageId']) {
54 // Membership payment was not done via online contribution page or free membership. Check for default membership renewal page from CiviMember Settings
55 $defaultRenewPageId = Civi::settings()->get('default_renewal_contribution_page');
56 if ($defaultRenewPageId) {
57 //CRM-14831 - check if membership type is present in contrib page
58 $memBlock = CRM_Member_BAO_Membership::getMembershipBlock($defaultRenewPageId);
59 if (!empty($memBlock['membership_types'])) {
60 $memTypes = explode(',', $memBlock['membership_types']);
61 if (in_array($dao->membership_type_id, $memTypes)) {
62 $membership[$dao->id]['renewPageId'] = $defaultRenewPageId;
63 }
64 }
65 }
66 }
67 }
68
69 $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
70 $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
71
72 $this->assign('activeMembers', $activeMembers);
73 $this->assign('inActiveMembers', $inActiveMembers);
74 }
75
76 /**
77 * the main function that is called when the page
78 * loads, it decides the which action has to be taken for the page.
79 *
80 */
81 public function run() {
82 parent::preProcess();
83 $this->listMemberships();
84 }
85
86 }