118 lines
4.5 KiB
PHP
118 lines
4.5 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 LmsquizQuestionController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
|
|
protected $_options;
|
|
protected $_corrects;
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'lms';
|
|
$this->_module = 'lmsquizquestion';
|
|
$this->_viewname = 'lmsquiz';
|
|
$this->_title = 'LMS Quiz Question';
|
|
$this->_base_url = '/lmsquizquestion';
|
|
}
|
|
|
|
public function list(Request $request)
|
|
{
|
|
$entity_id = $request->session()->get('entity_id');
|
|
if ($entity_id === 0) {
|
|
return redirect('/lmsquizquestions')->withError('Question not found!');
|
|
}
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module . '/get_all', ['entity_id' => $entity_id]);
|
|
// echo '<pre>'; print_r($response); exit;
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $response->data->items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_list_buttons()
|
|
{
|
|
return [['title' => 'Add New', 'link' => $this->_base_url . '/addnew'], ['title' => 'Back to Quizs', 'link' => '/quizs']];
|
|
}
|
|
|
|
protected function get_list_fields()
|
|
{
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete']],
|
|
//'media_thumb' => ['title' => 'Media Thumb', 'type' => 'image'],
|
|
'question' => ['title' => 'Question', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values)
|
|
{
|
|
$groups = $this->getlambda('get', 'ums', 'group', 'dropdown');
|
|
$groups_dd = [];
|
|
foreach ($groups->data->items as $group) {
|
|
$groups_dd[$group->id] = $group->name;
|
|
}
|
|
return [
|
|
'question' => ['title' => 'Question', 'type' => 'text', 'required' => true, 'fullwidth' => true],
|
|
'code' => ['title' => 'Code (small caps without spaces and special chars except "_")', 'type' => 'text', 'required' => true],
|
|
'type' => ['title' => 'Question Type', 'type' => 'select', 'required' => true, 'values' => ['text' => 'Text', 'number' => 'Number', 'date' => 'Date', 'email' => 'Email', 'url' => 'Url', 'dropdown' => 'Dropdown', 'checkbox' => 'Checkbox', 'radio' => 'Radio', 'radiometrix' => 'RadioMetrix', 'multitextbox' => 'Multi Text Boxes', 'contacts' => 'Contacts', 'file' => 'File Upload']],
|
|
'required' => ['title' => 'Is Required', 'type' => 'yesno', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']],
|
|
'options' => ['title' => 'Options', 'type' => 'mapping', 'fullwidth' => true],
|
|
];
|
|
}
|
|
|
|
protected function _beforesave($type, $request)
|
|
{
|
|
$data = $request->except('_token');
|
|
$data['entity_id'] = $request->session()->get('entity_id');
|
|
$options = [];
|
|
if (isset($data['option_value'])) {
|
|
foreach ($data['option_value'] as $k => $ov) {
|
|
$options[] = ['value' => $ov, 'display' => $data['option_name'][$k], 'cost' => $data['option_cost'][$k]];
|
|
}
|
|
$data['options'] = $options;
|
|
unset($data['option_value']);
|
|
unset($data['option_name']);
|
|
unset($data['option_cost']);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values)
|
|
{
|
|
return $values;
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, 'lmsquizquestions' . '/delete', ['id' => $id]);
|
|
// echo '<pre>';
|
|
// print_r($response);
|
|
// exit;
|
|
if ($response->statusCode == 200 && $response->status == "success") {
|
|
return redirect('lmsquiz/edit?id=' . $response->data->item->quiz_id)->withMessage('Successfully Marked Deleted !!!');
|
|
} else {
|
|
return redirect('lmsquiz/edit?id=' . $response->data->item->quiz_id)->withError('Some Error occured! ' . $response->body->message);
|
|
}
|
|
}
|
|
}
|