added some seeds and change some small details
This commit is contained in:
parent
fd715bda05
commit
32d5e034e1
7 changed files with 107 additions and 20 deletions
app
database
factories
migrations
2016_08_30_201515_create_tests_table.php2016_08_31_115508_create_questions_table.php2016_08_31_144334_create_options_table.php
seeds
resources/views/layouts
22
app/User.php
22
app/User.php
|
@ -61,18 +61,18 @@ class User extends Authenticatable
|
|||
|
||||
public function isModerator()
|
||||
{
|
||||
if (!$this->access_level == 2) {
|
||||
return false;
|
||||
if ($this->access_level == 2) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isAdministrator()
|
||||
{
|
||||
if (!$this->access_level == 3) {
|
||||
return false;
|
||||
if ($this->access_level == 3) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,7 +85,7 @@ class User extends Authenticatable
|
|||
$this->name = $request["name"];
|
||||
$this->email = $request["email"];
|
||||
$this->passwordHash($request["password"]);
|
||||
if (Auth::user()->access_level == 2) {
|
||||
if (Auth::user()->isModerator()) {
|
||||
$this->save();
|
||||
return true;
|
||||
}
|
||||
|
@ -116,12 +116,12 @@ class User extends Authenticatable
|
|||
return true;
|
||||
}
|
||||
|
||||
if (Auth::user()->group_id == $this->group_id && Auth::user()->access_level >= 2) {
|
||||
if (Auth::user()->group_id == $this->group_id && Auth::user()->isModerator) {
|
||||
$this->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Auth::user()->access_level >= 3) {
|
||||
if (Auth::user()->isAdministrator()) {
|
||||
$this->delete();
|
||||
return true;
|
||||
}
|
||||
|
@ -178,14 +178,14 @@ class User extends Authenticatable
|
|||
|
||||
public function getGeneralTests()
|
||||
{
|
||||
return Test::where("group_id", 0)->get();
|
||||
return Test::where("group_id", 1)->get();
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
$test_general = $this->getGeneralTests();
|
||||
|
||||
if ($this->group_id == 0) {
|
||||
if ($this->group_id == 1) {
|
||||
return $test_general;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,40 @@ $factory->define(App\User::class, function (Faker\Generator $faker) {
|
|||
'name' => $faker->name,
|
||||
'email' => $faker->safeEmail,
|
||||
'password' => $password ?: $password = bcrypt('secret'),
|
||||
'remember_token' => str_random(10),
|
||||
'access_level' => 1,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Group::class, function (Faker\Generator $faker) {
|
||||
|
||||
return [
|
||||
'name' => $faker->company
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Test::class, function (Faker\Generator $faker) {
|
||||
|
||||
return [
|
||||
'title' => $faker->sentence(3, true),
|
||||
'question_count' => 6,
|
||||
'question_count_to_fail' => 2
|
||||
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Question::class, function (Faker\Generator $faker) {
|
||||
|
||||
return [
|
||||
'title' => $faker->sentence(6, true),
|
||||
'question' => $faker->paragraph(3, true),
|
||||
'question_type' => "radio"
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Option::class, function (Faker\Generator $faker) {
|
||||
|
||||
return [
|
||||
'option' => $faker->sentence(4, true),
|
||||
'correct_answer' => 0
|
||||
];
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ class CreateTestsTable extends Migration
|
|||
Schema::create('tests', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('title');
|
||||
$table->integer('group_id')->unsigned()->index()->nullable()->default(0);
|
||||
$table->integer('group_id')->unsigned()->index()->nullable()->default(1);
|
||||
$table->integer('question_count')->unsigned();
|
||||
$table->integer('question_count_to_fail')->unsigned()->nullable();
|
||||
$table->timestamps();
|
||||
|
@ -30,6 +30,6 @@ class CreateTestsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('table');
|
||||
Schema::drop('tests');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class CreateQuestionsTable extends Migration
|
|||
$table->integer('test_id')->unsigned()->index();
|
||||
$table->string('title');
|
||||
$table->text('question');
|
||||
$table->integer('answer_id')->unsigned()->index();
|
||||
$table->string('question_type');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ class CreateOptionsTable extends Migration
|
|||
$table->increments('id');
|
||||
$table->integer('question_id')->unsigned()->index();
|
||||
$table->string('option');
|
||||
$table->integer('correct_answer');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,6 +11,56 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
// $this->call(UsersTableSeeder::class);
|
||||
factory(App\Group::class)->create([
|
||||
'name' => 'WalbeckDK'
|
||||
])->each(function($g) {
|
||||
$g->users()->save(factory(App\User::class)->create([
|
||||
'name' => 'Magnus Walbeck',
|
||||
'email' => 'admin@walbeck.dk',
|
||||
'password' => bcrypt('magnus'),
|
||||
'access_level' => 3,
|
||||
]));
|
||||
$g->users()->save(factory(App\User::class)->create([
|
||||
'name' => 'Mod',
|
||||
'email' => 'mod@walbeck.dk',
|
||||
'password' => bcrypt('magnus'),
|
||||
'access_level' => 2,
|
||||
]));
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
});
|
||||
|
||||
factory(App\Group::class, 5)->create()->each(function($g) {
|
||||
$g->users()->save(factory(App\User::class)->make());
|
||||
$g->users()->save(factory(App\User::class)->make());
|
||||
$g->users()->save(factory(App\User::class)->make());
|
||||
$g->users()->save(factory(App\User::class)->make());
|
||||
$g->users()->save(factory(App\User::class)->make());
|
||||
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
$g->tests()->save(factory(App\Test::class)->make());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
$t->questions()->save(factory(App\Question::class, 6)->create()->each(function($q) {
|
||||
DB::table('options')->insert([
|
||||
'question_id' => $q->id,
|
||||
'option' => "true",
|
||||
'correct_answer' => 1,
|
||||
]);
|
||||
DB::table('options')->insert([
|
||||
'question_id' => $q->id,
|
||||
'option' => "false",
|
||||
'correct_answer' => 0,
|
||||
]);
|
||||
}));
|
||||
*/
|
|
@ -45,10 +45,12 @@
|
|||
<li><a href="/home">Tests</a></li>
|
||||
<li><a href="/stats">Statistik</a></li>
|
||||
<li><a href="/settings">Indstillinger</a></li>
|
||||
@if (Auth::user()->access_level == 2)
|
||||
<li><a href="/mod">Moderator</a></li>
|
||||
@elseif (Auth::user()->access_level == 3)
|
||||
<li><a href="/admin">Admin</a></li>
|
||||
@if (Auth::check())
|
||||
@if (Auth::user()->isModerator())
|
||||
<li><a href="/mod">Moderator</a></li>
|
||||
@elseif (Auth::user()->isAdministrator())
|
||||
<li><a href="/admin">Admin</a></li>
|
||||
@endif
|
||||
@endif
|
||||
</ul>
|
||||
|
||||
|
|
Reference in a new issue