public function correctAnswers(Quiz $quiz)
 {
     $questions = $quiz->questions()->get();
     $correctanswers = [];
     foreach ($questions as $question) {
         $correctanswers[] = $question->correctAnswers()->first()->option()->first();
     }
     return $correctanswers;
 }
 public function actionQuiz($id)
 {
     $quiz = new Quiz();
     $quiz->id = $id;
     if (Yii::$app->request->post()) {
         return $this->render('single_quiz', ['quizQuestion' => $quiz->getQuiz($id), 'result' => $quiz->getQuizResult(array_sum(Yii::$app->request->post('answers')))]);
     }
     return $this->render('single_quiz', ['quizQuestion' => $quiz->getQuiz($id)]);
 }
 public function participants(Quiz $quiz)
 {
     $participants = $quiz->participants()->get();
     foreach ($participants as $participant) {
         $participant['name'] = $participant->user()->first()->name;
         $participant['score'] = $participant->scores()->whereQuizId($quiz->id)->first()->score;
         $participant['time'] = $participant->scores()->whereQuizId($quiz->id)->first()->time;
     }
     return $participants;
 }
 public function setStatus(Request $request, $id)
 {
     $quiz = Quiz::findOrFail($id);
     $quiz->lead_status = 1;
     $quiz->save();
     return redirect()->back()->withInput();
 }
Example #5
0
 public function detachFrom(Request $request)
 {
     $this->validate($request, ['classroom_id' => 'required', 'quiz_id' => 'required'], ['required' => 'Kolom :attribute diperlukan']);
     $quiz = Quiz::findOrFail($request->quiz_id);
     $quiz->classrooms()->detach($request->classroom_id);
     \Flash::success('Quiz berhasil batalkan.');
     return redirect()->back();
 }
 public function destroy($quizId, $questionId)
 {
     $quiz = Quiz::with('multiplechoices')->findOrFail($quizId);
     $question = $quiz->multiplechoices()->where('id', $questionId)->first();
     $question->delete();
     \Flash::success('Pertanyaan berhasil dihapus.');
     return redirect()->back();
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $quiz = Quiz::find($id);
     if (empty($quiz)) {
         Flash::error('Quiz not found');
         return redirect(route('admin.quizzes.index'));
     }
     return view('admin.quizzes.show')->with('quiz', $quiz);
 }
 public function run()
 {
     DB::table('quizzes')->delete();
     Quiz::create(['title' => 'Quiz Contest 2013', 'date_time' => new DateTime('2013-03-15 11:00 GMT'), 'duration' => 50, 'description' => 'UU ICT CLUB Foundation Festival Quiz Contest 2013']);
     Quiz::create(['title' => 'ICT Quiz 2015', 'date_time' => new DateTime('2015-11-01 13:00 GMT'), 'duration' => 120, 'description' => 'First Test Quiz']);
     Quiz::create(['title' => 'Science Quiz 2015', 'date_time' => new DateTime('2015-11-05 14:00 GMT'), 'duration' => 60, 'description' => 'Second Test Quiz']);
     Quiz::create(['title' => 'Technology Quiz 2015', 'date_time' => new DateTime('2015-11-11 11:00 GMT'), 'duration' => 180, 'description' => 'Third Test Quiz']);
     $participants = array(["quiz_id" => 2, "student_id" => 1], ["quiz_id" => 2, "student_id" => 2], ["quiz_id" => 3, "student_id" => 3], ["quiz_id" => 3, "student_id" => 1], ["quiz_id" => 4, "student_id" => 2], ["quiz_id" => 4, "student_id" => 3]);
     DB::table('quiz_student')->insert($participants);
 }
