Files
nnterp-react-admin/database/seeders/DemoSkillsMatrixSeeder.php
2026-03-14 13:37:29 +08:00

146 lines
5.8 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class DemoSkillsMatrixSeeder extends Seeder
{
public function run(DemoContext $ctx): void
{
if (DB::table('skill_categories')->where('created_by', $ctx->userId)->exists()) {
return;
}
// 1. Skill Categories
// Valid enum values: technical, soft, certification, industry
$categoryTypes = [
'Technical' => 'technical',
'Soft Skills' => 'soft',
'Industry Knowledge' => 'industry',
'Compliance' => 'certification',
];
$categories = [];
foreach ($categoryTypes as $name => $type) {
$categories[] = DB::table('skill_categories')->insertGetId([
'name' => $name,
'type' => $type,
'sort_order' => (count($categories) + 1) * 10,
'is_active' => true,
'created_by' => $ctx->userId,
'created_at' => now(),
'updated_at' => now(),
]);
}
// 2. Skills (3 per category)
$skillData = [
[$categories[0], ['Laravel/PHP', 'React/TypeScript', 'Database Design']],
[$categories[1], ['Communication', 'Leadership', 'Problem Solving']],
[$categories[2], ['Tax Regulations', 'Audit Standards', 'Financial Reporting']],
[$categories[3], ['Data Privacy', 'Anti-Money Laundering', 'Workplace Safety']],
];
$skillIds = [];
foreach ($skillData as [$catId, $names]) {
foreach ($names as $j => $name) {
$skillIds[] = DB::table('skills')->insertGetId([
'name' => $name,
'category_id' => $catId,
'is_active' => true,
'training_url' => $j === 0 ? 'https://training.example.com/' . strtolower(str_replace(' ', '-', $name)) : null,
'training_notes' => $j === 0 ? "Recommended training for $name" : null,
'created_by' => $ctx->userId,
'created_at' => now(),
'updated_at' => now(),
]);
}
}
$ctx->skillIds = $skillIds;
// 3. Employee Skills (random proficiency per employee)
foreach ($ctx->employeeUserIds as $empUserId) {
$assignedSkills = array_rand(array_flip($skillIds), min(6, count($skillIds)));
if (!is_array($assignedSkills)) $assignedSkills = [$assignedSkills];
foreach ($assignedSkills as $skillId) {
$level = rand(1, 5);
DB::table('employee_skills')->insert([
'user_id' => $empUserId,
'skill_id' => $skillId,
'proficiency_level' => $level,
'verified_at' => $level >= 3 ? now()->subDays(rand(5, 60)) : null,
'verified_by' => $level >= 3 ? $ctx->userId : null,
'created_by' => $ctx->userId,
'created_at' => now()->subDays(rand(10, 90)),
'updated_at' => now(),
]);
}
}
// 4. Skill Requirements (linked to first 2 designations)
$desigs = array_slice($ctx->designationIds, 0, 2);
foreach ($desigs as $desigId) {
$reqSkills = array_slice($skillIds, 0, 4);
foreach ($reqSkills as $skillId) {
DB::table('skill_requirements')->insert([
'designation_id' => $desigId,
'skill_id' => $skillId,
'min_proficiency' => rand(2, 4),
'is_required' => rand(0, 1) === 1,
'created_by' => $ctx->userId,
'created_at' => now(),
'updated_at' => now(),
]);
}
}
// 5. Skill Assessments (history)
foreach (array_slice($ctx->employeeUserIds, 0, 3) as $empUserId) {
foreach (array_slice($skillIds, 0, 3) as $skillId) {
DB::table('skill_assessments')->insert([
'user_id' => $empUserId,
'skill_id' => $skillId,
'assessor_id' => $ctx->userId,
'previous_level' => rand(0, 2),
'new_level' => rand(3, 5),
'notes' => 'Quarterly assessment',
'created_at' => now()->subDays(rand(30, 90)),
'updated_at' => now(),
]);
}
}
// 6. Review Cycle + Skill Reviews
$cycleId = DB::table('review_cycles')->insertGetId([
'name' => 'Q1 2026 Peer Review',
'status' => 'closed',
'start_date' => now()->subMonths(2)->format('Y-m-d'),
'end_date' => now()->subMonth()->format('Y-m-d'),
'created_by' => $ctx->userId,
'created_at' => now()->subMonths(2),
'updated_at' => now()->subMonth(),
]);
$employees = array_slice($ctx->employeeUserIds, 0, 4);
foreach ($employees as $revieweeId) {
$reviewers = array_filter($employees, fn($id) => $id !== $revieweeId);
foreach (array_slice($reviewers, 0, 2) as $reviewerId) {
DB::table('skill_reviews')->insert([
'review_cycle_id' => $cycleId,
'reviewee_id' => $revieweeId,
'reviewer_id' => $reviewerId,
'skill_id' => $skillIds[array_rand($skillIds)],
'rating' => rand(2, 5),
'feedback' => 'Good progress in this area.',
'status' => 'completed',
'created_at' => now()->subMonth(),
'updated_at' => now()->subMonth(),
]);
}
}
}
}