-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e7b129
commit 779974d
Showing
16 changed files
with
740 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/Webkul/Admin/src/DataGrids/Settings/MarketingEventDataGrid.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Webkul\Admin\DataGrids\Settings; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use Webkul\DataGrid\DataGrid; | ||
|
||
class MarketingEventDataGrid extends DataGrid | ||
{ | ||
/** | ||
* Prepare query builder. | ||
*/ | ||
public function prepareQueryBuilder() | ||
{ | ||
$queryBuilder = DB::table('marketing_events') | ||
->addSelect( | ||
'marketing_events.id', | ||
'marketing_events.name', | ||
'marketing_events.description', | ||
'marketing_events.date', | ||
); | ||
|
||
$this->addFilter('id', 'marketing_events.id'); | ||
|
||
return $queryBuilder; | ||
} | ||
|
||
/** | ||
* Add columns. | ||
* | ||
* @return void | ||
*/ | ||
public function prepareColumns() | ||
{ | ||
$this->addColumn([ | ||
'index' => 'id', | ||
'label' => trans('admin::app.settings.marketing-events.index.datagrid.id'), | ||
'type' => 'string', | ||
'sortable' => true, | ||
'searchable' => true, | ||
'filterable' => true, | ||
]); | ||
|
||
$this->addColumn([ | ||
'index' => 'name', | ||
'label' => trans('admin::app.settings.marketing-events.index.datagrid.name'), | ||
'type' => 'string', | ||
'sortable' => true, | ||
'searchable' => true, | ||
'filterable' => true, | ||
]); | ||
|
||
$this->addColumn([ | ||
'index' => 'description', | ||
'label' => trans('admin::app.settings.marketing-events.index.datagrid.description'), | ||
'type' => 'string', | ||
'sortable' => true, | ||
]); | ||
|
||
$this->addColumn([ | ||
'index' => 'date', | ||
'label' => trans('admin::app.settings.marketing-events.index.datagrid.date'), | ||
'type' => 'string', | ||
'sortable' => true, | ||
]); | ||
} | ||
|
||
/** | ||
* Prepare actions. | ||
* | ||
* @return void | ||
*/ | ||
public function prepareActions() | ||
{ | ||
// TODO: Implement the bouncer for this actions. | ||
$this->addAction([ | ||
'index' => 'edit', | ||
'icon' => 'icon-edit', | ||
'title' => trans('admin::app.settings.marketing-events.index.datagrid.edit'), | ||
'method' => 'GET', | ||
'url' => fn ($row) => route('admin.settings.marketing_events.edit', $row->id), | ||
]); | ||
|
||
$this->addAction([ | ||
'index' => 'delete', | ||
'icon' => 'icon-delete', | ||
'title' => trans('admin::app.settings.marketing-events.index.datagrid.delete'), | ||
'method' => 'DELETE', | ||
'url' => fn ($row) => route('admin.settings.marketing_events.delete', $row->id), | ||
]); | ||
} | ||
|
||
/** | ||
* Prepare mass actions. | ||
*/ | ||
public function prepareMassActions(): void | ||
{ | ||
$this->addMassAction([ | ||
'icon' => 'icon-delete', | ||
'title' => trans('admin::app.settings.marketing-events.index.datagrid.delete'), | ||
'method' => 'POST', | ||
'url' => route('admin.settings.marketing_events.mass_delete'), | ||
]); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
packages/Webkul/Admin/src/Http/Controllers/Settings/MarketingEventController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace Webkul\Admin\Http\Controllers\Settings; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\View\View; | ||
use Webkul\Admin\DataGrids\Settings\MarketingEventDataGrid; | ||
use Webkul\Admin\Http\Controllers\Controller; | ||
use Webkul\Admin\Http\Requests\MassDestroyRequest; | ||
use Webkul\MarketingEvents\Repositories\MarketingEventRepository; | ||
|
||
class MarketingEventController extends Controller | ||
{ | ||
/** | ||
* Create a new controller instance. | ||
*/ | ||
public function __construct(protected MarketingEventRepository $marketingEventRepository) | ||
{ | ||
} | ||
|
||
/** | ||
* Display a listing of the marketing events. | ||
*/ | ||
public function index(): View|JsonResponse | ||
{ | ||
if (request()->ajax()) { | ||
return datagrid(MarketingEventDataGrid::class)->process(); | ||
} | ||
|
||
return view('admin::settings.marketing-events.index'); | ||
} | ||
|
||
/** | ||
* Store a newly created marketing event in storage. | ||
*/ | ||
public function store(): JsonResponse | ||
{ | ||
$validatedData = $this->validate(request(), [ | ||
'name' => 'required', | ||
'description' => 'required', | ||
'date' => 'required|date|after_or_equal:today', | ||
]); | ||
|
||
Event::dispatch('settings.marketing-event.create.before'); | ||
|
||
$marketingEvent = $this->marketingEventRepository->create($validatedData); | ||
|
||
Event::dispatch('settings.marketing-event.create.after', $marketingEvent); | ||
|
||
return response()->json([ | ||
'message' => trans('admin::app.settings.marketing-events.index.create-success'), | ||
'data' => $marketingEvent, | ||
]); | ||
} | ||
|
||
/** | ||
* Update the specified marketing event in storage. | ||
*/ | ||
public function update(int $id): JsonResponse | ||
{ | ||
$validatedData = $this->validate(request(), [ | ||
'name' => 'required', | ||
'description' => 'required', | ||
'date' => 'required|date|after_or_equal:today', | ||
]); | ||
|
||
Event::dispatch('settings.marketing-event.update.before', $id); | ||
|
||
$marketingEvent = $this->marketingEventRepository->update($validatedData, $id); | ||
|
||
Event::dispatch('settings.marketing-event.update.after', $marketingEvent); | ||
|
||
return response()->json([ | ||
'message' => trans('admin::app.settings.marketing-events.index.update-success'), | ||
'data' => $marketingEvent, | ||
]); | ||
} | ||
|
||
/** | ||
* Remove the specified marketing event from storage. | ||
*/ | ||
public function destroy(int $id): JsonResponse | ||
{ | ||
Event::dispatch('settings.marketing-event.delete.before', $id); | ||
|
||
$this->marketingEventRepository->delete($id); | ||
|
||
Event::dispatch('settings.marketing-event.delete.after', $id); | ||
|
||
return response()->json([ | ||
'message' => trans('admin::app.settings.marketing-events.index.delete-success'), | ||
]); | ||
} | ||
|
||
/** | ||
* Remove the specified marketing events from storage. | ||
* | ||
* @param MassDestroyRequest $massDestroyRequest | ||
* @return JsonResponse | ||
*/ | ||
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse | ||
{ | ||
$marketingEvents = $this->marketingEventRepository->findWhereIn('id', $massDestroyRequest->input('indices')); | ||
|
||
dd($marketingEvents); | ||
|
||
foreach ($marketingEvents as $marketingEvent) { | ||
Event::dispatch('settings.marketing-event.delete.before', $marketingEvent); | ||
|
||
$this->marketingEventRepository->delete($marketingEvent->id); | ||
|
||
Event::dispatch('settings.marketing-event.delete.after', $marketingEvent); | ||
} | ||
|
||
return response()->json([ | ||
'message' => trans('admin::app.settings.marketing-events.index.delete-success'), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.