|  | @@ 448-499 (lines=52) @@ | 
                                                            
                                    | 445 |  |      * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID | 
                                                            
                                    | 446 |  |      *                    (i.e. RAP) | 
                                                            
                                    | 447 |  |      */ | 
                                                            
                                    | 448 |  |     public function get_registrations_per_day_and_per_status_report($period = '-1 month') | 
                                                            
                                    | 449 |  |     { | 
                                                            
                                    | 450 |  |         global $wpdb; | 
                                                            
                                    | 451 |  |         $registration_table = $wpdb->prefix . 'esp_registration'; | 
                                                            
                                    | 452 |  |         $event_table = $wpdb->posts; | 
                                                            
                                    | 453 |  |         $sql_date = date("Y-m-d H:i:s", strtotime($period)); | 
                                                            
                                    | 454 |  |         //prepare the query interval for displaying offset | 
                                                            
                                    | 455 |  |         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date'); | 
                                                            
                                    | 456 |  |         //inner date query | 
                                                            
                                    | 457 |  |         $inner_date_query = "SELECT DISTINCT REG_date from $registration_table "; | 
                                                            
                                    | 458 |  |         $inner_where = " WHERE"; | 
                                                            
                                    | 459 |  |         //exclude events not authored by user if permissions in effect | 
                                                            
                                    | 460 |  |         if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { | 
                                                            
                                    | 461 |  |             $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID"; | 
                                                            
                                    | 462 |  |             $inner_where .= " post_author = " . get_current_user_id() . " AND"; | 
                                                            
                                    | 463 |  |         } | 
                                                            
                                    | 464 |  |         $inner_where .= " REG_date >= '$sql_date'"; | 
                                                            
                                    | 465 |  |         $inner_date_query .= $inner_where; | 
                                                            
                                    | 466 |  |         //start main query | 
                                                            
                                    | 467 |  |         $select = "SELECT DATE($query_interval) as Registration_REG_date, "; | 
                                                            
                                    | 468 |  |         $join = ''; | 
                                                            
                                    | 469 |  |         $join_parts = array(); | 
                                                            
                                    | 470 |  |         $select_parts = array(); | 
                                                            
                                    | 471 |  |         //loop through registration stati to do parts for each status. | 
                                                            
                                    | 472 |  |         foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { | 
                                                            
                                    | 473 |  |             if ($STS_ID === EEM_Registration::status_id_incomplete) { | 
                                                            
                                    | 474 |  |                 continue; | 
                                                            
                                    | 475 |  |             } | 
                                                            
                                    | 476 |  |             $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID"; | 
                                                            
                                    | 477 |  |             $join_parts[] = "$registration_table AS $STS_code ON $STS_code.REG_date = dates.REG_date AND $STS_code.STS_ID = '$STS_ID'"; | 
                                                            
                                    | 478 |  |         } | 
                                                            
                                    | 479 |  |         //setup the selects | 
                                                            
                                    | 480 |  |         $select .= implode(', ', $select_parts); | 
                                                            
                                    | 481 |  |         $select .= " FROM ($inner_date_query) AS dates LEFT JOIN "; | 
                                                            
                                    | 482 |  |         //setup the joins | 
                                                            
                                    | 483 |  |         $join .= implode(" LEFT JOIN ", $join_parts); | 
                                                            
                                    | 484 |  |         //now let's put it all together | 
                                                            
                                    | 485 |  |         $query = $select . $join . ' GROUP BY Registration_REG_date'; | 
                                                            
                                    | 486 |  |         //and execute it | 
                                                            
                                    | 487 |  |         $results = $wpdb->get_results($query, ARRAY_A); | 
                                                            
                                    | 488 |  |         return $results; | 
                                                            
                                    | 489 |  |     } | 
                                                            
                                    | 490 |  |  | 
                                                            
                                    | 491 |  |  | 
                                                            
                                    | 492 |  |  | 
                                                            
                                    | 493 |  |     /** | 
                                                            
                                    | 494 |  |      *        get the number of registrations per event  for the Registration Admin page Reports Tab | 
                                                            
                                    | 495 |  |      * | 
                                                            
                                    | 496 |  |      * @access        public | 
                                                            
                                    | 497 |  |      * @param $period string which can be passed to php's strtotime function (eg "-1 month") | 
                                                            
                                    | 498 |  |      * @return stdClass[] each with properties event_name, reg_limit, and total | 
                                                            
                                    | 499 |  |      */ | 
                                                            
                                    | 500 |  |     public function get_registrations_per_event_report($period = '-1 month') | 
                                                            
                                    | 501 |  |     { | 
                                                            
                                    | 502 |  |         $date_sql = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)), | 
                                                                                
                                |  | @@ 533-581 (lines=49) @@ | 
                                                            
                                    | 530 |  |      * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID | 
                                                            
                                    | 531 |  |      *                    (i.e. RAP) | 
                                                            
                                    | 532 |  |      */ | 
                                                            
                                    | 533 |  |     public function get_registrations_per_event_and_per_status_report($period = '-1 month') | 
                                                            
                                    | 534 |  |     { | 
                                                            
                                    | 535 |  |         global $wpdb; | 
                                                            
                                    | 536 |  |         $registration_table = $wpdb->prefix . 'esp_registration'; | 
                                                            
                                    | 537 |  |         $event_table = $wpdb->posts; | 
                                                            
                                    | 538 |  |         $sql_date = date("Y-m-d H:i:s", strtotime($period)); | 
                                                            
                                    | 539 |  |         //inner date query | 
                                                            
                                    | 540 |  |         $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table "; | 
                                                            
                                    | 541 |  |         $inner_where = " WHERE"; | 
                                                            
                                    | 542 |  |         //exclude events not authored by user if permissions in effect | 
                                                            
                                    | 543 |  |         if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { | 
                                                            
                                    | 544 |  |             $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID"; | 
                                                            
                                    | 545 |  |             $inner_where .= " post_author = " . get_current_user_id() . " AND"; | 
                                                            
                                    | 546 |  |         } | 
                                                            
                                    | 547 |  |         $inner_where .= " REG_date >= '$sql_date'"; | 
                                                            
                                    | 548 |  |         $inner_date_query .= $inner_where; | 
                                                            
                                    | 549 |  |         //build main query | 
                                                            
                                    | 550 |  |         $select = "SELECT Event.post_title as Registration_Event, "; | 
                                                            
                                    | 551 |  |         $join = ''; | 
                                                            
                                    | 552 |  |         $join_parts = array(); | 
                                                            
                                    | 553 |  |         $select_parts = array(); | 
                                                            
                                    | 554 |  |         //loop through registration stati to do parts for each status. | 
                                                            
                                    | 555 |  |         foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { | 
                                                            
                                    | 556 |  |             if ($STS_ID === EEM_Registration::status_id_incomplete) { | 
                                                            
                                    | 557 |  |                 continue; | 
                                                            
                                    | 558 |  |             } | 
                                                            
                                    | 559 |  |             $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID"; | 
                                                            
                                    | 560 |  |             $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"; | 
                                                            
                                    | 561 |  |         } | 
                                                            
                                    | 562 |  |         //setup the selects | 
                                                            
                                    | 563 |  |         $select .= implode(', ', $select_parts); | 
                                                            
                                    | 564 |  |         $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN "; | 
                                                            
                                    | 565 |  |         //setup remaining joins | 
                                                            
                                    | 566 |  |         $join .= implode(" LEFT JOIN ", $join_parts); | 
                                                            
                                    | 567 |  |         //now put it all together | 
                                                            
                                    | 568 |  |         $query = $select . $join . ' GROUP BY Registration_Event'; | 
                                                            
                                    | 569 |  |         //and execute | 
                                                            
                                    | 570 |  |         $results = $wpdb->get_results($query, ARRAY_A); | 
                                                            
                                    | 571 |  |         return $results; | 
                                                            
                                    | 572 |  |     } | 
                                                            
                                    | 573 |  |  | 
                                                            
                                    | 574 |  |  | 
                                                            
                                    | 575 |  |  | 
                                                            
                                    | 576 |  |     /** | 
                                                            
                                    | 577 |  |      * Returns the EE_Registration of the primary attendee on the transaction id provided | 
                                                            
                                    | 578 |  |      * | 
                                                            
                                    | 579 |  |      * @param int $TXN_ID | 
                                                            
                                    | 580 |  |      * @return EE_Registration | 
                                                            
                                    | 581 |  |      */ | 
                                                            
                                    | 582 |  |     public function get_primary_registration_for_transaction_ID($TXN_ID = 0) | 
                                                            
                                    | 583 |  |     { | 
                                                            
                                    | 584 |  |         if ( ! $TXN_ID) { |