/** * Output JSON output of comments in a review * * @param $id * @return Response */ public function viewByReviewIdAction($id) { $review = Reviews::find($id); if (!$review) { return showErrorResponse('Review not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_REVIEW_MISSING); } if (!Restaurants::isExists($review->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::REVIEW, $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::REVIEW, $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 Review * @param $id * @throws $e */ public function deleteReview($id) { $connection = $this->getConnection(); try { $connection->beginTransaction(); $review = Reviews::find($id); if ($review) { //delete review $review->delete(); //delete activities $activities = new Activities(); $activities->deleteActivity(CONSTANTS::REVIEW, $id); //delete comments $comments = new Comments(); $comments->deleteCommentByType(CONSTANTS::REVIEW, $id); //delete likes $like = new Like(); $like->deleteLikes(CONSTANTS::REVIEW, $id); } else { throw new \Exception('No review found'); } $connection->commit(); } catch (\Exception $e) { $connection->rollBack(); throw $e; } }
/** * 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(); } } }
/** Returns formatted array of restaurants for nearby restaurants API * * @params $data * @return array */ public static function nearRestaurantFormat($data) { $short_restaurant_url = route('short_restaurant_view', ['encoded_id' => recordEncode($data->id)]); $arr = array(KeyParser::id => $data->id, KeyParser::short_url => $short_restaurant_url, KeyParser::name => $data->name, KeyParser::address => $data->address, KeyParser::thumbnail => $data->thumbnail, KeyParser::rating => $data->rating, KeyParser::budget => $data->budget, KeyParser::review_count => Reviews::getByRestaurantId($data->id)->count(), KeyParser::longitude => $data->longitude, KeyParser::latitude => $data->latitude, KeyParser::distance => $data->distance); return $arr; }
/** * 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; } }
/** * Get the list of users that likes the activity * * @param request $request * @return Response */ public function likerListAction(Request $request) { $viewer_id = $request->viewer_id; $type = $request->type; $type_id = $request->type_id; $error_msg = checkTypeId($type, $type_id); if ($error_msg) { return $error_msg; } $liker_list = Like::getLikerList($type, $type_id); $json_return[KeyParser::data] = array(); if ($liker_list) { foreach ($liker_list as $index => $liker) { $user_id = $liker->user_id; $user_data = Users::find($user_id); if ($user_data) { $array = ModelFormatter::userLongFormat($user_data); $array += array(KeyParser::follower_count => Follow::getCountByUserId($user_id, CONSTANTS::FOLLOW_FOLLOWER), KeyParser::review_count => Reviews::getCountByUserId($user_id), KeyParser::is_followed_by_viewer => Follow::isFollowed($viewer_id, $user_id)); $json_return[KeyParser::data][] = $array; unset($array); } // end of check $user_date } $json_return[KeyParser::like_count] = Like::getCount($type, $type_id); } $json_return[KeyParser::page] = array(KeyParser::current => $liker_list->currentPage(), KeyParser::number => $liker_list->lastPage()); return response()->json($json_return); }
/** * Returns a list of Twitter friends which you have not yet followed * * @param Request $request * @return Response * @throws Exception */ public function followTwitterUsersAction(Request $request) { $json_return[KeyParser::data] = array(KeyParser::users => array(), Keyparser::is_private => CONSTANTS::TWITTER_PUBLIC); $user_id = $request->json()->get('User')['user_id']; $twitter_id = $request->json()->get('User')['twitter_id']; if (!$twitter_id || !$user_id) { return showErrorResponse('Failed to access Twitter account'); } $settings = array('oauth_access_token' => Config::get('services.twitter.oauth_access_token'), 'oauth_access_token_secret' => Config::get('services.twitter.oauth_access_token_secret'), 'consumer_key' => Config::get('services.twitter.consumer_key'), 'consumer_secret' => Config::get('services.twitter.consumer_secret')); $url = 'https://api.twitter.com/1.1/friends/ids.json'; $getfield = "?user_id={$twitter_id}"; $requestMethod = 'GET'; $twitter = new \TwitterAPIExchange($settings); $response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(); $friends = json_decode($response); $twitter_friends = array(); $followed_users = array(); $friend_count = 0; if (isset($friends->error)) { $json_return[KeyParser::data][Keyparser::is_private] = CONSTANTS::TWITTER_PRIVATE; } else { foreach ($friends->ids as $friend_id) { $friend_user = Users::getByTwitterId($friend_id); if (!$friend_user) { continue; } $is_followed = Follow::isFollowed($user_id, $friend_user->id); $follower_count = Follow::getCountByUserId($friend_user->id, CONSTANTS::FOLLOW_FOLLOWER); $review_count = Reviews::getCountByUserId($friend_user->id); if (!$is_followed && $friend_user->id != $user_id) { $twitter_friends[$friend_count] = ModelFormatter::userFormat($friend_user); $twitter_friends[$friend_count] += array(KeyParser::follower_count => $follower_count, KeyParser::review_count => $review_count, KeyParser::is_followed_by_viewer => $is_followed); } elseif ($is_followed && $friend_user->id != $user_id) { $followed_users[$friend_count] = ModelFormatter::userFormat($friend_user); $followed_users[$friend_count] += array(KeyParser::follower_count => $follower_count, KeyParser::review_count => $review_count, KeyParser::is_followed_by_viewer => $is_followed); } $friend_count++; } $twitter_friends = array_merge($twitter_friends, $followed_users); $json_return[KeyParser::data][KeyParser::users] = $twitter_friends; } return response()->json($json_return); }
/** * 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; }
public function review_content(Request $request) { $this->data['review'] = Reviews::where('product_id', $request->product_id)->Paginate(5); return view('product/review_content')->with('data', $this->data); }
public function delete($id) { $product = Product::find($id); $category = Category::where('id', $product->category_id)->first(); $inOrder = OrderDetail::where('product_id', $id)->where('review', null)->get(); $reviews = Reviews::where('product_id', $id)->get(); $subcategory = Subcategory::where('id', $product->subcategory_id)->first(); if (!$product) { return redirect('master/produk/list')->with('error', 'Data tidak ada'); } else { $image = unserialize($product->image); $path = base_path() . '/storage/photo_product/'; if (count($inOrder) > 0) { $product->status = 'unactive'; if ($product->save()) { return redirect('master/produk/list')->with('success', 'Produk tidak bisa di hapus karena masih dalam order, produk sementara di non aktifkan'); } else { return redirect('master/produk/list')->with('error', '404'); } } elseif (count($inOrder) == 0) { if ($product->delete()) { foreach ($reviews as $review) { $reviews->delete(); } foreach ($inOrder as $order_product) { foreach ($order_product as $orders) { $PaymentConfirmation = PaymentConfirmation::where('order_id', $orders->id)->first(); $PaymentConfirmation->delete(); } $orders = Order::where('id', $order_product->order_id)->get(); $orders->delete(); } $total_product = $category->total_product - 1; $category->total_product = $total_product; $category->save(); $total_subcategory = $subcategory->total_product - 1; $subcategory->total_product = $total_subcategory; $subcategory->save(); if (!$image == NULL) { foreach ($image as $image) { File::delete($path . $image); } } return redirect('master/produk/list')->with('success', 'Produk ' . $product->name . ' Berhasil Dihapus'); } else { return redirect('master/produk/list')->with('error', '404'); } } } }
public function add_review(Request $request) { $order = Order::where('id', $request->order_id)->first(); $order->order_status = 'Diterima'; $order->save(); $orderdetail = OrderDetail::where('order_id', $request->order_id)->where('product_id', $request->product_id)->get(); foreach ($orderdetail as $value) { $value->review = 'reviewed'; $value->save(); } $product = Product::where('id', $request->product_id)->first(); $product->rating += $request->rating; $product->save(); $review = new Reviews(); $review->user_id = Sentinel::getUser()->id; $review->product_id = $product->id; $review->rating = $request->rating; $review->review = $request->review; $review->status = 'publish'; $review->save(); }
/** * 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; }
/** * Review Restaurant * route: reviews/restaurant/{id} * * @param $id * @optional ?page ?viewer_id * @return Response */ public function restaurantAction($id) { $reviews = Reviews::getByRestaurantIdPaginated($id); $reviews_array = Reviews::reviewsQueries($reviews); $page[KeyParser::current] = $reviews->currentPage(); $page[KeyParser::number] = $reviews->lastPage(); $json_return = array(KeyParser::data => $reviews_array, KeyParser::page => $page); return response()->json($json_return); }