From 9a43dcf79862f0e54deab84de8dcf96096200c88 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Thu, 23 Jul 2026 14:03:48 +0330 Subject: [PATCH] feat: add seed data for clinic, doctors, and secretaries --- seed_testdata.php | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 seed_testdata.php diff --git a/seed_testdata.php b/seed_testdata.php new file mode 100644 index 00000000..04bfe0d1 --- /dev/null +++ b/seed_testdata.php @@ -0,0 +1,94 @@ +bootEnv(__DIR__ . '/.env'); + +$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', (bool) ($_SERVER['APP_DEBUG'] ?? true)); +$kernel->boot(); + +$em = $kernel->getContainer()->get('doctrine')->getManager(); + +$factory = new PasswordHasherFactory([User::class => ['algorithm' => 'auto']]); +$hasher = new UserPasswordHasher($factory); + +const PASSWORD = 'QaTest@1234'; + +/** ساخت کاربرِ لاگین‌پذیر با نقش و پسورد مشترک. */ +function makeUser($em, $hasher, string $mobile, string $name, array $roles): User +{ + $u = new User($mobile); + $u->setPasswordHash($hasher->hashPassword($u, PASSWORD)); + $u->setRealName($name)->setRoles($roles)->setStatus(1); + $em->persist($u); + return $u; +} + +$report = []; + +// ── کلینیک نمونه: مالک + ۳ پزشک عضو ──────────────────────────────────────── +$clinicOwner = makeUser($em, $hasher, '09150000001', 'مدیر کلینیک نمونه', ['ROLE_USER', 'ROLE_CLINIC']); +$clinic = new Clinic($clinicOwner); +$clinic->setName('کلینیک نمونه')->setIsActive(true); +$em->persist($clinic); +$report[] = ['کلینیک — مالک', '09150000001', 'ROLE_CLINIC']; + +$clinicDoctorNames = [ + '09150000011' => 'دکتر علی احمدی', + '09150000012' => 'دکتر مریم رضایی', + '09150000013' => 'دکتر حسن کریمی', +]; +foreach ($clinicDoctorNames as $mobile => $name) { + $u = makeUser($em, $hasher, $mobile, $name, ['ROLE_USER', 'ROLE_DOCTOR']); + $d = new Doctor($u, $name); + $d->setGender('man')->setActiveDoctorAppointment(true); + $em->persist($d); + $clinic->getDoctors()->add($d); + $report[] = ['کلینیک — پزشک عضو', $mobile, $name]; +} + +// منشیِ کلینیک: یک رکورد DoctorSecretary per پزشکِ کلینیک (OWNER_CLINIC) +$clinicSec = makeUser($em, $hasher, '09150000021', 'منشی کلینیک نمونه', ['ROLE_USER', 'ROLE_SECRETARY']); +foreach ($clinic->getDoctors() as $d) { + $em->persist(new DoctorSecretary($d, $clinicSec, DoctorSecretary::OWNER_CLINIC, $clinic)); +} +$report[] = ['کلینیک — منشی (هر ۳ پزشک)', '09150000021', 'ROLE_SECRETARY']; + +// ── پزشکان مستقل: هرکدام + منشیِ اختصاصی ──────────────────────────────────── +$independent = [ + ['09150000031', 'دکتر زهرا موسوی', '09150000041', 'منشی دکتر موسوی'], + ['09150000032', 'دکتر رضا نجفی', '09150000042', 'منشی دکتر نجفی'], + ['09150000033', 'دکتر سارا حسینی', '09150000043', 'منشی دکتر حسینی'], +]; +foreach ($independent as [$docMobile, $docName, $secMobile, $secName]) { + $du = makeUser($em, $hasher, $docMobile, $docName, ['ROLE_USER', 'ROLE_DOCTOR']); + $d = new Doctor($du, $docName); + $d->setActiveDoctorAppointment(true); + $em->persist($d); + $report[] = ['پزشک مستقل', $docMobile, $docName]; + + $su = makeUser($em, $hasher, $secMobile, $secName, ['ROLE_USER', 'ROLE_SECRETARY']); + $em->persist(new DoctorSecretary($d, $su, DoctorSecretary::OWNER_DOCTOR)); + $report[] = [' └ منشیِ همان پزشک', $secMobile, $secName]; +} + +$em->flush(); + +echo "\n✅ Seed کامل شد — پسورد همه: " . PASSWORD . "\n\n"; +printf("%-32s %-14s %s\n", 'نقش', 'موبایل', 'نام/نقش'); +echo str_repeat('─', 70) . "\n"; +foreach ($report as [$role, $mobile, $name]) { + printf("%-32s %-14s %s\n", $role, $mobile, $name); +} +echo "\n";