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
19 * Page for displaying list of membership types
21 class CRM_Member_Page_MembershipType
extends CRM_Core_Page
{
24 * The action links that we need to display for the browse screen.
28 public static $_links = NULL;
30 public $useLivePageJS = TRUE;
36 * (reference) of action links
38 public function &links() {
39 if (!(self
::$_links)) {
41 CRM_Core_Action
::UPDATE
=> [
43 'url' => 'civicrm/admin/member/membershipType/add',
44 'qs' => 'action=update&id=%%id%%&reset=1',
45 'title' => ts('Edit Membership Type'),
47 CRM_Core_Action
::DISABLE
=> [
48 'name' => ts('Disable'),
49 'ref' => 'crm-enable-disable',
50 'title' => ts('Disable Membership Type'),
52 CRM_Core_Action
::ENABLE
=> [
53 'name' => ts('Enable'),
54 'ref' => 'crm-enable-disable',
55 'title' => ts('Enable Membership Type'),
57 CRM_Core_Action
::DELETE
=> [
58 'name' => ts('Delete'),
59 'url' => 'civicrm/admin/member/membershipType/add',
60 'qs' => 'action=delete&id=%%id%%',
61 'title' => ts('Delete Membership Type'),
71 * This method is called after the page is created. It checks for the
72 * type of action and executes that action.
73 * Finally it calls the parent's run method.
77 public function run() {
85 * Browse all membership types.
90 public function browse() {
91 // get all membership types sorted by weight
93 $dao = new CRM_Member_DAO_MembershipType();
95 $dao->orderBy('weight');
98 while ($dao->fetch()) {
99 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
100 && !CRM_Core_Permission
::check('view contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($dao->financial_type_id
))
104 $links = self
::links();
105 $membershipType[$dao->id
] = [];
106 CRM_Core_DAO
::storeValues($dao, $membershipType[$dao->id
]);
108 $membershipType[$dao->id
]['period_type'] = CRM_Utils_Array
::value($dao->period_type
, CRM_Core_SelectValues
::periodType(), '');
109 $membershipType[$dao->id
]['visibility'] = CRM_Utils_Array
::value($dao->visibility
, CRM_Core_SelectValues
::memberVisibility(), '');
111 //adding column for relationship type label. CRM-4178.
112 if ($dao->relationship_type_id
) {
113 //If membership associated with 2 or more relationship then display all relationship with comma separated
114 $relTypeIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->relationship_type_id
);
115 $relTypeNames = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->relationship_direction
);
116 $membershipType[$dao->id
]['relationshipTypeName'] = NULL;
117 foreach ($relTypeIds as $key => $value) {
118 $relationshipName = 'label_' . $relTypeNames[$key];
119 if ($membershipType[$dao->id
]['relationshipTypeName']) {
120 $membershipType[$dao->id
]['relationshipTypeName'] .= ", ";
122 $membershipType[$dao->id
]['relationshipTypeName'] .= CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_RelationshipType',
123 $value, $relationshipName
126 $membershipType[$dao->id
]['maxRelated'] = $membershipType[$dao->id
]['max_related'] ??
NULL;
128 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() && !CRM_Core_Permission
::check('edit contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($dao->financial_type_id
))) {
129 unset($links[CRM_Core_Action
::UPDATE
], $links[CRM_Core_Action
::ENABLE
], $links[CRM_Core_Action
::DISABLE
]);
131 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() && !CRM_Core_Permission
::check('delete contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($dao->financial_type_id
))) {
132 unset($links[CRM_Core_Action
::DELETE
]);
134 // form all action links
135 $action = array_sum(array_keys($this->links()));
137 // update enable/disable links depending on if it is is_reserved or is_active
138 if (!isset($dao->is_reserved
)) {
139 if ($dao->is_active
) {
140 $action -= CRM_Core_Action
::ENABLE
;
143 $action -= CRM_Core_Action
::DISABLE
;
145 $membershipType[$dao->id
]['order'] = $membershipType[$dao->id
]['weight'];
146 $membershipType[$dao->id
]['action'] = CRM_Core_Action
::formLink($links, $action,
150 'membershipType.manage.action',
157 $returnURL = CRM_Utils_System
::url('civicrm/admin/member/membershipType', "reset=1&action=browse");
158 CRM_Utils_Weight
::addOrder($membershipType, 'CRM_Member_DAO_MembershipType',
162 CRM_Member_BAO_MembershipType
::convertDayFormat($membershipType);
163 $this->assign('rows', $membershipType);