| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Dummy_Data; |
| 4 |
|
| 5 |
use Booktics\Models\Service_Model; |
| 6 |
use Exception; |
| 7 |
|
| 8 |
class Dummy_Data_Manager { |
| 9 |
private $generator; |
| 10 |
|
| 11 |
public function __construct() { |
| 12 |
$this->generator = new Generator(); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Generate dummy data for onboarding |
| 17 |
*/ |
| 18 |
public function generate_onboarding_data( $service_count = 3 ) { |
| 19 |
$result = $this->create_services( $service_count ); |
| 20 |
if ( empty( $result['service_ids'] ) ) { |
| 21 |
return false; |
| 22 |
} |
| 23 |
|
| 24 |
return array( |
| 25 |
'services' => $result['service_ids'], |
| 26 |
'errors' => $result['errors'], |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Create fake services |
| 32 |
* |
| 33 |
* @param int $count Number of services to create |
| 34 |
* |
| 35 |
* @return array Created service IDs |
| 36 |
*/ |
| 37 |
public function create_services( int $count = 3 ): array { |
| 38 |
$result = array( |
| 39 |
'service_ids' => array(), |
| 40 |
'errors' => array(), |
| 41 |
); |
| 42 |
$current_services = Service_Model::paginate(); |
| 43 |
if ( $current_services['total'] > 0 ) { |
| 44 |
return $result; |
| 45 |
} |
| 46 |
|
| 47 |
$service_model = new \Booktics\Models\Service_Model(); |
| 48 |
$service_ids = array(); |
| 49 |
$service_types = array( |
| 50 |
'Consultation' => 30, |
| 51 |
'Check-up' => 60, |
| 52 |
'Therapy' => 45, |
| 53 |
'Examination' => 90, |
| 54 |
'Follow-up' => 20, |
| 55 |
'Massage' => 60, |
| 56 |
'Treatment' => 45, |
| 57 |
'Evaluation' => 30, |
| 58 |
); |
| 59 |
|
| 60 |
for ( $i = 0; $i < $count; $i++ ) { |
| 61 |
$service_name = $this->generator->random_element( array_keys( $service_types ) ); |
| 62 |
$duration = $service_types[ $service_name ]; |
| 63 |
$description = $this->generator->sentence( 7 ); |
| 64 |
$service_data = array( |
| 65 |
'title' => $service_name, |
| 66 |
'description' => $description, |
| 67 |
'content' => $description, |
| 68 |
'duration_time' => $duration, |
| 69 |
'duration_unit' => 'minutes', |
| 70 |
'charge_amount' => $this->generator->number_between( 50, 300 ), |
| 71 |
'status' => 'active', |
| 72 |
); |
| 73 |
|
| 74 |
try { |
| 75 |
$service_id = $service_model->create( $service_data ); |
| 76 |
if ( $service_id ) { |
| 77 |
$result['service_ids'][] = $service_id; |
| 78 |
} |
| 79 |
} catch ( Exception $e ) { |
| 80 |
$result['errors'][] = 'Failed to create service: ' . $e->getMessage(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
return $result; |
| 85 |
} |
| 86 |
} |
| 87 |
|