Code Duplication    Length = 39-41 lines in 2 locations

core/db_models/EEM_Registration.model.php 2 locations

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