Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
norka
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ann
norka
Commits
a6ebb497
Commit
a6ebb497
authored
Aug 02, 2017
by
Ann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes
parent
3561f9f6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
46 deletions
+89
-46
app/FireBase.php
+43
-16
app/Http/Controllers/NotificationController.php
+45
-29
routes/web.php
+1
-1
No files found.
app/FireBase.php
View file @
a6ebb497
...
...
@@ -10,18 +10,18 @@ class FireBase extends Model
{
$client
=
new
\GuzzleHttp\Client
();
foreach
(
$devicetokens
as
$dt
)
{
$payload
[
'to'
]
=
$dt
->
device_token
;
$request
=
$client
->
post
(
'https://fcm.googleapis.com/fcm/send'
,
[
'headers'
=>
[
'Content-Type'
=>
'application/json'
,
'Authorization'
=>
'key=AAAAWfL3zi0:APA91bFh4mFhA3vMO0NhCJ-ym2D1wMtKiu3ZMHXIzOv3kDtmpmO9LCm_5VDIUcp4Kav4KkB7gswvLR__zrZ-XadeAYtIcP83ajFJPZBNPlZT6HBQnfVHy7Pvbzm0neyR4UPU8FxYlSN7'
,
],
'json'
=>
$payload
]);
$json
=
$request
->
getBody
();
$data
=
json_decode
(
$json
,
true
);
$payload
[
'to'
]
=
$dt
->
device_token
;
$request
=
$client
->
post
(
'https://fcm.googleapis.com/fcm/send'
,
[
'headers'
=>
[
'Content-Type'
=>
'application/json'
,
'Authorization'
=>
'key=AAAAWfL3zi0:APA91bFh4mFhA3vMO0NhCJ-ym2D1wMtKiu3ZMHXIzOv3kDtmpmO9LCm_5VDIUcp4Kav4KkB7gswvLR__zrZ-XadeAYtIcP83ajFJPZBNPlZT6HBQnfVHy7Pvbzm0neyR4UPU8FxYlSN7'
,
],
'json'
=>
$payload
]);
$json
=
$request
->
getBody
();
$data
=
json_decode
(
$json
,
true
);
}
return
$data
;
...
...
@@ -48,14 +48,41 @@ class FireBase extends Model
return
$data
;
}
public
static
function
pushTopic
(
$payload
,
$category
)
public
static
function
pushTopic
(
$payload
,
$category
)
{
// dd(json_encode($payload));
//dd($data);
$client
=
new
\GuzzleHttp\Client
();
// $payload['to'] = '/topics/'.$category;
$payload
[
'condition'
]
=
'"Australia" in topics && "India" in topics'
;
// dd( $payload['condition']);
$countryOrstate
=
explode
(
','
,
$category
);
$countCat
=
count
(
$countryOrstate
);
if
(
$countCat
==
1
)
{
$payload
[
'to'
]
=
'/topics/'
.
$countryOrstate
[
0
];
}
else
{
$condition
=
''
;
for
(
$i
=
0
;
$i
<
$countCat
;
$i
++
)
{
if
(
$condition
==
''
)
$condition
=
"'"
.
$countryOrstate
[
$i
]
.
"'"
.
' in topics'
;
else
{
$countryOrstate
[
$i
]
=
"'"
.
$countryOrstate
[
$i
]
.
"'"
;
$condition
=
$condition
.
' || '
.
$countryOrstate
[
$i
]
.
' in topics'
;
}
}
$payload
[
'condition'
]
=
$condition
;
}
// $payload['condition'] ="'Australia' in topics || 'India' in topics";
// dd( $payload['condition']);
$request
=
$client
->
post
(
'https://android.googleapis.com/gcm/send'
,
[
'headers'
=>
[
'Content-Type'
=>
'application/json'
,
...
...
app/Http/Controllers/NotificationController.php
View file @
a6ebb497
...
...
@@ -17,54 +17,56 @@ class NotificationController extends Controller
{
$client
=
new
\GuzzleHttp\Client
();
$response
=
$client
->
request
(
'GET'
,
'http://www.ifm.co.in/webservice/listcountry'
);
$country
=
json_decode
(
$response
->
getBody
()
->
getContents
())
->
countryList
;
$country
=
json_decode
(
$response
->
getBody
()
->
getContents
())
->
countryList
;
$client
=
new
\GuzzleHttp\Client
();
$response
=
$client
->
request
(
'GET'
,
'http://www.ifm.co.in/webservice/liststate?country_id=101'
);
$state
=
json_decode
(
$response
->
getBody
()
->
getContents
())
->
stateList
;
return
view
(
"notification_add"
,
compact
(
'country'
,
'state'
));
$state
=
json_decode
(
$response
->
getBody
()
->
getContents
())
->
stateList
;
return
view
(
"notification_add"
,
compact
(
'country'
,
'state'
));
}
public
function
getStates
(
Request
$request
)
{
$countryId
=
$request
->
countries
;
$client
=
new
\GuzzleHttp\Client
();
$response
=
$client
->
request
(
'GET'
,
'http://www.ifm.co.in/webservice/liststate?country_id='
.
$countryId
);
$state
=
json_decode
(
$response
->
getBody
()
->
getContents
())
->
stateList
;
$response
=
$client
->
request
(
'GET'
,
'http://www.ifm.co.in/webservice/liststate?country_id='
.
$countryId
);
$state
=
json_decode
(
$response
->
getBody
()
->
getContents
())
->
stateList
;
return
$state
;
}
public
function
showAll
()
{
// $response = Laracurl::get('http://www.ifm.co.in/webservice/listcountry');
// $response = Laracurl::get('http://www.ifm.co.in/webservice/listcountry');
$notification
=
Notification
::
orderby
(
'id'
,
'desc'
)
->
get
();
$notification
=
Notification
::
orderby
(
'id'
,
'desc'
)
->
get
();
$data
[
'notification'
]
=
$notification
;
return
view
(
"notification_list"
,
compact
(
'notification'
));
}
public
function
index
(
Request
$request
)
{
$userid
=
$request
->
userid
;
if
(
$request
->
id
==
null
)
{
$district
=
NativeAddress
::
where
(
'user_id'
,
'='
,
$userid
)
->
pluck
(
'district'
);
$notification
=
Notification
::
where
(
'district'
,
'='
,
strval
(
$district
[
0
]))
->
take
(
50
)
->
get
();
$arr
=
[];
$userid
=
$request
->
userid
;
if
(
$request
->
id
==
null
)
{
$district
=
NativeAddress
::
where
(
'user_id'
,
'='
,
$userid
)
->
pluck
(
'district'
);
$notification
=
Notification
::
where
(
'district'
,
'='
,
strval
(
$district
[
0
]))
->
take
(
50
)
->
get
();
$arr
=
[];
$d
=
[];
foreach
(
$notification
as
$key
=>
$not
)
{
foreach
(
$notification
as
$key
=>
$not
)
{
if
(
in_array
(
$not
->
notification_date
,
$arr
))
{
if
(
in_array
(
$not
->
notification_date
,
$arr
))
{
}
else
{
$arr
[]
=
$not
->
notification_date
;
}
else
{
$arr
[]
=
$not
->
notification_date
;
$d
[
$key
][
'date'
]
=
$not
->
notification_date
;
$d
[
$key
][
'notification'
]
=
Notification
::
where
(
'notification_date'
,
$not
->
notification_date
)
$d
[
$key
][
'notification'
]
=
Notification
::
where
(
'notification_date'
,
$not
->
notification_date
)
->
where
(
'district'
,
'='
,
strval
(
$district
[
0
]))
->
get
();
}
}
$data
[
'notification'
]
=
$d
;
$data
[
'status'
]
=
1
;
$data
[
'notification'
]
=
$d
;
$data
[
'status'
]
=
1
;
$data
[
'message'
]
=
"Notifications retrieved successfully"
;
return
response
(
$data
,
200
);
}
else
{
...
...
@@ -76,8 +78,9 @@ class NotificationController extends Controller
public
function
show
(
$id
)
{
return
Notification
::
with
([
'NotificationType'
,
'NotificationType.id'
])
->
find
(
$id
);
return
Notification
::
with
([
'NotificationType'
,
'NotificationType.id'
])
->
find
(
$id
);
}
public
function
store
(
Request
$request
)
{
$input
=
$request
->
all
();
...
...
@@ -103,31 +106,44 @@ class NotificationController extends Controller
$not
->
description
=
$input
[
'description'
];
$not
->
notification_date
=
date
(
"Y-m-d h:i:s"
,
strtotime
(
$request
->
notification_date
));
$not
->
save
();
$category
=
$input
[
'category'
];
$country
=
$input
[
'country'
];
$category
=
$input
[
'category'
];
$country
=
$input
[
'country'
];
$state
=
$input
[
'state'
];
if
(
$not
)
{
$data
[
'status'
]
=
1
;
$data
[
'notification_id'
]
=
$not
->
id
;
$data
[
'message'
]
=
"Notification added successfully"
;
$devicetokens
=
DB
::
table
(
'device as dv'
)
$devicetokens
=
DB
::
table
(
'device as dv'
)
->
join
(
'users as us'
,
'dv.user_id'
,
'='
,
'us.id'
)
->
select
(
'dv.device_token'
)
->
get
();
if
(
$input
[
'notification_type_id'
]
==
1
)
{
if
(
$category
==
"country"
)
{
if
(
$category
==
"country"
)
{
FireBase
::
pushTopic
([
'notification'
=>
[
'title'
=>
substr
(
$not
->
title
,
0
,
100
),
'text'
=>
substr
(
strip_tags
(
$not
->
description
),
0
,
200
),
'sound'
=>
'default'
,
'click_action'
=>
'FCM_PLUGIN_ACTIVITY'
],
'data'
=>
[
'type'
=>
'notification'
]
],
$country
);
}
else
if
(
$category
==
"state"
)
{
FireBase
::
pushTopic
([
'notification'
=>
[
'title'
=>
substr
(
$not
->
title
,
0
,
100
),
'text'
=>
substr
(
strip_tags
(
$not
->
description
),
0
,
200
),
'sound'
=>
'default'
,
'click_action'
=>
'FCM_PLUGIN_ACTIVITY'
'sound'
=>
'default'
,
'click_action'
=>
'FCM_PLUGIN_ACTIVITY'
],
'data'
=>
[
'type'
=>
'notification'
]
],
$country
);
],
$state
);
}
else
{
}
// FireBase::pushToAll([
// 'notification' => [
...
...
routes/web.php
View file @
a6ebb497
...
...
@@ -12,7 +12,7 @@
*/
Route
::
get
(
'/'
,
function
()
{
return
view
(
'
auth/
login'
);
return
view
(
'login'
);
});
//return view('auth/login');
Route
::
get
(
'/admin/dashboard'
,
function
()
{
return
view
(
'index'
);});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment