@@ 411-462 (lines=52) @@ | ||
408 | * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID |
|
409 | * (i.e. RAP) |
|
410 | */ |
|
411 | public function get_registrations_per_day_and_per_status_report( $period = '-1 month' ) { |
|
412 | global $wpdb; |
|
413 | $registration_table = $wpdb->prefix . 'esp_registration'; |
|
414 | $event_table = $wpdb->posts; |
|
415 | $sql_date = date("Y-m-d H:i:s", strtotime($period) ); |
|
416 | ||
417 | //prepare the query interval for displaying offset |
|
418 | $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'dates.REG_date' ); |
|
419 | ||
420 | //inner date query |
|
421 | $inner_date_query = "SELECT DISTINCT REG_date from $registration_table "; |
|
422 | $inner_where = " WHERE"; |
|
423 | //exclude events not authored by user if permissions in effect |
|
424 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) { |
|
425 | $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID"; |
|
426 | $inner_where .= " post_author = " . get_current_user_id() . " AND"; |
|
427 | } |
|
428 | $inner_where .= " REG_date >= '$sql_date'"; |
|
429 | $inner_date_query .= $inner_where; |
|
430 | ||
431 | //start main query |
|
432 | $select = "SELECT DATE($query_interval) as Registration_REG_date, "; |
|
433 | $join = ''; |
|
434 | $join_parts = array(); |
|
435 | $select_parts = array(); |
|
436 | ||
437 | //loop through registration stati to do parts for each status. |
|
438 | foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) { |
|
439 | if ( $STS_ID === EEM_Registration::status_id_incomplete ) { |
|
440 | continue; |
|
441 | } |
|
442 | $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID"; |
|
443 | $join_parts[] = "$registration_table AS $STS_code ON $STS_code.REG_date = dates.REG_date AND $STS_code.STS_ID = '$STS_ID'"; |
|
444 | } |
|
445 | ||
446 | //setup the selects |
|
447 | $select .= implode(', ', $select_parts ); |
|
448 | $select .= " FROM ($inner_date_query) AS dates LEFT JOIN "; |
|
449 | ||
450 | //setup the joins |
|
451 | $join .= implode( " LEFT JOIN ", $join_parts ); |
|
452 | ||
453 | //now let's put it all together |
|
454 | $query = $select . $join . ' GROUP BY Registration_REG_date'; |
|
455 | ||
456 | //and execute it |
|
457 | $results = $wpdb->get_results( |
|
458 | $query, |
|
459 | ARRAY_A |
|
460 | ); |
|
461 | return $results; |
|
462 | } |
|
463 | ||
464 | ||
465 | ||
@@ 509-557 (lines=49) @@ | ||
506 | * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID |
|
507 | * (i.e. RAP) |
|
508 | */ |
|
509 | public function get_registrations_per_event_and_per_status_report( $period = '-1 month' ) { |
|
510 | global $wpdb; |
|
511 | $registration_table = $wpdb->prefix . 'esp_registration'; |
|
512 | $event_table = $wpdb->posts; |
|
513 | $sql_date = date("Y-m-d H:i:s", strtotime($period) ); |
|
514 | ||
515 | //inner date query |
|
516 | $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table "; |
|
517 | $inner_where = " WHERE"; |
|
518 | //exclude events not authored by user if permissions in effect |
|
519 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) { |
|
520 | $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID"; |
|
521 | $inner_where .= " post_author = " . get_current_user_id() . " AND"; |
|
522 | } |
|
523 | $inner_where .= " REG_date >= '$sql_date'"; |
|
524 | $inner_date_query .= $inner_where; |
|
525 | ||
526 | //build main query |
|
527 | $select = "SELECT Event.post_title as Registration_Event, "; |
|
528 | $join = ''; |
|
529 | $join_parts = array(); |
|
530 | $select_parts = array(); |
|
531 | ||
532 | //loop through registration stati to do parts for each status. |
|
533 | foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) { |
|
534 | if ( $STS_ID === EEM_Registration::status_id_incomplete ) { |
|
535 | continue; |
|
536 | } |
|
537 | $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID"; |
|
538 | $join_parts[] = "$registration_table AS $STS_code ON $STS_code.EVT_ID = dates.EVT_ID AND $STS_code.STS_ID = '$STS_ID' AND $STS_code.REG_date = dates.REG_date"; |
|
539 | } |
|
540 | ||
541 | //setup the selects |
|
542 | $select .= implode( ', ', $select_parts ); |
|
543 | $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN "; |
|
544 | ||
545 | //setup remaining joins |
|
546 | $join .= implode( " LEFT JOIN ", $join_parts ); |
|
547 | ||
548 | //now put it all together |
|
549 | $query = $select . $join . ' GROUP BY Registration_Event'; |
|
550 | ||
551 | //and execute |
|
552 | $results = $wpdb->get_results( |
|
553 | $query, |
|
554 | ARRAY_A |
|
555 | ); |
|
556 | return $results; |
|
557 | } |
|
558 | ||
559 | ||
560 | /** |