Beispiel #1
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);
 }
Beispiel #2
0
 /**
  * Output JSON output of comments in a checkin
  *
  * @param $id
  * @return Response
  */
 public function viewByCheckinAction($id)
 {
     $checkin = CheckIns::find($id);
     if (!$checkin) {
         return showErrorResponse('Checkin not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_CHECKIN_MISSING);
     }
     if (!Restaurants::isExists($checkin->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::CHECKIN, $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::CHECKIN, $id);
         $json_return[KeyParser::page] = array(KeyParser::current => $comments->currentPage(), KeyParser::number => $comments->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;
}
 /**
  * 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();
         }
     }
 }
Beispiel #5
0
 /**
  * Delete Checkin
  * @param $id
  * @throws $e
  */
 public function deleteCheckin($id)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $checkin = CheckIns::find($id);
         if ($checkin) {
             //delete checkin
             $checkin->delete();
             //delete activities
             $activities = new Activities();
             $activities->deleteActivity(CONSTANTS::CHECKIN, $id);
             //delete comments
             $comments = new Comments();
             $comments->deleteCommentByType(CONSTANTS::CHECKIN, $id);
             //delete likes
             $like = new Like();
             $like->deleteLikes(CONSTANTS::CHECKIN, $id);
         } else {
             throw new \Exception('No checkin found');
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Beispiel #6
0
 /**
  * Review Delete
  * route: checkin/delete/{id}
  *
  * @param $id
  * @return request
  */
 public function deleteAction($id)
 {
     try {
         $checkin = new CheckIns();
         $checkin->deleteCheckin($id);
         $json_return[KeyParser::data] = array(KeyParser::id => $id, KeyParser::is_success => CONSTANTS::DELETE_SUCCESS);
     } catch (\Exception $e) {
         $message = "Failed to delete checkin with ID {$id}";
         return showErrorResponse($message);
     }
     return response()->json($json_return);
 }
Beispiel #7
0
 /**
  * Returns an array of restaurant data for use /bookmarks/user/{user_id} API
  *
  * @param Restaurants $data
  * @return array
  */
 public static function restaurantBookmarkListViewFormat(Restaurants $data)
 {
     $short_restaurant_url = route('short_restaurant_view', ['encoded_id' => recordEncode($data->id)]);
     $array_return = array(KeyParser::id => $data->id, KeyParser::name => $data->name, KeyParser::short_url => $short_restaurant_url, KeyParser::address => $data->address, KeyParser::telephone => $data->telephone, KeyParser::budget => $data->budget, KeyParser::can_deliver => $data->can_deliver, KeyParser::can_dinein => $data->can_dinein, KeyParser::can_dineout => $data->can_dineout, KeyParser::is_24hours => $data->is_24hours, KeyParser::operating_to => $data->operating_to, KeyParser::operating_from => $data->operating_from, KeyParser::smoking => $data->smoking, KeyParser::credit_card => $data->credit_card, KeyParser::longitude => $data->longitude, KeyParser::latitude => $data->latitude, KeyParser::rating => $data->rating, KeyParser::review_count => Reviews::getByRestaurantId($data->id)->count(), KeyParser::checkin_count => CheckIns::getByRestaurantId($data->id)->count(), KeyParser::view_count => $data->view_count, KeyParser::status_close => $data->status_close, KeyParser::status_verify => $data->status_verify, KeyParser::user_id => $data->user_id, KeyParser::thumbnail => $data->thumbnail);
     return $array_return;
 }
Beispiel #8
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;
     }
 }
Beispiel #9
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;
 }
Beispiel #10
0
 /**
  * Returns either review, checkin, or bookmark activity based on $type parameter.
  *
  * @param $type - activity type. Either 'checkin', 'review', or 'bookmark'
  * @param $type_id - ID for checkin/review/bookmark activity
  * @return mixed
  */
 public static function getActivityType($type, $type_id)
 {
     $arr = array();
     switch ($type) {
         case CONSTANTS::CHECKIN:
             $check_in = CheckIns::find($type_id);
             if ($check_in) {
                 $arr[KeyParser::checkin] = ModelFormatter::checkinFormat($check_in);
             } else {
                 $arr[KeyParser::checkin] = array();
             }
             $photos = Photos::getByType(CONSTANTS::CHECKIN, $type_id);
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
         case CONSTANTS::REVIEW:
             $review = Reviews::find($type_id);
             if ($review) {
                 $arr[KeyParser::review] = ModelFormatter::reviewFormat($review);
             } else {
                 $arr[KeyParser::review] = array();
             }
             $photos = Photos::getByType(CONSTANTS::REVIEW, $type_id);
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
         case CONSTANTS::PHOTO_UPLOAD_RESTAURANT:
             $photos = Photos::where('id', $type_id)->get();
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
     }
     unset($photos_arr);
     return $arr;
 }