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