-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
163 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Juzaweb\Notification\Actions; | ||
|
||
use Juzaweb\Abstracts\Action; | ||
use Juzaweb\Facades\HookAction; | ||
|
||
class MainAction extends Action | ||
{ | ||
/** | ||
* Execute the actions. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$this->addAction(Action::BACKEND_CALL_ACTION, [$this, 'addAdminMenus']); | ||
$this->addAction(Action::BACKEND_CALL_ACTION, [$this, 'addSettingPage']); | ||
} | ||
|
||
public function addAdminMenus() | ||
{ | ||
HookAction::addAdminMenu( | ||
trans('juzaweb::app.notifications'), | ||
'notification', | ||
[ | ||
'icon' => 'fa fa-bell', | ||
'position' => 100 | ||
] | ||
); | ||
} | ||
|
||
public function addSettingPage() | ||
{ | ||
HookAction::addSettingForm('notification', [ | ||
'name' => trans('juzaweb::app.notification'), | ||
'view' => view('juno::setting.form'), | ||
]); | ||
} | ||
} |
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,123 @@ | ||
<?php | ||
|
||
namespace Juzaweb\Notification\Http\Datatable; | ||
|
||
use Illuminate\Database\Query\Builder; | ||
use Illuminate\Support\Arr; | ||
use Juzaweb\Abstracts\DataTable; | ||
use Juzaweb\Notification\Models\ManualNotification; | ||
use Juzaweb\Notification\SendNotification; | ||
use Juzaweb\Notification\Jobs\SendNotification as SendNotificationJob; | ||
|
||
class NotificationDatatable extends DataTable | ||
{ | ||
/** | ||
* Columns datatable | ||
* | ||
* @return array | ||
*/ | ||
public function columns() | ||
{ | ||
return [ | ||
'subject' => [ | ||
'label' => trans('juzaweb::app.subject'), | ||
'formatter' => [$this, 'rowActionsFormatter'], | ||
], | ||
'method' => [ | ||
'label' => trans('juzaweb::app.via'), | ||
'width' => '15%', | ||
'formatter' => function ($value, $row, $index) { | ||
if ($row->method) { | ||
return $row->method; | ||
} | ||
|
||
return trans('juzaweb::app.all'); | ||
} | ||
], | ||
'error' => [ | ||
'label' => trans('juzaweb::app.error'), | ||
'width' => '20%', | ||
], | ||
'created_at' => [ | ||
'label' => trans('juzaweb::app.created_at'), | ||
'width' => '15%', | ||
'align' => 'center', | ||
'formatter' => function ($value, $row, $index) { | ||
return jw_date_format($row->created_at); | ||
} | ||
], | ||
'status' => [ | ||
'label' => trans('juzaweb::app.status'), | ||
'width' => '15%', | ||
'formatter' => function ($value, $row, $index) { | ||
switch ($value) { | ||
case 0: return trans('juzaweb::app.error'); | ||
case 1: return trans('juzaweb::app.sended'); | ||
case 2: return trans('juzaweb::app.pending'); | ||
case 3: return trans('juzaweb::app.sending'); | ||
case 4: return trans('juzaweb::app.unsent'); | ||
} | ||
} | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Query data datatable | ||
* | ||
* @param array $data | ||
* @return Builder | ||
*/ | ||
public function query($data) | ||
{ | ||
$query = ManualNotification::query(); | ||
if ($keyword = Arr::get($data, 'keyword')) { | ||
$query->where(function (Builder $q) use ($keyword) { | ||
$q->orWhere('name', 'like', '%'. $keyword .'%'); | ||
$q->orWhere('subject', 'like', '%'. $keyword .'%'); | ||
}); | ||
} | ||
|
||
if ($status = Arr::get($data, 'status')) { | ||
if (!is_null($status)) { | ||
$query->where('status', '=', $status); | ||
} | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
public function bulkActions($action, $ids) | ||
{ | ||
switch ($action) { | ||
case 'delete': | ||
ManualNotification::destroy($ids); | ||
break; | ||
case 'send': | ||
ManualNotification::whereIn('id', $ids) | ||
->update([ | ||
'status' => 2 | ||
]); | ||
|
||
$useMethod = config('juzaweb.notification.method'); | ||
if (in_array($useMethod, ['sync', 'queue'])) { | ||
foreach ($ids as $id) { | ||
$notification = ManualNotification::find($id); | ||
if (empty($notification)) { | ||
continue; | ||
} | ||
|
||
switch ($useMethod) { | ||
case 'sync': | ||
(new SendNotification($notification))->send(); | ||
break; | ||
case 'queue': | ||
SendNotificationJob::dispatch($notification); | ||
break; | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
} |