-
-
Notifications
You must be signed in to change notification settings - Fork 751
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 0455cdd
Showing
17 changed files
with
727 additions
and
6 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/Marketing/EventDataGrid.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\Marketing; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use Webkul\DataGrid\DataGrid; | ||
|
||
class EventDataGrid extends DataGrid | ||
{ | ||
/** | ||
* Prepare query builder. | ||
*/ | ||
public function prepareQueryBuilder() | ||
{ | ||
$queryBuilder = DB::table('events') | ||
->addSelect( | ||
'events.id', | ||
'events.name', | ||
'events.description', | ||
'events.date', | ||
); | ||
|
||
$this->addFilter('id', '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'), | ||
]); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/EventController.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,115 @@ | ||
<?php | ||
|
||
namespace Webkul\Admin\Http\Controllers\Settings\Marketing; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\View\View; | ||
use Webkul\Admin\DataGrids\Settings\Marketing\EventDataGrid; | ||
use Webkul\Admin\Http\Controllers\Controller; | ||
use Webkul\Admin\Http\Requests\MassDestroyRequest; | ||
use Webkul\Marketing\Repositories\EventRepository; | ||
|
||
class EventController extends Controller | ||
{ | ||
/** | ||
* Create a new controller instance. | ||
*/ | ||
public function __construct(protected EventRepository $eventRepository) {} | ||
|
||
/** | ||
* Display a listing of the marketing events. | ||
*/ | ||
public function index(): View|JsonResponse | ||
{ | ||
if (request()->ajax()) { | ||
return datagrid(EventDataGrid::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->eventRepository->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->eventRepository->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->eventRepository->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. | ||
*/ | ||
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse | ||
{ | ||
$marketingEvents = $this->eventRepository->findWhereIn('id', $massDestroyRequest->input('indices')); | ||
|
||
dd($marketingEvents); | ||
|
||
foreach ($marketingEvents as $marketingEvent) { | ||
Event::dispatch('settings.marketing-event.delete.before', $marketingEvent); | ||
|
||
$this->eventRepository->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
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.