Skip to content

Commit 5044222

Browse files
Merge pull request #7 from vivek-webkul/patch-1
[Added models contracts and missing translation.]
2 parents 66d678d + 23abf32 commit 5044222

File tree

15 files changed

+206
-139
lines changed

15 files changed

+206
-139
lines changed

CHANGELOG for v0.1.x.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
#### This changelog consists the bug & security fixes and new features being included in the releases listed below.
44

5+
## **v0.1.3(26th of December, 2019)** - *Release*
6+
7+
* [Update] Added missing language translations.
8+
9+
* [Update] Added contract for the PushNotificaton Model.
10+
11+
* [Update] composer.json file added.
12+
513
## **v0.1.2(7th of August, 2019)** - *Release*
614

715
* [feature] Push Notifications added.

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ It packs in lots of demanding features that allows your business to scale in no
3434
Webkul\PWA\Providers\PWAServiceProvider::class
3535
~~~
3636

37+
* Goto config/concord.php file and add following line under 'modules'
38+
39+
~~~
40+
\Webkul\PWA\Providers\ModuleServiceProvider::class
41+
~~~
42+
3743
* Goto composer.json file and add following line under 'psr-4'
3844

3945
~~~
40-
"Webkul\\PWA\\": "packages/Webkul/PWA"
46+
"Webkul\\PWA\\": "packages/Webkul/PWA/src"
4147
~~~
4248

4349
* Install Jenssegers Agent via following command
@@ -64,6 +70,10 @@ Jenssegers\Agent\AgentServiceProvider::class
6470
composer dump-autoload
6571
~~~
6672

73+
~~~
74+
php artisan migrate
75+
~~~
76+
6777
~~~
6878
php artisan route:cache
6979
~~~

packages/Webkul/PWA/composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "Bagisto/Laravel-Progressive-Web-App",
3+
"description": "Progressive Web Application transform your website like Mobile Application",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "viveksharma-webkul",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"require": {},
12+
"autoload": {
13+
"psr-4": {
14+
"Webkul\\Pos\\": "src/"
15+
}
16+
},
17+
"extra": {
18+
"laravel": {
19+
"providers": [
20+
"Webkul\\PWA\\Providers\\PWAServiceProvider"
21+
],
22+
"aliases": {}
23+
}
24+
},
25+
"minimum-stability": "dev"
26+
}

packages/Webkul/PWA/src/Config/menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
], [
1010
'key' => 'PWA.index',
1111
'route' => 'pwa.pushnotification.index',
12-
'name' => 'Push Notification',
12+
'name' => 'pwa::app.admin.layouts.push-notification',
1313
'sort' => 1
1414
]
1515
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Webkul\PWA\Contracts;
4+
5+
interface PushNotification
6+
{
7+
}

packages/Webkul/PWA/src/DataGrids/PushNotificationDataGrid.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,21 @@
33
namespace Webkul\PWA\DataGrids;
44

55
use Webkul\Ui\DataGrid\DataGrid;
6-
use LaravelFCM\Message\OptionsBuilder;
7-
use LaravelFCM\Message\PayloadDataBuilder;
8-
use LaravelFCM\Message\PayloadNotificationBuilder;
9-
use FCM;
106
use DB;
117

