@@ -136,7 +136,7 @@ public function index($content_id, $record_id = null)
136
136
//------------------------------//
137
137
if ($ this ->request ->is ('post ' ))
138
138
{
139
- $ details = []; // 成績詳細情報
139
+ $ details = []; // 成績詳細情報
140
140
$ full_score = 0 ; // 最高点
141
141
$ pass_score = 0 ; // 合格基準点
142
142
$ my_score = 0 ; // 得点
@@ -145,44 +145,46 @@ public function index($content_id, $record_id = null)
145
145
//------------------------------//
146
146
// 成績の詳細情報の作成 //
147
147
//------------------------------//
148
- $ i = 0 ;
149
148
foreach ($ contentsQuestions as $ contentsQuestion )
150
149
{
151
150
$ question_id = $ contentsQuestion ['ContentsQuestion ' ]['id ' ]; // 問題ID
152
- $ answer = $ this ->getData ('answer_ ' . $ question_id ); // 解答
151
+ $ answer = $ this ->getData ('answer_ ' .$ question_id ); // 解答(複数選択問題の場合、配列)
152
+
153
153
$ correct = $ contentsQuestion ['ContentsQuestion ' ]['correct ' ]; // 正解
154
- $ corrects = explode (', ' , $ correct ); // 複数選択
154
+ $ corrects = explode (', ' , $ correct ); // 複数選択問題の正解(配列)
155
155
156
- $ is_correct = ($ answer == $ correct ) ? 1 : 0 ; // 正誤判定
157
156
$ score = $ contentsQuestion ['ContentsQuestion ' ]['score ' ]; // 配点
158
- $ full_score += $ score ; // 合計点(配点の合計)
157
+
159
158
160
159
// 複数選択問題の場合
161
160
if (count ($ corrects ) > 1 )
162
161
{
163
- $ answers = $ this ->getData ('answer_ ' .$ question_id );
164
- $ answer = @implode (', ' , $ answers );
165
- $ is_correct = $ this ->isMultiCorrect ($ answers , $ corrects ) ? 1 : 0 ;
166
- //debug($is_correct);
162
+ // 全ての解答と正解が一致するか確認
163
+ $ is_correct = $ this ->isMultiCorrect ($ answer , $ corrects ) ? 1 : 0 ;
164
+
165
+ // データベース格納用に解答をカンマ区切りの文字列に変更
166
+ $ answer = is_array ($ answer ) ? implode (', ' , $ answer ) : null ;
167
167
}
168
168
else
169
169
{
170
- $ answer = $ this ->getData ('answer_ ' .$ question_id );
171
170
$ is_correct = ($ answer == $ correct ) ? 1 : 0 ;
172
171
}
173
172
173
+ // 合計点(配点の合計)
174
+ $ full_score += $ score ;
175
+
176
+ // 得点(正解した問題の配点の合計)
174
177
if ($ is_correct == 1 )
175
178
$ my_score += $ score ;
176
179
177
180
// 問題の正誤
178
- $ details [$ i ] = [
181
+ $ details [] = [
179
182
'question_id ' => $ question_id , // 問題ID
180
183
'answer ' => $ answer , // 解答
181
184
'correct ' => $ correct , // 正解
182
185
'is_correct ' => $ is_correct , // 正誤
183
186
'score ' => $ score , // 配点
184
187
];
185
- $ i ++;
186
188
}
187
189
188
190
// 合格基準得点
0 commit comments