3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Page for displaying list of membership types
23 class CRM_Member_Page_MembershipType
extends CRM_Core_Page
{
26 * The action links that we need to display for the browse screen.
30 public static $_links = NULL;
32 public $useLivePageJS = TRUE;
38 * (reference) of action links
40 public function &links() {
41 if (!(self
::$_links)) {
43 CRM_Core_Action
::UPDATE
=> [
45 'url' => 'civicrm/admin/member/membershipType/add',
46 'qs' => 'action=update&id=%%id%%&reset=1',
47 'title' => ts('Edit Membership Type'),
49 CRM_Core_Action
::DISABLE
=> [
50 'name' => ts('Disable'),
51 'ref' => 'crm-enable-disable',
52 'title' => ts('Disable Membership Type'),
54 CRM_Core_Action
::ENABLE
=> [
55 'name' => ts('Enable'),
56 'ref' => 'crm-enable-disable',
57 'title' => ts('Enable Membership Type'),
59 CRM_Core_Action
::DELETE
=> [
60 'name' => ts('Delete'),
61 'url' => 'civicrm/admin/member/membershipType/add',
62 'qs' => 'action=delete&id=%%id%%',
63 'title' => ts('Delete Membership Type'),
73 * This method is called after the page is created. It checks for the
74 * type of action and executes that action.
75 * Finally it calls the parent's run method.
79 public function run() {
87 * Browse all membership types.
92 public function browse() {
93 // get all membership types sorted by weight
95 $dao = new CRM_Member_DAO_MembershipType();
97 $dao->orderBy('weight');
100 while ($dao->fetch()) {
101 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
102 && !CRM_Core_Permission
::check('view contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($dao->financial_type_id
))
106 $links = self
::links();
107 $membershipType[$dao->id
] = [];
108 CRM_Core_DAO
::storeValues($dao, $membershipType[$dao->id
]);
110 $membershipType[$dao->id
]['period_type'] = CRM_Utils_Array
::value($dao->period_type
, CRM_Core_SelectValues
::periodType(), '');
111 $membershipType[$dao->id
]['visibility'] = CRM_Utils_Array
::value($dao->visibility
, CRM_Core_SelectValues
::memberVisibility(), '');
113 //adding column for relationship type label. CRM-4178.
114 if ($dao->relationship_type_id
) {
115 //If membership associated with 2 or more relationship then display all relationship with comma separated
116 $relTypeIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->relationship_type_id
);
117 $relTypeNames = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->relationship_direction
);
118 $membershipType[$dao->id
]['relationshipTypeName'] = NULL;
119 foreach ($relTypeIds as $key => $value) {
120 $relationshipName = 'label_' . $relTypeNames[$key];
121 if ($membershipType[$dao->id
]['relationshipTypeName']) {
122 $membershipType[$dao->id
]['relationshipTypeName'] .= ", ";
124 $membershipType[$dao->id
]['relationshipTypeName'] .= CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_RelationshipType',
125 $value, $relationshipName
128 $membershipType[$dao->id
]['maxRelated'] = $membershipType[$dao->id
]['max_related'] ??
NULL;
130 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() && !CRM_Core_Permission
::check('edit contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($dao->financial_type_id
))) {
131 unset($links[CRM_Core_Action
::UPDATE
], $links[CRM_Core_Action
::ENABLE
], $links[CRM_Core_Action
::DISABLE
]);
133 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() && !CRM_Core_Permission
::check('delete contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($dao->financial_type_id
))) {
134 unset($links[CRM_Core_Action
::DELETE
]);
136 // form all action links
137 $action = array_sum(array_keys($this->links()));
139 // update enable/disable links depending on if it is is_reserved or is_active
140 if (!isset($dao->is_reserved
)) {
141 if ($dao->is_active
) {
142 $action -= CRM_Core_Action
::ENABLE
;
145 $action -= CRM_Core_Action
::DISABLE
;
147 $membershipType[$dao->id
]['order'] = $membershipType[$dao->id
]['weight'];
148 $membershipType[$dao->id
]['action'] = CRM_Core_Action
::formLink($links, $action,
152 'membershipType.manage.action',
159 $returnURL = CRM_Utils_System
::url('civicrm/admin/member/membershipType', "reset=1&action=browse");
160 CRM_Utils_Weight
::addOrder($membershipType, 'CRM_Member_DAO_MembershipType',
164 CRM_Member_BAO_MembershipType
::convertDayFormat($membershipType);
165 $this->assign('rows', $membershipType);