2019-11-16 07:21:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\BulkActions\Settings;
|
|
|
|
|
|
|
|
|
|
use App\Abstracts\BulkAction;
|
2019-12-23 09:46:00 +00:00
|
|
|
use App\Jobs\Setting\DeleteCategory;
|
|
|
|
|
use App\Jobs\Setting\UpdateCategory;
|
2019-11-16 07:21:14 +00:00
|
|
|
use App\Models\Setting\Category;
|
2023-10-03 08:06:08 +00:00
|
|
|
use App\Traits\Categories as Helper;
|
2019-11-16 07:21:14 +00:00
|
|
|
|
|
|
|
|
class Categories extends BulkAction
|
|
|
|
|
{
|
2023-10-03 08:06:08 +00:00
|
|
|
use Helper;
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
public $model = Category::class;
|
|
|
|
|
|
2022-06-01 07:15:55 +00:00
|
|
|
public $text = 'general.categories';
|
|
|
|
|
|
|
|
|
|
public $path = [
|
|
|
|
|
'group' => 'settings',
|
|
|
|
|
'type' => 'categories',
|
|
|
|
|
];
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
public $actions = [
|
2023-10-03 08:06:08 +00:00
|
|
|
'edit' => [
|
|
|
|
|
'icon' => 'edit',
|
|
|
|
|
'name' => 'general.edit',
|
|
|
|
|
'message' => '',
|
|
|
|
|
'permission' => 'update-settings-categories',
|
|
|
|
|
'type' => 'modal',
|
|
|
|
|
'handle' => 'update',
|
|
|
|
|
],
|
2022-06-01 07:15:55 +00:00
|
|
|
'enable' => [
|
|
|
|
|
'icon' => 'check_circle',
|
|
|
|
|
'name' => 'general.enable',
|
|
|
|
|
'message' => 'bulk_actions.message.enable',
|
|
|
|
|
'permission' => 'update-settings-categories',
|
2019-11-16 07:21:14 +00:00
|
|
|
],
|
2022-06-01 07:15:55 +00:00
|
|
|
'disable' => [
|
|
|
|
|
'icon' => 'hide_source',
|
|
|
|
|
'name' => 'general.disable',
|
|
|
|
|
'message' => 'bulk_actions.message.disable',
|
|
|
|
|
'permission' => 'update-settings-categories',
|
2019-11-16 07:21:14 +00:00
|
|
|
],
|
2022-06-01 07:15:55 +00:00
|
|
|
'delete' => [
|
|
|
|
|
'icon' => 'delete',
|
|
|
|
|
'name' => 'general.delete',
|
|
|
|
|
'message' => 'bulk_actions.message.delete',
|
|
|
|
|
'permission' => 'delete-settings-categories',
|
2019-12-27 12:42:22 +00:00
|
|
|
],
|
2019-11-16 07:21:14 +00:00
|
|
|
];
|
|
|
|
|
|
2023-10-03 08:06:08 +00:00
|
|
|
public function edit($request)
|
2022-06-22 14:14:28 +00:00
|
|
|
{
|
2023-10-03 08:06:08 +00:00
|
|
|
$selected = $this->getSelectedInput($request);
|
2026-03-13 21:54:31 +00:00
|
|
|
|
2023-10-03 08:06:08 +00:00
|
|
|
$types = $this->getCategoryTypes();
|
2022-06-22 14:14:28 +00:00
|
|
|
|
2023-10-03 08:06:08 +00:00
|
|
|
return $this->response('bulk-actions.settings.categories.edit', compact('selected', 'types'));
|
|
|
|
|
}
|
2022-06-22 14:14:28 +00:00
|
|
|
|
2023-10-03 08:06:08 +00:00
|
|
|
public function update($request)
|
|
|
|
|
{
|
|
|
|
|
$categories = $this->getSelectedRecords($request);
|
|
|
|
|
|
|
|
|
|
foreach ($categories as $category) {
|
|
|
|
|
try {
|
|
|
|
|
$request->merge([
|
|
|
|
|
'enabled' => $category->enabled,
|
|
|
|
|
]); // for update job authorize..
|
|
|
|
|
|
|
|
|
|
$this->dispatch(new UpdateCategory($category, $this->getUpdateRequest($request)));
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
flash($e->getMessage())->error()->important();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-22 14:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
public function disable($request)
|
|
|
|
|
{
|
2019-12-23 09:46:00 +00:00
|
|
|
$categories = $this->getSelectedRecords($request);
|
2019-11-16 07:21:14 +00:00
|
|
|
|
|
|
|
|
foreach ($categories as $category) {
|
2019-12-23 09:46:00 +00:00
|
|
|
try {
|
|
|
|
|
$this->dispatch(new UpdateCategory($category, $request->merge(['enabled' => 0])));
|
|
|
|
|
} catch (\Exception $e) {
|
2021-02-12 16:26:38 +00:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroy($request)
|
|
|
|
|
{
|
2019-12-23 09:46:00 +00:00
|
|
|
$categories = $this->getSelectedRecords($request);
|
2019-11-16 07:21:14 +00:00
|
|
|
|
|
|
|
|
foreach ($categories as $category) {
|
2019-12-23 09:46:00 +00:00
|
|
|
try {
|
|
|
|
|
$this->dispatch(new DeleteCategory($category));
|
|
|
|
|
} catch (\Exception $e) {
|
2021-02-12 16:26:38 +00:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-03 08:06:08 +00:00
|
|
|
|
|
|
|
|
public function getSelectedRecords($request, $relationships = null)
|
|
|
|
|
{
|
|
|
|
|
if (empty($relationships)) {
|
|
|
|
|
$model = $this->model::query();
|
|
|
|
|
} else {
|
|
|
|
|
$relationships = Arr::wrap($relationships);
|
|
|
|
|
|
|
|
|
|
$model = $this->model::with($relationships);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $model->getWithoutChildren()->find($this->getSelectedInput($request));
|
|
|
|
|
}
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|