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