Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Page for displaying list of membership types | |
38 | */ | |
39 | class CRM_Member_Page_MembershipType extends CRM_Core_Page { | |
40 | ||
41 | /** | |
fe482240 | 42 | * The action links that we need to display for the browse screen. |
6a488035 TO |
43 | * |
44 | * @var array | |
6a488035 TO |
45 | */ |
46 | static $_links = NULL; | |
47 | ||
96f50de2 CW |
48 | public $useLivePageJS = TRUE; |
49 | ||
6a488035 | 50 | /** |
fe482240 | 51 | * Get action Links. |
6a488035 | 52 | * |
a6c01b45 CW |
53 | * @return array |
54 | * (reference) of action links | |
6a488035 | 55 | */ |
00be9182 | 56 | public function &links() { |
6a488035 TO |
57 | if (!(self::$_links)) { |
58 | self::$_links = array( | |
59 | CRM_Core_Action::UPDATE => array( | |
60 | 'name' => ts('Edit'), | |
61 | 'url' => 'civicrm/admin/member/membershipType/add', | |
62 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
63 | 'title' => ts('Edit Membership Type'), | |
64 | ), | |
65 | CRM_Core_Action::DISABLE => array( | |
66 | 'name' => ts('Disable'), | |
4d17a233 | 67 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
68 | 'title' => ts('Disable Membership Type'), |
69 | ), | |
70 | CRM_Core_Action::ENABLE => array( | |
71 | 'name' => ts('Enable'), | |
4d17a233 | 72 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
73 | 'title' => ts('Enable Membership Type'), |
74 | ), | |
75 | CRM_Core_Action::DELETE => array( | |
76 | 'name' => ts('Delete'), | |
77 | 'url' => 'civicrm/admin/member/membershipType/add', | |
78 | 'qs' => 'action=delete&id=%%id%%', | |
79 | 'title' => ts('Delete Membership Type'), | |
80 | ), | |
81 | ); | |
82 | } | |
83 | return self::$_links; | |
84 | } | |
85 | ||
86 | /** | |
87 | * Run the page. | |
88 | * | |
89 | * This method is called after the page is created. It checks for the | |
90 | * type of action and executes that action. | |
91 | * Finally it calls the parent's run method. | |
92 | * | |
93 | * @return void | |
6a488035 | 94 | */ |
00be9182 | 95 | public function run() { |
6a488035 TO |
96 | $this->browse(); |
97 | ||
98 | // parent run | |
99 | return parent::run(); | |
100 | } | |
101 | ||
102 | /** | |
103 | * Browse all membership types. | |
104 | * | |
105 | * | |
106 | * @return void | |
6a488035 | 107 | */ |
00be9182 | 108 | public function browse() { |
6a488035 TO |
109 | // get all membership types sorted by weight |
110 | $membershipType = array(); | |
111 | $dao = new CRM_Member_DAO_MembershipType(); | |
112 | ||
113 | $dao->orderBy('weight'); | |
114 | $dao->find(); | |
115 | ||
6a488035 | 116 | while ($dao->fetch()) { |
40c655aa | 117 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() |
66af7c48 PN |
118 | && !CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id)) |
119 | ) { | |
ad268ba4 E |
120 | continue; |
121 | } | |
122 | $links = self::links(); | |
6a488035 | 123 | $membershipType[$dao->id] = array(); |
40c655aa | 124 | CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]); |
6a488035 | 125 | |
dbd82592 CW |
126 | $membershipType[$dao->id]['period_type'] = CRM_Utils_Array::value($dao->period_type, CRM_Core_SelectValues::periodType(), ''); |
127 | $membershipType[$dao->id]['visibility'] = CRM_Utils_Array::value($dao->visibility, CRM_Core_SelectValues::memberVisibility(), ''); | |
128 | ||
6a488035 TO |
129 | //adding column for relationship type label. CRM-4178. |
130 | if ($dao->relationship_type_id) { | |
131 | //If membership associated with 2 or more relationship then display all relationship with comma separated | |
132 | $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_type_id); | |
133 | $relTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_direction); | |
134 | $membershipType[$dao->id]['relationshipTypeName'] = NULL; | |
135 | foreach ($relTypeIds as $key => $value) { | |
136 | $relationshipName = 'label_' . $relTypeNames[$key]; | |
137 | if ($membershipType[$dao->id]['relationshipTypeName']) { | |
138 | $membershipType[$dao->id]['relationshipTypeName'] .= ", "; | |
139 | } | |
140 | $membershipType[$dao->id]['relationshipTypeName'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', | |
141 | $value, $relationshipName | |
142 | ); | |
143 | } | |
144 | $membershipType[$dao->id]['maxRelated'] = CRM_Utils_Array::value('max_related', $membershipType[$dao->id]); | |
145 | } | |
66af7c48 | 146 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { |
ad268ba4 E |
147 | unset($links[CRM_Core_Action::UPDATE], $links[CRM_Core_Action::ENABLE], $links[CRM_Core_Action::DISABLE]); |
148 | } | |
66af7c48 | 149 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { |
ad268ba4 E |
150 | unset($links[CRM_Core_Action::DELETE]); |
151 | } | |
6a488035 TO |
152 | // form all action links |
153 | $action = array_sum(array_keys($this->links())); | |
154 | ||
155 | // update enable/disable links depending on if it is is_reserved or is_active | |
156 | if (!isset($dao->is_reserved)) { | |
157 | if ($dao->is_active) { | |
158 | $action -= CRM_Core_Action::ENABLE; | |
159 | } | |
160 | else { | |
161 | $action -= CRM_Core_Action::DISABLE; | |
162 | } | |
163 | $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight']; | |
ad268ba4 | 164 | $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, |
87dab4a4 AH |
165 | array('id' => $dao->id), |
166 | ts('more'), | |
167 | FALSE, | |
168 | 'membershipType.manage.action', | |
169 | 'MembershipType', | |
170 | $dao->id | |
6a488035 TO |
171 | ); |
172 | } | |
173 | } | |
174 | ||
175 | $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse"); | |
176 | CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType', | |
177 | 'id', $returnURL | |
178 | ); | |
179 | ||
180 | CRM_Member_BAO_MembershipType::convertDayFormat($membershipType); | |
181 | $this->assign('rows', $membershipType); | |
182 | } | |
96025800 | 183 | |
6a488035 | 184 | } |