3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Page for displaying list of Payment-Instrument
23 class CRM_Member_Page_DashBoard
extends CRM_Core_Page
{
26 * Heart of the viewing process. The runner gets all the meta data for
27 * the contact and calls the appropriate type of page to view.
31 public function preProcess() {
33 //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect
34 //what they have access to
35 //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time)
36 if (!CRM_Core_Permission
::check('view all contacts') && !CRM_Core_Permission
::check('edit all contacts')) {
37 $this->showMembershipSummary
= FALSE;
38 $this->assign('membershipSummary', FALSE);
41 $this->assign('membershipSummary', TRUE);
42 CRM_Utils_System
::setTitle(ts('CiviMember'));
43 $membershipSummary = array();
44 $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
45 $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
47 $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
50 $date = CRM_Utils_Date
::getToday();
53 // You can force the dashboard to display based upon a certain date
54 $ym = CRM_Utils_Array
::value('date', $_GET);
57 if (preg_match('/^\d{6}$/', $ym) == 0 ||
58 !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) ||
59 substr($ym, 0, 1) == 0
61 CRM_Core_Error
::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
65 $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
66 $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) +
1, 1, substr($ym, 0, 4)));
67 $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
68 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
69 $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2);
72 $ym = sprintf("%04d-%02d", $today['year'], $today['mon']);
73 $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']);
74 $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
75 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
79 $monthStart = $ym . '-01';
80 $yearStart = substr($ym, 0, 4) . '-01-01';
82 $membershipTypes = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
84 //$membership = new CRM_Member_BAO_Membership;
86 foreach ($membershipTypes as $key => $value) {
88 $membershipSummary[$key]['premonth']['new'] = array(
89 'count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $preMonth, $preMonthEnd),
93 $membershipSummary[$key]['premonth']['renew'] = array(
94 'count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $preMonth, $preMonthEnd),
98 $membershipSummary[$key]['premonth']['total'] = array(
99 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd),
103 $membershipSummary[$key]['month']['new'] = array(
104 'count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $monthStart, $ymd),
108 $membershipSummary[$key]['month']['renew'] = array(
109 'count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $monthStart, $ymd),
113 $membershipSummary[$key]['month']['total'] = array(
114 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd),
118 $membershipSummary[$key]['year']['new'] = array(
119 'count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $yearStart, $ymd),
123 $membershipSummary[$key]['year']['renew'] = array(
124 'count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $yearStart, $ymd),
128 $membershipSummary[$key]['year']['total'] = array(
129 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd),
133 $membershipSummary[$key]['current']['total'] = array(
134 'count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current),
138 $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd));
140 //LCD also get summary stats for membership owners
141 $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array(
142 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1),
146 $membershipSummary[$key]['month_owner']['month_owner'] = array(
147 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd, 0, 1),
151 $membershipSummary[$key]['year_owner']['year_owner'] = array(
152 'count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd, 0, 1),
156 $membershipSummary[$key]['current_owner']['current_owner'] = array(
157 'count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current, 0, 1),
161 $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd, 0, 1));
165 $status = CRM_Member_BAO_MembershipStatus
::getMembershipStatusCurrent();
166 $status = implode(',', $status);
168 foreach ($membershipSummary as $typeID => $details) {
169 if (!$isCurrentMonth) {
170 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
171 "reset=1&force=1&start=&end=$ymd&status=$status&membership_type_id=$typeID"
173 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&membership_type_id=$typeID&owner=1");
176 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
177 "reset=1&force=1&status=$status"
179 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
181 $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&membership_type_id=$typeID");
182 $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&membership_type_id=$typeID&owner=1");
187 $newCountPreMonth = $newCountMonth = $newCountYear = 0;
188 $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
190 $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
191 $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
192 foreach ($membershipSummary as $key => $value) {
193 $newCountPreMonth = $newCountPreMonth +
$value['premonth']['new']['count'];
194 $renewCountPreMonth = $renewCountPreMonth +
$value['premonth']['renew']['count'];
195 $totalCountPreMonth = $totalCountPreMonth +
$value['premonth']['total']['count'];
196 $newCountMonth = $newCountMonth +
$value['month']['new']['count'];
197 $renewCountMonth = $renewCountMonth +
$value['month']['renew']['count'];
198 $totalCountMonth = $totalCountMonth +
$value['month']['total']['count'];
199 $newCountYear = $newCountYear +
$value['year']['new']['count'];
200 $renewCountYear = $renewCountYear +
$value['year']['renew']['count'];
201 $totalCountYear = $totalCountYear +
$value['year']['total']['count'];
202 $totalCountCurrent = $totalCountCurrent +
$value['current']['total']['count'];
203 $totalCountTotal = $totalCountTotal +
$value['total']['total']['count'];
205 //LCD add owner values
206 $totalCountPreMonth_owner = $totalCountPreMonth_owner +
$value['premonth_owner']['premonth_owner']['count'];
207 $totalCountMonth_owner = $totalCountMonth_owner +
$value['month_owner']['month_owner']['count'];
208 $totalCountYear_owner = $totalCountYear_owner +
$value['year_owner']['year_owner']['count'];
209 $totalCountCurrent_owner = $totalCountCurrent_owner +
$value['current_owner']['current_owner']['count'];
210 $totalCountTotal_owner = $totalCountTotal_owner +
$value['total_owner']['total_owner']['count'];
213 $totalCount['premonth']['new'] = array(
214 'count' => $newCountPreMonth,
217 $totalCount['premonth']['renew'] = array(
218 'count' => $renewCountPreMonth,
221 $totalCount['premonth']['total'] = array(
222 'count' => $totalCountPreMonth,
225 $totalCount['month']['new'] = array(
226 'count' => $newCountMonth,
229 $totalCount['month']['renew'] = array(
230 'count' => $renewCountMonth,
233 $totalCount['month']['total'] = array(
234 'count' => $totalCountMonth,
237 $totalCount['year']['new'] = array(
238 'count' => $newCountYear,
241 $totalCount['year']['renew'] = array(
242 'count' => $renewCountYear,
245 $totalCount['year']['total'] = array(
246 'count' => $totalCountYear,
249 $totalCount['current']['total'] = array(
250 'count' => $totalCountCurrent,
251 'url' => CRM_Utils_System
::url('civicrm/member/search',
252 "reset=1&force=1&status=$status"
256 $totalCount['total']['total'] = array(
257 'count' => $totalCountTotal,
258 'url' => CRM_Utils_System
::url('civicrm/member/search',
259 "reset=1&force=1&status=$status"
263 if (!$isCurrentMonth) {
264 $totalCount['total']['total'] = array(
265 'count' => $totalCountTotal,
266 'url' => CRM_Utils_System
::url('civicrm/member/search',
267 "reset=1&force=1&status=$status&start=&end=$ymd"
272 // Activity search also unable to handle owner vs. inherited
274 //LCD add owner values
275 $totalCount['premonth_owner']['premonth_owner'] = array(
276 'count' => $totalCountPreMonth_owner,
277 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"),
280 $totalCount['month_owner']['month_owner'] = array(
281 'count' => $totalCountMonth_owner,
282 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"),
285 $totalCount['year_owner']['year_owner'] = array(
286 'count' => $totalCountYear_owner,
287 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"),
290 $totalCount['current_owner']['current_owner'] = array(
291 'count' => $totalCountCurrent_owner,
292 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
295 $totalCount['total_owner']['total_owner'] = array(
296 'count' => $totalCountTotal_owner,
297 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
300 if (!$isCurrentMonth) {
301 $totalCount['total_owner']['total_owner'] = array(
302 'count' => $totalCountTotal_owner,
303 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"),
308 $this->assign('membershipSummary', $membershipSummary);
309 $this->assign('totalCount', $totalCount);
310 $this->assign('month', CRM_Utils_Date
::customFormatTs($monthStartTs, '%B'));
311 $this->assign('year', date('Y', $monthStartTs));
312 $this->assign('premonth', CRM_Utils_Date
::customFormat($preMonth, '%B'));
313 $this->assign('currentMonth', date('F'));
314 $this->assign('currentYear', date('Y'));
315 $this->assign('isCurrent', $isCurrentMonth);
316 $this->assign('preMonth', $isPreviousMonth);
320 * the main function that is called when the page loads,
321 * it decides the which action has to be taken for the page.
325 public function run() {
328 $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL);
329 $controller->setEmbedded(TRUE);
330 $controller->reset();
331 $controller->set('limit', 20);
332 $controller->set('force', 1);
333 $controller->set('context', 'dashboard');
334 $controller->process();
337 return parent
::run();