public function checkout(Request $request)
 {
     $response = new stdClass();
     if ($request->isMethod('post')) {
         $postData = $request->all();
         $userId = $postData['id'];
         $token = $postData['token'];
         $amount = $postData['money'];
         $name = $postData['name'];
         $addrLine1 = $postData['addrLine1'];
         $city = $postData['city'];
         $state = $postData['state'];
         $country = $postData['country'];
         $email = $postData['email'];
         $zipCode = $postData['zipCode'];
         $phoneNumber = $postData['phoneNumber'];
         $authFlag = false;
         if (isset($postData['api_token'])) {
             $apiToken = $postData['api_token'];
             if ($apiToken == $this->API_TOKEN) {
                 $authFlag = true;
             } else {
                 $authFlag = false;
             }
         }
         if ($authFlag) {
             $rules = array('money' => 'required|regex:/^[0-9]+([.][0-9]{0,2}+)?$/', 'name' => 'required', 'addrLine1' => 'required', 'city' => 'required', 'state' => 'required', 'zipCode' => 'required', 'country' => 'required', 'email' => 'required', 'phoneNumber' => 'required');
             $message = array('money.required' => 'Please Enter Amount that you want to add to your wallet', 'money.regex' => 'Please Enter a valid Amount i.e. number or decimal value ', 'name.required' => 'please enter your name', 'addrLine1.required' => 'please enter address', 'city.required' => 'please enter city', 'state.required' => 'please enter state', 'zipCode.required' => 'please provide zip code', 'country.required' => 'please specify country name', 'email.required' => 'please enter your email', 'phoneNumber.required' => 'please enter your phone number');
             $validator = Validator::make($request->all(), $rules, $message);
             if (!$validator->fails()) {
                 \Twocheckout::privateKey('1768AF13-92B6-4B9D-8493-66E884E98FEF');
                 \Twocheckout::sellerId('901311477');
                 \Twocheckout::sandbox(true);
                 #Uncomment to use Sandbox
                 \Twocheckout::verifySSL(false);
                 try {
                     $charge = \Twocheckout_Charge::auth(array("merchantOrderId" => "123", "token" => $token, "currency" => 'USD', "total" => $amount, "billingAddr" => array("name" => $name, "addrLine1" => $addrLine1, "city" => $city, "state" => $state, "zipCode" => $zipCode, "country" => $country, "email" => $email, "phoneNumber" => $phoneNumber)));
                     //                        echo json_encode($charge,true);die;
                     //                        echo '<pre>';
                     //            print_r($charge);die;
                     if ($charge['response']['responseCode'] == 'APPROVED') {
                         //                            echo "Thanks for your Order!";
                         //                            echo "<h3>Return Parameters:</h3>";
                         //                            echo "<pre>";
                         //                            print_r($charge);
                         //                            echo "</pre>";
                         //                            echo die;
                         $transactionId = $charge['response']['transactionId'];
                         $objModelTransaction = new Transaction();
                         $input = array('tx_id' => '', 'tx_type' => '1', 'tx_mode' => '1', 'tx_code' => ' ', 'transaction_id' => $transactionId, 'user_id' => $userId, 'amount' => $amount, 'payment_time' => time() + 19800);
                         $result = $objModelTransaction->addNewTransaction($input);
                         //code for increasing the amount (updating the account bal)
                         // first checking that user has details in usersmeta table or not, if not then acc_bal will be 0 & add users with amount
                         // or if yes then update accountbalance
                         $objModelUsermeta = new Usersmeta();
                         $whereForUpdateUser = array('rawQuery' => 'user_id = ?', 'bindParams' => [$userId]);
                         $isUserAvailable = $objModelUsermeta->getUsermetaWhere($whereForUpdateUser);
                         if ($isUserAvailable) {
                             $accountBal = $isUserAvailable->account_bal;
                             $totalBalance = $accountBal + $amount;
                             $dataForUpdateUser = array('account_bal' => $totalBalance);
                             //                        return $dataForUpdateUser;
                             $updated = $objModelUsermeta->updateUsermetaWhere($dataForUpdateUser, $whereForUpdateUser);
                         } else {
                             $accountBal = 0;
                             $totalBalance = $accountBal + $amount;
                             $addData = array('user_id' => $userId, 'account_bal' => $totalBalance);
                             $addUsermeta = $objModelUsermeta->addUsermeta($addData);
                         }
                         // code for generating NOTIFICATION
                         $objModelNotification = Notification::getInstance();
                         $input = array('notification_id' => '', 'user_id' => $userId, 'notifications_txt' => '$ ' . $amount . ' is successfully credited to your account through 2CO credit card payment');
                         $addNotification = $objModelNotification->addNewNotification($input);
                         $response->code = 200;
                         $response->message = "Payment Approved";
                         $response->data = $totalBalance;
                         echo json_encode($response, true);
                     }
                 } catch (\Twocheckout_Error $e) {
                     echo json_encode($e->getMessage(), true);
                     //                        print_r($e->getMessage());
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Add new follow data
  *
  * @param $follower_id
  * @param $followed_id
  * @throws \Exception
  */
 public function addFollow($follower_id, $followed_id)
 {
     try {
         DB::beginTransaction();
         $this->follower_user_id = $follower_id;
         $this->followed_user_id = $followed_id;
         $this->date_created = date('Y-m-d H:i:s');
         $this->save();
         $notification_data = new Notification();
         $notification_data->addNotificationNewFollower($follower_id, $followed_id);
         DB::commit();
     } catch (\Exception $e) {
         DB::rollback();
         throw $e;
     }
 }
Exemplo n.º 3
0
 public function readAction(Request $request)
 {
     $data = $request->json()->get('Notification');
     if (!$data) {
         return showErrorResponse('Incorrect request parameters', HTTP_UNPROCESSABLE_ENTITY);
     }
     $notification = Notification::find($data[CONSTANTS::KEY_ID]);
     if ($notification) {
         $notification = ModelFormatter::notificationFormat($notification->updateStatus(CONSTANTS::NOTIFICATION_STATUS_READ));
     }
     $json_return[KeyParser::data][KeyParser::notification] = $notification;
     return response()->json($json_return);
 }
Exemplo n.º 4
0
 /**
  * Add like data
  *
  * @param $type_id
  * @param $type
  * @param $user_id
  * @param $like_object
  * @param $like_type
  * @return $this
  * @throws \Exception
  */
 public function addLike($type_id, $type, $user_id, $like_object, $like_type)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $this->type_id = $type_id;
         $this->type = $type;
         $this->user_id = $user_id;
         $this->date_created = date('Y-m-d H:i:s');
         $this->save();
         $restaurant_id = $like_object['restaurant_id'];
         $owner_id = $like_object['user_id'];
         if ($user_id != $owner_id) {
             $notification_data = new Notification();
             $notification_data->addLikeNotification($user_id, $owner_id, $like_type, $type_id, $restaurant_id);
         }
         $connection->commit();
         return $this;
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Exemplo n.º 5
0
 /** Add new notification data for Photo
  *
  * @param $user_id_from
  * @param $user_id_to
  * @param $type_id
  * @param $restaurant_id
  * @throws \Exception
  */
 public function addNotificationNewPhoto($user_id_from, $user_id_to, $type_id, $restaurant_id)
 {
     try {
         $notification_data = new Notification();
         $notification_data->user_id_from = $user_id_from;
         $notification_data->user_id_to = $user_id_to;
         $notification_data->type = CONSTANTS::NOTIFICATION_TYPE_UPLOADED_PHOTO;
         $notification_data->type_id = $type_id;
         $notification_data->restaurant_id = $restaurant_id;
         $notification_data->date_created = date('Y-m-d H:i:s');
         $notification_data->save();
         $notification_data->sendPush();
     } catch (\Exception $e) {
         throw $e;
     }
 }
 public function getNotificationById($id)
 {
     $result = Notification::whereId($id)->first();
     //first() function in sql returns the first value of the selected column
     return $result;
 }
 public function expressCallback(Request $request)
 {
     //        return 23;
     $response = new stdClass();
     $postData = $request->all();
     $userId = $postData['id'];
     $amount = $postData['amount'];
     $payerid = $postData['PayerID'];
     $token = $postData['token'];
     //        print_r($token);print_r($payerid);die;
     $authFlag = false;
     if (isset($postData['api_token'])) {
         $apiToken = $postData['api_token'];
         if ($apiToken == $this->API_TOKEN) {
             $authFlag = true;
         }
     }
     if ($authFlag) {
         $objpaypal = Paypal::getInstance();
         $result = $objpaypal->ConfirmPayment($amount, $token, $payerid);
         //                echo"<pre>";print_r($result);die;
         //            echo json_encode($result, true);
         if ($result) {
             //                $function_result=$this->myCurlFunction();
             //                return $function_result;
             if ($result['ACK'] == "Success") {
                 //                    $response->code = 200;
                 //                    $response->message = "Amount added to your Wallet Successfully.";
                 $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID'];
                 $data['acknowledgement'] = $result['ACK'];
                 $data['amount'] = $amount;
                 $data['paymentTime'] = date('Y-m-d H:i:s');
                 $transactionId = $data['transactionId'];
                 $amount = $data['amount'];
                 $paymentTime = $data['paymentTime'];
                 $objModelTransaction = new Transaction();
                 $input = array('tx_id' => '', 'tx_type' => '1', 'tx_mode' => '0', 'tx_code' => ' ', 'transaction_id' => $transactionId, 'user_id' => $userId, 'amount' => $amount, 'payment_time' => strtotime($paymentTime));
                 $result = $objModelTransaction->addNewTransaction($input);
                 //code for increasing the amount (updating the account bal)
                 // first checking that user has details in usersmeta table or not, if not then acc_bal will be 0 & add users with amount
                 // or if yes then update accountbalance
                 $objModelUsermeta = new Usersmeta();
                 $whereForUpdateUser = array('rawQuery' => 'user_id = ?', 'bindParams' => [$userId]);
                 $isUserAvailable = $objModelUsermeta->getUsermetaWhere($whereForUpdateUser);
                 if ($isUserAvailable) {
                     $accountBal = $isUserAvailable->account_bal;
                     $totalBalance = $accountBal + $amount;
                     $dataForUpdateUser = array('account_bal' => $totalBalance);
                     //                        return $dataForUpdateUser;
                     $updated = $objModelUsermeta->updateUsermetaWhere($whereForUpdateUser, $dataForUpdateUser);
                 } else {
                     $accountBal = 0;
                     $totalBalance = $accountBal + $amount;
                     $addData = array('user_id' => $userId, 'account_bal' => $totalBalance);
                     $addUsermeta = $objModelUsermeta->addUsermeta($addData);
                 }
                 // code for generating NOTIFICATION
                 $objModelNotification = Notification::getInstance();
                 $input = array('notification_id' => '', 'user_id' => $userId, 'notifications_txt' => '$ ' . $amount . ' is successfully credited to your account');
                 $addNotification = $objModelNotification->addNewNotification($input);
                 $response->code = 200;
                 $response->message = "Amount added to your Wallet Successfully.";
                 //                    $response->notification="Your Account is Successfully Credited.";
                 $response->data = $totalBalance;
                 //                    echo '<pre>';print_r($response);die;
                 //                    return $response;
                 echo json_encode($response, true);
             } else {
                 if ($result['ACK'] == "SuccessWithWarning") {
                     //                        return 6;
                     $response->code = 07;
                     $response->message = "Amount added to your Wallet Successfully.";
                     $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID'];
                     $data['acknowledgement'] = $result['ACK'];
                     $data['amount'] = $amount;
                     $data['paymentTime'] = date('Y-m-d H:i:s');
                     $response->data = $data;
                     echo json_encode($response, true);
                     //                        echo'<pre>';print_r($data);die;
                     //                        return $response->data = $data;
                     //                        echo "<pre>";
                     //                        print_r($result);
                     //                        die;
                     //                        return 7;
                 } else {
                     $response->code = 400;
                     $response->message = "Some ERROR OCCURRED.";
                     echo "<pre>";
                     print_r($result);
                     die;
                 }
             }
         }
         //                if ($result['ACK'] == "Success") {
         //                    $response->code = 200;
         //                    $response->message = "Payment model created successfully.";
         //                    $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID'];
         //                    $data['acknowledgement'] = $result['ACK'];
         //                    $data['amount'] = $amount;
         //                    $data['paymentTime'] = date('Y-m-d H:i:s');
         //                    $response->data = $data;
         //                }
         //                if ($result) {
         //                    $response->code = 200;
         //                    $response->message = "Payment model created successfully.";
         //                    $response->data = 1;
         //                    echo json_encode($response, true);
     } else {
         $response->code = 400;
         $response->message = "Error in getting callback results. auth flag is not set";
         $response->data = null;
         echo json_encode($response, true);
     }
     //
     //        $payerid = $request->input('PayerID');
     //        $token = $request->input('token');
     //
     //        $objpaypal = paypal::getInstance();
     //        $result = $objpaypal->ConfirmPayment($amount, $token, $payerid);
     //
     ////        echo "<pre>";print_r($result);
     ////        die;
     //        if ($result['ACK'] == "Success") {
     //            $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID'];
     //            $data['acknowledgement'] = $result['ACK'];
     //            $data['amount'] = $amount;
     //            $data['paymentTime'] = date('Y-m-d H:i:s');
     //        } else {
     //            echo "<pre>";
     //            print_r($result);
     //            die;
     //        }
     //        echo "<pre>";
     //        print_r($data);
     //        die;
 }
Exemplo n.º 8
0
 /**
  * Review Add
  * route: checkins/add
  *
  * @param Request $request
  * @return Response
  * @throws Exception
  */
 public function addAction(Request $request)
 {
     $data = $request->only('json', 'fileField');
     $data_photos = $data['fileField'];
     $data_json = json_decode(file_get_contents($data['json']), true);
     if (!isset($data_json['CheckIn']) || !isset($data_json['CheckIn']['user_id']) || !isset($data_json['CheckIn']['restaurant_id']) || !isset($data_json['CheckIn']['message'])) {
         $message = "Format should be: {'CheckIn': {'user_id': <int>, 'restaurant_id': <int>, 'message': <string>}, 'Photos': []}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // check for valid data
     //Check if restaurant ID is existing
     $restaurant = Restaurants::find($data_json['CheckIn']['restaurant_id']);
     if (!$restaurant) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data_json['CheckIn']['message']);
     if ($ng_words) {
         $message = "Bad words found: " . implode(', ', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     // check of Ng Words
     try {
         DB::beginTransaction();
         // Save Checkin Data
         $checkin = new CheckIns();
         $new_checkin = $checkin->addCheckin($data_json['CheckIn']);
         // Save and Upload Photo
         $photos_upload = new Photos();
         $photos_upload->saveUploadedPhotos($data_photos, $data_json['CheckIn'], CONSTANTS::CHECKIN, $new_checkin->id);
         // Send Notification to Followers about the new Checkin
         $followers = Follow::getFollowerUsersAll($new_checkin->user_id);
         $notification = new Notification();
         foreach ($followers as $follower) {
             $notification->addNotificationNewCheckin($new_checkin->user_id, $follower->follower_user_id, $new_checkin->id, $new_checkin->restaurant_id);
         }
         //Add Activity
         $activity = new Activities();
         $new_activity = $activity->addActivity(CONSTANTS::CHECKIN, $new_checkin->id, $new_checkin->user_id, $new_checkin->restaurant_id);
         $photos = Photos::getByType(CONSTANTS::CHECKIN, $new_checkin->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $user = Users::find($new_checkin->user_id);
         $json_return[KeyParser::data] = array(KeyParser::activity => ModelFormatter::activityFormat($new_activity), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::checkin => ModelFormatter::checkinFormat($new_checkin), KeyParser::photos => $photos_array);
         //DB Commit
         DB::commit();
         return response()->json($json_return);
     } catch (\Exception $e) {
         DB::rollback();
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }
Exemplo n.º 9
0
 /**
  * Upload Photo Routine for Restaurant
  * route: photos/upload/restaurant
  *
  * @param Request $request
  * @return Mixed
  */
 public function photoUploadRestaurantAction(Request $request)
 {
     $data = $request->only('json', 'fileField');
     $data_photos = $data['fileField'];
     $data_json = json_decode(file_get_contents($data['json']), true);
     try {
         DB::beginTransaction();
         foreach ($data_json['Photos'] as $data_json_photo) {
             foreach ($data_photos as $key => $data_photo) {
                 $photo_text = "";
                 if (isset($data_json_photo['Photo']['text'])) {
                     $photo_text = $data_json_photo['Photo']['text'];
                     // Check Ng Words
                     $ng_words = NgWord::ngword_filter($photo_text);
                     if ($ng_words) {
                         $message = "Bad word(s) found: " . implode(' ', $ng_words);
                         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
                     }
                     // check of Ng Words
                 }
                 $data_photos[$key]->text = $photo_text;
             }
         }
         $restaurant_id = $data_json['Restaurant']['restaurant_id'];
         $user_id = $data_json['Restaurant']['user_id'];
         // Save and Upload Photo
         $photos_upload = new Photos();
         $success_photo = $photos_upload->saveUploadedPhotos($data_photos, $data_json['Restaurant'], CONSTANTS::RESTAURANT, $restaurant_id);
         $followers = Follow::getFollowerUsersAll($user_id);
         $notification = new Notification();
         //Add Activity
         foreach ($success_photo as $photo) {
             $activity = new Activities();
             $activity->addActivity(CONSTANTS::PHOTO_UPLOAD_RESTAURANT, $photo->id, $user_id, $restaurant_id);
             foreach ($followers as $follower) {
                 $notification->addNotificationNewPhoto($user_id, $follower->follower_user_id, $photo->id, $restaurant_id);
             }
         }
         $photos_array = Photos::convertPhotosToArray($success_photo);
         $restaurant = Restaurants::find($restaurant_id);
         $user = Users::find($user_id);
         $json_return[KeyParser::data] = array(KeyParser::activity => ModelFormatter::activityFormat($activity), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         DB::commit();
         return response()->json($json_return);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }
Exemplo n.º 10
0
 /**
  * Add new comment to table
  *
  * @param $text
  * @param $type
  * @param $type_id
  * @param $user_id
  * @throws \Exception
  */
 public function addComment($text, $type, $type_id, $user_id)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $type_object = null;
         switch ($type) {
             case CONSTANTS::REVIEW:
                 $type_object = Reviews::find($type_id);
                 if (!$type_object) {
                     //Review not Found
                     throw new \Exception(CONSTANTS::ERROR_CODE_REVIEW_MISSING);
                 }
                 $this->type = CONSTANTS::REVIEW;
                 $comment_type = CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_REVIEW;
                 break;
             case CONSTANTS::CHECKIN:
                 $type_object = CheckIns::find($type_id);
                 if (!$type_object) {
                     throw new \Exception(CONSTANTS::ERROR_CODE_CHECKIN_MISSING);
                 }
                 $this->type = CONSTANTS::CHECKIN;
                 $comment_type = CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_CHECKIN;
                 break;
             case CONSTANTS::PHOTO:
                 $type_object = Photos::find($type_id);
                 if (!$type_object) {
                     throw new \Exception(CONSTANTS::ERROR_CODE_PHOTO_MISSING);
                 }
                 $this->type = CONSTANTS::PHOTO;
                 $comment_type = CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_PHOTO;
                 break;
             default:
                 throw new \Exception(CONSTANTS::ERROR_CODE_INVALID_TYPE);
         }
         $this->type_id = $type_id;
         $this->comment = $text;
         $this->status = CONSTANTS::STATUS_ENABLED;
         $this->user_id = $user_id;
         $this->date_created = date('Y-m-d H:i:s');
         $this->save();
         $restaurant_id = $type_object['restaurant_id'];
         $owner_id = $type_object['user_id'];
         if ($user_id != $owner_id) {
             $notification_data = new Notification();
             $notification_data->addCommentNotification($user_id, $owner_id, $comment_type, $type_id, $restaurant_id);
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Exemplo n.º 11
0
 /**
  * Get the review, checkin, bookmark, follow, photos, comments, and notification data of a user
  *
  * @param $id
  * @param $viewer_id
  * @return array
  */
 public static function getStatistics($id, $viewer_id = false)
 {
     $user = self::find($id);
     if (!$user) {
         return array();
     }
     $user_array = ModelFormatter::userLongFormat($user);
     $user_array[KeyParser::review_count] = Reviews::getCountByUserId($id);
     $user_array[KeyParser::checkin_count] = CheckIns::getCountByUserId($id);
     $user_array[KeyParser::bookmark_count] = Bookmarks::getCountByUserId($id);
     $user_array[KeyParser::following_count] = Follow::getCountByUserId($id, CONSTANTS::FOLLOW_FOLLOWED);
     $user_array[KeyParser::follower_count] = Follow::getCountByUserId($id, CONSTANTS::FOLLOW_FOLLOWER);
     $user_array[KeyParser::photo_count] = Photos::getCountByUserId($id);
     $user_array[KeyParser::comment_count] = Comments::getCountByUserId($id);
     $user_array[KeyParser::unread_notification_count] = Notification::getNotificationByUserToCustomPaginate(CONSTANTS::NOTIFICATION_STATUS_UNREAD, CONSTANTS::ORDER_DESC, $id, null, true);
     $user_array[KeyParser::new_notification_count] = Notification::getNotificationByUserToCustomPaginate(CONSTANTS::NOTIFICATION_STATUS_NEW, CONSTANTS::ORDER_DESC, $id, null, true);
     if ($viewer_id) {
         $user_array[KeyParser::is_followed_by_viewer] = Follow::isFollowed($viewer_id, $id);
     }
     return $user_array;
 }
Exemplo n.º 12
0
 /**
  * Create a new user
  *
  * @param Request $request
  * @return Response
  * @throws FacebookRequestException
  */
 public function addAction(Request $request)
 {
     $data = $request->json()->get('User');
     if (!$data) {
         return showErrorResponse('Incorrect request parameters', HTTP_UNPROCESSABLE_ENTITY);
     }
     try {
         $new_user = new Users();
         $new_user->addUser($data);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     //Send push notifications to all Facebook friends who are using Masarap
     $fb_access_token = $data[CONSTANTS::KEY_FB_ACCESS_TOKEN];
     if (!$fb_access_token) {
         return showErrorResponse('Failed to access Facebook account');
     }
     FacebookSession::setDefaultApplication(Config::get('services.facebook.client_id'), Config::get('services.facebook.client_secret'));
     FacebookSession::enableAppSecretProof(false);
     $facebook_session = new FacebookSession($fb_access_token);
     $facebook_response = (new FacebookRequest($facebook_session, 'GET', '/me/friends/'))->execute();
     $friend_list = $facebook_response->getResponse();
     $failed_notifications = array();
     foreach ($friend_list->data as $friend) {
         $friend_user = Users::getByFbId($friend->id);
         if (!$friend_user) {
             continue;
         }
         $params = array(CONSTANTS::KEY_USER_ID_FROM => $new_user->id, CONSTANTS::KEY_USER_ID_TO => $friend_user->id, CONSTANTS::KEY_TYPE => CONSTANTS::NOTIFICATION_TYPE_FRIEND_JOIN, CONSTANTS::KEY_TYPE_ID => $new_user->id);
         try {
             $notification = new Notification();
             $notification->addGeneralNotification($params);
         } catch (\Exception $e) {
             $failed_notifications[] = $friend_user->id;
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::user => ModelFormatter::userLongFormat($new_user), KeyParser::message => 'User successfully registered and push notifications are sent to Facebook friends', KeyParser::unsent_notifications => $failed_notifications);
     return response()->json($json_return);
 }
Exemplo n.º 13
0
 /**
  * Review Add
  * route: reviews/add
  *
  * @param Request $request
  * @return Response
  * @throws Exception
  */
 public function addAction(Request $request)
 {
     $json = Input::get('json', '');
     $data = $request->only('json', 'fileField');
     $data_photos = $data['fileField'];
     if ($json) {
         $data_json['Review'] = $request->json()->get('Review');
     } else {
         $data_json = json_decode(file_get_contents($data['json']), true);
     }
     if (!isset($data_json['Review']) || !isset($data_json['Review']['user_id']) || !isset($data_json['Review']['restaurant_id']) || !isset($data_json['Review']['title']) || !isset($data_json['Review']['text']) || !isset($data_json['Review']['rating'])) {
         $message = "Format {'Review': {'user_id': <int>, 'restaurant_id': <int>, 'title': <string>, 'text': <string>, 'rating': <double>}, 'Photos': []}";
         return showErrorResponse($message);
     }
     // check fo valid data
     if (!Restaurants::isExists($data_json['Review']['restaurant_id'])) {
         return showErrorResponse("Restaurant data not found", HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     if (!in_array($data_json['Review']['rating'], array('0.5', '1.0', '1', '1.5', '2.0', '2', '2.5', '3.0', '3', '3.5', '4.0', '4', '4.5', '5.0', '5'))) {
         $message = "Rating must not be 0. Any of 0.5, 1.0, 1.5, ..., 5.0";
         return showErrorResponse($message);
     }
     // check for rating value
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data_json['Review']['title'] . ' ' . $data_json['Review']['text']);
     if ($ng_words) {
         $message = "Bad word(s) found: " . implode(' ', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     // check of Ng Words
     try {
         DB::beginTransaction();
         // Save Review Data
         $review = new Reviews();
         $new_review = $review->addReview($data_json['Review']);
         // Save and Upload Photo
         $photos_upload = new Photos();
         $photos_upload->saveUploadedPhotos($data_photos, $data_json['Review'], CONSTANTS::REVIEW, $new_review->id);
         //@TODO Restaurant Rating Implementation create a cron job for Rating Implementation
         // Send Notification to Followers about the new Review
         $followers = Follow::getFollowerUsersAll($new_review->user_id);
         foreach ($followers as $follower) {
             $notification = new Notification();
             $notification->addNotificationNewReview($new_review->user_id, $follower->follower_user_id, $new_review->id, $new_review->restaurant_id);
         }
         //Add Activity
         $activity = new Activities();
         $new_activity = $activity->addActivity(CONSTANTS::REVIEW, $new_review->id, $new_review->user_id, $new_review->restaurant_id);
         $photos = Photos::getByType(CONSTANTS::REVIEW, $new_review->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $restaurant = Restaurants::find($new_review->restaurant_id);
         $user = Users::find($new_review->user_id);
         $json_return[KeyParser::data] = array(KeyParser::activity => ModelFormatter::activityFormat($new_activity), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::review => ModelFormatter::reviewFormat($new_review), KeyParser::photos => $photos_array);
         DB::commit();
         return response()->json($json_return);
     } catch (\Exception $e) {
         DB::rollback();
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }