3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
37 * Page for displaying list of Payment-Instrument
39 class CRM_Member_Page_DashBoard
extends CRM_Core_Page
{
42 * Heart of the viewing process. The runner gets all the meta data for
43 * the contact and calls the appropriate type of page to view.
47 public function preProcess() {
49 //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect
50 //what they have access to
51 //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time)
52 if (!CRM_Core_Permission
::check('view all contacts') && !CRM_Core_Permission
::check('edit all contacts')) {
53 $this->showMembershipSummary
= FALSE;
54 $this->assign('membershipSummary', FALSE);
57 $this->assign('membershipSummary', TRUE);
58 CRM_Utils_System
::setTitle(ts('CiviMember'));
59 $membershipSummary = array();
60 $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
61 $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
63 $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
66 $date = CRM_Utils_Date
::getToday();
69 // You can force the dashboard to display based upon a certain date
70 $ym = CRM_Utils_Array
::value('date', $_GET);
73 if (preg_match('/^\d{6}$/', $ym) == 0 ||
74 !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) ||
75 substr($ym, 0, 1) == 0
77 CRM_Core_Error
::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
81 $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
82 $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) +
1, 1, substr($ym, 0, 4)));
83 $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
84 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
85 $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2);
88 $ym = sprintf("%04d-%02d", $today['year'], $today['mon']);
89 $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']);
90 $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
91 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
95 $monthStart = $ym . '-01';
96 $yearStart = substr($ym, 0, 4) . '-01-01';
98 $membershipTypes = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
100 //$membership = new CRM_Member_BAO_Membership;
102 foreach ($membershipTypes as $key => $value) {
104 $membershipSummary[$key]['premonth']['new'] = array(
105 'count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $preMonth, $preMonthEnd),
109 $membershipSummary[$key]['premonth']['renew'] = array(
110 'count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $preMonth, $preMonthEnd),
114 $membershipSummary[$key]['premonth']['total'] = array(
115 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd),
119 $membershipSummary[$key]['month']['new'] = array(
120 'count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $monthStart, $ymd),
124 $membershipSummary[$key]['month']['renew'] = array(
125 'count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $monthStart, $ymd),
129 $membershipSummary[$key]['month']['total'] = array(
130 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd),
134 $membershipSummary[$key]['year']['new'] = array(
135 'count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $yearStart, $ymd),
139 $membershipSummary[$key]['year']['renew'] = array(
140 'count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $yearStart, $ymd),
144 $membershipSummary[$key]['year']['total'] = array(
145 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd),
149 $membershipSummary[$key]['current']['total'] = array(
150 'count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current),
154 $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd));
156 //LCD also get summary stats for membership owners
157 $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array(
158 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1),
162 $membershipSummary[$key]['month_owner']['month_owner'] = array(
163 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd, 0, 1),
167 $membershipSummary[$key]['year_owner']['year_owner'] = array(
168 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd, 0, 1),
172 $membershipSummary[$key]['current_owner']['current_owner'] = array(
173 'count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current, 0, 1),
177 $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd, 0, 1));
181 $status = CRM_Member_BAO_MembershipStatus
::getMembershipStatusCurrent();
182 $status = implode(',', $status);
184 /*@codingStandardsIgnoreStart
185 Disabled for lack of appropriate search
187 The Membership search isn't able to properly filter by join or renewal events.
188 Until that works properly, the subtotals shouldn't get links.
190 foreach ($membershipSummary as $typeID => $details) {
191 foreach ($details as $key => $value) {
194 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$preMonth&joinEnd=$preMonthEnd&start=$preMonth&end=$preMonthEnd");
195 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$prePreMonthEnd&start=$preMonth&end=$preMonthEnd");
196 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd");
200 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$monthStart&joinEnd=$ymd&start=$monthStart&end=$ymd");
201 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preMonthStart&start=$monthStart&end=$ymd");
202 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd");
206 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$yearStart&joinEnd=$ymd&start=$yearStart&end=$ymd");
207 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preYearStart&start=$yearStart&end=$ymd");
208 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd");
212 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
216 if (!$isCurrentMonth) {
217 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
218 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
222 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
223 "reset=1&force=1&status=$status"
230 case 'premonth_owner':
231 $membershipSummary[$typeID][$key]['premonth_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd&owner=1");
235 $membershipSummary[$typeID][$key]['month_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd&owner=1");
239 $membershipSummary[$typeID][$key]['year_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd&owner=1");
242 case 'current_owner':
243 $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
247 if (!$isCurrentMonth) {
248 $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1");
251 $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
258 @codingStandardsIgnoreEnd */
260 // Temporary replacement for current totals column
262 foreach ($membershipSummary as $typeID => $details) {
263 if (!$isCurrentMonth) {
264 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
265 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
267 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1");
270 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
271 "reset=1&force=1&status=$status"
273 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
275 $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
276 $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
279 $totalCount = array();
281 $newCountPreMonth = $newCountMonth = $newCountYear = 0;
282 $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
284 $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
285 $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
286 foreach ($membershipSummary as $key => $value) {
287 $newCountPreMonth = $newCountPreMonth +
$value['premonth']['new']['count'];
288 $renewCountPreMonth = $renewCountPreMonth +
$value['premonth']['renew']['count'];
289 $totalCountPreMonth = $totalCountPreMonth +
$value['premonth']['total']['count'];
290 $newCountMonth = $newCountMonth +
$value['month']['new']['count'];
291 $renewCountMonth = $renewCountMonth +
$value['month']['renew']['count'];
292 $totalCountMonth = $totalCountMonth +
$value['month']['total']['count'];
293 $newCountYear = $newCountYear +
$value['year']['new']['count'];
294 $renewCountYear = $renewCountYear +
$value['year']['renew']['count'];
295 $totalCountYear = $totalCountYear +
$value['year']['total']['count'];
296 $totalCountCurrent = $totalCountCurrent +
$value['current']['total']['count'];
297 $totalCountTotal = $totalCountTotal +
$value['total']['total']['count'];
299 //LCD add owner values
300 $totalCountPreMonth_owner = $totalCountPreMonth_owner +
$value['premonth_owner']['premonth_owner']['count'];
301 $totalCountMonth_owner = $totalCountMonth_owner +
$value['month_owner']['month_owner']['count'];
302 $totalCountYear_owner = $totalCountYear_owner +
$value['year_owner']['year_owner']['count'];
303 $totalCountCurrent_owner = $totalCountCurrent_owner +
$value['current_owner']['current_owner']['count'];
304 $totalCountTotal_owner = $totalCountTotal_owner +
$value['total_owner']['total_owner']['count'];
307 $totalCount['premonth']['new'] = array(
308 'count' => $newCountPreMonth,
309 //'url' => CRM_Utils_System::url('civicrm/activity/search',
310 // "reset=1&force=1&signupType=1&dateLow=$preMonth&dateHigh=$preMonthEnd"
314 $totalCount['premonth']['renew'] = array(
315 'count' => $renewCountPreMonth,
316 //'url' => CRM_Utils_System::url('civicrm/activity/search',
317 // "reset=1&force=1&signupType=2&dateLow=$preMonth&dateHigh=$preMonthEnd"
321 $totalCount['premonth']['total'] = array(
322 'count' => $totalCountPreMonth,
323 //'url' => CRM_Utils_System::url('civicrm/activity/search',
324 // "reset=1&force=1&signupType=3&dateLow=$preMonth&dateHigh=$preMonthEnd"
328 $totalCount['month']['new'] = array(
329 'count' => $newCountMonth,
330 //'url' => CRM_Utils_System::url('civicrm/activity/search',
331 // "reset=1&force=1&signupType=1&dateLow=$monthStart&dateHigh=$ymd"
335 $totalCount['month']['renew'] = array(
336 'count' => $renewCountMonth,
337 //'url' => CRM_Utils_System::url('civicrm/activity/search',
338 // "reset=1&force=1&signupType=2&dateLow=$monthStart&dateHigh=$ymd"
342 $totalCount['month']['total'] = array(
343 'count' => $totalCountMonth,
344 //'url' => CRM_Utils_System::url('civicrm/activity/search',
345 // "reset=1&force=1&signupType=3&dateLow=$monthStart&dateHigh=$ymd"
349 $totalCount['year']['new'] = array(
350 'count' => $newCountYear,
351 //'url' => CRM_Utils_System::url('civicrm/activity/search',
352 // "reset=1&force=1&signupType=1&dateLow=$yearStart&dateHigh=$ymd"
356 $totalCount['year']['renew'] = array(
357 'count' => $renewCountYear,
358 //'url' => CRM_Utils_System::url('civicrm/activity/search',
359 // "reset=1&force=1&signupType=2&dateLow=$yearStart&dateHigh=$ymd"
363 $totalCount['year']['total'] = array(
364 'count' => $totalCountYear,
365 //'url' => CRM_Utils_System::url('civicrm/activity/search',
366 // "reset=1&force=1&signupType=3&dateLow=$yearStart&dateHigh=$ymd"
370 $totalCount['current']['total'] = array(
371 'count' => $totalCountCurrent,
372 'url' => CRM_Utils_System
::url('civicrm/member/search',
373 "reset=1&force=1&status=$status"
377 $totalCount['total']['total'] = array(
378 'count' => $totalCountTotal,
379 'url' => CRM_Utils_System
::url('civicrm/member/search',
380 "reset=1&force=1&status=$status"
384 if (!$isCurrentMonth) {
385 $totalCount['total']['total'] = array(
386 'count' => $totalCountTotal,
387 'url' => CRM_Utils_System
::url('civicrm/member/search',
388 "reset=1&force=1&status=$status&start=&end=$ymd"
393 // Activity search also unable to handle owner vs. inherited
395 //LCD add owner values
396 $totalCount['premonth_owner']['premonth_owner'] = array(
397 'count' => $totalCountPreMonth_owner,
398 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"),
401 $totalCount['month_owner']['month_owner'] = array(
402 'count' => $totalCountMonth_owner,
403 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"),
406 $totalCount['year_owner']['year_owner'] = array(
407 'count' => $totalCountYear_owner,
408 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"),
411 $totalCount['current_owner']['current_owner'] = array(
412 'count' => $totalCountCurrent_owner,
413 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
416 $totalCount['total_owner']['total_owner'] = array(
417 'count' => $totalCountTotal_owner,
418 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
421 if (!$isCurrentMonth) {
422 $totalCount['total_owner']['total_owner'] = array(
423 'count' => $totalCountTotal_owner,
424 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"),
429 $this->assign('membershipSummary', $membershipSummary);
430 $this->assign('totalCount', $totalCount);
431 $this->assign('month', CRM_Utils_Date
::customFormatTs($monthStartTs, '%B'));
432 $this->assign('year', date('Y', $monthStartTs));
433 $this->assign('premonth', CRM_Utils_Date
::customFormat($preMonth, '%B'));
434 $this->assign('currentMonth', date('F'));
435 $this->assign('currentYear', date('Y'));
436 $this->assign('isCurrent', $isCurrentMonth);
437 $this->assign('preMonth', $isPreviousMonth);
441 * the main function that is called when the page loads,
442 * it decides the which action has to be taken for the page.
446 public function run() {
449 $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL);
450 $controller->setEmbedded(TRUE);
451 $controller->reset();
452 $controller->set('limit', 20);
453 $controller->set('force', 1);
454 $controller->set('context', 'dashboard');
455 $controller->process();
458 return parent
::run();