added seed for questions and options and passed test now show up under completed tests

This commit is contained in:
mwalbeck 2016-09-23 16:02:13 +02:00
parent 711dd87d32
commit 8afccdc7f5
7 changed files with 72 additions and 20 deletions

View file

@ -19,6 +19,11 @@ class Test extends Model
return $this->belongsTo(Company::class);
}
public function testdetails()
{
return $this->hasMany(Testdetail::class);
}
public function randomizeQuestions()

View file

@ -6,6 +6,7 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Group;
use App\Testdetail;
class User extends Authenticatable
{
@ -178,17 +179,28 @@ class User extends Authenticatable
{
$test_general = $this->getGeneralTests();
if ($this->group_id == 1) {
return $test_general;
if ($this->group_id > 1) {
$test_group = $this->group->getGroupTests();
$unsorted_tests = $test_group->merge($test_general);
} else {
$unsorted_tests = $test_general;
}
$test_group = $this->group->getGroupTests();
$available_tests = [];
$completed_tests = [];
if ($test_group == null) {
return $test_general;
foreach ($unsorted_tests as $test) {
$testdetail = $test->testdetails()->where("user_id", $this->id)->first();
if ($testdetail && $testdetail->passed) {
$completed_tests[] = $test;
} else {
$available_tests[] = $test;
}
}
return $test_group->merge($test_general);
$tests = [$available_tests, $completed_tests];
return $tests;
}
public function storeTestdetails($test, $has_failed)

View file

@ -48,6 +48,27 @@ class DatabaseSeeder extends Seeder
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
});
$tests = App\Test::all();
foreach ($tests as $test) {
$test->questions()->save(factory(App\Question::class)->make());
$test->questions()->save(factory(App\Question::class)->make());
$test->questions()->save(factory(App\Question::class)->make());
$test->questions()->save(factory(App\Question::class)->make());
$test->questions()->save(factory(App\Question::class)->make());
$test->questions()->save(factory(App\Question::class)->make());
}
$questions = App\Question::all();
foreach ($questions as $question) {
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make([
'option' => "This is the correct answer",
'correct_answer' => 1,
]));
}
}
}

View file

@ -9,20 +9,20 @@
<div class="panel-body">
<table class="table">
<tr>
<th>#</th>
<th>Test</th>
<th>Nr. of Questions</th>
<th></th>
</tr>
@foreach ($tests as $test)
<tr>
<td>1</td>
<td>{{ $test->title }}</td>
<td>
<form method="get" class="pull-right">
<button class="btn btn-xs btn-default pull-left" formaction="/test/{{ $test->id }}">Start</button>
</form>
</td>
</tr>
@foreach ($tests[0] as $test)
<tr>
<td>{{ $test->title }}</td>
<td>{{ $test->question_count }}</td>
<td>
<form method="get" class="pull-right">
<button class="btn btn-xs btn-default pull-left" formaction="/test/{{ $test->id }}">Start</button>
</form>
</td>
</tr>
@endforeach
</table>
</div>
@ -30,6 +30,20 @@
<div class="panel panel-default">
<div class="panel-heading">Completed Tests</div>
<div class="panel-body">
<table class="table">
<tr>
<th>Test</th>
<th>Nr. of Questions</th>
<th>Date Completed</th>
</tr>
@foreach ($tests[1] as $test)
<tr>
<td>{{ $test->title }}</td>
<td>{{ $test->question_count }}</td>
<td>Date</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>

View file

@ -15,7 +15,7 @@
</div>
<div class="form-group">
<label>Question</label>
<input type="text" class="form-control" name="question" value="{{ $question->question }}">
<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
</div>
<div class="form-group">

View file

@ -13,7 +13,7 @@
</div>
<div class="form-group">
<label>Question</label>
<input type="text" class="form-control" name="question">
<textarea class="form-control" name="question" rows="5"></textarea>
<input type="checkbox" name="multiple_answers_question" value="1"> Multiple Answers Required
</div>
<div class="form-group">

View file

@ -40,7 +40,7 @@
@foreach ($questions as $question)
<tr>
<td>1</td>
<td>{{ $question->question }}</td>
<td>{{ $question->title }}</td>
<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>