128
/**
139
* OrderDataGrid Class
1410
*
1511
* @author Aayush Bhatt <[email protected]>
12+
* @author Vivek Sharma <[email protected]>
1613
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
1714
*/
18-
1915
class PushNotificationDataGrid extends DataGrid
2016
{
2117
protected $index = 'id'; // the column that needs to be treated as index column
2218

2319
protected $sortOrder = 'desc'; // asc or desc
2420

25-
protected $itemsPerPage = 5; // enables the pagination
26-
2721
public function prepareQueryBuilder()
2822
{
2923
$queryBuilder = DB::table('push_notifications')
@@ -36,7 +30,7 @@ public function addColumns()
3630
{
3731
$this->addColumn([
3832
'index' => 'id',
39-
'label' => trans('pwa::app.admin.system.id'),
33+
'label' => trans('pwa::app.admin.datagrid.id'),
4034
'type' => 'number',
4135
'searchable' => true,
4236
'sortable' => true,
@@ -45,7 +39,7 @@ public function addColumns()
4539

4640
$this->addColumn([
4741
'index' => 'title',
48-
'label' => trans('pwa::app.admin.system.pushnotificationtitle'),
42+
'label' => trans('pwa::app.admin.datagrid.title'),
4943
'type' => 'string',
5044
'searchable' => true,
5145
'sortable' => true,
@@ -54,7 +48,7 @@ public function addColumns()
5448

5549
$this->addColumn([
5650
'index' => 'description',
57-
'label' => trans('pwa::app.admin.system.pushnotificationdescription'),
51+
'label' => trans('pwa::app.admin.datagrid.description'),
5852
'type' => 'string',
5953
'searchable' => false,
6054
'sortable' => false,
@@ -63,9 +57,9 @@ public function addColumns()
6357

6458
$this->addColumn([
6559
'index' => 'targeturl',
66-
'label' => trans('pwa::app.admin.system.targeturl'),
60+
'label' => trans('pwa::app.admin.datagrid.target-url'),
6761
'type' => 'string',
68-
'searchable' => false,
62+
'searchable' => true,
6963
'sortable' => false,
7064
'filterable' => false
7165
]);

packages/Webkul/PWA/src/Http/Controllers/PushNotificationController.php

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,43 @@
33
namespace Webkul\PWA\Http\Controllers;
44

55
use Illuminate\Http\Request;
6-
use Webkul\PWA\Models\PushNotification as PushNotification;
76
use Webkul\PWA\Repositories\PushNotificationRepository as PushNotificationRepository;
8-
use LaravelFCM\Message\OptionsBuilder;
9-
use LaravelFCM\Message\PayloadDataBuilder;
10-
use LaravelFCM\Message\PayloadNotificationBuilder;
11-
use FCM;
12-
use DB;
137

8+
/**
9+
* Push Notification controller
10+
*
11+
* @author Vivek Sharma <[email protected]>
12+
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
13+
*/
1414
class PushNotificationController extends Controller
1515
{
16+
/**
17+
* Display a listing of the resource.
18+
*
19+
* @return \Illuminate\Http\Response
20+
*/
1621
protected $_config;
1722

18-
public function __construct(PushNotificationRepository $PushNotificationRepository)
23+
/**
24+
* PushNotificationRepository object
25+
*
26+
* @var array
27+
*/
28+
protected $pushNotificationRepository;
29+
30+
/**
31+
* Create a new controller instance.
32+
*
33+
* @param \Webkul\Core\Repositories\CoreConfigRepository $coreConfig
34+
* @return void
35+
*/
36+
public function __construct(PushNotificationRepository $pushNotificationRepository)
1937
{
20-
$this->PushNotificationRepository = $PushNotificationRepository;
38+
$this->pushNotificationRepository = $pushNotificationRepository;
2139

2240
$this->_config = request('_config');
2341
}
42+
2443
/**
2544
* Display a listing of the resource.
2645
*
@@ -49,7 +68,6 @@ public function create()
4968
*/
5069
public function store(Request $request)
5170
{
52-
5371
// $this->validate($request, [
5472
// 'title' => 'required',
5573
// 'description' => 'required',
@@ -61,25 +79,14 @@ public function store(Request $request)
6179
$data = $request->all();
6280

6381
// call the repository
64-
$pushnotification = $this->PushNotificationRepository->create($data);
82+
$this->pushNotificationRepository->create($data);
6583

6684
// flash message
6785
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Push Notification']));
6886

6987
return redirect()->route($this->_config['redirect']);
7088
}
7189

72-
/**
73-
* Display the specified resource.
74-
*
75-
* @param int $id
76-
* @return \Illuminate\Http\Response
77-
*/
78-
public function show($id)
79-
{
80-
81-
}
82-
8390
/**
8491
* Show the form for editing the specified resource.
8592
*
@@ -88,8 +95,7 @@ public function show($id)
8895
*/
8996
public function edit($id)
9097
{
91-
92-
$pushnotification = $this->PushNotificationRepository->find($id);
98+
$pushnotification = $this->pushNotificationRepository->find($id);
9399

94100
return view($this->_config['view'], compact('pushnotification'));
95101
}
@@ -103,8 +109,7 @@ public function edit($id)
103109
*/
104110
public function update(Request $request, $id)
105111
{
106-
107-
$pushnotification = $this->PushNotificationRepository->update(request()->all(), $id);
112+
$this->pushNotificationRepository->update(request()->all(), $id);
108113

109114
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Push Notification']));
110115

@@ -119,65 +124,68 @@ public function update(Request $request, $id)
119124
*/
120125
public function destroy($id)
121126
{
122-
$pushnotification = $this->PushNotificationRepository->findOrFail($id);
123-
$this->PushNotificationRepository->delete($id);
127+
$pushnotification = $this->pushNotificationRepository->findOrFail($id);
128+
129+
$this->pushNotificationRepository->delete($id);
130+
124131
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Push Notification']));
132+
125133
return redirect()->back();
126134
}
127135

128136
public function pushtofirebase($id) // send push notification to multiple devices
129137
{
130-
$pushnotification = \DB::table('push_notifications')->find($id);
138+
$pushnotification = $this->pushNotificationRepository->findOrFail($id);
139+
131140
$title = $pushnotification->title;
132141
$body = $pushnotification->description;
133142
$badge = $pushnotification->imageurl;
134143
$targeturl = $pushnotification->targeturl;
135144

136145
$url = 'https://fcm.googleapis.com/fcm/send';
137146

138-
$topic = 'bagisto';
139-
140-
$fields = array(
141-
'to' => '/topics/bagisto',
142-
'data' => [
143-
'body' => $body,
144-
'title' => $title,
145-
'click_action' => $targeturl
146-
]
147+
$topic = 'bagisto';
147148

148-
);
149+
$fields = array(
150+
'to' => '/topics/' . $topic,
151+
'data' => [
152+
'body' => $body,
153+
'title' => $title,
154+
'click_action' => $targeturl
155+
]
156+
);
149157

150-
$server_key = "AIzaSyBjbet3YzHEAp-YEkRN50zWx3asw0d07MA";
158+
$server_key = "AIzaSyBjbet3YzHEAp-YEkRN50zWx3asw0d07MA";
151159

152-
$headers = array(
153-
'Content-Type:application/json',
154-
'Authorization:key='.$server_key,
155-
);
160+
$headers = array(
161+
'Content-Type:application/json',
162+
'Authorization:key=' . $server_key,
163+
);
156164

157-
// Open connection
158-
$ch = curl_init();
165+
// Open connection
166+
$ch = curl_init();
159167

160-
curl_setopt( $ch, CURLOPT_URL, $url );
168+
curl_setopt( $ch, CURLOPT_URL, $url );
161169

162-
curl_setopt( $ch, CURLOPT_POST, true );
170+
curl_setopt( $ch, CURLOPT_POST, true );
163171

164-
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
172+
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
165173

166-
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
167-
// Disabling SSL Certificate support temporarly
168-
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true );
174+
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
175+
// Disabling SSL Certificate support temporarly
176+
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true );
169177

170-
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
171-
// Execute post
172-
$result = curl_exec( $ch );
178+
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
179+
// Execute post
180+
$result = curl_exec( $ch );
173181

174-
if ( $result === false ) {
175-
die('Curl failed: ' . curl_error($ch));
176-
}
182+
if ( $result === false ) {
183+
die('Curl failed: ' . curl_error($ch));
184+
}
177185

178-
curl_close( $ch );
186+
curl_close( $ch );
179187

180-
// Close connection
181-
return redirect()->back();
188+
// Close connection
189+
return redirect()->back();
182190
}
183191
}

packages/Webkul/PWA/src/Models/PushNotification.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace Webkul\PWA\Models;
44

55
use Illuminate\Database\Eloquent\Model;
6+
use Webkul\PWA\Contracts\PushNotification as PushNotificationContract;
67

7-
class PushNotification extends Model
8+
class PushNotification extends Model implements PushNotificationContract
89
{
9-
protected $table = "push_notifications";
10+
protected $table = 'push_notifications';
1011

1112
public $primaryKey = 'id';
1213

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Webkul\PWA\Providers;
4+
5+
use Konekt\Concord\BaseModuleServiceProvider;
6+
7+
class ModuleServiceProvider extends BaseModuleServiceProvider
8+
{
9+
protected $models = [
10+
\Webkul\PWA\Models\PushNotification::class
11+
];
12+
}

0 commit comments

Comments
 (0)