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

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.2. 91 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.2/code/core/appointment/schedule/schedule-collection.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.2/raw/core/appointment/schedule/schedule-collection.php
- Modified: 2025-07-10T05:36:58+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.2/code/core/appointment/schedule/schedule-collection.php#L10-L20`.

```php
<?php
declare(strict_types=1);

namespace Booktics\Appointment\Schedule;

use DateTime;

/**
 * Class schedule collection
 */
class Schedule_Collection {
    /**
     * @var mixed
     */
    protected $id;

    /**
     * Store collection of schedules
     *
     * @var Schedule_Entry[]
     */
    private array $entries = [];

    /**
     * Constructor for schedule collections
     *
     * @param array $raw_data
     * @param mixed $id
     */
    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 Schedule_Entry[]
     */
    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'));
        foreach ($this->entries as $entry) {
            if ($entry->get_custom_date() === $date->format('Y-m-d')) {
                $custom_date_entry = $entry;
                break;
            } elseif (empty($entry->get_custom_date()) && (int)$entry->get_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;
    }

    /**
     * Get all entries
     *
     * @return Schedule_Entry[]
     */
    public function get_entries(): array {
        return $this->entries;
    }
}

```
