Merge pull request #17679 from civicrm/5.27
[civicrm-core.git] / CRM / Member / Page / MembershipStatus.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 * Page for displaying list of membership types
22 */
23 class CRM_Member_Page_MembershipStatus extends CRM_Core_Page_Basic {
24
25 public $useLivePageJS = TRUE;
26
27 /**
28 * The action links that we need to display for the browse screen.
29 *
30 * @var array
31 */
32 public static $_links = NULL;
33
34 /**
35 * Get BAO Name.
36 *
37 * @return string
38 * Classname of BAO.
39 */
40 public function getBAOName() {
41 return 'CRM_Member_BAO_MembershipStatus';
42 }
43
44 /**
45 * Get action Links.
46 *
47 * @return array
48 * (reference) of action links
49 */
50 public function &links() {
51 if (!(self::$_links)) {
52 self::$_links = [
53 CRM_Core_Action::UPDATE => [
54 'name' => ts('Edit'),
55 'url' => 'civicrm/admin/member/membershipStatus',
56 'qs' => 'action=update&id=%%id%%&reset=1',
57 'title' => ts('Edit Membership Status'),
58 ],
59 CRM_Core_Action::DISABLE => [
60 'name' => ts('Disable'),
61 'ref' => 'crm-enable-disable',
62 'title' => ts('Disable Membership Status'),
63 ],
64 CRM_Core_Action::ENABLE => [
65 'name' => ts('Enable'),
66 'ref' => 'crm-enable-disable',
67 'title' => ts('Enable Membership Status'),
68 ],
69 CRM_Core_Action::DELETE => [
70 'name' => ts('Delete'),
71 'url' => 'civicrm/admin/member/membershipStatus',
72 'qs' => 'action=delete&id=%%id%%',
73 'title' => ts('Delete Membership Status'),
74 ],
75 ];
76 }
77 return self::$_links;
78 }
79
80 /**
81 * Browse all custom data groups.
82 *
83 *
84 * @return void
85 */
86 public function browse() {
87 // get all custom groups sorted by weight
88 $membershipStatus = [];
89 $dao = new CRM_Member_DAO_MembershipStatus();
90
91 $dao->orderBy('weight');
92 $dao->find();
93
94 while ($dao->fetch()) {
95 $membershipStatus[$dao->id] = [];
96 CRM_Core_DAO::storeValues($dao, $membershipStatus[$dao->id]);
97
98 // form all action links
99 $action = array_sum(array_keys($this->links()));
100 // update enable/disable links depending on if it is is_reserved or is_active
101 if (!$dao->is_reserved) {
102 if ($dao->is_active) {
103 $action -= CRM_Core_Action::ENABLE;
104 }
105 else {
106 $action -= CRM_Core_Action::DISABLE;
107 }
108 $membershipStatus[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
109 ['id' => $dao->id],
110 ts('more'),
111 FALSE,
112 'membershipStatus.manage.action',
113 'MembershipStatus',
114 $dao->id
115 );
116 }
117 $startEvent = $membershipStatus[$dao->id]['start_event'] ?? NULL;
118 $endEvent = $membershipStatus[$dao->id]['end_event'] ?? NULL;
119 $startEventUnit = $membershipStatus[$dao->id]['start_event_adjust_unit'] ?? NULL;
120 $endEventUnit = $membershipStatus[$dao->id]['end_event_adjust_unit'] ?? NULL;
121 $startEventInterval = $membershipStatus[$dao->id]['start_event_adjust_interval'] ?? NULL;
122 $endEventInterval = $membershipStatus[$dao->id]['end_event_adjust_interval'] ?? NULL;
123
124 if ($startEvent) {
125 $membershipStatus[$dao->id]['start_event'] = ($startEvent == 'join_date') ? 'member since' : str_replace("_", " ", $startEvent);
126 }
127 if ($endEvent) {
128 $membershipStatus[$dao->id]['end_event'] = ($endEvent == 'join_date') ? 'member since' : str_replace("_", " ", $endEvent);
129 }
130 if ($startEventUnit && $startEventInterval) {
131 $membershipStatus[$dao->id]['start_event_adjust_unit_interval'] = "{$startEventInterval} {$startEventUnit}";
132 }
133 if ($endEventUnit && $endEventInterval) {
134 $membershipStatus[$dao->id]['end_event_adjust_interval'] = "{$endEventInterval} {$endEventUnit}";
135 }
136 }
137 // Add order changing widget to selector
138 $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', "reset=1&action=browse");
139 CRM_Utils_Weight::addOrder($membershipStatus, 'CRM_Member_DAO_MembershipStatus',
140 'id', $returnURL
141 );
142
143 $this->assign('rows', $membershipStatus);
144 }
145
146 /**
147 * Get name of edit form.
148 *
149 * @return string
150 * Classname of edit form.
151 */
152 public function editForm() {
153 return 'CRM_Member_Form_MembershipStatus';
154 }
155
156 /**
157 * Get edit form name.
158 *
159 * @return string
160 * name of this page.
161 */
162 public function editName() {
163 return 'Membership Status';
164 }
165
166 /**
167 * Get user context.
168 *
169 * @param null $mode
170 *
171 * @return string
172 * user context.
173 */
174 public function userContext($mode = NULL) {
175 return 'civicrm/admin/member/membershipStatus';
176 }
177
178 }