private function addNormalUser($aRequest) { $aUser = array(); foreach ($this->aUserParams as $sParam) { switch ($sParam) { case "username": $aUser[$sParam] = strtolower($aRequest[$sParam]); break; case "logo": $aUser['photo'] = Backend::uploadPhotos($aRequest['logo'], 'logo'); break; default: $aUser[$sParam] = $aRequest[$sParam]; break; } } $aUser['date_registered'] = date('Y-m-d h:i:s'); $aUser['age'] = $aRequest['date_of_birth']; $aUser['user_mobile'] = $aRequest['telephone']; $aUser['user_status'] = 'active'; unset($aUser['date_of_birth']); unset($aUser['telephone']); //Hashing the password to be saved encrypted $aUser['password'] = Hash::make($aUser['password']); DB::table('users')->insert($aUser); $dIdUser = DB::table('users')->where(array('username' => $aUser['username']))->get(array('id_user')); DB::table('user_rating')->insert(array('id_user' => $dIdUser[0]->id_user, 'likes_count' => 0)); echo "You've registered successfully!"; return redirect()->intended('/'); }
public function checkout() { //Check if user is logged in if (!Backend::validateUser()) { return redirect('/'); } $aRequest = \Request::all(); //This is a temprory array that will be used to create a temp item to be used in saved and any processing on item before saving it. $tempItem = array(); if (!isset($aRequest['items'])) { return; } /* * Total price will be saved here, * this also will be used to indicate the last price that will be required on each restaurant */ foreach ($aRequest['items'] as $item) { $dTotalPrice = 0; $oItem = DB::table('food')->where(array('id_item' => $item['id_item']))->get(array("id_restaurant", "price"))[0]; $tempItem['id_item'] = $item['id_item']; $tempItem['qty'] = $item['qty']; $tempItem['spicy'] = $item['spicy']; //$tempItem['note']=$item['note']; $tempItem['total_price'] = $oItem->price * $item['qty']; $dTotalPrice += $tempItem['total_price']; $aRestaurants[$oItem->id_restaurant]['total_price'] = $dTotalPrice; $aRestaurants[$oItem->id_restaurant]['items'][] = $tempItem; $tempItem = array(); } $sNote = $aRequest['note']; $sLocation = json_encode($aRequest['location']); foreach ($aRestaurants as $id_restaurant => $aRestaurant) { $id_user = \Session::all()['id_user']; $sOrderDetails = json_encode($aRestaurant); $aOrder = array('id_user' => $id_user, 'id_restaurant' => $id_restaurant, 'order_details' => $sOrderDetails, 'note' => $sNote, 'location' => $sLocation, 'date_inserted' => Date('Y-m-d h:i:s'), 'status' => 'not_approved_yet'); DB::table('orders')->insert($aOrder); } \Session::forget('cart'); return redirect('/'); }
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 static function ago($datetime) { $interval = date_create('now')->diff($datetime); $suffix = $interval->invert ? ' ago' : ''; if ($v = $interval->y >= 1) { return Backend::pluralize($interval->y, 'year') . $suffix; } if ($v = $interval->m >= 1) { return Backend::pluralize($interval->m, 'month') . $suffix; } if ($v = $interval->d >= 1) { return Backend::pluralize($interval->d, 'day') . $suffix; } if ($v = $interval->h >= 1) { return Backend::pluralize($interval->h, 'hour') . $suffix; } if ($v = $interval->i >= 1) { return Backend::pluralize($interval->i, 'minute') . $suffix; } return Backend::pluralize($interval->s, 'second') . $suffix; }
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 GetRestaurantsList($aData) { $aRestaurants = array(); /* * Get the search term from the Data */ $searchTerms = explode(' ', $aData['searchTerm']); /* * Put the table name in order to be used in updating the query */ $query = DB::table('restaurants'); $aSearchTerms = array(); if (!empty($searchTerms[0])) { /* * Make sure to get all the combination of the data */ foreach ($searchTerms as $term) { $aSearchTerms[] = ucfirst($term); $aSearchTerms[] = strtolower($term); $aSearchTerms[] = ucfirst(strtolower($term)); } /* * This foreach, will update the query, puting the likes * in searching for the used columns. * if you want to serach in another column * just add a new line like how it is written. */ foreach ($aSearchTerms as $term) { $query->where('restaurant_name', 'LIKE', '%' . $term . '%')->orWhere('username', 'LIKE', '%' . $term . '%')->orWhere('bio', 'LIKE', '%' . $term . '%')->orWhere('cuisines', 'LIKE', '%' . $term . '%'); } /* * Get a list of Restaurants IDS */ $aRestaurantsIdsSearchTerm = $query->get(array("id_restaurant")); } /* * If the location data was sent with the query */ if (isset($aData['location']) && $aData['location'] != '') { if (!empty($aData['location'])) { $query->where('id_country', '=', $aData['location']); } } if (isset($aData['no_smoking']) && ($aData['no_smoking'] = 'yes')) { $sSmoking = 'yes'; } else { if (isset($aData['no_smoking']) && ($aData['no_smoking'] = 'no')) { $sSmoking = 'no'; } } if (isset($sSmoking)) { $query->orWhere('smoking_allowed', '=', $sSmoking); } $aRestaurantsIds = $query->get(array("id_restaurant")); if (isset($aRestaurantsIdsSearchTerm)) { array_merge($aRestaurantsIds, $aRestaurantsIdsSearchTerm); } foreach ($aRestaurantsIds as $aRestaurantsId) { $aResults[] = $aRestaurantsId->id_restaurant; } $query = DB::table('food'); if (!empty($searchTerms[0])) { foreach ($aSearchTerms as $term) { $query->where('name', 'LIKE', '%' . $term . '%')->orWhere("type", 'LIKE', '%' . $term . '%')->orWhere("description", 'LIKE', '%' . $term . '%'); } } /* * Check if the needed food is healthy */ if (isset($aData['food_health'])) { $query->where('healthy', '=', $aData['food_health']); } if (isset($aData['price_range'])) { $aPriceRange = explode(" - ", $aData['price_range']); $dFrom = trim(str_replace('$', '', $aPriceRange[0])); $dTo = trim(str_replace('$', '', $aPriceRange[1])); if (isset($dTo) && isset($dFrom)) { $query->whereBetween("price", array($dFrom, $dTo)); } } $aRestaurantsIds = $query->get(array("id_restaurant")); foreach ($aRestaurantsIds as $aRestaurantsId) { $aResults[] = $aRestaurantsId->id_restaurant; } if (!empty($aResults[0])) { $aRestaurants = DB::table("restaurants")->whereIn("id_restaurant", $aResults)->get(Backend::$aRestaurantsParams); foreach ($aRestaurants as $restaurant) { $restaurant->opening_days = Backend::checkifOpen($restaurant->opening_days); } } $aFinalResult = array(); //32.0265737,35.8360242 lat long, use if failed if (isset($aData['userlat']) && isset($aData['userlong'])) { if ($aData['userlat'] != 0 && $aData['userlong'] != 0) { foreach ($aRestaurants as $restaurant) { if (!empty($restaurant->location)) { $point = json_decode($restaurant->location); } if (isset($point->lat)) { $dCalculatedDist = $this->haversineGreatCircleDistance($aData['userlat'], $aData['userlong'], $point->lat, $point->long) / 1000; if ($dCalculatedDist <= $aData['distance']) { $restaurant->location = $dCalculatedDist; $aFinalResult[] = $restaurant; } } } //Search based on location! return $aFinalResult; } } return $aRestaurants; }
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)); }