Code Duplication    Length = 34-34 lines in 2 locations

core/db_models/EEM_Event.model.php 2 locations

@@ 468-501 (lines=34) @@
465
     * @return EE_Event[]|int
466
     * @throws \EE_Error
467
     */
468
    public function get_upcoming_events($query_params, $count = false)
469
    {
470
        if (array_key_exists(0, $query_params)) {
471
            $where_params = $query_params[0];
472
            unset($query_params[0]);
473
        } else {
474
            $where_params = array();
475
        }
476
        // if we have count make sure we don't include group by
477
        if ($count && isset($query_params['group_by'])) {
478
            unset($query_params['group_by']);
479
        }
480
        // let's add specific query_params for active_events
481
        // keep in mind this will override any sent status in the query AND any date queries.
482
        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
483
        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
484
        if (isset($where_params['Datetime.DTT_EVT_start'])) {
485
            $where_params['Datetime.DTT_EVT_start*****'] = array(
486
                '>',
487
                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
488
            );
489
        } else {
490
            $where_params['Datetime.DTT_EVT_start'] = array(
491
                '>',
492
                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
493
            );
494
        }
495
        $query_params[0] = $where_params;
496
        // don't use $query_params with count()
497
        // because we don't want to include additional query clauses like "GROUP BY"
498
        return $count
499
            ? $this->count(array($where_params), 'EVT_ID', true)
500
            : $this->get_all($query_params);
501
    }
502
503
504
@@ 515-548 (lines=34) @@
512
     * @return EE_Event[]|int
513
     * @throws \EE_Error
514
     */
515
    public function get_active_and_upcoming_events($query_params, $count = false)
516
    {
517
        if (array_key_exists(0, $query_params)) {
518
            $where_params = $query_params[0];
519
            unset($query_params[0]);
520
        } else {
521
            $where_params = array();
522
        }
523
        // if we have count make sure we don't include group by
524
        if ($count && isset($query_params['group_by'])) {
525
            unset($query_params['group_by']);
526
        }
527
        // let's add specific query_params for active_events
528
        // keep in mind this will override any sent status in the query AND any date queries.
529
        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
530
        // add where params for DTT_EVT_end
531
        if (isset($where_params['Datetime.DTT_EVT_end'])) {
532
            $where_params['Datetime.DTT_EVT_end*****'] = array(
533
                '>',
534
                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
535
            );
536
        } else {
537
            $where_params['Datetime.DTT_EVT_end'] = array(
538
                '>',
539
                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
540
            );
541
        }
542
        $query_params[0] = $where_params;
543
        // don't use $query_params with count()
544
        // because we don't want to include additional query clauses like "GROUP BY"
545
        return $count
546
            ? $this->count(array($where_params), 'EVT_ID', true)
547
            : $this->get_all($query_params);
548
    }
549
550
551