PHP code example of tourze / train-category-bundle

1. Go to this page and download the library: Download tourze/train-category-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / train-category-bundle example snippets


// config/bundles.php
return [
    // ...
    Tourze\TrainCategoryBundle\TrainCategoryBundle::class => ['all' => true],
];

use Tourze\TrainCategoryBundle\Service\CategoryService;

// 获取服务
$categoryService = $this->container->get(CategoryService::class);

// 创建分类
$category = $categoryService->createCategory('新分类', $parentCategory);

// 获取树形结构
$tree = $categoryService->getCategoryTree();

// 获取子分类
$children = $categoryService->getChildren($parentCategory);

use Tourze\TrainCategoryBundle\Service\CategorySearchService;

$searchService = $this->container->get(CategorySearchService::class);

// 高级搜索
$results = $searchService->advancedSearch([
    'title' => '电工',
    'level' => 2,
    'hasRequirements' => true,
    'minAge' => 18,
    'maxAge' => 60,
]);

// 智能推荐
$recommendations = $searchService->getRecommendations([
    'age' => 25,
    'industry' => '建筑施工',
    'experience' => '初级',
]);

use Tourze\TrainCategoryBundle\Service\CategoryStatisticsService;

$statisticsService = $this->container->get(CategoryStatisticsService::class);

// 获取概览统计
$overview = $statisticsService->getOverviewStatistics();

// 获取健康度报告
$healthReport = $statisticsService->getHealthReport();

// 导出统计报表
$csvData = $statisticsService->exportStatistics('csv');

use Tourze\TrainCategoryBundle\Service\CategoryImportExportService;

$importExportService = $this->container->get(CategoryImportExportService::class);

// 导出分类数据
$excelData = $importExportService->exportCategories('excel');

// 导入分类数据
$result = $importExportService->importCategories($filePath, 'excel');

// 获取工种培训分类
$procedure = new GetJobTrainingCategory();
$result = $procedure->call(['jobType' => 'electrician']);

use Tourze\TrainCategoryBundle\Service\CategoryValidationService;

class CustomValidationService extends CategoryValidationService
{
    public function validateCustomRule(Category $category): array
    {
        $errors = [];
        // 自定义验证逻辑
        return $errors;
    }
}

use Tourze\TrainCategoryBundle\Service\CategorySearchService;

class CustomSearchService extends CategorySearchService
{
    public function searchByCustomCriteria(array $criteria): array
    {
        // 自定义搜索逻辑
        return $this->categoryRepository->findBy($criteria);
    }
}
bash
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
bash
# 生产环境数据(推荐)
php bin/console doctrine:fixtures:load --group=production

# 开发环境数据(包含测试数据)
php bin/console doctrine:fixtures:load --group=dev

# 自定义加载
php bin/console doctrine:fixtures:load --append \
  --fixtures=src/DataFixtures/CategoryFixtures.php \
  --fixtures=src/DataFixtures/CategoryRequirementFixtures.php