Commit 8617bd77 authored by Antoine Le Gonidec's avatar Antoine Le Gonidec

Archive — List dependencies

Fix #10
parent bc7b9c77
......@@ -3,12 +3,16 @@
namespace App;
class Archive extends Model {
private $dependencies_table = 'dependencies';
private $dependencies_relationships_table = 'archive_dependency';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [ 'archives', 'archive', 'scripts' ];
protected $appends = [ 'archives', 'archive', 'scripts', 'dependencies' ];
/**
* The attributes that should be hidden for arrays.
......@@ -74,6 +78,31 @@ class Archive extends Model {
return $collection;
}
/**
* Get list of dependencies from dedicated database table
*
* @return array
*/
public function getDependenciesAttribute() {
$dependencies_table = app('db')->table($this->dependencies_table);
$dependencies_relationships_table = app('db')->table($this->dependencies_relationships_table);
$type = $this->type;
$generic_dependencies = $dependencies_relationships_table->where('archive_type', $type)
->pluck('dependency_name');
foreach ( $generic_dependencies as $name ) {
$dependencies_table = app('db')->table($this->dependencies_table);
$packages = $dependencies_table->where('name', $name)
->pluck('package', 'system')
->toArray();
foreach ( $packages as $system => $package ) {
if ( ! isset($dependencies[$system]) || ! in_array($package, $dependencies[$system]) ) {
$dependencies[$system][] = $package;
}
}
}
return $dependencies;
}
/**
* Return list of all archives as an array
*
......
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