Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * Page for displaying list of membership types | |
20 | */ | |
21 | class CRM_Member_Page_MembershipStatus extends CRM_Core_Page_Basic { | |
22 | ||
96f50de2 CW |
23 | public $useLivePageJS = TRUE; |
24 | ||
6a488035 | 25 | /** |
fe482240 | 26 | * The action links that we need to display for the browse screen. |
6a488035 TO |
27 | * |
28 | * @var array | |
6a488035 | 29 | */ |
971e129b | 30 | public static $_links = NULL; |
6a488035 TO |
31 | |
32 | /** | |
fe482240 | 33 | * Get BAO Name. |
6a488035 | 34 | * |
a6c01b45 CW |
35 | * @return string |
36 | * Classname of BAO. | |
6a488035 | 37 | */ |
00be9182 | 38 | public function getBAOName() { |
6a488035 TO |
39 | return 'CRM_Member_BAO_MembershipStatus'; |
40 | } | |
41 | ||
42 | /** | |
fe482240 | 43 | * Get action Links. |
6a488035 | 44 | * |
a6c01b45 CW |
45 | * @return array |
46 | * (reference) of action links | |
6a488035 | 47 | */ |
00be9182 | 48 | public function &links() { |
6a488035 | 49 | if (!(self::$_links)) { |
be2fb01f CW |
50 | self::$_links = [ |
51 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
52 | 'name' => ts('Edit'), |
53 | 'url' => 'civicrm/admin/member/membershipStatus', | |
54 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
55 | 'title' => ts('Edit Membership Status'), | |
be2fb01f CW |
56 | ], |
57 | CRM_Core_Action::DISABLE => [ | |
6a488035 | 58 | 'name' => ts('Disable'), |
4d17a233 | 59 | 'ref' => 'crm-enable-disable', |
6a488035 | 60 | 'title' => ts('Disable Membership Status'), |
be2fb01f CW |
61 | ], |
62 | CRM_Core_Action::ENABLE => [ | |
6a488035 | 63 | 'name' => ts('Enable'), |
4d17a233 | 64 | 'ref' => 'crm-enable-disable', |
6a488035 | 65 | 'title' => ts('Enable Membership Status'), |
be2fb01f CW |
66 | ], |
67 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
68 | 'name' => ts('Delete'), |
69 | 'url' => 'civicrm/admin/member/membershipStatus', | |
70 | 'qs' => 'action=delete&id=%%id%%', | |
71 | 'title' => ts('Delete Membership Status'), | |
be2fb01f CW |
72 | ], |
73 | ]; | |
6a488035 TO |
74 | } |
75 | return self::$_links; | |
76 | } | |
77 | ||
6a488035 TO |
78 | /** |
79 | * Browse all custom data groups. | |
80 | * | |
81 | * | |
82 | * @return void | |
6a488035 | 83 | */ |
00be9182 | 84 | public function browse() { |
6a488035 | 85 | // get all custom groups sorted by weight |
be2fb01f | 86 | $membershipStatus = []; |
6a488035 TO |
87 | $dao = new CRM_Member_DAO_MembershipStatus(); |
88 | ||
89 | $dao->orderBy('weight'); | |
90 | $dao->find(); | |
91 | ||
92 | while ($dao->fetch()) { | |
be2fb01f | 93 | $membershipStatus[$dao->id] = []; |
6a488035 TO |
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, | |
be2fb01f | 107 | ['id' => $dao->id], |
87dab4a4 AH |
108 | ts('more'), |
109 | FALSE, | |
110 | 'membershipStatus.manage.action', | |
111 | 'MembershipStatus', | |
112 | $dao->id | |
6a488035 TO |
113 | ); |
114 | } | |
0edb432e JP |
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) { | |
6a488035 TO |
123 | $membershipStatus[$dao->id]['start_event'] = ($startEvent == 'join_date') ? 'member since' : str_replace("_", " ", $startEvent); |
124 | } | |
0edb432e | 125 | if ($endEvent) { |
6a488035 TO |
126 | $membershipStatus[$dao->id]['end_event'] = ($endEvent == 'join_date') ? 'member since' : str_replace("_", " ", $endEvent); |
127 | } | |
0edb432e JP |
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 | } | |
6a488035 TO |
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 | /** | |
fe482240 | 145 | * Get name of edit form. |
6a488035 | 146 | * |
a6c01b45 CW |
147 | * @return string |
148 | * Classname of edit form. | |
6a488035 | 149 | */ |
00be9182 | 150 | public function editForm() { |
6a488035 TO |
151 | return 'CRM_Member_Form_MembershipStatus'; |
152 | } | |
153 | ||
154 | /** | |
fe482240 | 155 | * Get edit form name. |
6a488035 | 156 | * |
a6c01b45 CW |
157 | * @return string |
158 | * name of this page. | |
6a488035 | 159 | */ |
00be9182 | 160 | public function editName() { |
6a488035 TO |
161 | return 'Membership Status'; |
162 | } | |
163 | ||
164 | /** | |
165 | * Get user context. | |
166 | * | |
da6b46f4 EM |
167 | * @param null $mode |
168 | * | |
a6c01b45 CW |
169 | * @return string |
170 | * user context. | |
6a488035 | 171 | */ |
00be9182 | 172 | public function userContext($mode = NULL) { |
6a488035 TO |
173 | return 'civicrm/admin/member/membershipStatus'; |
174 | } | |
96025800 | 175 | |
6a488035 | 176 | } |