Пример #1
1
 public function send($message, $data)
 {
     if ($this->isAndroid()) {
         $push = PushNotification::app(['environment' => 'production', 'apiKey' => env('GCM_API_KEY'), 'service' => 'gcm']);
     } else {
         if ($this->isIos()) {
             $push = PushNotification::app(['environment' => 'development', 'certificate' => base_path('ck.pem'), 'passPhrase' => 'push', 'service' => 'apns']);
         }
     }
     if (isset($push)) {
         $push->to($this->push_token)->send($message, $data);
     }
 }
Пример #2
0
 /**
  * getFeedback function
  *
  * Returns an array of expired/invalid tokens to be removed from iOS PUSH notifications.
  *
  * We need to run this once ~ 24hrs
  *
  * @access public
  *
  * @param string $token - A valid token (can be any valid token)
  * @param string $message - Nil value for message
  *
  * @return array
  */
 public function getFeedback($token, $message = '')
 {
     $feedback = PushNotification::app($this->certificate)->to($token)->send($message);
     return $feedback->getFeedback();
 }
Пример #3
0
 /**
  * Push this reservation to specified devices
  *
  * @param  int  $id
  * @return Response
  */
 public function push($id, $tokenArr, $showNotification)
 {
     try {
         $reservation = array();
         $key = 'reservation_id';
         $value = (int) $id;
         $reservation[$key] = $value;
         //Int type
         $reservationIntAttrArr = ReservationAttributesInteger::where('reservation_id', (int) $id)->get();
         foreach ($reservationIntAttrArr as $reservationIntAttr) {
             $key = $reservationIntAttr->attribute->alias;
             $value = $reservationIntAttr->attribute_value;
             $reservation[$key] = $value;
             //Check log for same attribute
             $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationIntAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
             if ($reservationStatusLog != null) {
                 $reservationIntAttrLogArr = ReservationAttributesIntegerLog::where(['reservation_attribute_id' => $reservationIntAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                 foreach ($reservationIntAttrLogArr as $reservationIntAttrLog) {
                     $key = "old_" . $reservationIntAttrLog->attribute->alias;
                     $value = $reservationIntAttrLog->old_attribute_value;
                     $reservation[$key] = $value;
                 }
             }
         }
         //Float type
         $reservationFloatAttrArr = ReservationAttributesFloat::where('reservation_id', (int) $id)->get();
         foreach ($reservationFloatAttrArr as $reservationFloatAttr) {
             $key = $reservationFloatAttr->attribute->alias;
             $value = $reservationFloatAttr->attribute_value;
             $reservation[$key] = $value;
         }
         //Date type
         $reservationDateAttrArr = ReservationAttributesDate::where('reservation_id', (int) $id)->get();
         foreach ($reservationDateAttrArr as $reservationDateAttr) {
             $key = $reservationDateAttr->attribute->alias;
             $value = $reservationDateAttr->attribute_value;
             $reservation[$key] = $value;
             //Check log for same attribute
             $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationDateAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
             if ($reservationStatusLog != null) {
                 $reservationDateAttrLogArr = ReservationAttributesDateLog::where(['reservation_attribute_id' => $reservationDateAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                 foreach ($reservationDateAttrLogArr as $reservationDateAttrLog) {
                     $key = "old_" . $reservationDateAttrLog->attribute->alias;
                     $value = $reservationDateAttrLog->old_attribute_value;
                     $reservation[$key] = $value;
                 }
             }
         }
         //Text type
         $reservationTextAttrArr = ReservationAttributesText::where('reservation_id', (int) $id)->get();
         foreach ($reservationTextAttrArr as $reservationTextAttr) {
             $key = $reservationTextAttr->attribute->alias;
             $value = $reservationTextAttr->attribute_value;
             $reservation[$key] = $value;
             $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationTextAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
             if ($reservationStatusLog != null) {
                 $reservationTextAttrLogArr = ReservationAttributesTextLog::where(['reservation_attribute_id' => $reservationTextAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                 foreach ($reservationTextAttrLogArr as $reservationTextAttrLog) {
                     $key = "old_" . $reservationTextAttrLog->attribute->alias;
                     $value = $reservationTextAttrLog->old_attribute_value;
                     $reservation[$key] = $value;
                 }
             }
         }
         //Boolean type
         $reservationBoolAttrArr = ReservationAttributesBoolean::where('reservation_id', (int) $id)->get();
         foreach ($reservationBoolAttrArr as $reservationBoolAttr) {
             $key = $reservationBoolAttr->attribute->alias;
             $value = $reservationBoolAttr->attribute_value;
             if ($value == 1) {
                 $reservation[$key] = true;
             } else {
                 $reservation[$key] = false;
             }
         }
         //VarChar type
         $reservationVarcharAttrArr = ReservationAttributesVarchar::where('reservation_id', (int) $id)->get();
         foreach ($reservationVarcharAttrArr as $reservationVarcharAttr) {
             $key = $reservationVarcharAttr->attribute->alias;
             $value = $reservationVarcharAttr->attribute_value;
             $reservation[$key] = $value;
         }
         //Get Customer
         $reservationDetail = ReservationDetail::where('id', (int) $id)->first();
         if ($reservationDetail) {
             $reservation['reservation_type'] = $reservationDetail->reservation_type;
             $customer = array();
             $customer['id'] = $reservationDetail->user->id;
             $customer['full_name'] = $reservationDetail->user->full_name;
             $customer['email'] = $reservationDetail->user->email;
             $customer['phone_number'] = $reservationDetail->user->phone_number;
             $customer['points_earned'] = $reservationDetail->user->points_earned;
             $customer['rating'] = UserRating::where(['user_id' => $reservationDetail->user, 'id' => $reservationDetail->id])->avg('rating');
             if ($customer['rating'] == null) {
                 $customer['rating'] = 0.0;
             }
             $customerPreferences = UserAttributesVarChar::where(['user_id' => $reservationDetail->user->id, 'user_attribute_id' => ReservationController::$cust_pref_attr_id])->first();
             if ($customerPreferences) {
                 $customer['customer_preferences'] = $customerPreferences->attribute_value;
             }
             $reservation['customer'] = $customer;
         }
         //Get Location
         $reservationDetail = ReservationDetail::where('id', (int) $id)->first();
         if ($reservationDetail) {
             $location = array();
             $vendorLocation = VendorLocation::where('id', $reservationDetail->vendor_location_id)->first();
             $location['location_id'] = $vendorLocation->location_id;
             $location['location'] = Location::where('id', $vendorLocation->location_id)->first()->name;
             $reservation['location'] = $location;
         }
         //Get Product
         $reservationDetail = ReservationDetail::where('id', (int) $id)->first();
         if ($reservationDetail && $reservationDetail->reservation_type == 'experience') {
             $product = array();
             $product['product_id'] = $reservationDetail->product_id;
             $product['product'] = Product::where('id', $reservationDetail->product_id)->first()->name;
             $addonsArr = Product::where('product_parent_id', $reservationDetail->product_id)->get();
             if (sizeof($addonsArr) > 0) {
                 $productAddonArr = array();
                 foreach ($addonsArr as $addon) {
                     $addons = array();
                     $addons['addon_id'] = $addon->id;
                     $addons['addon_name'] = $addon->name;
                     $reservationAddonDetail = ReservationAddonsVariantsDetail::where(['reservation_id' => (int) $id, 'reservation_status_id' => $reservation['reservation_status_id'], 'options_id' => $addon->id])->first();
                     if ($reservationAddonDetail != null) {
                         $addons['no_of_persons'] = $reservationAddonDetail->no_of_persons;
                     }
                     array_push($productAddonArr, $addons);
                 }
                 $product['addons'] = $productAddonArr;
             }
             $reservation['product'] = $product;
         }
         if ($showNotification) {
             $reservation["show_notfn"] = 1;
         } else {
             $reservation["show_notfn"] = 0;
         }
         //$tokenArr = json_decode($input['tokens'], true);
         foreach ($tokenArr as $token) {
             PushNotification::app('appNameAndroid')->to($token['token'])->send(json_encode($reservation));
         }
         $arrResponse['status'] = Config::get('constants.API_SUCCESS');
         return response()->json($arrResponse, 200);
     } catch (\Exception $e) {
         return response()->json(['message' => 'An application error occured.', 'error' => $e->getMessage()], 500);
     }
 }
Пример #4
0
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('/push', function () {
    $devices = \App\Device::all();
    foreach ($devices as $device) {
        \Davibennun\LaravelPushNotification\Facades\PushNotification::app('appNameIOS')->to($device->token)->send('Hello World, i`m a push message');
    }
    echo 'pushed';
});
Route::get('/categories', function () {
    $categories = \App\Category::all();
    return view('categories.index', compact('categories'));
});
Route::get('/categories/{categoryId}', function ($categoryId) {
    $category = \App\Category::find($categoryId);
    $ranks = \App\Rank::where('category_id', '=', $categoryId)->with('place')->get();
    $lat = 48.83213;
    $lon = 2.3218;
    $radius = 3;
    $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->orderby('distance', 'asc')->whereHas('ranks', function ($query) use($categoryId) {
        $query->where('category_id', '=', $categoryId);