Code Duplication    Length = 25-26 lines in 3 locations

core/db_models/EEM_Datetime.model.php 3 locations

@@ 432-456 (lines=25) @@
429
     * @return EE_Datetime[]
430
     * @throws EE_Error
431
     */
432
    public function get_datetimes_for_event_ordered_by_start_time(
433
        $EVT_ID,
434
        $include_expired = true,
435
        $include_deleted = true,
436
        $limit = null
437
    ) {
438
        // sanitize EVT_ID
439
        $EVT_ID         = absint($EVT_ID);
440
        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
441
        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
442
        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
443
        if (! $include_expired) {
444
            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
445
        }
446
        if ($include_deleted) {
447
            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
448
        }
449
        if ($limit) {
450
            $query_params['limit'] = $limit;
451
        }
452
        /** @var EE_Datetime[] $result */
453
        $result = $this->get_all($query_params);
454
        $this->assume_values_already_prepared_by_model_object($old_assumption);
455
        return $result;
456
    }
457
458
459
    /**
@@ 470-494 (lines=25) @@
467
     * @return EE_Datetime[]
468
     * @throws EE_Error
469
     */
470
    public function get_datetimes_for_ticket_ordered_by_start_time(
471
        $TKT_ID,
472
        $include_expired = true,
473
        $include_deleted = true,
474
        $limit = null
475
    ) {
476
        // sanitize TKT_ID
477
        $TKT_ID         = absint($TKT_ID);
478
        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
479
        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
480
        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
481
        if (! $include_expired) {
482
            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
483
        }
484
        if ($include_deleted) {
485
            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
486
        }
487
        if ($limit) {
488
            $query_params['limit'] = $limit;
489
        }
490
        /** @var EE_Datetime[] $result */
491
        $result = $this->get_all($query_params);
492
        $this->assume_values_already_prepared_by_model_object($old_assumption);
493
        return $result;
494
    }
495
496
497
    /**
@@ 509-534 (lines=26) @@
506
     * @return EE_Datetime[]
507
     * @throws EE_Error
508
     */
509
    public function get_datetimes_for_ticket_ordered_by_DTT_order(
510
        $TKT_ID,
511
        $include_expired = true,
512
        $include_deleted = true,
513
        $limit = null
514
    ) {
515
        // sanitize id.
516
        $TKT_ID         = absint($TKT_ID);
517
        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
518
        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
519
        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
520
        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
521
        if (! $include_expired) {
522
            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
523
        }
524
        if ($include_deleted) {
525
            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
526
        }
527
        if ($limit) {
528
            $query_params['limit'] = $limit;
529
        }
530
        /** @var EE_Datetime[] $result */
531
        $result = $this->get_all($query_params);
532
        $this->assume_values_already_prepared_by_model_object($old_assumption);
533
        return $result;
534
    }
535
536
537
    /**