feat: add seed data for clinic, doctors, and secretaries

This commit is contained in:
hamed
2026-07-23 14:03:48 +03:30
parent e279812b96
commit 9a43dcf798
+94
View File
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use App\Auth\Entity\User;
use App\Clinic\Entity\Clinic;
use App\Doctor\Entity\Doctor;
use App\Secretary\Entity\DoctorSecretary;
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
(new Dotenv())->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";