|
@@ 530-570 (lines=41) @@
|
| 527 |
|
* @throws EE_Error |
| 528 |
|
* (i.e. RAP) |
| 529 |
|
*/ |
| 530 |
|
public function get_registrations_per_day_and_per_status_report($period = '-1 month') |
| 531 |
|
{ |
| 532 |
|
global $wpdb; |
| 533 |
|
$registration_table = $wpdb->prefix . 'esp_registration'; |
| 534 |
|
$event_table = $wpdb->posts; |
| 535 |
|
$sql_date = date('Y-m-d H:i:s', strtotime($period)); |
| 536 |
|
//prepare the query interval for displaying offset |
| 537 |
|
$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date'); |
| 538 |
|
//inner date query |
| 539 |
|
$inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} "; |
| 540 |
|
$inner_where = ' WHERE'; |
| 541 |
|
//exclude events not authored by user if permissions in effect |
| 542 |
|
if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
| 543 |
|
$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
| 544 |
|
$inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
| 545 |
|
} |
| 546 |
|
$inner_where .= " REG_date >= '{$sql_date}'"; |
| 547 |
|
$inner_date_query .= $inner_where; |
| 548 |
|
//start main query |
| 549 |
|
$select = "SELECT DATE({$query_interval}) as Registration_REG_date, "; |
| 550 |
|
$join = ''; |
| 551 |
|
$join_parts = array(); |
| 552 |
|
$select_parts = array(); |
| 553 |
|
//loop through registration stati to do parts for each status. |
| 554 |
|
foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
| 555 |
|
if ($STS_ID === EEM_Registration::status_id_incomplete) { |
| 556 |
|
continue; |
| 557 |
|
} |
| 558 |
|
$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}"; |
| 559 |
|
$join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'"; |
| 560 |
|
} |
| 561 |
|
//setup the selects |
| 562 |
|
$select .= implode(', ', $select_parts); |
| 563 |
|
$select .= " FROM ($inner_date_query) AS dates LEFT JOIN "; |
| 564 |
|
//setup the joins |
| 565 |
|
$join .= implode(' LEFT JOIN ', $join_parts); |
| 566 |
|
//now let's put it all together |
| 567 |
|
$query = $select . $join . ' GROUP BY Registration_REG_date'; |
| 568 |
|
//and execute it |
| 569 |
|
return $wpdb->get_results($query, ARRAY_A); |
| 570 |
|
} |
| 571 |
|
|
| 572 |
|
|
| 573 |
|
/** |
|
@@ 622-660 (lines=39) @@
|
| 619 |
|
* @throws EE_Error |
| 620 |
|
* (i.e. RAP) |
| 621 |
|
*/ |
| 622 |
|
public function get_registrations_per_event_and_per_status_report($period = '-1 month') |
| 623 |
|
{ |
| 624 |
|
global $wpdb; |
| 625 |
|
$registration_table = $wpdb->prefix . 'esp_registration'; |
| 626 |
|
$event_table = $wpdb->posts; |
| 627 |
|
$sql_date = date('Y-m-d H:i:s', strtotime($period)); |
| 628 |
|
//inner date query |
| 629 |
|
$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table "; |
| 630 |
|
$inner_where = ' WHERE'; |
| 631 |
|
//exclude events not authored by user if permissions in effect |
| 632 |
|
if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
| 633 |
|
$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
| 634 |
|
$inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
| 635 |
|
} |
| 636 |
|
$inner_where .= " REG_date >= '{$sql_date}'"; |
| 637 |
|
$inner_date_query .= $inner_where; |
| 638 |
|
//build main query |
| 639 |
|
$select = 'SELECT Event.post_title as Registration_Event, '; |
| 640 |
|
$join = ''; |
| 641 |
|
$join_parts = array(); |
| 642 |
|
$select_parts = array(); |
| 643 |
|
//loop through registration stati to do parts for each status. |
| 644 |
|
foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
| 645 |
|
if ($STS_ID === EEM_Registration::status_id_incomplete) { |
| 646 |
|
continue; |
| 647 |
|
} |
| 648 |
|
$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}"; |
| 649 |
|
$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"; |
| 650 |
|
} |
| 651 |
|
//setup the selects |
| 652 |
|
$select .= implode(', ', $select_parts); |
| 653 |
|
$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN "; |
| 654 |
|
//setup remaining joins |
| 655 |
|
$join .= implode(' LEFT JOIN ', $join_parts); |
| 656 |
|
//now put it all together |
| 657 |
|
$query = $select . $join . ' GROUP BY Registration_Event'; |
| 658 |
|
//and execute |
| 659 |
|
return $wpdb->get_results($query, ARRAY_A); |
| 660 |
|
} |
| 661 |
|
|
| 662 |
|
|
| 663 |
|
/** |