@@ -10,6 +10,8 @@ final class CourseStepsGetController
1010{
1111 const VIDEO_DURATION_PAUSES_MULTIPLIER = 1.1 ;
1212 const QUIZ_TIME_PER_QUESTION_MULTIPLIER = 0.5 ;
13+ const STEP_TYPE_VIDEO = 'video ' ;
14+ const STEP_TYPE_QUIZ = 'quiz ' ;
1315 private Platform $ platform ;
1416
1517 public function __construct (Platform $ platform )
@@ -32,43 +34,43 @@ public function get(string $courseId): string
3234 continue ;
3335 }
3436
35- $ type = $ row [1 ];
37+ [$ stepId , $ type , $ quizTotalQuestions , $ videoDuration ] = $ row ;
38+ 3639 $ stepDurationInMinutes = 0 ;
37- $ points = 0 ;
40+ $ points = 0 ;
3841
39- $ videoDuration = $ row [3 ];
40- if ($ type === 'video ' ) {
42+ if ($ type === self ::STEP_TYPE_VIDEO ) {
4143 $ stepDurationInMinutes = $ videoDuration * self ::VIDEO_DURATION_PAUSES_MULTIPLIER ;
4244 }
4345
44- $ quizTotalQuestions = $ row [2 ];
45- if ($ type === 'quiz ' ) {
46+ if ($ type === self ::STEP_TYPE_QUIZ ) {
4647 $ stepDurationInMinutes = $ quizTotalQuestions * self ::QUIZ_TIME_PER_QUESTION_MULTIPLIER ;
4748 }
4849
49- if ($ type !== ' video ' && $ type !== ' quiz ' ) {
50+ if ($ type !== self :: STEP_TYPE_VIDEO && $ type !== self :: STEP_TYPE_QUIZ ) {
5051 continue ;
5152 }
5253
53- if ($ type === ' video ' ) {
54+ if ($ type === self :: STEP_TYPE_VIDEO ) {
5455 $ points = $ stepDurationInMinutes * 100 ;
5556 }
5657
57- if ($ type === ' quiz ' ) {
58+ if ($ type === self :: STEP_TYPE_QUIZ ) {
5859 $ points = $ quizTotalQuestions * self ::QUIZ_TIME_PER_QUESTION_MULTIPLIER * 10 ;
5960 }
6061
6162 $ results .= json_encode (
6263 [
63- 'id ' => $ row [ 0 ] ,
64- 'type ' => $ row [ 1 ] ,
64+ 'id ' => $ stepId ,
65+ 'type ' => $ type ,
6566 'duration ' => $ stepDurationInMinutes ,
66- 'points ' => $ points
67+ 'points ' => $ points,
6768 ],
6869 JSON_THROW_ON_ERROR
6970 );
7071
71- if ($ index !== count ($ csvLines ) - 1 ) {
72+ $ hasMoreRows = $ index !== count ($ csvLines ) - 1 ;
73+ if ($ hasMoreRows ) {
7274 $ results .= ', ' ;
7375 }
7476 }
0 commit comments