akaunting/app/BulkActions/Common/Dashboards.php

81 lines
2.3 KiB
PHP
Raw Normal View History

2020-01-07 17:15:00 +03:00
<?php
namespace App\BulkActions\Common;
use App\Abstracts\BulkAction;
use App\Jobs\Common\DeleteDashboard;
use App\Jobs\Common\UpdateDashboard;
use App\Models\Common\Dashboard;
class Dashboards extends BulkAction
{
public $model = Dashboard::class;
2022-06-01 10:15:55 +03:00
public $text = 'general.dashboards';
public $path = [
'group' => 'common',
'type' => 'dashboards',
];
2020-01-07 17:15:00 +03:00
public $actions = [
2022-06-01 10:15:55 +03:00
'enable' => [
'icon' => 'check_circle',
'name' => 'general.enable',
'message' => 'bulk_actions.message.enable',
'permission' => 'update-common-dashboards',
2020-01-07 17:15:00 +03:00
],
2022-06-01 10:15:55 +03:00
'disable' => [
'icon' => 'hide_source',
'name' => 'general.disable',
'message' => 'bulk_actions.message.disable',
'permission' => 'update-common-dashboards',
2020-01-07 17:15:00 +03:00
],
2022-06-01 10:15:55 +03:00
'delete' => [
'icon' => 'delete',
'name' => 'general.delete',
'message' => 'bulk_actions.message.delete',
'permission' => 'delete-common-dashboards',
2020-01-07 17:15:00 +03:00
],
];
public function enable($request)
{
$dashboards = $this->getSelectedRecords($request);
foreach ($dashboards as $dashboard) {
try {
$this->dispatch(new UpdateDashboard($dashboard, $request->merge(['enabled' => 1])));
} catch (\Exception $e) {
flash($e->getMessage())->error()->important();
2020-01-07 17:15:00 +03:00
}
}
}
public function disable($request)
{
$dashboards = $this->getSelectedRecords($request);
foreach ($dashboards as $dashboard) {
try {
$this->dispatch(new UpdateDashboard($dashboard, $request->merge(['enabled' => 0])));
} catch (\Exception $e) {
flash($e->getMessage())->error()->important();
2020-01-07 17:15:00 +03:00
}
}
}
public function destroy($request)
{
$dashboards = $this->getSelectedRecords($request);
foreach ($dashboards as $dashboard) {
try {
$this->dispatch(new DeleteDashboard($dashboard));
} catch (\Exception $e) {
flash($e->getMessage())->error()->important();
2020-01-07 17:15:00 +03:00
}
}
}
}