Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b1b2f8

Browse files
ESTE ES UN STEP TEMPORAL
1 parent 53fa661 commit 0b1b2f8

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,60 @@ public function get(string $courseId): string
7979

8080
$results .= ']';
8181

82+
$results = '[';
83+
84+
$csvLines = explode(PHP_EOL, $csv);
85+
86+
foreach ($csvLines as $index => $row) {
87+
$row = str_getcsv($row);
88+
89+
if (empty($csv)) {
90+
continue;
91+
}
92+
93+
[$stepId, $type, $quizTotalQuestions, $videoDuration] = $row;
94+
95+
$stepDurationInMinutes = 0;
96+
$points = 0;
97+
98+
if ($type === self::STEP_TYPE_VIDEO) {
99+
$stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER;
100+
}
101+
102+
if ($type === self::STEP_TYPE_QUIZ) {
103+
$stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER;
104+
}
105+
106+
if ($type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ) {
107+
continue;
108+
}
109+
110+
if ($type === self::STEP_TYPE_VIDEO) {
111+
$points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE;
112+
}
113+
114+
if ($type === self::STEP_TYPE_QUIZ) {
115+
$points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE;
116+
}
117+
118+
$results .= json_encode(
119+
[
120+
'id' => $stepId,
121+
'type' => $type,
122+
'duration' => $stepDurationInMinutes,
123+
'points' => $points,
124+
],
125+
JSON_THROW_ON_ERROR
126+
);
127+
128+
$hasMoreRows = $index !== count($csvLines) - 1;
129+
if ($hasMoreRows) {
130+
$results .= ',';
131+
}
132+
}
133+
134+
$results .= ']';
135+
82136
return $results;
83137
}
84138
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /