143 lines
5.8 KiB
PHP
143 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Kreait\Firebase\Factory;
|
|
use Response;
|
|
use App\Http\Requests\LambdaRequest;
|
|
|
|
class LmsquizController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
|
|
protected $_options;
|
|
protected $_corrects;
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'lms';
|
|
$this->_module = 'lmsquiz';
|
|
$this->_viewname = 'lmsquiz';
|
|
$this->_title = 'LMS Quiz';
|
|
$this->_base_url = '/lmsquiz';
|
|
}
|
|
|
|
protected function get_list_fields()
|
|
{
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete', 'lmsquizsubmission' => ['icon' => 'form-select', 'querystring' => 'quiz_id={ID}']]],
|
|
'title' => ['title' => 'Name', 'type' => 'text'],
|
|
'show_score' => ['title' => 'Show Score', 'type' => 'text'],
|
|
'show_answers' => ['title' => 'Show Answers', 'type' => 'text'],
|
|
'number_attempts' => ['title' => 'No. of Attempts', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select']
|
|
];
|
|
}
|
|
|
|
|
|
protected function get_form_fields($type, $values)
|
|
{
|
|
return [
|
|
'title' => ['title' => 'Name', 'type' => 'text', 'required' => true, 'fullwidth' => true],
|
|
'show_score' => ['title' => 'Show Score', 'type' => 'select', 'required' => true, 'values' => ['Yes' => 'Yes', 'No' => 'No']],
|
|
'show_answers' => ['title' => 'Show Answers', 'type' => 'select', 'required' => true, 'values' => ['Yes' => 'Yes', 'No' => 'No']],
|
|
'limit_attempts' => ['title' => 'Limit Attempts', 'type' => 'select', 'required' => true, 'values' => ['Yes' => 'Yes', 'No' => 'No']],
|
|
'number_attempts' => ['title' => 'No. of attempts', 'type' => 'number', 'required' => true],
|
|
'passing_percent' => ['title' => 'Passing Percentage', 'type' => 'number', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']]
|
|
];
|
|
}
|
|
|
|
public function form($type, $id = null)
|
|
{
|
|
$values = [];
|
|
$questions = [];
|
|
if ($type == 'edit') {
|
|
$this->_request->session()->put('current_quiz', $id);
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module . '/get_one', ['id' => $id]);
|
|
$values = $response->data->item;
|
|
|
|
$questions = LambdaRequest::signedrequest('get', $this->_service, 'lmsquizquestions/get_all', ['quiz_id' => $id]);
|
|
$questions = $questions->data->items;
|
|
}
|
|
$data = $this->_beforeform($type, $values);
|
|
$fields = $this->get_form_fields($type, $values);
|
|
|
|
return $this->view('form')->with([
|
|
'title' => $this->_title,
|
|
'mode' => $type,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'item' => $values,
|
|
'questions' => $questions
|
|
]);
|
|
}
|
|
|
|
|
|
public function addquestion($request) {
|
|
$post = $request->input();
|
|
$quiz_id = $request->session()->get('current_quiz');
|
|
return $this->view('question-form')->with('quiz_id', $quiz_id)->with('edit', false);
|
|
}
|
|
public function editquestion($request) {
|
|
$post = $request->input();
|
|
$quiz_id = $request->session()->get('current_quiz');
|
|
$question = LambdaRequest::signedrequest('get', $this->_service, 'lmsquizquestions/get_one', ['id' => $post['id']]);
|
|
$question = $question->data->item;
|
|
return $this->view('question-form')->with('quiz_id', $quiz_id)->with('edit', true)->with('question', $question);
|
|
}
|
|
|
|
public function postaddquestion($request) {
|
|
$post = $request->input();
|
|
$quiz_id = $request->session()->get('current_quiz');
|
|
$options = [];
|
|
foreach ($post['options'] as $index => $value) {
|
|
$options[] = ['option' => $value, 'is_correct' => ($index == $post['correct_ans']) ];
|
|
}
|
|
LambdaRequest::signedrequest('post', $this->_service, 'lmsquizquestions/create', ['quiz_id' => $quiz_id, 'question' => $post['question'], 'options' => $options]);
|
|
$message = 'Question added successfully!';
|
|
return redirect('/lmsquiz/edit?id='.$quiz_id)->with('message', $message);
|
|
}
|
|
|
|
public function posteditquestion($request) {
|
|
$post = $request->input();
|
|
//echo '<pre>'; print_r($post); exit;
|
|
$quiz_id = $request->session()->get('current_quiz');
|
|
$options = [];
|
|
foreach ($post['options'] as $index => $value) {
|
|
$options[] = ['option' => $value, 'is_correct' => ($index == $post['correct_ans']) ];
|
|
}
|
|
LambdaRequest::signedrequest('post', $this->_service, 'lmsquizquestions/update', ['id' => $post['id'], 'quiz_id' => $quiz_id, 'question' => $post['question'], 'options' => $options]);
|
|
$message = 'Question added successfully!';
|
|
return redirect('/lmsquiz/edit?id='.$quiz_id)->with('message', $message);
|
|
}
|
|
|
|
|
|
public function questions(Request $request) {
|
|
$entity_id = $request->input('id', 0);
|
|
if($entity_id === 0) {
|
|
return redirect('/quizs')->withError('Quiz not found!');
|
|
} else {
|
|
$request->session()->put('entity_id', $entity_id);
|
|
return redirect('/quizquestions');
|
|
}
|
|
}
|
|
|
|
public function lmsquizsubmission(Request $request) {
|
|
$quiz_id = $request->input('quiz_id', 0);
|
|
if($quiz_id === 0) {
|
|
return redirect('/lmsquizs')->withError('Quiz not found!');
|
|
} else {
|
|
$request->session()->put('quiz_id', $quiz_id);
|
|
return redirect('/lmsquizsubmissions');
|
|
}
|
|
}
|
|
} |