/** * Displays photo info * * @param $id * @return \Illuminate\View\View */ public function viewAction($id) { $data = array(); $errors = array(); if (!$id) { $errors[] = 'Invalid photo ID'; $data['errors'] = $errors; return view('cms.photos.view', $data); } $photo = PhotosCms::find($id); if (!$photo) { $errors[] = 'Photo not found'; $data['errors'] = $errors; return view('cms.photos.view', $data); } $photo = $photo->toArray(); switch ($photo['type']) { case 1: $photo['type'] = 'Review'; break; case 2: $photo['type'] = 'Check-In'; break; case 6: $photo['type'] = 'Restaurant Photo'; break; default: break; } $photo['url'] = env('WEB_HOST') . 'uploads/default/' . $photo['url']; switch ($photo['status']) { case 0: $photo['status'] = 'Deactivated'; break; case 1: $photo['status'] = 'Active'; break; default: break; } $photo['date_uploaded'] = date('M d, Y H:i:s', strtotime($photo['date_uploaded'])); $data['photo'] = $photo; return view('cms.photos.view', $data); }
/** * 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(); } } }
/** * Return the details of the reported photo * Used for the View popup * * @param $photo_id * @return View */ public function viewPhotoAction($photo_id) { $data = array(); $photo = PhotosCms::find($photo_id)->toArray(); if ($photo) { foreach ($photo as $key => $value) { if ($key == 'type') { if ($value === CONSTANTS::REVIEW) { $photo[$key] = 'Review'; } elseif ($value === CONSTANTS::CHECKIN) { $photo[$key] = 'Checkin'; } elseif ($value === CONSTANTS::BOOKMARK) { $photo[$key] = 'Bookmark'; } elseif ($value === CONSTANTS::COMMENT) { $photo[$key] = 'Comment'; } elseif ($value === CONSTANTS::PHOTO) { $photo[$key] = 'Photo'; } elseif ($value === CONSTANTS::RESTAURANT) { $photo[$key] = 'Restaurant'; } } if ($key == 'status') { if ($value === CONSTANTS::STATUS_ACTIVE) { $photo[$key] = 'Active'; } else { $photo[$key] = 'Inactive'; } } } $data['photo'] = $photo; } return view('cms.reported.photos.view', $data); }