Added validation for options, change a bit of layout and added some html5 validation
This commit is contained in:
parent
71c79d3b2a
commit
aa6e5653e1
19 changed files with 78 additions and 136 deletions
app
resources/views
|
@ -206,14 +206,10 @@ class TestController extends Controller
|
|||
{
|
||||
$question = new Question;
|
||||
$question->addQuestion($test, $request);
|
||||
$option1 = new Option;
|
||||
$option1->addOption($question, $request, 1);
|
||||
$option2 = new Option;
|
||||
$option2->addOption($question, $request, 2);
|
||||
$option3 = new Option;
|
||||
$option3->addOption($question, $request, 3);
|
||||
$option4 = new Option;
|
||||
$option4->addOption($question, $request, 4);
|
||||
foreach ($request["options"] as $optionData) {
|
||||
$option = new Option;
|
||||
$option->addOption($question, $optionData);
|
||||
}
|
||||
return redirect("/admin/tests/$test->id");
|
||||
}
|
||||
|
||||
|
@ -222,10 +218,10 @@ class TestController extends Controller
|
|||
$test = $question->test;
|
||||
$question->updateQuestion($request);
|
||||
$options = $question->options;
|
||||
$options[0]->updateOption($request, 1);
|
||||
$options[1]->updateOption($request, 2);
|
||||
$options[2]->updateOption($request, 3);
|
||||
$options[3]->updateOption($request, 4);
|
||||
$optionsData = $request["options"];
|
||||
foreach ($options as $key => $option) {
|
||||
$option->updateOption($optionsData[$key+1]);
|
||||
}
|
||||
return redirect("/admin/tests/$test->id");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class StoreOptions extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (Auth::user()->isAdministrator()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Auth::user()->isModerator()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
"question_id" => "required|integer|exists:questions,id|min:1",
|
||||
"option" => "required|string|alpha_dash|max:255",
|
||||
"correct_answer" => "boolean"
|
||||
];
|
||||
}
|
||||
}
|
|
@ -37,7 +37,9 @@ class StoreQuestion extends FormRequest
|
|||
"question" => "required|string|alpha_dash",
|
||||
"question_type" => "string|in:radio,checkbox|max:255",
|
||||
"correct_answers" => "integer|min:1",
|
||||
"multiple_anwsers_question" => "boolean"
|
||||
"multiple_anwsers_question" => "boolean",
|
||||
"options.*.option" => "required|string|alpha_dash|max:255",
|
||||
"options.*.correct_answer" => "boolean"
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,24 +17,24 @@ class Option extends Model
|
|||
return true;
|
||||
}
|
||||
|
||||
public function addOption($question, $request, $nr)
|
||||
public function addOption($question, $optionData)
|
||||
{
|
||||
$this->option = $request->get("option{$nr}");
|
||||
if ($request->get("correct_answer{$nr}") == null) {
|
||||
$this->correct_answer = 0;
|
||||
$this->option = $optionData["option"];
|
||||
if (array_key_exists("correct_answer", $optionData)) {
|
||||
$this->correct_answer = 1;
|
||||
} else {
|
||||
$this->correct_answer = $request->get("correct_answer{$nr}");
|
||||
$this->correct_answer = 0;
|
||||
}
|
||||
$question->options()->save($this);
|
||||
}
|
||||
|
||||
public function updateOption($request, $nr)
|
||||
public function updateOption($optionData)
|
||||
{
|
||||
$this->option = $request->get("option{$nr}");
|
||||
if ($request->get("correct_answer{$nr}") == null) {
|
||||
$this->correct_answer = 0;
|
||||
$this->option = $optionData["option"];
|
||||
if (array_key_exists("correct_answer", $optionData)) {
|
||||
$this->correct_answer = 1;
|
||||
} else {
|
||||
$this->correct_answer = $request->get("correct_answer{$nr}");
|
||||
$this->correct_answer = 0;
|
||||
}
|
||||
$this->update();
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class Question extends Model
|
|||
$test->questions()->save($this);
|
||||
}
|
||||
|
||||
public function updateQuestion(Request $request)
|
||||
public function updateQuestion($request)
|
||||
{
|
||||
$this->title = $request->title;
|
||||
$this->question = $request->question;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
@endif
|
||||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
<button class="btn btn-xs btn-default pull-left" formaction="/test/{{ $test->id }}">Start</button>
|
||||
<button class="btn btn-xs btn-primary pull-left" formaction="/test/{{ $test->id }}">Start</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -52,9 +52,9 @@
|
|||
<button type="submit" class="btn btn-default" formaction="/test/{{ $question->test_id }}/retry">Retry</button>
|
||||
<button type="submit" class="btn btn-default" formaction="/test/{{ $question->test_id }}/end">End</button>
|
||||
@elseif (session("last_question") == true)
|
||||
<button type="submit" class="btn btn-default" formaction="/test/{{ $question->test_id }}/end">End</button>
|
||||
<button type="submit" class="btn btn-success" formaction="/test/{{ $question->test_id }}/end">End</button>
|
||||
@else
|
||||
<button type="submit" class="btn btn-default" formaction="/test/question">Next</button>
|
||||
<button type="submit" class="btn btn-primary" formaction="/test/question">Next</button>
|
||||
@endif
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
<button type="submit" class="btn btn-default">Yes</button>
|
||||
<button type="submit" class="btn btn-danger">Yes</button>
|
||||
</form>
|
||||
<form method="GET" action="/{{ Auth::user()->getAdminPath() }}/tests">
|
||||
<button type="submit" class="btn btn-default">No</button>
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
{{ method_field('PATCH') }}
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="form-control" name="title" value="{{ $test->title }}">
|
||||
<input type="text" class="form-control" name="title" value="{{ $test->title }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Number of Questions</label>
|
||||
<input type="text" class="form-control" name="question_count" value="{{ $test->question_count }}">
|
||||
<input type="number" class="form-control" name="question_count" value="{{ $test->question_count }}" min="1" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Number of Wrong Questions Allowed</label>
|
||||
<input type="text" class="form-control" name="question_count_to_fail" value="{{ $test->question_count_to_fail }}">
|
||||
<input type="number" class="form-control" name="question_count_to_fail" value="{{ $test->question_count_to_fail }}" min="0">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Time Limit</label>
|
||||
|
@ -53,7 +53,7 @@
|
|||
</select>
|
||||
</div>
|
||||
@endif
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>s
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="form-control" name="title">
|
||||
<input type="text" class="form-control" name="title" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Number of Questions</label>
|
||||
<input type="text" class="form-control" name="question_count">
|
||||
<input type="number" class="form-control" name="question_count" min="1" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Number of Wrong Questions Allowed</label>
|
||||
<input type="text" class="form-control" name="question_count_to_fail">
|
||||
<input type="number" class="form-control" name="question_count_to_fail" min="0">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Time Limit</label>
|
||||
|
@ -50,7 +50,7 @@
|
|||
</select>
|
||||
</div>
|
||||
@endif
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
<button type="submit" class="btn btn-default">Yes</button>
|
||||
<button type="submit" class="btn btn-danger">Yes</button>
|
||||
</form>
|
||||
<form method="GET" action="/{{ Auth::user()->getAdminPath() }}/tests">
|
||||
<button type="submit" class="btn btn-default">No</button>
|
||||
|
|
|
@ -20,34 +20,26 @@
|
|||
{{ method_field('PATCH') }}
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="form-control" name="title" value="{{ $question->title }}">
|
||||
<input type="text" class="form-control" name="title" value="{{ $question->title }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Question</label>
|
||||
<textarea class="form-control" name="question" rows="5">{{ $question->question }}</textarea>
|
||||
<input type="checkbox" name="multiple_answers_question" value="1" @if ($question->correct_answer == 1) checked @endif> Multiple Answers Required
|
||||
<textarea class="form-control" name="question" rows="5" required>{{ $question->question }}</textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 1</label>
|
||||
<input type="text" class="form-control" name="option1" value="{{ $options[0]->option }}">
|
||||
<input type="checkbox" name="correct_answer1" value="1" @if ($options[0]->correct_answer == 1) checked @endif> Correct Answer
|
||||
<label>Multiple Answers Required</label>
|
||||
<select class="form-control" name="multiple_answers_question">
|
||||
<option value="0" @if ($question->multiple_answers_question == 0) selected @endif>No</option>
|
||||
<option value="1" @if ($question->multiple_answers_question == 1) selected @endif>Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 2</label>
|
||||
<input type="text" class="form-control" name="option2" value="{{ $options[1]->option }}">
|
||||
<input type="checkbox" name="correct_answer2" value="1" @if ($options[1]->correct_answer == 1) checked @endif> Correct Answer
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 3</label>
|
||||
<input type="text" class="form-control" name="option3" value="{{ $options[2]->option }}">
|
||||
<input type="checkbox" name="correct_answer3" value="1" @if ($options[2]->correct_answer == 1) checked @endif> Correct Answer
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 4</label>
|
||||
<input type="text" class="form-control" name="option4" value="{{ $options[3]->option }}">
|
||||
<input type="checkbox" name="correct_answer4" value="1" @if ($options[3]->correct_answer == 1) checked @endif> Correct Answer
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
@for ($i = 1; $i < 5; $i++)
|
||||
<div class="form-group">
|
||||
<label>Option {{ $i }}</label><input class="pull-right" type="checkbox" name="options[{{ $i }}][correct_answer]" value="1" @if ($options[$i-1]->correct_answer == 1) checked @endif><span class="pull-right" style="padding:2px;">Correct Answer</span>
|
||||
<input type="text" class="form-control" name="options[{{ $i }}][option]" value="{{ $options[$i-1]->option }}" required>
|
||||
</div>
|
||||
@endfor
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -18,34 +18,26 @@
|
|||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="form-control" name="title">
|
||||
<input type="text" class="form-control" name="title" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Question</label>
|
||||
<textarea class="form-control" name="question" rows="5"></textarea>
|
||||
<input type="checkbox" name="multiple_answers_question" value="1"> Multiple Answers Required
|
||||
<textarea class="form-control" name="question" rows="5" required></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 1</label>
|
||||
<input type="text" class="form-control" name="option1">
|
||||
<input type="checkbox" name="correct_answer1" value="1"> Correct Answer
|
||||
<label>Multiple Answers Required</label>
|
||||
<select class="form-control" name="multiple_answers_question">
|
||||
<option value="0">No</option>
|
||||
<option value="1">Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 2</label>
|
||||
<input type="text" class="form-control" name="option2">
|
||||
<input type="checkbox" name="correct_answer2" value="1"> Correct Answer
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 3</label>
|
||||
<input type="text" class="form-control" name="option3">
|
||||
<input type="checkbox" name="correct_answer3" value="1"> Correct Answer
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Option 4</label>
|
||||
<input type="text" class="form-control" name="option4">
|
||||
<input type="checkbox" name="correct_answer4" value="1"> Correct Answer
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
@for ($i = 1; $i < 5; $i++)
|
||||
<div class="form-group">
|
||||
<label>Option {{ $i }}</label><input class="pull-right" type="checkbox" name="options[{{ $i }}][correct_answer]" value="1"><span class="pull-right" style="padding:2px;">Correct Answer</span>
|
||||
<input type="text" class="form-control" name="options[{{ $i }}][option]" required>
|
||||
</div>
|
||||
@endfor
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<div class="panel-heading">Test</div>
|
||||
<div class="panel-body">
|
||||
<form method="get">
|
||||
<button class="btn btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">Delete</button>
|
||||
<button class="btn btn-danger pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">Delete</button>
|
||||
<button class="btn btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/edit">Edit</button>
|
||||
</form>
|
||||
<strong>Title:</strong><br>
|
||||
|
@ -33,7 +33,7 @@
|
|||
<th>Question</th>
|
||||
<th>
|
||||
<form method="get">
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/question">Add Question</button>
|
||||
<button class="btn btn-sm btn-primary pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/question">Add Question</button>
|
||||
</form>
|
||||
</th>
|
||||
</tr>
|
||||
|
@ -44,7 +44,7 @@
|
|||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}/edit">Edit</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}/delete">Delete</button>
|
||||
<button class="btn btn-sm btn-danger pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}/delete">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<th>Test</th>
|
||||
<th>
|
||||
<form method="get">
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/new">Add Test</button>
|
||||
<button class="btn btn-sm btn-primary pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/new">Add Test</button>
|
||||
</form>
|
||||
</th>
|
||||
</tr>
|
||||
|
@ -24,8 +24,8 @@
|
|||
@if (Auth::user()->access_level == 2 AND !$test->group_id == 0 OR Auth::user()->access_level == 3)
|
||||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}">Edit</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">Delete</button>
|
||||
<button class="btn btn-sm btn-default pull-left" style="margin-right:2px;"formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}">Edit</button>
|
||||
<button class="btn btn-sm btn-danger pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
@endif
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/users/{{ $user->id }}">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
<button type="submit" class="btn btn-default">Yes</button>
|
||||
<button type="submit" class="btn btn-danger">Yes</button>
|
||||
</form>
|
||||
<form method="GET" action="/{{ Auth::user()->getAdminPath() }}/users">
|
||||
<button type="submit" class="btn btn-default">No</button>
|
||||
|
|
|
@ -18,15 +18,15 @@
|
|||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" name="name">
|
||||
<input type="text" class="form-control" name="name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Email</label>
|
||||
<input type="email" class="form-control" name="email">
|
||||
<input type="email" class="form-control" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input type="password" class="form-control" name="password">
|
||||
<input type="password" class="form-control" name="password" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Enabled</label>
|
||||
|
@ -45,7 +45,7 @@
|
|||
</select>
|
||||
</div>
|
||||
@endif
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<label>Repeat New Password</label>
|
||||
<input type="password" class="form-control" name="password2_new">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -45,7 +45,7 @@
|
|||
<label>Email</label>
|
||||
<input type="text" class="form-control" name="email" value="{{ $user->email }}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<th>User</th>
|
||||
<th>
|
||||
<form method="get">
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/users/new">Add User</button>
|
||||
<button class="btn btn-sm btn-primary pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/users/new">Add User</button>
|
||||
</form>
|
||||
</th>
|
||||
</tr>
|
||||
|
@ -23,7 +23,7 @@
|
|||
<td>{{ $user->name }} ({{ $user->email }})</td>
|
||||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/users/{{ $user->id }}/delete">Delete</button>
|
||||
<button class="btn btn-sm btn-danger pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/users/{{ $user->id }}/delete">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Reference in a new issue