Skip to content

Commit

Permalink
marketing events.
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-webkul committed Oct 29, 2024
1 parent 9e7b129 commit 779974d
Show file tree
Hide file tree
Showing 16 changed files with 740 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"Webkul\\Core\\": "packages/Webkul/Core/src",
"Webkul\\Email\\": "packages/Webkul/Email/src",
"Webkul\\EmailTemplate\\": "packages/Webkul/EmailTemplate/src",
"Webkul\\MarketingEvents\\": "packages/Webkul/MarketingEvents/src",
"Webkul\\Installer\\": "packages/Webkul/Installer/src",
"Webkul\\Lead\\": "packages/Webkul/Lead/src",
"Webkul\\Product\\": "packages/Webkul/Product/src",
Expand Down
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\Facade;
use Illuminate\Support\ServiceProvider;
use Webkul\WebForm\Contracts\WebForm;

return [

Expand Down Expand Up @@ -208,6 +209,7 @@
Webkul\DataGrid\Providers\DataGridServiceProvider::class,
Webkul\EmailTemplate\Providers\EmailTemplateServiceProvider::class,
Webkul\Email\Providers\EmailServiceProvider::class,
Webkul\MarketingEvents\Providers\MarketingEventServiceProvider::class,
Webkul\Installer\Providers\InstallerServiceProvider::class,
Webkul\Lead\Providers\LeadServiceProvider::class,
Webkul\Product\Providers\ProductServiceProvider::class,
Expand Down
11 changes: 10 additions & 1 deletion packages/Webkul/Admin/src/Config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,16 @@
'route' => 'admin.settings.email_templates.index',
'sort' => 2,
'icon-class' => 'icon-settings-mail',
], [
],
[
'key' => 'settings.automation.events',
'name' => 'admin::app.layouts.events',
'info' => 'admin::app.layouts.events-info',
'route' => 'admin.settings.marketing_events.index',
'sort' => 2,
'icon-class' => 'icon-settings-mail',
],
[
'key' => 'settings.automation.webhooks',
'name' => 'admin::app.layouts.webhooks',
'info' => 'admin::app.layouts.webhooks-info',
Expand Down
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'),
]);
}
}
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'),
]);
}
}
35 changes: 34 additions & 1 deletion packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,37 @@
],
],

'marketing-events' => [
'index' => [
'create-btn' => 'Create Marketing Event',
'title' => 'Marketing Events',
'create-success' => 'Marketing Event created successfully.',
'update-success' => 'Marketing Event updated successfully.',
'delete-success' => 'Marketing Event deleted successfully.',
'delete-failed' => 'Marketing Event can not be deleted.',

'datagrid' => [
'delete' => 'Delete',
'edit' => 'Edit',
'id' => 'ID',
'name' => 'Name',
'description' => 'Description',
'date' => 'Date',
],

'create' => [
'title' => 'Create Marketing Event',
'name' => 'Name',
'date' => 'Date',
'description' => 'Description',
],

'edit' => [
'title' => 'Edit Marketing Event',
],
],
],

'tags' => [
'index' => [
'create-btn' => 'Create Tag',
Expand Down Expand Up @@ -1776,7 +1807,7 @@
'title' => 'About Lead',
],

'quotes'=> [
'quotes' => [
'subject' => 'Subject',
'expired-at' => 'Expired At',
'sub-total' => 'Sub Total',
Expand Down Expand Up @@ -1960,6 +1991,8 @@
'email-templates' => 'Email Templates',
'email' => 'Email',
'email-templates-info' => 'Add, edit or delete email templates from CRM',
'events' => 'Events',
'events-info' => 'Add, edit or delete events from CRM',
'workflows' => 'Workflows',
'workflows-info' => 'Add, edit or delete workflows from CRM',
'webhooks' => 'Webhooks',
Expand Down
Loading

0 comments on commit 779974d

Please sign in to comment.