Ejemplo n.º 1
0
 public static function notify($type, User $fromUser, User $toUser, Topic $topic, Reply $reply = null)
 {
     if (Notification::isNotified($fromUser->id, $toUser->id, $topic->id, $type)) {
         return;
     }
     $nowTimestamp = Carbon::now()->toDateTimeString();
     $data = ['from_user_id' => $fromUser->id, 'user_id' => $toUser->id, 'topic_id' => $topic->id, 'reply_id' => $reply ? $reply->id : 0, 'body' => $reply ? $reply->body : '', 'type' => $type, 'created_at' => $nowTimestamp, 'updated_at' => $nowTimestamp];
     $toUser->increment('notification_count', 1);
     Notification::insert([$data]);
     self::pushNotification($data);
 }
Ejemplo n.º 2
0
 public static function nonamenotify($type, User $toUser, Article $article, Reply $reply = null)
 {
     // if ($fromUser->id == $toUser->id) {
     //     return;
     // }自己不通知自己
     if (Notification::isNotified(null, $toUser->id, $article->id, $type)) {
         return;
     }
     $nowTimestamp = Carbon::now()->toDateTimeString();
     $data[] = ['user_id' => $toUser->id, 'article_id' => $article->id, 'reply_id' => $reply ? $reply->id : 0, 'body' => $reply ? $reply->body : '', 'type' => $type, 'created_at' => $nowTimestamp, 'updated_at' => $nowTimestamp];
     $toUser->increment('notification_count', 1);
     Notification::insert($data);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CreateNotificationRequest $request)
 {
     $input = $request->all();
     if ($input['user_selection'] == 'user_list') {
         $user_obj = User::findOrFail($input['user_id']);
     } else {
         $user_obj = User::where('subscription', $input['user_selection'])->get()->toArray();
     }
     define('API_ACCESS_KEY', 'AIzaSyAglCBzKTWNam2prAZ6mjJfY0gn9os3M7s');
     $data = array();
     $all_data = array();
     foreach ($user_obj as $user) {
         $data['user_id'] = $user['id'];
         $data['title'] = $input['title'];
         $data['description'] = $input['description'];
         $data['image_url'] = $input['image_url'];
         $data['type'] = $input['type'];
         $data['image_url'] = $input['image_url'];
         $data['created_at'] = date('Y-m-d H:i:s');
         $all_data[] = $data;
         $device_id = $user['device_id'];
         //echo $device_id;
         // API access key from Google API's Console
         $registrationIds = array($device_id);
         // prep the bundle
         $msg = array('message' => $input['description'], 'title' => $input['title'], 'vibrate' => 1, 'sound' => 1);
         /* $msg = array
         		 (
         		 'message' 	=> 'here is a message. message',
         		 'title'		=> 'This is a title. title',
         		 'subtitle'	=> 'This is a subtitle. subtitle',
         		 'tickerText'	=> 'Ticker text here...Ticker text here...Ticker text here',
         		 'vibrate'	=> 1,
         		 'sound'		=> 1,
         		 'largeIcon'	=> 'large_icon',
         		 'smallIcon'	=> 'small_icon'
         		 ); */
         $fields = array('registration_ids' => $registrationIds, 'data' => $msg);
         $headers = array('Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json');
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
         $result = curl_exec($ch);
     }
     curl_close($ch);
     $data = array(array('name' => 'Coder 1', 'rep' => '4096'), array('name' => 'Coder 2', 'rep' => '2048'));
     Notification::insert($all_data);
     //$notification = Notification::create($request->all());
     //return redirect()->route('notifications.index');
     return redirect()->action('NotificationsController@index');
 }