PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.2
Booktics – Appointment Booking Calendar for Service Businesses v1.0.2
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
booktics / core / appointment / schedule / schedule-collection.php

schedule-collection.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.2, at core/appointment/schedule/schedule-collection.php

91 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 namespace Booktics\Appointment\Schedule;
5
6 use DateTime;
7
8 /**
9 * Class schedule collection
10 */
11 class Schedule_Collection {
12 /**
13 * @var mixed
14 */
15 protected $id;
16
17 /**
18 * Store collection of schedules
19 *
20 * @var Schedule_Entry[]
21 */
22 private array $entries = [];
23
24 /**
25 * Constructor for schedule collections
26 *
27 * @param array $raw_data
28 * @param mixed $id
29 */
30 public function __construct(array $raw_data, $id = null) {
31 $this->id = $id;
32 foreach ($raw_data as $item) {
33 $this->entries[] = new Schedule_Entry($item);
34 }
35 }
36
37 /**
38 * Get collection of date entry for matching date
39 *
40 * @param DateTime $date
41 * @return Schedule_Entry[]
42 */
43 public function get_dates(DateTime $date): array {
44 return array_filter($this->entries, function ($entry) use ($date) {
45 return $entry->matches_date($date);
46 });
47 }
48
49 /**
50 * Get the first date for the date range
51 *
52 * @param DateTime $date
53 * @return Schedule_Entry|null
54 */
55 public function get_first_date(DateTime $date): ?Schedule_Entry {
56 if (!is_array($this->entries)) {
57 return null;
58 }
59 $custom_date_entry = null;
60 $week_day_entry = null;
61 $dow = intval($date->format('N'));
62 foreach ($this->entries as $entry) {
63 if ($entry->get_custom_date() === $date->format('Y-m-d')) {
64 $custom_date_entry = $entry;
65 break;
66 } elseif (empty($entry->get_custom_date()) && (int)$entry->get_day_of_week() === $dow) {
67 $week_day_entry = $entry;
68 }
69 }
70 return $custom_date_entry ?? $week_day_entry;
71 }
72
73 /**
74 * Get id
75 *
76 * @return mixed
77 */
78 public function get_id() {
79 return $this->id;
80 }
81
82 /**
83 * Get all entries
84 *
85 * @return Schedule_Entry[]
86 */
87 public function get_entries(): array {
88 return $this->entries;
89 }
90 }
91