Exemple #1
0
 /**
  * Get comment count by user id
  *
  * @param $user_id
  * @return mixed
  */
 public static function getCountByUserId($user_id)
 {
     $user_comments = self::where('user_id', $user_id)->get();
     $user_valid_comments = 0;
     foreach ($user_comments as $user_comment) {
         switch ($user_comment->type) {
             case CONSTANTS::REVIEW:
                 $review = Reviews::find($user_comment->type_id);
                 if ($review && Restaurants::isExists($review->restaurant_id)) {
                     $user_valid_comments++;
                 }
                 break;
             case CONSTANTS::CHECKIN:
                 $checkin = CheckIns::find($user_comment->type_id);
                 if ($checkin && Restaurants::isExists($checkin->restaurant_id)) {
                     $user_valid_comments++;
                 }
                 break;
             case CONSTANTS::PHOTO:
                 $photo = Photos::find($user_comment->type_id);
                 if ($photo && Restaurants::isExists($photo->restaurant_id)) {
                     $user_valid_comments++;
                 }
                 break;
         }
     }
     return $user_valid_comments;
 }
 /**
  * Display restaurants having a particular category
  *
  * @param $id
  * @return \Illuminate\View\View
  */
 public function viewAction($id)
 {
     $data = array();
     if (!$id) {
         $data['errors'][] = 'Invalid ID';
     } else {
         $data['id'] = $id;
     }
     $category = Categories::find($id);
     if (!$category) {
         $data['errors'][] = 'Category not found.';
         return view('cms.category.view', $data);
     }
     $restaurants_category = RestaurantsCategory::where('category_id', $id)->get();
     if ($restaurants_category) {
         $restaurants = array();
         foreach ($restaurants_category as $restaurant_category) {
             $restaurant = Restaurants::find($restaurant_category->restaurant_id);
             if (!$restaurant) {
                 $data['errors'][] = 'Cannot find restaurant ID ' . $restaurant->id . '.';
                 return view('cms.category.view', $data);
             }
             $restaurants[] = array('id' => $restaurant->id, 'name' => $restaurant->name, 'address' => $restaurant->address, 'telephone' => $restaurant->telephone, 'rating' => $restaurant->rating, 'budget' => $restaurant->budget);
             $restaurant = null;
         }
         $data['restaurants'] = $restaurants;
     }
     $data['page_title'] = ': ' . $category->name;
     return view('cms.category.view', $data);
 }
 /**
  * Display the list of menu
  *
  * @param $restaurant_id
  * @return \Illuminate\View\View
  */
 public function viewAction($restaurant_id)
 {
     $restaurant = Restaurants::find($restaurant_id);
     $menu = MenuCms::where('restaurant_id', $restaurant_id)->get();
     $data = array('menu' => $menu->count() ? $menu : [], 'restaurant' => $restaurant, 'stylesheets' => array('data_table'), 'javascripts' => array('data_table', 'menu'));
     return view('cms.menu.view', $data);
 }
