PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.63
Timetics – Appointment Booking Calendar & Scheduling v1.0.63
1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 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.19 1.0.2 1.0.20 1.0.21 1.0.22 All 64 releases
timetics / core / dummy-data / dummy-data-generator.php

dummy-data-generator.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.63, at core/dummy-data/dummy-data-generator.php

434 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Timetics\Core\DummyData;
3
4 defined( 'ABSPATH' ) || exit;
5
6 use Timetics\Core\Appointments\Appointment;
7 use Timetics\Core\Staffs\Staff;
8 use Timetics\Core\Customers\Customer;
9 use TimeticsPro\Core\SeatPlan\SeatPlan;
10
11 /**
12 * Dummy Data Generator
13 *
14 * @package Timetics
15 */
16 class Dummy_Data_Generator {
17
18 /**
19 * @var \Faker\Generator
20 */
21 private $faker;
22
23 /**
24 * Constructor
25 *
26 * @param object $faker Faker instance.
27 */
28 public function __construct($faker = null) {
29 if ( is_null( $faker ) ) {
30 $this->faker = Factory::create();
31 } else {
32 $this->faker = $faker;
33 }
34 }
35
36 /**
37 * Generate dummy data
38 *
39 * @param int $total Total number of items to generate.
40 *
41 * @return void
42 */
43 public function generate() {
44 $this->generate_appointments();
45 }
46
47 /**
48 * Generate dummy appointments
49 *
50 * @param int $total Total number of appointments to generate.
51 *
52 * @return void
53 */
54 public function generate_appointments( $type = 'One-to-One', $total = 1, $capacity = 5 ) {
55 $items = $total;
56 $factory = $this->faker;
57 $factory = Factory::create();
58 $visibility = ['enabled', 'disabled'];
59 $staff = $this->get_staff();
60
61 for ( $i = 1; $i <= $items; $i++ ) {
62 $meeting = new Appointment();
63
64 $appointment_data = [
65 'name' => $this->get_meeting_title(),
66 'description' => $factory->paragraph( 7 ),
67 'type' => $type,
68 'locations' => $this->get_locations( $factory->address ),
69 'staff' => [$staff],
70 'duration' => $this->get_duration(),
71 'price' => $this->get_price(),
72 'capacity' => $capacity,
73 'visibility' => 'enabled',
74 'schedule' => $this->get_schedule( $staff ),
75 'timezone' => 'Asia/Dhaka',
76 'availability' => $this->get_availability(),
77 ];
78
79 $meeting->set_props( $appointment_data );
80 $meeting->save();
81
82 if ( 'seat' === $type ) {
83 $this->generate_seat_plan( $meeting->get_id() );
84 }
85 }
86 }
87
88 /**
89 * Generate dummy staff data
90 *
91 * @param int $total Total number of staff to generate.
92 *
93 * @return void
94 */
95 private function generte_staff( $total = 2 ) {
96 $items = $total;
97 $factory = $this->faker;
98
99 for ( $i = 1; $i <= $items; $i++ ) {
100 $staff = new Staff();
101 $args = [
102 'first_name' => $factory->first_name,
103 'last_name' => $factory->last_name,
104 'user_email' => $factory->email,
105 'user_login' => $factory->username,
106 'phone' => $factory->phone_number,
107 'schedule' => timetics_get_option( 'availability' ),
108 'user_pass' => $factory->password,
109 ];
110
111 $staff->create( $args );
112 }
113 }
114
115 /**
116 * Get meeting
117 *
118 * @return integer
119 */
120 private function get_meeting() {
121 $meetings = $this->get_meeting_ids();
122
123 return $meetings[array_rand( $meetings )];
124 }
125
126 /**
127 * Get meeting title
128 *
129 * @return string
130 */
131 private function get_meeting_title() {
132 $meeting_titles = [
133 "Project Kickoff Meeting",
134 "Weekly Standup",
135 "Client Demo Presentation",
136 "Marketing Strategy Session",
137 "Design Review Meeting",
138 "Sprint Planning",
139 "Product Roadmap Discussion",
140 "Team Retrospective",
141 "Sales Performance Review",
142 "Budget Planning Meeting",
143 "Technical Architecture Review",
144 "Hiring Panel Interview",
145 "Customer Feedback Review",
146 "Quarterly Business Review",
147 "Onboarding Session",
148 "Security & Compliance Briefing",
149 "Feature Launch Meeting",
150 "Investor Update Call",
151 "Support Team Sync",
152 "Content Planning Workshop"
153 ];
154
155 return $meeting_titles[ array_rand( $meeting_titles ) ];
156 }
157
158 /**
159 * Get staff id
160 *
161 * @return integer
162 */
163 private function get_staff() {
164 $users = get_users( ['role' => 'administrator'] );
165
166 if ( ! empty( $users ) ) {
167 return $users[0]->ID;
168 }
169
170 return 1;
171 }
172
173 /**
174 * Get customer id
175 *
176 * @return integer
177 */
178 private function get_customer() {
179 $customers = $this->get_customer_ids();
180
181 return $customers[array_rand( $customers )];
182 }
183
184 /**
185 * Get staff ids
186 *
187 * @return array
188 */
189 private function get_staff_ids() {
190 $staff = new Staff();
191
192 $users = $staff->all();
193
194 $ids = [];
195
196 foreach ( $users['items'] as $user ) {
197 $ids[] = $user->ID;
198 }
199
200 return $ids;
201 }
202
203 /**
204 * Get all meeting ids
205 *
206 * @return array
207 */
208 private function get_meeting_ids() {
209 $ids = [];
210 $meeting = new Appointment();
211 $meetings = $meeting->all();
212
213 foreach ( $meetings['items'] as $meeting_ob ) {
214 $ids[] = $meeting_ob->ID;
215 }
216
217 return $ids;
218 }
219
220 /**
221 * Get customer ids
222 *
223 * @return array
224 */
225 private function get_customer_ids() {
226 $customer = new Customer();
227
228 $users = $customer->all();
229
230 $ids = [];
231
232 foreach ( $users['items'] as $user ) {
233 $ids[] = $user->ID;
234 }
235
236 return $ids;
237 }
238
239 /**
240 * Generate meeting schedule
241 *
242 * @return array
243 */
244 private function get_schedule( $staff ) {
245 return [
246 $staff => [
247 'Sun' => [
248 [
249 'start' => '9:00am',
250 'end' => '5:00pm',
251 ],
252 ],
253 'Mon' => [
254 [
255 'start' => '9:00am',
256 'end' => '5:00pm',
257 ],
258 ],
259 'Tue' => [
260 [
261 'start' => '9:00am',
262 'end' => '5:00pm',
263 ],
264 ],
265 'Wed' => [
266 [
267 'start' => '9:00am',
268 'end' => '5:00pm',
269 ],
270 ],
271 'Thu' => [
272 [
273 'start' => '9:00am',
274 'end' => '5:00pm',
275 ],
276 ],
277 'Fri' => [
278 [
279 'start' => '9:00am',
280 'end' => '5:00pm',
281 ],
282 ],
283 'Sat' => [
284 [
285 'start' => '9:00am',
286 'end' => '5:00pm',
287 ],
288 ],
289 ],
290 ];
291 }
292
293 /**
294 * Generate locations
295 *
296 * @param string $address
297 *
298 * @return string
299 */
300 private function get_locations( $address ) {
301 return [
302 [
303 'location' => $address,
304 'location_type' => 'in-person-meeting',
305 ],
306 ];
307 }
308
309 /**
310 * Generate availability
311 *
312 * @return array
313 */
314 private function get_availability() {
315 return [
316 'start' => gmdate( 'Y-m-d' ),
317 'end' => gmdate( 'Y-m-d', strtotime( '+1 month', time() ) ),
318 ];
319 }
320
321 /**
322 * Get generate price
323 *
324 * @return array
325 */
326 private function get_price() {
327 return [
328 [
329 'ticket_name' => 'default',
330 'ticket_price' => 0,
331 'ticket_quantity' => '20',
332 ],
333 ];
334 }
335
336 /**
337 * Get meeting duration
338 *
339 * @return string
340 */
341 private function get_duration() {
342 $numbers = [15, 30, 60];
343 $number = $numbers[array_rand( $numbers )];
344 $unit = 'min';
345
346 $duration = "$number $unit";
347
348 return $duration;
349 }
350
351 /**
352 * Generate seat plan
353 *
354 * @param int $meeting_id Meeting ID.
355 *
356 * @return void
357 */
358 private function generate_seat_plan( $meeting_id ) {
359 if ( ! class_exists( 'TimeticsPro' ) ) {
360 return;
361 }
362
363 $meeting = new Appointment( $meeting_id );
364 $seat_capacity = 20;
365 $seat_ids = [];
366 $positions = $this->get_positions();
367
368 for( $i = 0; $i < $seat_capacity; $i++) {
369 $position = $positions[$i];
370
371 $data = [
372 'angle' => "0",
373 'cursor' => "pointer",
374 'fill' => "black",
375 'fontSize' => null,
376 'height' => 20,
377 'label' => "",
378 'number' => "1",
379 'positionX' => $position[0],
380 'positionY' => $position[1],
381 'price' => "71",
382 'radius' => "10",
383 'scaleX' => 1,
384 'scaleY' => 1,
385 'shapeType' => "chair",
386 'stroke' => "black",
387 'strokeWidth' => 1,
388 'text' => null,
389 'ticketType' => "default",
390 'type' => "path",
391 'width' => 20,
392 'zoomX' => 1.6342283377796114,
393 'zoomY' => 1.6342283377796114,
394 'meeting' => $meeting_id,
395 ];
396
397 $seat_ids[] = SeatPlan::insert( $data );
398 }
399
400 $config = [
401 'canvasDimensions' => [
402 'width' => 1000,
403 'height' => 1000,
404 ],
405 'selectColor' => '#000000',
406 'unavailableColor' => '#dd4d4d',
407 'canvasBgImage' => '',
408 ];
409
410 $meeting->update(
411 [
412 'seat_plan' => $seat_ids,
413 'seat_plan_settings' => $config,
414 ]
415 );
416 }
417
418 /**
419 * Get seat positions
420 *
421 * @return array
422 */
423 private function get_positions() {
424 $positions = [
425 ["15", "200"], ["50", "200"], ["85", "200"], ["120", "200"], ["155", "200"],
426 ["15", "235"], ["50", "235"], ["85", "235"], ["120", "235"], ["155", "235"],
427 ["15", "270"], ["50", "270"], ["85", "270"], ["120", "270"], ["155", "270"],
428 ["15", "305"], ["50", "305"], ["85", "305"], ["120", "305"], ["155", "305"]
429 ];
430
431 return $positions;
432 }
433 }
434