toString(); $this->connection()->executeStatement( "INSERT INTO subjects (id, tenant_id, school_id, name, code, status, created_at, updated_at) VALUES (:id, :tenant, :school, :name, :code, 'active', NOW(), NOW())", [ 'id' => $id, 'tenant' => $tenantId, 'school' => $schoolId, 'name' => $name, 'code' => $code, ], ); return $id; } protected function insertClass(string $tenantId, string $schoolId): string { $id = Uuid::uuid4()->toString(); $this->connection()->executeStatement( "INSERT INTO school_classes (id, tenant_id, school_id, academic_year_id, name, level, status, created_at, updated_at) VALUES (:id, :tenant, :school, :year, '6e A', '6e', 'active', NOW(), NOW())", [ 'id' => $id, 'tenant' => $tenantId, 'school' => $schoolId, 'year' => $schoolId, ], ); return $id; } protected function insertUser(string $tenantId, string $email): string { $id = Uuid::uuid4()->toString(); $this->connection()->executeStatement( "INSERT INTO users (id, tenant_id, email, first_name, last_name, roles, statut, school_name, image_rights_status, created_at, updated_at) VALUES (:id, :tenant, :email, 'Test', 'User', '[\"ROLE_USER\"]', 'active', 'Test School', 'not_requested', NOW(), NOW())", [ 'id' => $id, 'tenant' => $tenantId, 'email' => $email, ], ); return $id; } protected function insertTeacherAssignment( string $tenantId, string $teacherId, string $classId, string $subjectId, string $academicYearId, ): void { $this->connection()->executeStatement( "INSERT INTO teacher_assignments (id, tenant_id, teacher_id, school_class_id, subject_id, academic_year_id, start_date, status, created_at, updated_at) VALUES (:id, :tenant, :teacher, :class, :subject, :year, NOW(), 'active', NOW(), NOW())", [ 'id' => Uuid::uuid4()->toString(), 'tenant' => $tenantId, 'teacher' => $teacherId, 'class' => $classId, 'subject' => $subjectId, 'year' => $academicYearId, ], ); } protected function insertEvaluation( string $tenantId, string $classId, string $subjectId, string $teacherId, string $title, ): string { $id = Uuid::uuid4()->toString(); $this->connection()->executeStatement( 'INSERT INTO evaluations (id, tenant_id, class_id, subject_id, teacher_id, title, evaluation_date) VALUES (:id, :tenant, :class, :subject, :teacher, :title, CURRENT_DATE)', [ 'id' => $id, 'tenant' => $tenantId, 'class' => $classId, 'subject' => $subjectId, 'teacher' => $teacherId, 'title' => $title, ], ); return $id; } protected function insertGrade(string $tenantId, string $evaluationId, string $studentId, float $value): void { $this->connection()->executeStatement( 'INSERT INTO grades (id, tenant_id, evaluation_id, student_id, value, created_by) VALUES (:id, :tenant, :eval, :student, :value, :student)', [ 'id' => Uuid::uuid4()->toString(), 'tenant' => $tenantId, 'eval' => $evaluationId, 'student' => $studentId, 'value' => $value, ], ); } /** * Purge les tables de seeding pour les tenants donnés. * * L'ordre respecte les clés étrangères (grades → evaluations → teacher_assignments → subjects → school_classes → users). * * @param list $tenantIds */ protected function cleanupSubjectStatsData(array $tenantIds): void { if ($tenantIds === []) { return; } $placeholders = implode(',', array_map(static fn (int $i) => ':tenant_' . $i, array_keys($tenantIds))); $params = []; foreach ($tenantIds as $i => $tenantId) { $params['tenant_' . $i] = $tenantId; } foreach ( [ 'grades', 'evaluations', 'teacher_assignments', 'subjects', 'school_classes', 'users', ] as $table ) { $this->connection()->executeStatement( sprintf('DELETE FROM %s WHERE tenant_id IN (%s)', $table, $placeholders), $params, ); } } }