コード例 #1
0
 /**
  * Edit suggested restaurant
  *
  * @param $id
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function editSuggestedAction($id, Request $request)
 {
     if ($request->isMethod('GET')) {
         $data = array();
         $restaurant = RestaurantsSuggest::find($id);
         $categories = CategoriesCms::where('type', 'cuisine')->orderBy('name')->get();
         $data = array('restaurant' => $restaurant ? $restaurant : array(), 'categories' => $categories->toArray() ? $categories : array(), 'id' => $id, 'javascripts' => array('restaurant_suggest'), 'page_title' => 'Edit Suggested Restaurant');
         return view('cms.restaurant.suggested.edit', $data);
     } elseif ($request->isMethod('POST')) {
         extract($request->all());
         $errors = array();
         if (!$name) {
             $errors[] = 'Restaurant name is missing';
         }
         if (!$address) {
             $errors[] = 'Restaurant address is missing';
         }
         if (!$telephone) {
             $errors[] = 'Phone number is missing';
         }
         if (!$budget) {
             $errors[] = 'Budget is missing';
         }
         if ($budget && !is_numeric($budget)) {
             $errors[] = 'Budget is invalid';
         }
         if (!$latitude) {
             $errors[] = 'Latitude is missing';
         }
         if ($latitude && !is_numeric($latitude)) {
             $errors[] = 'Latitude is invalid';
         }
         if (!$longitude) {
             $errors[] = 'Longitude is missing';
         }
         if ($longitude && !is_numeric($longitude)) {
             $errors[] = 'Longitude is invalid';
         }
         if (!$operating_time) {
             $errors[] = 'Operating Time is missing';
         }
         if (!$cuisines) {
             $errors[] = 'Cuisines are missing';
         }
         if ($errors) {
             \Session::flash('errors', $errors);
             return redirect('cms/restaurant/suggested/edit/' . $id);
         }
         try {
             $restaurant = new RestaurantsSuggestCms();
             $restaurant->editRestaurantSuggest($id, $name, $address, $telephone, $budget, $latitude, $longitude, $operating_time, $credit_card, $smoking, $is_24hours, $can_dinein, $can_dineout, $can_deliver, $cuisines, $other_details);
             \Session::flash('success', 'Suggested Restaurant has been updated');
             return redirect('cms/restaurant/suggested/view/' . $id);
         } catch (Exception $e) {
             \Session::flash('errors', array('An unexpected error occured while trying to update suggested restaurant.'));
             return redirect('cms/restaurant/suggested/edit/' . $id);
         }
     }
 }
コード例 #2
0
 /**
  * Add new restaurant suggest and return JSON data
  * route: /restaurants/suggest
  *
  * @param Request $request
  * @return Response
  */
 public function suggestAction(Request $request)
 {
     $data = $request->json()->get('restaurant');
     if (!isset($data['name']) || !isset($data['address']) || !isset($data['latitude']) || !isset($data['longitude']) || !isset($data['user_id'])) {
         $message = "Format should be: {'restaurant': {'name': <string>, 'address': <string>, 'latitude': <double>, 'longitude': <double>, 'user_id': <int>}}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data['name'] . ' ' . $data['telephone'] . ' ' . $data['address'] . ' ' . $data['cuisines'] . ' ' . $data['other_details']);
     if ($ng_words) {
         $message = "Bad words found: " . implode(', ', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     try {
         $restaurant_suggest = new RestaurantsSuggest();
         $restaurant_suggest->addRestaurantSuggest($data);
         $json_return[KeyParser::data] = ModelFormatter::restaurantSuggestFormat($restaurant_suggest);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     return response()->json($json_return);
 }