# booktics/1.0.1/core/appointment/schedule/schedule-collection.php

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.1. 83 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.1/code/core/appointment/schedule/schedule-collection.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.1/raw/core/appointment/schedule/schedule-collection.php
- Modified: 2025-07-09T06:46:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/booktics/1.0.1/code/core/appointment/schedule/schedule-collection.php#L10-L20`.

```php
<?php

namespace Booktics\Appointment\Schedule;

use DateTime;

/**
 * Class schedule collection
 */
class Schedule_Collection {

    protected $id;

    /**
     * Store collection of schedules
     *
     * @var []
     */
    protected $entries = [];

    /**
     * Constructor for schedule collections
     *
     * @param array $raw_data
     */
    public function __construct( array $raw_data, $id = null ) {
        $this->id = $id;
        foreach ( $raw_data as $item ) {
            $this->entries[] = new Schedule_Entry( $item );
        }
    }

    /**
     * Get collection of date entry for matching date
     *
     * @param DateTime $date
     *
     * @return  array
     */
    public function get_dates( DateTime $date ): array {
        return array_filter( $this->entries, function ( $entry ) use ( $date ) {
            return $entry->matches_date( $date );
        } );
    }

    /**
     * Get the first date for the date range
     *
     * @param DateTime $date
     *
     * @return Schedule_Entry|null
     */
    public function get_first_date( DateTime $date ): ?Schedule_Entry {
        if ( ! is_array( $this->entries ) ) {
            return null;
        }

        $custom_date_entry = null;
        $week_day_entry    = null;
        $dow               = intval( $date->format( 'N' ) ); // 1 = Monday

        foreach ( $this->entries as $entry ) {
            if ( $entry->custom_date === $date->format( 'Y-m-d' ) ) {
                $custom_date_entry = $entry;
                break;
            } elseif ( empty( $entry->custom_date ) && (int) $entry->day_of_week === $dow ) {
                $week_day_entry = $entry;
            }
        }

        return $custom_date_entry ?? $week_day_entry;
    }

    /**
     * Get id
     *
     * @return mixed
     */
    public function get_id() {
        return $this->id;
    }
}

```
