public function showCart() { $aSession = \Session::all(); $aCart = isset($aSession['cart']) ? $aSession['cart'] : array(); $cartTotalPrice = 0; $aCartData = array(); if (isset($aCart['items'])) { foreach ($aCart['items'] as $aItem) { if (isset($aItem['idRestaurant'])) { $aRestaurant = DB::table('restaurants')->where(array("id_restaurant" => $aItem['idRestaurant']))->get(array("restaurant_name")); $sRestaurant = $aRestaurant[0]->restaurant_name; $oItem = DB::table('food')->where(array('id_item' => $aItem['idItem']))->get(array('name', 'price'))[0]; $aItem['name'] = $oItem->name; $aItem['total_price'] = $oItem->price * $aItem['amount']; $cartTotalPrice += $aItem['total_price']; $aCartData['restaurants'][$sRestaurant][] = $aItem; } } } $aCartData['tax'] = 0.16; $aCartData['total_price_with_out_tax'] = $cartTotalPrice; $aCartData['total_price_with_tax'] = $cartTotalPrice * $aCartData['tax'] + $cartTotalPrice; $aData = Backend::LoginData(); return view("pages.cartPage")->with(array('cartData' => $aCartData, 'data' => $aData)); }
public function login() { $aRequest = \Input::all(); $sUsername = $aRequest['username']; $sPassword = $aRequest['password']; //Check if there's a user with this name, if yes, get all needed information for them $aResult = DB::table('users')->where(array('username' => $sUsername))->get(array('*')); if (!empty($aResult)) { //If execution reached here then the user is normal user. $sUserType = 'user'; } if (empty($aResult)) { //Check if the user is a restaurant $aResult = DB::table('restaurants')->where(array('username' => $sUsername))->get(array('*')); $sUserType = 'restaurant'; } if (empty($aResult)) { return redirect('login')->withErrors('User not found!'); } if (Hash::check($sPassword, $aResult[0]->password)) { \Session::put('loggedin', 'true'); \Session::put('username', $sUsername); \Session::put('user_type', $sUserType); if ($sUserType == 'user') { //add empty array of items \Session::put('cart', array('items' => array())); \Session::put('id_user', $aResult[0]->id_user); } else { if ($sUserType == 'restaurant') { \Session::put('id_user', $aResult[0]->id_restaurant); } } $data = Backend::LoginData(); return redirect()->intended('/')->with(array('data' => $data)); } else { return redirect('login')->withErrors(['Please check your credentials!!', 'Error']); } }
public function showRestaurantsOrders() { if (!Backend::validateUser()) { return redirect('/'); } $aSession = \Session::all(); $aOrdersList = DB::table('orders')->where(array('id_restaurant' => $aSession['id_user']))->WhereNotIn('status', array('DONE'))->orderBy('date_inserted', 'desc')->get(array('*')); $aTmpOrder = array(); $dTotalPrice = 0; $aOrders = array(); foreach ($aOrdersList as $oOrder) { $aTmpOrder['customer'] = DB::table('users')->where(array('id_user' => $oOrder->id_user))->get(array('first_name', 'last_name', 'user_mobile', 'username', 'email'))[0]; $oOrderDetails = json_decode($oOrder->order_details); $oOrder->order_details = $this->parseOrderDetails($oOrderDetails); $oOrder->status = str_replace('_', ' ', $oOrder->status); $oLocation = json_decode($oOrder->location); if (!empty($oLocation->lat)) { $aTmpOrder['location'] = "http://maps.google.com/maps?q={$oLocation->lat},{$oLocation->long}"; } $aTmpOrder['info'] = $oOrder; $dTotalPrice += $oOrderDetails->total_price; $oOrder->date_inserted = Backend::ago(new \DateTime($oOrder->date_inserted)); $aOrders[] = $aTmpOrder; $aTmpOrder = []; } $data = Backend::LoginData(); $data['isRestaurant'] = true; $data['status'] = array('preparing', 'canceled', 'not approved yet', 'on the way'); return view('pages.orders')->with(array('orders' => $aOrders, 'data' => $data)); }
public function profile($sUsername) { //Get if the user is logged in or not $bLoggedIn = \Session::get("loggedin"); $data = Backend::LoginData(); //In default the profile's vistor is not the owner of it. $data['profileOwner'] = 'no'; if (isset($data['logged']) && $data['logged'] == 'yes') { $dVisitorId = $data['id_user']; $sUser = $data['username']; /* * Check if this page is for the logged in uesr * to show him more options. */ if ($sUsername == \Session::get('username')) { $data['profileOwner'] = 'yes'; } } else { $data['logged'] = 'no'; $data['user_type'] = "visitor"; } /* * Get the username and put it in data */ if (!empty($sUser)) { $data['username'] = $sUser; } /* * Get the Id of the logged in user */ if (!empty($dVisitorId)) { $data['visitor_id'] = $dVisitorId; } /* * Check if the user is a normal user 'Customers' */ $aUserData = DB::table('users')->where(array('username' => $sUsername))->get(array("id_user", "username", "first_name", "last_name", "email", "id_country", "gender", "age", "user_bio", "user_mobile", "user_status", "user_type", "photo")); if (empty($aUserData)) { /* * Being here means that the username is not for a normal user, * Check restauarant's table to check if the username is for a restaurant. */ $aParams = array('username', 'id_restaurant', 'id_country', 'restaurant_name', 'email', 'logo', 'telephone', 'twitter_account', 'bio', 'price_range', 'cuisines', 'opening_days', 'smoking_allowed', 'provide_ordering', 'website', 'rating', 'location'); $aUserData = DB::table('restaurants')->where(array('username' => $sUsername))->get($aParams); if (empty($aUserData)) { /* * If it came here means the username is not in the system * redirect the viewer to the home directory, * or maybe 'page not(404)found page' */ return redirect()->intended('/')->with(array('data' => $data)); } $oRestarant = $aUserData[0]; if (isset($oRestarant->cuisines)) { $sCuisineName = DB::table("cuisines")->where(array("id_cuisine" => $oRestarant->cuisines))->get(array("name")); if (!empty($sCuisineName)) { $oRestarant->cuisines = $sCuisineName[0]->name; } } $data['reviews_count'] = DB::table("reviews")->where(array("id_restaurant" => $oRestarant->id_restaurant))->count(array("*")); $oRestarant->opening_days = Backend::checkifOpen($oRestarant->opening_days); $oRestarant->location = json_decode($oRestarant->location); //username is for a restaurant, Redirect it to the restaurant's page. return view('pages.restaurantpage')->with(array('data' => $data, 'restaurant' => $oRestarant)); } /* * Get the user rating */ $aUserRating = DB::table('user_rating')->where(array('id_user' => $aUserData[0]->id_user))->get(array('likes_count')); /* * Get the user followers count */ $aUserFollower = DB::table("users_relationships")->where(array("id_other_user" => $aUserData[0]->id_user, "relationship_status" => "following"))->count(); $aUser['followers'] = $aUserFollower; /* * Get the user country */ $sCountry = DB::table("countries")->where(array('id_country' => $aUserData[0]->id_country))->get(array('country_name')); /* * Count how many reviews was written by the user */ $dReviewsCount = DB::table("reviews")->where(array("id_user" => $aUserData[0]->id_user))->count(array("*")); $aActivtiesList = DB::table("activities")->where(array("id_user" => $aUserData[0]->id_user))->orderBy("date_inserted", "desc")->get(array("*")); //Parse Activities $aActivties = array(); $aTmpActivity = array(); foreach ($aActivtiesList as $oActivity) { switch ($oActivity->type) { case "review": $aTmp = DB::table("reviews")->where(array("id_review" => $oActivity->id_other))->get(array("*")); if (count($aTmp) != 0) { $aRestaurantName = DB::table("restaurants")->where(array("id_restaurant" => $aTmp[0]->id_restaurant))->get(array("restaurant_name", "username")); $aTmpActivity['type'] = $oActivity->type; $aTmpActivity['other_name'] = $aRestaurantName[0]->restaurant_name; $aTmpActivity['content'] = $aTmp[0]->body; $aTmpActivity['rating'] = $aTmp[0]->rating; $aTmpActivity['date'] = $oActivity->date_inserted; $aTmpActivity['username'] = $aRestaurantName[0]->username; $aActivties[] = $aTmpActivity; } break; } } /* * Put the reviews count to 0 if there's no reviews */ if (!empty($dReviewsCount)) { $aUser['reviews_count'] = $dReviewsCount; } else { $aUser['reviews_count'] = 0; } /* * Get the user age */ $dInterval = Backend::getAge($aUserData[0]->age); $aUserData[0]->age = $dInterval; if (!empty($sCountry[0])) { //Set the user's country name $aUser['country'] = $sCountry[0]->country_name; } if (!empty($aUserRating)) { //Set the user rating $aUser['rating'] = $aUserRating[0]->likes_count; } $aUser['user'] = $aUserData[0]; /* * Show the normal user profile page, pass the needed data with the page */ return view('pages.profilepage')->with(array('data' => $data, 'aUser' => $aUser, 'aActivities' => $aActivties)); }
public function showReviews() { // dd(\Request::all()); $aRequest = \Request::all(); $oRestaurant = DB::table('restaurants')->where(array('username' => $aRequest['username']))->get(array('id_restaurant'))[0]; $aReviewsList = DB::table('reviews')->where(array('id_restaurant' => $oRestaurant->id_restaurant))->get(array('*')); $aReviews = array(); $aTempReview = array(); foreach ($aReviewsList as $oReview) { $oUser = DB::table('users')->where(array('id_user' => $oReview->id_user))->get(array('username'))[0]; $aTempReview['id_review'] = $oReview->id_review; $aTempReview['username'] = $oUser->username; $aTempReview['body'] = $oReview->body; $aTempReview['rating'] = $oReview->rating; switch ($oReview->rating) { case 'poor': $aTempReview['rating'] = 1; break; case 'good': $aTempReview['rating'] = 2; break; case 'vGood': $aTempReview['rating'] = 3; break; case 'excellent': $aTempReview['rating'] = 4; break; case 'extraordinary': $aTempReview['rating'] = 5; break; } $aTempReview['image'] = $oReview->review_image; $aTempReview['date_created'] = $oReview->date_created; $aReviews[] = $aTempReview; } $data = Backend::LoginData(); return view('/pages.reviews')->with(array('data' => $data, 'aReviews' => $aReviews)); }