Exemple #4
0
 /**
  * Add like on review, checkin or photo
  *
  * @param $request
  * @return mixed
  */
 public function addAction(Request $request)
 {
     $data = $request->json()->get('Like');
     $type = $data['type'];
     $type_id = $data['type_id'];
     $user_id = $data['user_id'];
     $user_data = Users::find($user_id);
     if (is_null($user_data)) {
         return showErrorResponse('Invalid user');
     }
     $is_liked = Like::isLiked($user_id, $type, $type_id);
     if ($is_liked) {
         $like_count = Like::getCount($type, $type_id);
         $json_return[KeyParser::data] = array(KeyParser::type => $type, KeyParser::type_id => $type_id, KeyParser::user_id => $user_id, KeyParser::is_existing => CONSTANTS::LIKE_IS_EXISTING, KeyParser::like_count => $like_count);
         return response()->json($json_return);
     }
     switch ($type) {
         case CONSTANTS::REVIEW:
             $like_object = Reviews::find($type_id);
             $like_type = CONSTANTS::NOTIFICATION_TYPE_LIKE_REVIEW;
             if (!$like_object) {
                 $status_code = CONSTANTS::ERROR_CODE_REVIEW_MISSING;
             }
             break;
         case CONSTANTS::CHECKIN:
             $like_object = CheckIns::find($type_id);
             $like_type = CONSTANTS::NOTIFICATION_TYPE_LIKE_CHECKIN;
             if (!$like_object) {
                 $status_code = CONSTANTS::ERROR_CODE_CHECKIN_MISSING;
             }
             break;
         case CONSTANTS::PHOTO:
             $like_object = Photos::find($type_id);
             $like_type = CONSTANTS::NOTIFICATION_TYPE_LIKE_PHOTO;
             if (!$like_object) {
                 $status_code = CONSTANTS::ERROR_CODE_PHOTO_MISSING;
             }
             break;
         default:
             return showErrorResponse('Invalid type', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_INVALID_TYPE);
     }
     if (!isset($like_object)) {
         return showErrorResponse('Invalid type id', HTTP_ACCEPTED, $status_code);
     }
     if (!Restaurants::isExists($like_object->restaurant_id)) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     try {
         $like_data = new Like();
         $query_response = $like_data->addLike($type_id, $type, $user_id, $like_object, $like_type);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     $json_return[KeyParser::data] = array(KeyParser::type => $query_response->type, KeyParser::type_id => $query_response->type_id, KeyParser::user_id => $query_response->user_id, KeyParser::is_existing => CONSTANTS::LIKE_IS_NOT_EXISTING, KeyParser::like_count => Like::getCount($type, $type_id));
     return response()->json($json_return);
 }
 /**
  * Returns the nearby restaurant activities of the user base on location
  * route: /activities/restaurant/near/{longitude}/{latitude}/{distance}
  * get user_id parameter to exclude current user data to show in teh activities
  *
  * @param $longitude
  * @param $latitude
  * @param $distance
  * @return response
  */
 public function getNearRestaurantActivitiesAction($longitude, $latitude, $distance)
 {
     $viewer_id = Input::get('viewer_id', 0);
     $restaurant_ids = array();
     $near_restaurant = Restaurants::getNearbyRestaurants($longitude, $latitude, $distance, CONSTANTS::RESTAURANTS_GET_NEARBY_PAGINATION_LIMIT);
     // get restaurant ids
     foreach ($near_restaurant as $restaurant) {
         $restaurant_ids[] = $restaurant->id;
     }
     $restaurant_activities = Activities::getRestaurantsActivities($restaurant_ids, $viewer_id);
     $activitiesArray = Activities::activitiesQueries($restaurant_activities);
     $page[KeyParser::current] = $restaurant_activities->currentPage();
     $page[KeyParser::number] = $restaurant_activities->lastPage();
     $json_return = array(KeyParser::data => $activitiesArray, KeyParser::page => $page);
     return response()->json($json_return);
 }
 /**
  * Returns restaurants recently viewed by a user
  *
  * @param $user_id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getAction($user_id)
 {
     $json_return = array();
     if (!$user_id) {
         return showErrorResponse('Invalid user_id');
     }
     $recently_viewed_data = LogRecentlyViewed::getByUserId($user_id);
     $recently_viewed_data = $recently_viewed_data->toArray();
     $page_data = $recently_viewed_data;
     unset($page_data['data']);
     $recently_viewed_data = $recently_viewed_data['data'];
     $recently_viewed = array();
     $restaurant = null;
     foreach ($recently_viewed_data as $rvd) {
         $restaurant = Restaurants::find($rvd['restaurant_id']);
         if ($restaurant) {
             $recently_viewed[] = ModelFormatter::restaurantFormat($restaurant);
         }
         $restaurant = null;
     }
     $json_return = array(KeyParser::data => $recently_viewed, KeyParser::page => array(KeyParser::current => $page_data['current_page'], KeyParser::number => $page_data['last_page']));
     return response()->json($json_return);
 }
Exemple #7
0
 public static function restaurantSearch($params)
 {
     $longitude = isset($params['long']) ? $params['long'] : 0;
     $latitude = isset($params['lat']) ? $params['lat'] : 0;
     $review_count_query = "(SELECT COUNT(id) FROM reviews WHERE reviews.restaurant_id = restaurants.id)";
     $checkin_count_query = "(SELECT COUNT(id) FROM check_ins WHERE check_ins.restaurant_id = restaurants.id)";
     $restaurants = Restaurants::select('restaurants.*', DB::raw("{$review_count_query} AS review_count"), DB::raw("{$checkin_count_query} AS checkin_count"));
     if (isset($params['name'])) {
         $restaurants->where('restaurants.name', 'LIKE', '%' . substr($params['name'], 0, 30) . '%');
     }
     if (isset($params['address'])) {
         $restaurants->where('restaurants.address', 'LIKE', '%' . substr($params['address'], 0, 30) . '%');
     }
     if (isset($params['tag']) && $params['tag'] != '') {
         $tag = $params['tag'];
         $restaurants->leftJoin('restaurants_category', 'restaurants.id', '=', 'restaurants_category.restaurant_id')->where('restaurants_category.category_id', $tag);
     }
     $search_results = $restaurants->paginate(CONSTANTS::RESTAURANTS_PARTIAL_SEARCH_PAGINATION_LIMIT);
     $distances = array();
     $data = array();
     foreach ($search_results as $count => $restaurant) {
         if ($restaurant['id'] == NULL) {
             continue;
         }
         if ($longitude > 0 && $latitude > 0) {
             $restaurant->distance = 3956 * 2 * asin(sqrt(pow(sin(($latitude - $restaurant->latitude) * pi() / 180 / 2), 2) + cos($latitude * pi() / 180) * cos($restaurant->latitude * pi() / 180) * pow(sin(($longitude - $restaurant->longitude) * pi() / 180 / 2), 2)));
         } else {
             $restaurant->distance = 0;
         }
         $data[$count]['restaurant'] = ModelFormatter::restaurantSearchFormat($restaurant);
         $distances[$count] = $restaurant->distance;
         $data[$count][KeyParser::categories] = Categories::getFormattedRestaurantCategories($restaurant->id);
     }
     array_multisort($distances, SORT_ASC, $data);
     $page = array(KeyParser::current => $search_results->currentPage(), KeyParser::number => $search_results->lastPage());
     return array(KeyParser::data => $data, KeyParser::page => $page);
 }
Exemple #8
0
 /**
  * Construct the needed Array for Checkins User and Restaurant
  * action:
  *
  * @param $checkins
  * @return mixed
  */
 public static function checkinsQueries($checkins)
 {
     $checkins_array = array();
     if (!$checkins) {
         return $checkins_array;
     }
     foreach ($checkins as $checkin) {
         $restaurant = Restaurants::find($checkin->restaurant_id);
         if (!$restaurant) {
             continue;
         }
         $user = Users::find($checkin->user_id);
         $photos = Photos::getByType(CONSTANTS::CHECKIN, $checkin->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $checkins_array[] = array(KeyParser::checkin => ModelFormatter::checkinFormat($checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         unset($restaurant);
         unset($user);
         unset($photos);
         unset($photos_array);
     }
     //end foreach
     return $checkins_array;
 }
 /**
  * @param Request $request
  * @param $id
  * @return Response
  * @throws Exception
  */
 public function editAction(Request $request, $id)
 {
     /* Multipart Procedure
        $data = $request->only('json');
        $data_json = json_decode(file_get_contents($data['json']), true);
        */
     $data_json['CheckIn'] = $request->json()->get('CheckIn');
     if (!isset($data_json['CheckIn']) || !isset($data_json['CheckIn']['message'])) {
         $message = "Format should be: {'CheckIn': 'message': <string>}}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // check fo valid data
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data_json['CheckIn']['message']);
     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 {
         // Edit Review Data
         $checkin = new Checkins();
         $edit_checkin = $checkin->editCheckin($id, $data_json['CheckIn']);
         $photos = Photos::getByType(CONSTANTS::CHECKIN, $edit_checkin->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $restaurant = Restaurants::find($edit_checkin->restaurant_id);
         if (!$restaurant) {
             return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
         }
         $user = Users::find($edit_checkin->user_id);
         $json_return[KeyParser::data] = array(KeyParser::checkin => ModelFormatter::checkinFormat($edit_checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         return response()->json($json_return);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }
Exemple #10
0
 /**
  * Output JSON output of comments in a photo
  *
  * @param $id
  * @return Response
  */
 public function viewByPhotoIdAction($id)
 {
     $photo = Photos::find($id);
     if (!$photo) {
         return showErrorResponse('Photo not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_PHOTO_MISSING);
     }
     if (!Restaurants::isExists($photo->restaurant_id)) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     $json_return = array(KeyParser::data => array(), KeyParser::comment_count => 0, KeyParser::page => array());
     $comments = Comments::getByTypePaginate(CONSTANTS::PHOTO, $id);
     if ($comments->count()) {
         foreach ($comments as $comment) {
             $json_return[KeyParser::data][] = array(KeyParser::comment => ModelFormatter::commentFormat($comment), KeyParser::user => Users::find($comment->user_id));
         }
         $json_return[KeyParser::comment_count] = Comments::getCountByType(CONSTANTS::PHOTO, $id);
         $json_return[KeyParser::page] = array(KeyParser::current => $comments->currentPage(), KeyParser::number => $comments->lastPage());
     }
     return response()->json($json_return);
 }
 /**
  * get all of the bookmarks of a user
  * /bookmarks/user/{user_id}
  *
  * @param $user_id
  * @return Response
  */
 public function userBookmarkListAction($user_id)
 {
     if (!is_numeric($user_id)) {
         return showErrorResponse('Incorrect User ID format');
     }
     $bookmark_list = Bookmarks::getBookmarkByUserId($user_id);
     $user_data = Users::find($user_id);
     $json_return[KeyParser::data] = array();
     if ($bookmark_list) {
         foreach ($bookmark_list as $bookmark) {
             $restaurant_data = Restaurants::find($bookmark->restaurant_id);
             if ($restaurant_data) {
                 $json_return[KeyParser::data][] = array(KeyParser::bookmark => ModelFormatter::bookmarkFormat($bookmark), KeyParser::user => ModelFormatter::userFormat($user_data), KeyParser::restaurant => ModelFormatter::restaurantBookmarkListViewFormat($restaurant_data), KeyParser::categories => Categories::getFormattedRestaurantCategories($bookmark->restaurant_id));
             }
         }
     }
     $json_return[KeyParser::page] = array(KeyParser::current => $bookmark_list->currentPage(), KeyParser::number => $bookmark_list->lastPage());
     return response()->json($json_return);
 }
function checkTypeId($type, $type_id)
{
    switch ($type) {
        case CONSTANTS::REVIEW:
            $object = Reviews::find($type_id);
            $message = "Review does not exist";
            $error_code = CONSTANTS::ERROR_CODE_REVIEW_MISSING;
            break;
        case CONSTANTS::CHECKIN:
            $object = CheckIns::find($type_id);
            $message = "Checkin does not exist";
            $error_code = CONSTANTS::ERROR_CODE_CHECKIN_MISSING;
            break;
        case CONSTANTS::BOOKMARK:
            $object = Bookmarks::find($type_id);
            $message = "Bookmark does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::COMMENT:
            $object = Comments::find($type_id);
            $message = "Comment does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::PHOTO:
            $object = Photos::find($type_id);
            $message = "Photo does not exist";
            $error_code = CONSTANTS::ERROR_CODE_PHOTO_MISSING;
            break;
        case CONSTANTS::RESTAURANT:
            $object = Restaurants::find($type_id);
            $message = "Restaurant does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case 'user':
            $object = Users::find($type_id);
            $message = "User does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        default:
            return showErrorResponse('Invalid type', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_INVALID_TYPE);
    }
    if (!$object) {
        return showErrorResponse($message, HTTP_ACCEPTED, $error_code);
    }
    return false;
}
Exemple #13
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
 }
Exemple #14
0
 /**
  * Query the users, restaurant, bookmarks, checkins, reviews
  *
  * @param int activities
  * @return mixed
  */
 public static function activitiesQueries($activities)
 {
     $activities_array = array();
     if ($activities->count()) {
         foreach ($activities as $activity) {
             $data = array();
             $data[KeyParser::activity] = ModelFormatter::activityFormat($activity);
             //GetUserInfo
             $user = Users::find($activity->user_id);
             if ($user) {
                 $data[KeyParser::user] = ModelFormatter::userFormat($user);
             } else {
                 $data[KeyParser::user][KeyParser::error] = "No Information";
             }
             //end check user
             //GetRestaurantInfo
             $restaurant = Restaurants::where('status_verify', CONSTANTS::STATUS_VERIFIED)->find($activity->restaurant_id);
             if ($restaurant) {
                 $data[KeyParser::restaurant] = ModelFormatter::restaurantFormat($restaurant);
             } else {
                 $data[KeyParser::restaurant][KeyParser::error] = "No Information";
             }
             // end check restaurant
             $data += self::getActivityType($activity->type, $activity->type_id);
             $activities_array[] = $data;
             unset($data);
         }
         //end foreach
     }
     //end count
     return $activities_array;
 }
 /**
  * Approve suggested restaurant
  *
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function approveSuggestedAction(Request $request)
 {
     DB::transaction(function () use($request) {
         $id = $request->input('id');
         $suggested_restaurant = RestaurantsSuggest::find($id);
         $suggested_restaurant->status_verify = CONSTANTS::STATUS_APPROVED;
         $suggested_restaurant->save();
         // Set the restaurant_id with initial value (90,000)
         $restaurant_id = CONSTANTS::SUGGESTED_RESTAURANT_INITIAL_ID;
         $restaurant_max_id = Restaurants::max('id');
         if ($restaurant_id <= $restaurant_max_id) {
             $restaurant_id = ++$restaurant_max_id;
         }
         $suggested_restaurant->id = $restaurant_id;
         $restaurant_cms = new RestaurantsCms();
         $restaurant_cms->addRestaurant($suggested_restaurant);
         $cuisines = explode(', ', $suggested_restaurant->cuisines);
         foreach ($cuisines as $cuisine) {
             $categoriesCms = CategoriesCms::where('name', $cuisine)->first();
             if ($categoriesCms) {
                 $restaurant_category = RestaurantsCategoryCms::getByRestaurantCatId($restaurant_id, $categoriesCms['id']);
             }
             if (!$restaurant_category) {
                 $restaurant_category = new RestaurantsCategoryCms();
                 $restaurant_category->addRestaurantCategory($restaurant_id, $categoriesCms['id']);
             }
         }
         $restaurant_cms->updateRestaurantSlugName();
     });
     return redirect('cms/restaurant/suggested/index')->with('success', 'Successfully added new restaurant!');
 }
Exemple #16
0
 /**
  * Construct the needed Array for Reviews User and Restaurant
  * action: userAction, restaurantAction
  *
  * @param $reviews
  * @return mixed
  */
 public static function reviewsQueries($reviews)
 {
     $reviews_array = array();
     if (!$reviews) {
         return $reviews_array;
     }
     foreach ($reviews as $review) {
         $restaurant = Restaurants::find($review->restaurant_id);
         if (!$restaurant) {
             continue;
         }
         $user = Users::find($review->user_id);
         $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         if ($user) {
             $reviews_array[] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         }
         //end of check user
         unset($restaurant);
         unset($user);
         unset($photos);
         unset($photos_array);
     }
     //end foreach
     return $reviews_array;
 }
 /**
  * Returns list of restaurant names for use in auto-complete
  * route: /restaurants/name_search/{search_key}
  *
  * @param $search_key
  * @return Response
  */
 public function restaurantsAutoCompleteAction($search_key)
 {
     $json_return[KeyParser::data] = Restaurants::getRestaurantNames($search_key);
     return response()->json($json_return);
 }
Exemple #18
0
 /**
  * Send push notification through GCM server
  *
  * @param Array $registration_ids = device_ids
  * @return result
  *
  */
 private function sendToGCM($registration_ids)
 {
     $user_notification_count = $this->getNotificationByUserTo($this->user_id_to, CONSTANTS::NOTIFICATION_STATUS_NEW, true);
     $type = $this->type;
     $activities = array();
     $user_count = 0;
     $username_array = array();
     $activity_type = 0;
     //Time Interval for notification groupings = 1 Day (86400 seconds)
     $date_range = array(KeyParser::date_from => date('Y-m-d H:i:s', time() - CONSTANTS::DAY_SECOND_VALUE), KeyParser::date_to => date('Y-m-d H:i:s'));
     //Build usernames_from array()
     if (strpos($type, 'photo')) {
         $activity_type = 5;
     } elseif (strpos($type, 'checkin')) {
         $activity_type = 2;
     } elseif (strpos($type, 'review')) {
         $activity_type = 1;
     }
     if ($type == CONSTANTS::NOTIFICATION_TYPE_LIKE_CHECKIN || $type == CONSTANTS::NOTIFICATION_TYPE_LIKE_REVIEW || $type == CONSTANTS::NOTIFICATION_TYPE_LIKE_PHOTO) {
         $activities = Like::getLikerList($activity_type, $this->type_id, false, $date_range);
     } else {
         if ($type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_CHECKIN || $type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_REVIEW || $type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_PHOTO) {
             $activities = Comments::getByType($activity_type, $this->type_id, $date_range);
         } else {
             $user_from = Users::find($this->user_id_from);
             $username_array[] = $user_from->getUserFullName();
         }
     }
     foreach ($activities as $activity) {
         if ($activity->user_id == $this->user_id_to) {
             continue;
         }
         $user_count++;
         $user_fullname = Users::getFullNameById($activity->user_id);
         if ($user_count <= CONSTANTS::NOTIFICATION_USER_GROUP_LIMIT && !in_array($user_fullname, $username_array)) {
             $username_array[] = $user_fullname;
         }
     }
     // Build payload
     $payload = array(KeyParser::id => $this->id, KeyParser::usernames_from => $username_array, KeyParser::count => $user_notification_count, KeyParser::type => $this->type, KeyParser::type_id => $this->type_id, KeyParser::restaurant_id => $this->restaurant_id, KeyParser::user_id_from => $this->user_id_from, KeyParser::user_id_to => $this->user_id_to, 'typeid' => '0', 'useridfrom' => '0', 'useridto' => '0', 'restaurantid' => '0', 'message' => $this->buildMessage());
     $restaurant_name = Restaurants::getRestaurantNameById($this->restaurant_id);
     if ($restaurant_name) {
         $payload[KeyParser::restaurant_name] = $restaurant_name;
     }
     $fields = array(KeyParser::registration_ids => $registration_ids, KeyParser::data => $payload);
     $headers = array('Authorization: key=' . GCM_API_KEY, 'Content-Type: application/json');
     //Prepare cURL
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, GCM_API_URL);
     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);
     return $result;
 }
Exemple #19
0
 /**
  * Review View
  * route: reviews/view{id}
  *
  * @param $id
  * @optional ?viewer_id
  * @return Response
  */
 public function viewAction($id)
 {
     $json_return = array();
     $review = Reviews::find($id);
     if (!$review) {
         return showErrorResponse('Review not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_REVIEW_MISSING);
     }
     $restaurant = Restaurants::find($review->restaurant_id);
     if (!$restaurant) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     $user = Users::find($review->user_id);
     $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id);
     $photos_array = Photos::convertPhotosToArray($photos);
     $comments = Comments::getByType(CONSTANTS::REVIEW, $review->id);
     $comments_array = array();
     if ($comments) {
         foreach ($comments as $comment) {
             $comments_array[] = ModelFormatter::commentFormat($comment);
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array, KeyParser::comments => $comments_array);
     return response()->json($json_return);
 }