/**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * Displays individual restaurant information
  * route: /restaurants/{restaurant_id}/{viewer_id?}
  *
  * @param id - restaurant ID
  * @param viewer_id - user ID of the viewer (Optional)
  * @return Response
  */
 public function viewAction($id)
 {
     $viewer_id = Input::get('viewer_id', null);
     $restaurant = Restaurants::find($id);
     $data = array();
     if ($restaurant) {
         $restaurant->view_count++;
         $restaurant->save();
         $restaurant_categories = RestaurantsCategory::getByRestaurantId($id);
         $photos = Photos::getByRestaurantId($id);
         $is_bookmarked = Bookmarks::isBookmarked($viewer_id, $restaurant->id);
         $data[KeyParser::restaurant] = ModelFormatter::restaurantViewFormat($restaurant, $is_bookmarked);
         foreach ($photos as $photo) {
             $data[KeyParser::photos][] = ModelFormatter::photosFormat($photo);
         }
         $data[KeyParser::categories] = Categories::getFormattedRestaurantCategories($restaurant->id);
         Categories::getFormattedRestaurantCategories($restaurant->id);
         $latest_activity = Activities::getLatestRestaurantActivity($id);
         if ($latest_activity) {
             $data[KeyParser::activity] = ModelFormatter::activityRestaurantViewFormat($latest_activity);
             $data[KeyParser::user] = Users::getStatistics($id);
             $data += Activities::getActivityType($latest_activity->type, $latest_activity->type_id);
         }
     }
     $recently_viewed = array();
     if ($viewer_id) {
         $where = array('user_id' => $viewer_id, 'restaurant_id' => $id);
         $rv = LogRecentlyViewed::where($where)->get()->first();
         if ($rv) {
             $rv->date_modified = date('Y-m-d H:i:s');
             $rv->save();
         }
         $rv = new LogRecentlyViewed();
         $rv->addNewLog($viewer_id, $id);
     }
     $json_return[KeyParser::data] = $data;
     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 #5
0
 /**
  * Build message for notification payload
  *
  * @return string
  */
 public function buildMessage()
 {
     $type = $this->type;
     $user_from = Users::find($this->user_id_from);
     $username_from = $user_from->getUserFullName();
     $restaurant_name = '';
     if ($this->restaurant_id != 0) {
         $restaurant = Restaurants::find($this->restaurant_id);
         $restaurant_name = $restaurant->name;
     }
     switch ($type) {
         case CONSTANTS::NOTIFICATION_TYPE_NEW_FOLLOWER:
             $message = "{$username_from} is now following you!";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_LIKE_REVIEW:
             $message = "{$username_from} liked your review.";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_LIKE_CHECKIN:
             $message = "{$username_from} liked your check-in at {$restaurant_name}.";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_LIKE_PHOTO:
             $message = "{$username_from} liked your photo";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_FRIEND_JOIN:
             $message = "Your facebook friend, {$username_from} started using Masarap!";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_CHECKIN:
             $message = "{$username_from} commented on your check-in at {$restaurant_name}.";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_PHOTO:
             $message = "{$username_from} commented on your photo.";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_REVIEW:
             $message = "{$username_from} commented on your review.";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_FOLLOWING_CHECKIN:
             $message = "{$username_from} checked in at {$restaurant_name}.";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_FOLLOWING_REVIEW:
             $message = "{$username_from} posted a review about {$restaurant_name}.";
             break;
         case CONSTANTS::NOTIFICATION_TYPE_UPLOADED_PHOTO:
             $message = "{$username_from} added a new photo for {$restaurant_name}.";
             break;
         default:
             $message = "You have new updates from Masarap.";
     }
     return $message;
 }
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 #7
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;
 }
 /**
  * Delete a restaurant and all data associated with it
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function deleteAction(Request $request)
 {
     try {
         $errors = array();
         if (!$request->isMethod('POST')) {
             throw new Exception('Must be a POST request.');
         }
         $is_ajax = $request->ajax();
         $connection = DB::connection();
         $connection->beginTransaction();
         $restaurant_id = $request->input('id');
         $restaurant = Restaurants::find($restaurant_id);
         if (!$restaurant) {
             throw new Exception('Restaurant not found');
         }
         $bookmarks = Bookmarks::where('restaurant_id', $restaurant_id);
         if ($bookmarks->get()->count()) {
             $bookmarks->delete();
         }
         $check_ins = CheckIns::where('restaurant_id', $restaurant_id);
         if ($check_ins->get()->count()) {
             $check_ins->delete();
         }
         $photos = PhotosCms::where('restaurant_id', $restaurant_id);
         if ($photos->get()->count()) {
             $photos->delete();
         }
         $restaurants_category = RestaurantsCategory::where('restaurant_id', $restaurant_id);
         if ($restaurants_category->get()->count()) {
             $restaurants_category->delete();
         }
         $reviews = Reviews::where('restaurant_id', $restaurant_id);
         if ($reviews->get()->count()) {
             $reviews->delete();
         }
         $restaurant->delete();
         $connection->commit();
         if ($is_ajax) {
             header('Content-Type: application/json');
             $success[] = 'Restaurant ID ' . $restaurant_id . ' has been deleted';
             echo json_encode(array('success' => $success));
             exit;
         } else {
             $success[] = 'Restaurant ID ' . $restaurant_id . ' has been deleted';
             \Session::flush('success', $success);
             return redirect()->back();
         }
     } catch (Exception $e) {
         $connection->rollBack();
         if ($is_ajax) {
             header('Content-Type: application/json');
             $errors[] = $e->getMessage();
             \Session::flush('errors', $errors);
             echo json_encode(array('errors' => $e->getMessage()));
             exit;
         } else {
             $errors[] = $e->getMessage();
             \Session::flush('errors', $errors);
             return redirect()->back();
         }
     }
 }
Exemple #9
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;
 }
Exemple #10
0
 /**
  * @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 #11
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
 }
 /**
  * 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);
 }
Exemple #13
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);
 }