-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScheduler.php
167 lines (141 loc) · 3.49 KB
/
Scheduler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
namespace Stanford\TrackCovidSharedAppointmentScheduler;
/**
* Class Scheduler
* @package Stanford\TrackCovidSharedAppointmentScheduler
* @property \Project $project
* @property array $sites;
* @property string $slotsEventId
* @property string $testingSitesEventId
* @property array $slots
*/
class Scheduler
{
use emLoggerTrait;
private $project;
private $sites;
private $slotsEventId;
private $testingSitesEventId;
private $slots;
/**
* Scheduler constructor.
* @param \Project $project
* @param array $sites
*/
public function __construct($project, $sites, $slotsEventId, $testingSitesEventId)
{
$this->setProject($project);
$this->setSites($sites);
$this->setSlotsEventId($slotsEventId);
$this->setTestingSitesEventId($testingSitesEventId);
$this->setSlots();
}
public function updateSlotBookedSpots($slot, $number = 1)
{
if ($slot['number_of_booked_slots']) {
$slot['number_of_booked_slots'] = $slot['number_of_booked_slots'] + $number;
} else {
$slot['number_of_booked_slots'] = 1;
}
/**
* if user is in different timezone then remove start and end fields.
*/
if (isset($slot['start_orig'])) {
unset($slot['start_orig']);
unset($slot['start']);
}
if (isset($slot['end_orig'])) {
unset($slot['end_orig']);
unset($slot['end']);
}
$response = \REDCap::saveData($this->getProject()->project_id, 'json', json_encode(array($slot)));
if (!empty($response['errors'])) {
if (is_array($response['errors'])) {
$this->emError(implode(",", $response['errors']));
} else {
$this->emError($response['errors']);
}
}
}
/**
* @return \Project
*/
public function getProject()
{
return $this->project;
}
/**
* @param \Project $project
*/
public function setProject(\Project $project)
{
$this->project = $project;
}
/**
* @return array
*/
public function getSites()
{
return $this->sites;
}
/**
* @param array $sites
*/
public function setSites($sites)
{
$this->sites = $sites;
}
/**
* @return string
*/
public function getSlotsEventId()
{
return $this->slotsEventId;
}
/**
* @param string $slotsEventId
*/
public function setSlotsEventId($slotsEventId)
{
$this->slotsEventId = $slotsEventId;
}
/**
* @return string
*/
public function getTestingSitesEventId()
{
return $this->testingSitesEventId;
}
/**
* @param string $testingSitesEventId
*/
public function setTestingSitesEventId($testingSitesEventId)
{
$this->testingSitesEventId = $testingSitesEventId;
}
/**
* @return array
*/
public function getSlots()
{
return $this->slots;
}
/**
* @param array $slots
*/
public function setSlots()
{
$param = array(
'project_id' => $this->getProject()->project_id,
'format' => 'array',
'events' => $this->getSlotsEventId()
);
$slots = \REDCap::getData($param);
$this->slots = $slots;
}
public function getSlot($id)
{
$slots = $this->getSlots();
return $slots[$id];
}
}