Commit 6879c8f8 authored by Antoine Le Gonidec's avatar Antoine Le Gonidec

Script — List archives in groups

Fix #13
parent e41fd802
......@@ -24,7 +24,7 @@ class Script extends Model {
*/
public function archives() {
return $this->BelongsToMany(Archive::class)
->withPivot('required');
->withPivot([ 'required', 'group' ]);
}
/**
......@@ -37,7 +37,9 @@ class Script extends Model {
$archives->each(function ($archive) {
$archive->makeHidden([ 'archive', 'scripts' ]);
$archive->required = (bool) $archive->pivot->required;
$archive->group = (int) $archive->pivot->group;
});
$archives = $archives->groupBy('group');
return $archives;
}
......
......@@ -24,6 +24,8 @@ class AddRelationshipBetweenArchivesAndScripts extends Migration {
->onDelete('cascade');
$table->boolean('required')
->default(true);
$table->unsignedInteger('group')
->default(0);
});
}
......
......@@ -3063,14 +3063,30 @@ class ArchivesAndScriptsRelationshipsSeeder extends Seeder {
*/
public function run() {
foreach ( $this->relationships as $relationship ) {
$archive = Archive::where('md5', $relationship['md5'])->first();
$script_id = Script::where('file', $relationship['file'])->pluck('id')->first();
if ( isset($relationship['required']) ) {
$required = $relationship['required'];
if ( isset($relationship['groups']) ) {
foreach( $relationship['groups'] as $group_id => $group ) {
foreach ( $group as $key => $value ) {
if ( $key === 'required' ) {
$required = $value;
} else {
$archive = Archive::where('md5', $value)->first();
$archive->scripts()->attach($script_id, [
'required' => $required,
'group' => $group_id,
]);
}
}
}
} else {
$required = true;
$archive = Archive::where('md5', $relationship['md5'])->first();
if ( isset($relationship['required']) ) {
$required = $relationship['required'];
} else {
$required = true;
}
$archive->scripts()->attach($script_id, [ 'required' => $required ]);
}
$archive->scripts()->attach($script_id, [ 'required' => $required ]);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment