1. Go to this page and download the library: Download tourze/train-course-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/ */
use Tourze\TrainCourseBundle\Entity\Course;
use Tourze\TrainCourseBundle\Entity\Chapter;
use Tourze\TrainCourseBundle\Entity\Video;
// Create course
$course = new Course();
$course->setTitle('Basic Knowledge of Safety Production');
$course->setDescription('This course introduces basic concepts and regulations of safety production');
$course->setPrice(99.00);
$course->setValidDays(365);
$course->setLearnHours(8);
// Create chapter
$chapter = new Chapter();
$chapter->setCourse($course);
$chapter->setTitle('Chapter 1: Overview of Safety Production');
$chapter->setSort(1);
// Create video
$video = new Video();
$video->setChapter($chapter);
$video->setTitle('1.1 Importance of Safety Production');
$video->setUrl('ali://xxxxx'); // Alibaba Cloud VOD video ID
$video->setDuration(600); // 10 minutes
use Tourze\TrainCourseBundle\Service\CourseService;
// Inject service
public function __construct(private CourseService $courseService) {}
// Get video play URL from lesson
$playUrl = $this->courseService->getLessonPlayUrl($lesson);
// Get course service
$courseService = $this->get(CourseService::class);
// Find course by ID
$course = $courseService->findById($courseId);
// Check if course is valid
$isValid = $courseService->isCourseValid($course);
// Get course total duration
$totalDuration = $courseService->getCourseTotalDuration($course);
// Get course progress for a user
$progress = $courseService->getCourseProgress($course, $userId);
// Set up playback control
$playControl = new CoursePlayControl();
$playControl->setCourse($course);
$playControl->setAllowFastForward(false);
$playControl->setAllowSpeedControl(true);
$playControl->setWatermarkText('Training Course');
$playControl->setMaxDeviceCount(3);
$entityManager->persist($playControl);
$entityManager->flush();
// Get comprehensive course analytics report
$courseAnalytics = $this->get(CourseAnalyticsService::class);
// Get analytics report for a specific course
$analyticsReport = $courseAnalytics->getCourseAnalyticsReport($course);
// Get course rankings with criteria
$rankings = $courseAnalytics->getCourseRankings([
'category' => $categoryId,
'limit' => 10
]);
// Get course configuration service
$configService = $this->get(CourseConfigService::class);
// Get video cache time
$cacheTime = $configService->getVideoPlayUrlCacheTime();
// Check if a feature is enabled
$isEnabled = $configService->isFeatureEnabled('video_watermark');
// Get all configuration
$allConfig = $configService->getAllConfig();
// Example: Check user access to course
if (!$this->courseService->hasAccess($user, $course)) {
throw new AccessDeniedException('User does not have access to this course');
}