2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeds;
|
|
|
|
|
|
|
|
use App\Abstracts\Model;
|
2020-01-07 17:15:00 +03:00
|
|
|
use App\Models\Auth\User;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Models\Common\Widget;
|
|
|
|
use App\Models\Common\Dashboard;
|
2020-01-07 17:15:00 +03:00
|
|
|
use App\Utilities\Widgets;
|
2019-11-16 10:21:14 +03:00
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class Dashboards extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
Model::unguard();
|
|
|
|
|
|
|
|
$this->create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function create()
|
|
|
|
{
|
|
|
|
$user_id = $this->command->argument('user');
|
|
|
|
$company_id = $this->command->argument('company');
|
|
|
|
|
2019-12-31 02:20:10 +03:00
|
|
|
$dashboard = Dashboard::create([
|
|
|
|
'company_id' => $company_id,
|
2020-01-07 17:15:00 +03:00
|
|
|
'name' => trans_choice('general.dashboards', 1),
|
2019-12-31 02:20:10 +03:00
|
|
|
'enabled' => 1,
|
|
|
|
]);
|
|
|
|
|
2020-01-07 17:15:00 +03:00
|
|
|
$widgets = Widgets::getClasses(false);
|
2019-12-31 02:20:10 +03:00
|
|
|
|
|
|
|
$sort = 1;
|
|
|
|
|
|
|
|
foreach ($widgets as $class => $name) {
|
|
|
|
Widget::create([
|
2019-11-16 10:21:14 +03:00
|
|
|
'company_id' => $company_id,
|
2019-12-31 02:20:10 +03:00
|
|
|
'dashboard_id' => $dashboard->id,
|
|
|
|
'class' => $class,
|
|
|
|
'name' => $name,
|
|
|
|
'sort' => $sort,
|
2020-01-16 14:20:08 +03:00
|
|
|
'settings' => (new $class())->getDefaultSettings(),
|
2019-12-31 02:20:10 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$sort++;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
2020-01-07 17:15:00 +03:00
|
|
|
|
|
|
|
User::find($user_id)->dashboards()->attach($dashboard->id);
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|