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 Payment-Instrument | |
20 | */ | |
21 | class CRM_Member_Page_DashBoard extends CRM_Core_Page { | |
22 | ||
23 | /** | |
24 | * Heart of the viewing process. The runner gets all the meta data for | |
25 | * the contact and calls the appropriate type of page to view. | |
26 | * | |
27 | * @return void | |
6a488035 | 28 | */ |
00be9182 | 29 | public function preProcess() { |
46c91013 E |
30 | |
31 | //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect | |
32 | //what they have access to | |
33 | //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time) | |
feead5e7 | 34 | if (!CRM_Core_Permission::check('view all contacts') && !CRM_Core_Permission::check('edit all contacts')) { |
46c91013 E |
35 | $this->showMembershipSummary = FALSE; |
36 | $this->assign('membershipSummary', FALSE); | |
37 | return; | |
38 | } | |
39 | $this->assign('membershipSummary', TRUE); | |
6a488035 | 40 | CRM_Utils_System::setTitle(ts('CiviMember')); |
affcc9d2 | 41 | $membershipSummary = []; |
4e636a74 AH |
42 | $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))); |
43 | $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))); | |
6a488035 TO |
44 | |
45 | $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4)); | |
46 | ||
4e636a74 AH |
47 | $today = getdate(); |
48 | $date = CRM_Utils_Date::getToday(); | |
6a488035 TO |
49 | $isCurrentMonth = 0; |
50 | ||
4e636a74 | 51 | // You can force the dashboard to display based upon a certain date |
9c1bc317 | 52 | $ym = $_GET['date'] ?? NULL; |
8ef12e64 | 53 | |
6a488035 TO |
54 | if ($ym) { |
55 | if (preg_match('/^\d{6}$/', $ym) == 0 || | |
56 | !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || | |
57 | substr($ym, 0, 1) == 0 | |
58 | ) { | |
79e11805 | 59 | CRM_Core_Error::statusBounce(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym))); |
6a488035 TO |
60 | } |
61 | ||
62 | $isPreviousMonth = 0; | |
4e636a74 AH |
63 | $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon']; |
64 | $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4))); | |
65 | $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4)); | |
66 | $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d'); | |
67 | $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2); | |
6a488035 TO |
68 | } |
69 | else { | |
4e636a74 AH |
70 | $ym = sprintf("%04d-%02d", $today['year'], $today['mon']); |
71 | $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']); | |
72 | $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']); | |
73 | $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d'); | |
74 | $isCurrentMonth = 1; | |
6a488035 TO |
75 | $isPreviousMonth = 1; |
76 | } | |
4e636a74 AH |
77 | $monthStart = $ym . '-01'; |
78 | $yearStart = substr($ym, 0, 4) . '-01-01'; | |
6a488035 TO |
79 | |
80 | $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); | |
81 | // added | |
82 | //$membership = new CRM_Member_BAO_Membership; | |
83 | ||
84 | foreach ($membershipTypes as $key => $value) { | |
85 | ||
b09fe5ed | 86 | $membershipSummary[$key]['premonth']['new'] = array( |
353ffa53 | 87 | 'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd), |
6a488035 | 88 | 'name' => $value, |
54c7d249 | 89 | 'url' => FALSE, |
6a488035 TO |
90 | ); |
91 | ||
b09fe5ed | 92 | $membershipSummary[$key]['premonth']['renew'] = array( |
353ffa53 | 93 | 'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd), |
6a488035 | 94 | 'name' => $value, |
54c7d249 | 95 | 'url' => FALSE, |
6a488035 TO |
96 | ); |
97 | ||
b09fe5ed | 98 | $membershipSummary[$key]['premonth']['total'] = array( |
353ffa53 | 99 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), |
6a488035 | 100 | 'name' => $value, |
54c7d249 | 101 | 'url' => FALSE, |
6a488035 TO |
102 | ); |
103 | ||
b09fe5ed | 104 | $membershipSummary[$key]['month']['new'] = array( |
353ffa53 | 105 | 'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd), |
6a488035 | 106 | 'name' => $value, |
54c7d249 | 107 | 'url' => FALSE, |
6a488035 TO |
108 | ); |
109 | ||
b09fe5ed | 110 | $membershipSummary[$key]['month']['renew'] = array( |
353ffa53 | 111 | 'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd), |
6a488035 | 112 | 'name' => $value, |
54c7d249 | 113 | 'url' => FALSE, |
6a488035 TO |
114 | ); |
115 | ||
b09fe5ed | 116 | $membershipSummary[$key]['month']['total'] = array( |
353ffa53 | 117 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), |
6a488035 | 118 | 'name' => $value, |
54c7d249 | 119 | 'url' => FALSE, |
6a488035 TO |
120 | ); |
121 | ||
b09fe5ed | 122 | $membershipSummary[$key]['year']['new'] = array( |
353ffa53 | 123 | 'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd), |
6a488035 | 124 | 'name' => $value, |
54c7d249 | 125 | 'url' => FALSE, |
6a488035 TO |
126 | ); |
127 | ||
b09fe5ed | 128 | $membershipSummary[$key]['year']['renew'] = array( |
353ffa53 | 129 | 'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd), |
6a488035 | 130 | 'name' => $value, |
54c7d249 | 131 | 'url' => FALSE, |
6a488035 TO |
132 | ); |
133 | ||
b09fe5ed | 134 | $membershipSummary[$key]['year']['total'] = array( |
353ffa53 | 135 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), |
6a488035 | 136 | 'name' => $value, |
54c7d249 | 137 | 'url' => FALSE, |
6a488035 TO |
138 | ); |
139 | ||
b09fe5ed | 140 | $membershipSummary[$key]['current']['total'] = array( |
353ffa53 | 141 | 'count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), |
6a488035 | 142 | 'name' => $value, |
54c7d249 | 143 | 'url' => FALSE, |
6a488035 TO |
144 | ); |
145 | ||
146 | $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd)); | |
147 | ||
148 | //LCD also get summary stats for membership owners | |
b09fe5ed | 149 | $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array( |
353ffa53 | 150 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1), |
6a488035 | 151 | 'name' => $value, |
54c7d249 | 152 | 'url' => FALSE, |
6a488035 TO |
153 | ); |
154 | ||
b09fe5ed | 155 | $membershipSummary[$key]['month_owner']['month_owner'] = array( |
353ffa53 | 156 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1), |
6a488035 | 157 | 'name' => $value, |
54c7d249 | 158 | 'url' => FALSE, |
6a488035 TO |
159 | ); |
160 | ||
b09fe5ed | 161 | $membershipSummary[$key]['year_owner']['year_owner'] = array( |
353ffa53 | 162 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1), |
6a488035 | 163 | 'name' => $value, |
54c7d249 | 164 | 'url' => FALSE, |
6a488035 TO |
165 | ); |
166 | ||
b09fe5ed | 167 | $membershipSummary[$key]['current_owner']['current_owner'] = array( |
353ffa53 | 168 | 'count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1), |
6a488035 | 169 | 'name' => $value, |
54c7d249 | 170 | 'url' => FALSE, |
6a488035 TO |
171 | ); |
172 | ||
173 | $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1)); | |
174 | //LCD end | |
175 | } | |
176 | ||
6a488035 TO |
177 | $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent(); |
178 | $status = implode(',', $status); | |
179 | ||
4e636a74 AH |
180 | foreach ($membershipSummary as $typeID => $details) { |
181 | if (!$isCurrentMonth) { | |
182 | $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', | |
f243df22 | 183 | "reset=1&force=1&start=&end=$ymd&membership_status_id=$status&membership_type_id=$typeID" |
4e636a74 | 184 | ); |
f243df22 | 185 | $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&membership_status_id=$status&membership_type_id=$typeID&owner=1"); |
4e636a74 AH |
186 | } |
187 | else { | |
188 | $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', | |
f243df22 | 189 | "reset=1&force=1&membership_status_id=$status" |
4e636a74 | 190 | ); |
f243df22 | 191 | $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&owner=1"); |
4e636a74 | 192 | } |
f243df22 | 193 | $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&membership_type_id=$typeID"); |
194 | $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&membership_type_id=$typeID&owner=1"); | |
4e636a74 | 195 | } |
6a488035 | 196 | |
03ee227b | 197 | $totalCount = []; |
6a488035 TO |
198 | |
199 | $newCountPreMonth = $newCountMonth = $newCountYear = 0; | |
200 | $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0; | |
201 | ||
202 | $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0; | |
203 | $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0; | |
204 | foreach ($membershipSummary as $key => $value) { | |
353ffa53 | 205 | $newCountPreMonth = $newCountPreMonth + $value['premonth']['new']['count']; |
6a488035 TO |
206 | $renewCountPreMonth = $renewCountPreMonth + $value['premonth']['renew']['count']; |
207 | $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['total']['count']; | |
353ffa53 TO |
208 | $newCountMonth = $newCountMonth + $value['month']['new']['count']; |
209 | $renewCountMonth = $renewCountMonth + $value['month']['renew']['count']; | |
210 | $totalCountMonth = $totalCountMonth + $value['month']['total']['count']; | |
211 | $newCountYear = $newCountYear + $value['year']['new']['count']; | |
212 | $renewCountYear = $renewCountYear + $value['year']['renew']['count']; | |
213 | $totalCountYear = $totalCountYear + $value['year']['total']['count']; | |
214 | $totalCountCurrent = $totalCountCurrent + $value['current']['total']['count']; | |
215 | $totalCountTotal = $totalCountTotal + $value['total']['total']['count']; | |
6a488035 TO |
216 | |
217 | //LCD add owner values | |
218 | $totalCountPreMonth_owner = $totalCountPreMonth_owner + $value['premonth_owner']['premonth_owner']['count']; | |
219 | $totalCountMonth_owner = $totalCountMonth_owner + $value['month_owner']['month_owner']['count']; | |
220 | $totalCountYear_owner = $totalCountYear_owner + $value['year_owner']['year_owner']['count']; | |
221 | $totalCountCurrent_owner = $totalCountCurrent_owner + $value['current_owner']['current_owner']['count']; | |
222 | $totalCountTotal_owner = $totalCountTotal_owner + $value['total_owner']['total_owner']['count']; | |
223 | } | |
224 | ||
225 | $totalCount['premonth']['new'] = array( | |
226 | 'count' => $newCountPreMonth, | |
54c7d249 | 227 | 'url' => FALSE, |
6a488035 TO |
228 | ); |
229 | ||
230 | $totalCount['premonth']['renew'] = array( | |
231 | 'count' => $renewCountPreMonth, | |
54c7d249 | 232 | 'url' => FALSE, |
6a488035 TO |
233 | ); |
234 | ||
235 | $totalCount['premonth']['total'] = array( | |
236 | 'count' => $totalCountPreMonth, | |
54c7d249 | 237 | 'url' => FALSE, |
6a488035 TO |
238 | ); |
239 | ||
240 | $totalCount['month']['new'] = array( | |
241 | 'count' => $newCountMonth, | |
54c7d249 | 242 | 'url' => FALSE, |
6a488035 TO |
243 | ); |
244 | ||
245 | $totalCount['month']['renew'] = array( | |
246 | 'count' => $renewCountMonth, | |
54c7d249 | 247 | 'url' => FALSE, |
6a488035 TO |
248 | ); |
249 | ||
250 | $totalCount['month']['total'] = array( | |
251 | 'count' => $totalCountMonth, | |
54c7d249 | 252 | 'url' => FALSE, |
6a488035 TO |
253 | ); |
254 | ||
255 | $totalCount['year']['new'] = array( | |
256 | 'count' => $newCountYear, | |
54c7d249 | 257 | 'url' => FALSE, |
6a488035 TO |
258 | ); |
259 | ||
260 | $totalCount['year']['renew'] = array( | |
261 | 'count' => $renewCountYear, | |
54c7d249 | 262 | 'url' => FALSE, |
6a488035 TO |
263 | ); |
264 | ||
265 | $totalCount['year']['total'] = array( | |
266 | 'count' => $totalCountYear, | |
54c7d249 | 267 | 'url' => FALSE, |
6a488035 TO |
268 | ); |
269 | ||
270 | $totalCount['current']['total'] = array( | |
271 | 'count' => $totalCountCurrent, | |
272 | 'url' => CRM_Utils_System::url('civicrm/member/search', | |
f243df22 | 273 | "reset=1&force=1&membership_status_id=$status" |
6a488035 TO |
274 | ), |
275 | ); | |
276 | ||
277 | $totalCount['total']['total'] = array( | |
278 | 'count' => $totalCountTotal, | |
279 | 'url' => CRM_Utils_System::url('civicrm/member/search', | |
f243df22 | 280 | "reset=1&force=1&membership_status_id=$status" |
6a488035 TO |
281 | ), |
282 | ); | |
283 | ||
284 | if (!$isCurrentMonth) { | |
285 | $totalCount['total']['total'] = array( | |
286 | 'count' => $totalCountTotal, | |
287 | 'url' => CRM_Utils_System::url('civicrm/member/search', | |
f243df22 | 288 | "reset=1&force=1&membership_status_id=$status&start=&end=$ymd" |
6a488035 TO |
289 | ), |
290 | ); | |
291 | } | |
292 | ||
4e636a74 AH |
293 | // Activity search also unable to handle owner vs. inherited |
294 | ||
6a488035 TO |
295 | //LCD add owner values |
296 | $totalCount['premonth_owner']['premonth_owner'] = array( | |
297 | 'count' => $totalCountPreMonth_owner, | |
54c7d249 | 298 | 'url' => FALSE, |
f243df22 | 299 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&start=$preMonth&end=$preMonthEnd&owner=1"), |
6a488035 TO |
300 | ); |
301 | ||
302 | $totalCount['month_owner']['month_owner'] = array( | |
303 | 'count' => $totalCountMonth_owner, | |
54c7d249 | 304 | 'url' => FALSE, |
f243df22 | 305 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&start=$monthStart&end=$ymd&owner=1"), |
6a488035 TO |
306 | ); |
307 | ||
308 | $totalCount['year_owner']['year_owner'] = array( | |
309 | 'count' => $totalCountYear_owner, | |
54c7d249 | 310 | 'url' => FALSE, |
f243df22 | 311 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&start=$yearStart&end=$ymd&owner=1"), |
6a488035 TO |
312 | ); |
313 | ||
314 | $totalCount['current_owner']['current_owner'] = array( | |
315 | 'count' => $totalCountCurrent_owner, | |
54c7d249 | 316 | 'url' => FALSE, |
f243df22 | 317 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&owner=1"), |
6a488035 TO |
318 | ); |
319 | ||
320 | $totalCount['total_owner']['total_owner'] = array( | |
321 | 'count' => $totalCountTotal_owner, | |
54c7d249 | 322 | 'url' => FALSE, |
f243df22 | 323 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&owner=1"), |
6a488035 TO |
324 | ); |
325 | ||
326 | if (!$isCurrentMonth) { | |
327 | $totalCount['total_owner']['total_owner'] = array( | |
328 | 'count' => $totalCountTotal_owner, | |
54c7d249 | 329 | 'url' => FALSE, |
f243df22 | 330 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&membership_status_id=$status&start=&end=$ymd&owner=1"), |
6a488035 TO |
331 | ); |
332 | } | |
333 | //LCD end | |
334 | ||
335 | $this->assign('membershipSummary', $membershipSummary); | |
336 | $this->assign('totalCount', $totalCount); | |
d2f262da | 337 | $this->assign('month', CRM_Utils_Date::customFormatTs($monthStartTs, '%B')); |
6a488035 | 338 | $this->assign('year', date('Y', $monthStartTs)); |
74d3ce5e | 339 | $this->assign('premonth', CRM_Utils_Date::customFormat($preMonth, '%B')); |
6a488035 TO |
340 | $this->assign('currentMonth', date('F')); |
341 | $this->assign('currentYear', date('Y')); | |
342 | $this->assign('isCurrent', $isCurrentMonth); | |
343 | $this->assign('preMonth', $isPreviousMonth); | |
344 | } | |
345 | ||
346 | /** | |
dc195289 | 347 | * the main function that is called when the page loads, |
6a488035 TO |
348 | * it decides the which action has to be taken for the page. |
349 | * | |
76e7a76c | 350 | * @return null |
6a488035 | 351 | */ |
00be9182 | 352 | public function run() { |
6a488035 TO |
353 | $this->preProcess(); |
354 | ||
355 | $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL); | |
356 | $controller->setEmbedded(TRUE); | |
357 | $controller->reset(); | |
358 | $controller->set('limit', 20); | |
359 | $controller->set('force', 1); | |
360 | $controller->set('context', 'dashboard'); | |
361 | $controller->process(); | |
362 | $controller->run(); | |
363 | ||
364 | return parent::run(); | |
365 | } | |
96025800 | 366 | |
6a488035 | 367 | } |