PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.18
Booktics – Appointment Booking Calendar for Service Businesses v1.0.18
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.18, at core/appointment/schedule/schedule-collection.php

94 lines 2.2 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 = array();
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(
45 $this->entries, function ( $entry ) use ( $date ) {
46 return $entry->matches_date( $date );
47 }
48 );
49 }
50
51 /**
52 * Get all schedule entries for the date range
53 *
54 * @param DateTime $date
55 * @return array Array of Schedule_Entry objects
56 */
57 public function get_first_date( DateTime $date ): array {
58 if ( ! is_array( $this->entries ) ) {
59 return array();
60 }
61 $custom_date_entries = array();
62 $week_day_entries = array();
63 $dow = intval( $date->format( 'N' ) );
64
65 foreach ( $this->entries as $entry ) {
66 if ( $entry->get_custom_date() === $date->format( 'Y-m-d' ) ) {
67 $custom_date_entries[] = $entry;
68 } elseif ( empty( $entry->get_custom_date() ) && (int) $entry->get_day_of_week() === $dow ) {
69 $week_day_entries[] = $entry;
70 }
71 }
72
73 // Prioritize custom date entries over regular weekday entries
74 return ! empty( $custom_date_entries ) ? $custom_date_entries : $week_day_entries;
75 }
76 /**
77 * Get id
78 *
79 * @return mixed
80 */
81 public function get_id() {
82 return $this->id;
83 }
84
85 /**
86 * Get all entries
87 *
88 * @return Schedule_Entry[]
89 */
90 public function get_entries(): array {
91 return $this->entries;
92 }
93 }
94