Example #9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Quiz::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'description' => $this->description, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #10
0
 public function submitQuiz(Request $request)
 {
     $this->validate($request, ['classroom_id' => 'required|exists:classrooms,id', 'quiz_id' => 'required|exists:quizzes,id', 'answers' => 'required'], ['required' => 'Kolom :attribute diperlukan!', 'exists' => 'Kolom :attribute tidak ditemukan!']);
     $quiz = Quiz::findOrFail($request->quiz_id);
     $total = $quiz->multiplechoices->count();
     $realAnswer = $quiz->multiplechoices->pluck('correct_answer', 'id')->toArray();
     $userAnswer = $request->answers;
     ksort($realAnswer);
     ksort($userAnswer);
     $unanswered = count(array_diff_key($realAnswer, $userAnswer));
     $correct = count(array_intersect_assoc($realAnswer, $userAnswer));
     $wrong = count(array_diff_assoc($realAnswer, $userAnswer));
     $data = ['answer' => json_encode($request->answers), 'unanswered' => $unanswered, 'correct' => $correct, 'wrong' => $total - $correct, 'score' => $correct / $total * 100];
     if ($request->status) {
         $data['status'] = 'done';
     }
     $quiz->students()->sync([Auth::user()->id => $data], false);
     return response()->json(['redirect' => route('classrooms.quizzes', $request->classroom_id), 'unanswered' => $unanswered]);
 }
Example #11
0
            </div>
        </header>
        <div class="body">
            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', ['attribute' => 'skill_id', 'content' => function ($data) {
    $skillName = Skill::findOne($data->skill_id)->title;
    return $skillName ? $skillName : '<span style="color:red">Không tìm danh mục</span>';
}, 'format' => 'raw'], ['attribute' => 'question', 'content' => function ($data) {
    return Html::a($data->question, ['view', 'id' => $data->id]);
}], 'answer', ['attribute' => 'difficulty', 'content' => function ($data) {
    switch ($data->difficulty) {
        case '0':
            return '<span class="btn-success label">Dễ</span>';
            break;
        case '1':
            return '<span class="btn-warning label">Trung bình</span>';
            break;
        default:
            return '<span class="btn-danger label">Khó</span>';
            break;
    }
}, 'format' => 'raw'], ['attribute' => 'state', 'content' => function ($data) {
    return Quiz::findOne($data['id'])->state == 1 ? '<span class="label-success label label-default">Kích hoạt</span>' : '<span class="label-default label">Không kích hoạt</span>';
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'header' => 'Thao tác', 'buttons' => ['delete' => function ($url, $model) {
    return '<a class="btn btn-danger" aria-label="Delete" data-confirm="Bạn có chắc muốn xóa danh mục này?" data-method="post" data-pjax="0" href="' . $url . '"><i class="icon icon-trash icon-white"></i></a>';
}]]]]);
?>
        </div>
    </div>
</div>
Example #12
0
echo Html::encode($this->title);
?>
</h4>
            <div class="toolbar">
                <p>
                    <?php 
echo Html::a('Tạo kỹ năng', ['create'], ['class' => 'btn btn-success']);
?>
                </p>
            </div>
        </header>
        <div class="body">
            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', ['attribute' => 'title', 'content' => function ($data) {
    return Html::a($data->title, ['view', 'id' => $data->id]);
}], ['attribute' => 'cat_id', 'content' => function ($data) {
    $categoryName = Category::findOne($data->cat_id)->title;
    return $categoryName ? $categoryName : '<span style="color:red">Không tìm danh mục</span>';
}], ['attribute' => 'Số câu quiz', 'content' => function ($data) {
    $quizs = Quiz::findAll(['skill_id' => $data->id]);
    return '<a href="' . Url::toRoute(['quiz/index', 'skill_id' => $data->id]) . '">' . count($quizs) . '</a>';
}, 'format' => 'raw'], ['attribute' => 'state', 'content' => function ($data) {
    return Skill::findOne($data['id'])->state == 1 ? '<span class="label-success label label-default">Kích hoạt</span>' : '<span class="label-default label">Không kích hoạt</span>';
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'header' => 'Thao tác', 'buttons' => ['delete' => function ($url, $model) {
    return '<a class="btn btn-danger" aria-label="Delete" data-confirm="Bạn có chắc muốn xóa danh mục này?" data-method="post" data-pjax="0" href="' . $url . '"><i class="icon icon-trash icon-white"></i></a>';
}]]]]);
?>
        </div>
    </div>
</div>
Example #13
0
 /**
  * Finds the Quiz model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Quiz the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Quiz::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Remove the specified Quiz from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     /** @var Quiz $quiz */
     $quiz = Quiz::find($id);
     if (empty($quiz)) {
         Flash::error('Quiz not found');
         return redirect(route('admin.quizzes.index'));
     }
     $quiz->delete();
     Flash::message('Quiz deleted successfully.');
     return redirect(route('admin.quizzes.index'));
 }