public function getPostPage() { $obj = new BaseController(); $campusid = $this->getDevice(); if ($campusid == 0) { $countryname = $obj->getCountryName(); if ($countryname == 'NONE') { return Redirect::route('selectcampus-get'); } else { //check whether the country name exists inthe db $locationcountry = Country::where('name', '=', $countryname); if ($locationcountry->count()) { $locationcountrycode = $locationcountry->first()->code; $locationcountrycode = strtolower($locationcountrycode); return Redirect::route('selectcountryid', $locationcountrycode); } else { return Redirect::route('selectcampus-get'); } } } $college = Institution::whereHas('Branch', function ($query) use($campusid) { $query->where('id', '=', $campusid); })->first(); View::share('college', $college); $mycampus = Branch::where('id', '=', $campusid)->first(); View::share('mycampus', $mycampus); if (Auth::user()) { return View::make('member.post'); } return View::make('guest.post'); }
protected function saveModel($airport = false) { if (Input::get('id')) { $airport = Airport::find(Input::get('id')); } if (!$airport) { $airport = new Airport(); } $airport->name = Input::get('name'); $address = $airport->address()->first() ?: new Address(); $country = Country::where('name', Input::get('country'))->first(); $address->country()->associate($country); $address->address = Input::get('address_address'); $address->postal_code = Input::get('address_postal_code'); $address->city = Input::get('address_city'); $address->state_province = Input::get('address_state_province'); $address->phone = Input::get('address_phone'); $address->fax = Input::get('address_fax'); $address->email = Input::get('address_email'); $address->website = Input::get('address_website'); $address->save(); $airport->address()->associate($address); $hotel->save(); return $airport; }
public static function updateWineryDetail($id, $input) { $winery = Winery::where('id', $id)->first(); $error_code = ApiResponse::OK; if ($winery) { if (!empty($input)) { if (!empty($input['brand_name'])) { $winery->brand_name = $input['brand_name']; } if (!empty($input['country_id'])) { if (Country::where('id', $input['country_id'])->first()) { $winery->country_id = $input['country_id']; } else { $winery->country_id = null; } } if (!empty($input['region'])) { $winery->region = $input['region']; } if (!empty($input['description'])) { $winery->description = $input['description']; } $winery->save(); $data = $winery->toArray(); } else { $error_code = ApiResponse::MISSING_PARAMS; $data = $input; } } else { $error_code = ApiResponse::UNAVAILABLE_WINERY; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINERY); } return array("code" => $error_code, "data" => $data); }
public static function timeline() { $user_id = Session::get('user_id'); $error_code = ApiResponse::OK; $user_timeline = array(); $user_timeline[] = $user_id; $user_follow = Follow::where('from_id', $user_id)->orderBy('updated_at', 'asc')->get(); if (isset($user_follow)) { foreach ($user_follow as $user) { $user_timeline[] = $user->to_id; } } $pagination = ApiResponse::pagination(); if ($pagination == false) { $error_code = ApiResponse::URL_NOT_EXIST; $data = ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST); } else { $page = $pagination['page']; $limit = $pagination['limit']; $ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->orderBy('updated_at', 'desc')->forPage($page, $limit)->get(); if (count($ratings) == 0) { $data = array(); } else { foreach ($ratings as $rating) { $winery = Winery::where('id', $rating->wine->winery_id)->first(); $rating->winery = $winery; $country = Country::where('id', $rating->winery->country_id)->first(); if ($country) { $rating->winery->country_name = $country->country_name; } else { $rating->winery->country_name = null; } $like = Like::where('user_id', $user_id)->where('rating_id', $rating->id)->first(); if ($like) { $rating->liked = true; } else { $rating->liked = false; } $wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $rating->wine_unique_id)->first(); if ($wishlist) { $rating->wishlist = true; } else { $rating->wishlist = false; } $rating->wine->image_url = Wine::getImageWineFromServer($user_id, $rating->wine->wine_unique_id, $rating->wine->image_url); if ($rating->wine->wine_flag != null) { $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag); } if ($rating->profile->image != null) { $rating->profile->image = URL::asset($rating->profile->image); } } $data = $ratings->toArray(); } } return array("code" => $error_code, "data" => $data); }
public function viewNoResult() { // Filtering $country = Country::where('val', 1)->lists('country', 'id'); $city = City::where('val', 1)->lists('city', 'id'); $filter_tours = Tour::where('val', 1)->get(); $filter_cities = City::where('val', 1)->get(); return array('filter_tours' => $filter_tours, 'filter_cities' => $filter_cities, 'country' => $country, 'city' => $city); }
public function run() { // Uncomment the below to wipe the table clean before populating DB::table('locations')->truncate(); $country = Country::where('name_en', 'Kuwait')->first(); $locations = array(['country_id' => $country->id, 'name_ar' => 'سالمية', 'name_en' => 'Salmiya', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]); // Uncomment the below to run the seeder DB::table('locations')->insert($locations); }
protected function saveModel($contact = false) { if (Input::get('id')) { $contact = Contact::find(Input::get('id')); } if (!$contact) { $contact = new Contact(); } $contact->function = Input::get('function'); $contact->first_name = Input::get('first_name'); $contact->last_name = Input::get('last_name'); $contact->references = Input::get('references'); $contact->notes = Input::get('notes'); $address = $contact->address()->first() ?: new Address(); $address_input = Input::get('address'); $country = Country::where('name', Input::get('country'))->first(); if ($country) { $address->country()->associate($country); } $address->address = isset($address_input['address']) ? $address_input['address'] : ''; $address->postal_code = isset($address_input['postal_code']) ? $address_input['postal_code'] : ''; $address->city = isset($address_input['city']) ? $address_input['city'] : ''; $address->state_province = isset($address_input['state_province']) ? $address_input['state_province'] : ''; $address->phone = isset($address_input['phone']) ? $address_input['phone'] : ''; $address->fax = isset($address_input['fax']) ? $address_input['fax'] : ''; $address->email = isset($address_input['email']) ? $address_input['email'] : ''; $address->website = isset($address_input['website']) ? $address_input['website'] : ''; $address->save(); $contact->address()->associate($address); $contact->save(); $parentQuery = Input::get('parent_model'); if (!empty($parentQuery)) { $parentModel = null; switch ($parentQuery) { case 'events': $relation = 'events'; $parentModel = 'Events'; break; case 'company': $relation = 'companies'; $parentModel = 'Company'; break; case 'venue': $relation = 'venues'; $parentModel = 'Venue'; break; default: break; } if (!empty($parentModel)) { $contact->{$relation}()->detach($parentModel::find(Input::get('parent_id'))); $contact->{$relation}()->attach($parentModel::find(Input::get('parent_id'))); } } return $contact; }
/** * Display a listing of the resource. * * @return Response */ public function index() { // Se valida si llega u filtro para consultar, de lo contrario se retorna la lista completa. if (Input::get(Config::get('constants.QUERY'))) { $countriesList = Country::where('countryId', 'LIKE', '%' . Input::get(Config::get('constants.QUERY')) . '%')->orWhere('name', 'LIKE', '%' . Input::get(Config::get('constants.QUERY')) . '%')->get(); } else { $countriesList = Country::all(); } return $this->respondWithCollection($countriesList, new CountryTransformer()); }
public function testGetTimelineSuccess() { $this->setUpRating(); $this->setUpCountry(); $this->setUpWineNote(); $this->setUpProfile(); $_params = $this->_params; $_params['user_id'] = "user_id"; $response = $this->_getAuth($_params); $error_code = ApiResponse::OK; $user_timeline = array(); $user_timeline[] = $this->_user_id; $user_follow = Follow::where('from_id', $this->_user_id)->orderBy('updated_at', 'asc')->get(); if (isset($user_follow)) { foreach ($user_follow as $user) { $user_timeline[] = $user->to_id; } } $pagination = ApiResponse::pagination(); $page = $pagination['page']; $limit = $pagination['limit']; $wine = Wine::with('winery')->forPage($page, $limit)->get(); $ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->forPage($page, $limit)->get(); foreach ($ratings as $rating) { $winery = Winery::where('id', $rating->wine->winery_id)->first(); $rating->winery = $winery; $country = Country::where('id', $rating->winery->country_id)->first(); $rating->winery->country_name = $country->country_name; $like = Like::where('user_id', $this->_user_id)->where('rating_id', $rating->id)->first(); if ($like) { $rating->liked = true; } else { $rating->liked = false; } $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $rating->wine_unique_id)->first(); if ($wishlist) { $rating->wishlist = true; } else { $rating->wishlist = false; } if ($rating->wine->image_url != null) { $rating->wine->image_url = URL::asset($rating->wine->image_url); } if ($rating->wine->wine_flag != null) { $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag); } if ($rating->profile->image != null) { $rating->profile->image = URL::asset($rating->profile->image); } $rating->winery = $rating->winery->toArray(); } $data = $ratings; $this->assertEquals(array("code" => ApiResponse::OK, "data" => $ratings->toArray()), json_decode($response->getContent(), true)); }
public function setCountryAttribute($value) { if (strlen($value) == 2) { $this->attributes['country_a2'] = strtoupper($value); } else { $operator = \Config::get('database.default') == 'pgsql' ? 'ilike' : 'like'; $country = Country::where('name', $operator, $value)->first(); if ($country) { $this->attributes['country_a2'] = $country->a2; } } $this->attributes['country_name'] = Addresses::countryName($this->attributes['country_a2']); }
public static function boot() { parent::boot(); static::saving(function ($address) { if (config('addressable.geocode')) { $address->geocode(); } if (empty($address->country_id)) { $defaultCountry = config('addressable.default_country'); $country = Country::where('cca2', '=', $defaultCountry)->first(['id']); $address->country_id = $country->id; } }); }
public function getProduct($id) { $phones = Product::find($id); if ($id <= 9) { $countrys = Country::where('category_id', '=', '1')->get(); $networks = Network::where('category_id', '=', '1')->get(); } elseif ($id <= 12) { $countrys = Country::where('category_id', '=', '2')->get(); $networks = Network::where('category_id', '=', '2')->get(); } elseif ($id <= 15) { $countrys = Country::where('category_id', '=', '3')->get(); $networks = Network::where('category_id', '=', '3')->get(); } return View::make('products.product')->with('phones', $phones)->with('networks', $networks)->with('countrys', $countrys); }
public function show($id) { if (Auth::user()) { $countryId = Auth::user()->country_id; } else { $location = GeoIPFacade::getLocation(); $countryId = Country::where('country_code', '=', $location['isoCode'])->first()->id; } $questionCountry = QuestionsCountry::firstOrNew(array('country_id' => $countryId, 'question_id' => $id)); $questionCountry->count++; $questionCountry->save(); // Get all the blog posts $question = Question::where('questions.id', '=', $id)->with('answer')->first(); return view('questions.view_question', compact('question')); }
public function postSelectPackage() { //verify the user input and create account $validator = Validator::make(Input::all(), array('Package' => 'required')); if ($validator->fails()) { return Redirect::route('advanced_squeeb-get')->withInput()->with('global', 'Please select a package.'); } else { $package = Input::get('Package'); View::share('package', $package); //check for the world package if ($package == 'pkg1') { $countries = Country::all(); View::share('countries', $countries); $obj = new BaseController(); $countryid = 0; $countryname = $obj->getCountryName(); if ($countryname != 'NONE') { $locationcountry = Country::where('name', '=', $countryname); if ($locationcountry->count()) { $countryid = $locationcountry->first()->id; $colleges = Institution::where('country_id', '=', $countryid)->get(); View::share('colleges', $colleges); } } View::share('countryid', $countryid); return View::make('guest.advancedselectcollege'); } else { if ($package == 'pkg2') { $countries = Country::all(); View::share('countries', $countries); $obj = new BaseController(); $countryid = 0; $countryname = $obj->getCountryName(); if ($countryname != 'NONE') { $locationcountry = Country::where('name', '=', $countryname); if ($locationcountry->count()) { $countryid = $locationcountry->first()->id; } } View::share('countryid', $countryid); return View::make('guest.advancedpostcountry')->with('msg', 'Country Squeeb Package'); } } if ($package == 'pkg3') { return View::make('guest.advancedpost')->with('msg', 'World Squeeb Package'); } } }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('territories', function ($table) { $table->increments('id')->unsigned(); $table->string('name', 25); $table->string('county', 2); $table->string('municipality', 2)->nullable(); $country = Country::where('name', 'Sweden')->first(); $table->integer('country_id')->unsigned()->default($country->id); $table->foreign('country_id')->references('id')->on('countries')->onDelete('CASCADE')->onUpdate('CASCADE'); $table->engine = 'InnoDB'; }); Schema::table('territories', function () { $sql = file_get_contents(base_path() . '/scripts/db/populate_territory.sql'); DB::statement($sql); DB::statement('update territories set country_id=(select id from countries where name=\'Sweden\')'); }); }
public function getChangeCampus() { $obj = new BaseController(); $countryname = $obj->getCountryName(); if ($countryname == 'NONE') { return Redirect::route('selectcampus-get'); } else { //check whether the country name exists inthe db $locationcountry = Country::where('name', '=', $countryname); if ($locationcountry->count()) { $locationcountrycode = $locationcountry->first()->code; $locationcountrycode = strtolower($locationcountrycode); return Redirect::route('selectcountryid', $locationcountrycode); } else { return Redirect::route('selectcampus-get'); } } }
protected function saveModel($company = false) { if (Input::get('id')) { $company = Company::find(Input::get('id')); } if (!$company) { $company = new Company(); } $company->name = Input::get('name'); $company->type = Input::get('type'); $company->references = Input::get('references'); $company->bank_details = Input::get('bank_details'); $company->tax_number = Input::get('tax_number'); $company->notes = Input::get('notes'); $address = $company->address()->first() ?: new Address(); $country = Country::where('id', Input::get('country'))->first(); $address->country()->associate($country); $address->address = Input::get('address_address'); $address->postal_code = Input::get('address_postal_code'); $address->city = Input::get('address_city'); $address->state_province = Input::get('address_state_province'); $address->phone = Input::get('address_phone'); $address->fax = Input::get('address_fax'); $address->email = Input::get('address_email'); $address->website = Input::get('address_website'); $address->save(); $company->address()->associate($address); $company->save(); if (Input::get('venue_id')) { $company->venues()->detach(Venue::find(Input::get('venue_id'))); $company->venues()->attach(Venue::find(Input::get('venue_id'))); } if (Input::get('contact_id')) { $company->contacts()->detach(Contact::find(Input::get('contact_id'))); $company->contacts()->attach(Contact::find(Input::get('contact_id'))); } if (Input::get('event_id')) { $company->events()->detach(Events::find(Input::get('event_id'))); $company->events()->attach(Events::find(Input::get('event_id'))); } return $company; }
protected function saveModel($venue = false) { if (Input::get('id')) { $venue = Venue::find(Input::get('id')); } if (!$venue) { $venue = new Venue(); } $venue->name = Input::get('name'); $venue->indoor_or_outdoor = Input::get('indoor_or_outdoor'); $venue->name_of_hall = Input::get('name_of_hall'); $venue->capacity = Input::get('capacity'); $venue->dimension_height = Input::get('dimension_height'); $venue->dimension_width = Input::get('dimension_width'); $venue->dimension_length = Input::get('dimension_length'); $venue->rigging_capacity = Input::get('rigging_capacity'); $venue->notes = Input::get('notes'); $address = $venue->address()->first() ?: new Address(); $country = Country::where('name', Input::get('country'))->first(); $address->country()->associate($country); $address->address = Input::get('address_address'); $address->postal_code = Input::get('address_postal_code'); $address->city = Input::get('address_city'); $address->state_province = Input::get('address_state_province'); $address->phone = Input::get('address_phone'); $address->fax = Input::get('address_fax'); $address->email = Input::get('address_email'); $address->website = Input::get('address_website'); $address->save(); $venue->address()->associate($address); $venue->save(); $venue->save(); if (Input::get('company_id')) { $venue->companies()->detach(Company::find(Input::get('company_id'))); $venue->companies()->attach(Company::find(Input::get('company_id'))); } if (Input::get('contact_id')) { $venue->contacts()->detach(Contact::find(Input::get('contact_id'))); $venue->contacts()->attach(Contact::find(Input::get('contact_id'))); } return $venue; }
public function address($a) { $lines = array(); if (isset($a['name']) && $a['name']) { $lines[] = '<strong>' . $a['name'] . '</strong>'; } if (isset($a['address_1']) && $a['address_1']) { $lines[] = $a['address_1']; } if (isset($a['address2']) && $a['address2']) { $lines[] = $a['address2']; } if (isset($a['city']) && $a['city'] || isset($a['state']) && $a['state'] || isset($a['zip']) && $a['zip']) { $line = array(); if (isset($a['city']) && $a['city']) { $line[] = $a['city']; } if (isset($a['state']) && $a['state']) { $line[] = $a['state']; } if (isset($a['zip']) && $a['zip']) { $line[] = $a['zip']; } $lines[] = implode(' ', $line); } if (isset($a['country_id']) && $a['country_id']) { $lines[] = Country::where('id', $a['country_id'])->pluck('name'); } if (isset($a['phone']) && $a['phone']) { $lines[] = $a['phone']; } if (isset($a['email']) && $a['email']) { $lines[] = $a['email']; } if (isset($a['web']) && $a['web']) { $lines[] = $a['web']; } $lines = join('<br>', $lines); return $lines; }
public function formResult() { $resultObject = simplexml_load_string($this->response); if (!$resultObject) { return false; } $receiverCode = substr($this->identifier, 0, 2); $receiverCountryName = Country::where('code', $receiverCode)->pluck('name_ru'); $senderCode = substr($this->identifier, 11, 2); $senderCountryName = Country::where('code', $senderCode)->pluck('name_ru'); $description = $resultObject->eventdescription; if ($this->strposArray($description, $this->badStatuses)) { return false; } $status = strpos($description, 'відправлене') ? 'Отправлено' : 'В обработке'; $dateLeave = $resultObject->eventdate; $routeStart = $resultObject->lastoffice . ' ' . $resultObject->lastofficeindex; if ($senderCountryName) { $routeStart .= ' (' . $senderCountryName . ')'; } $this->result = array('service' => $this->service, 'identifier' => $this->identifier, 'route_start' => TableBuilder::translate($routeStart, 'uk-ru'), 'route_end' => $receiverCountryName, 'date_leaving' => $dateLeave, 'status' => $status, 'other' => TableBuilder::translate($description, 'uk-ru')); return true; }
public static function country($code) { $country = Country::where('code', '=', $code)->get()->first(); return $country ? $country->name : 'Bolivia'; }
public function run() { DB::table('wines')->truncate(); DB::table('wineries')->truncate(); DB::connection()->disableQueryLog(); set_time_limit(3600); $c = 0; $i = 1; $count = 1; $winery_id = 1; try { $file = app_path() . '/rakuten_wine_data_20140905.csv'; //$file = app_path() . '/testcsv.csv'; $i = 1; $country_name_on_wines = Wine::take(300)->get(array('country_name')); $country_name_ja_list = Country::get(array('country_name_ja')); foreach ($country_name_ja_list as $country_name) { if ($country_name->country_name_ja != null) { if ($i == 1) { $re = $country_name->country_name_ja; $i++; } else { $re = $re . "|" . $country_name->country_name_ja; } } } $re_country_name = "'/" . $re . "/'"; $parser = \KzykHys\CsvParser\CsvParser::fromFile($file, array("encoding" => "UTF-8")); foreach ($parser as $column_wine) { echo $c++ . "\n"; if (count($column_wine) == 33) { $validator = Validator::make(array('rakuten_id' => $column_wine[0]), array('rakuten_id' => 'exists:wines2,rakuten_id')); if ($validator->passes()) { if ($column_wine[13] == 'NA' && $column_wine[14] !== 'NA') { $column_wine[13] = $column_wine[14]; } if ($column_wine[9] == 'NA' && $column_wine[10] !== 'NA') { $column_wine[9] = $column_wine[10]; } for ($j = 0; $j < 33; $j++) { if ($column_wine[$j] == 'NA') { $column_wine[$j] = ''; } } if ($column_wine[3] == '') { $column_wine[3] = $column_wine[1]; } if ($column_wine[9] != null) { $in_string = preg_match($re_country_name, $column_wine[9], $matches); if ($in_string == true) { //$country = explode('・', $country_name->country_name, -1); $country = Country::where('country_name_ja', $matches[0])->first(); if ($country) { $flag = $country->flag_url; } else { $flag = null; } } } $winery = Winery::where('brand_name', $column_wine[16])->first(); if ($winery == null) { $winery_data = array('id' => $winery_id, 'brand_name' => $column_wine[16], 'country_id' => '', 'country_name' => $column_wine[10], 'year' => $column_wine[14], 'winery_url' => $column_wine[18], 'region' => $column_wine[11], 'description' => ''); Winery::create($winery_data); $winery = $winery_id; $winery_id++; } else { $winery = $winery->id; } $wine = array('name' => $column_wine[3], 'name_en' => $column_wine[4], 'sub_name' => $column_wine[5], 'sub_name_en' => $column_wine[6], 'year' => $column_wine[13], 'winery_id' => $winery, 'rakuten_id' => $column_wine[0], 'original_name' => $column_wine[1], 'original_name_2' => $column_wine[2], 'country_name' => $column_wine[9], 'image_url' => $column_wine[27], 'wine_flag' => $flag, 'imformation_image' => $column_wine[21] . ',' . $column_wine[22] . ',' . $column_wine[23] . ',' . $column_wine[24] . ',' . $column_wine[25] . ',' . $column_wine[26], 'rakuten_url' => $column_wine[17], 'wine_unique_id' => $i . '_' . $column_wine[13], 'color' => $column_wine[12], 'average_price' => $column_wine[15], 'average_rate' => 0, 'rate_count' => 0, 'wine_type' => $column_wine[7], 'folder_code' => $column_wine[20]); if ($wine['year'] == '' || $wine['year'] == 0) { $wine['wine_unique_id'] = $i . '_' . $i; } Wine::create($wine); $i++; } } else { $error = implode(",", $column_wine); $file_error = app_path() . "/error.txt"; file_put_contents($file_error, $error . "\n", FILE_APPEND | LOCK_EX); } } } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } }
/** * Display the specified resource. * GET /recettes/{id} * * @param int $id * @return Response */ public function show($id) { $recette = Recette::find($id); // On ajoute le pays pour la recette. $recette['country'] = array(); $countries = Country::where('id', '=', $recette['idPays'])->firstOrFail(); $recette['country'] = $countries->nom; // On ajoute les auteurs pour la recette. $recette['authors'] = array(); $listIdauthors = DB::table('link_recette_author')->where('idRecette', '=', $recette['id'])->lists('idAutheur'); // On recherche les id de tous les auteurs de la recette $autheurs = Autheur::whereIn('id', $listIdauthors)->lists('nom'); // on recherche tous les noms des auteurs de la recette. $recette['authors'] = $autheurs; // On ajoute les catégories pour la recette. $recette['categories'] = array(); $listIdcategories = DB::table('link_recette_categorie')->where('idRecette', '=', $recette['id'])->lists('idCategorie'); $categories = Categorie::whereIn('id', $listIdcategories)->lists('nom'); $recette['categories'] = $categories; // On ajoute les photos pour chaque recette. $recette['photos'] = array(); $listIdphotos = DB::table('link_recette_photo')->where('idRecette', '=', $recette['id'])->lists('idPhoto'); $photos = Photo::whereIn('id', $listIdphotos)->lists('nom'); $recette['photos'] = $photos; // On ajoute la liste de chaque categorie d'ingredients pour chaque recette. $recette['ingredients'] = array(); $listIdCategorieIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->distinct()->lists('idCategorie'); $listIdIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->lists('idIngredient'); $listQuantIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->lists('idQuantite'); $listOrdreIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->lists('Ordre'); // On met dans un tableau le nombre d'ingredient par categorie $listNbrIngrParCat = array(); foreach ($listIdCategorieIngred as $idCatIngre) { $listNbrIngrParCat[sizeof($listNbrIngrParCat)] = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->where('idCategorie', '=', $idCatIngre)->distinct()->count(); } //On récupère le nom des catégories. $nomsCatIngredients = CategorieIngredient::whereIn('id', $listIdCategorieIngred)->lists('nom'); $ingredients = array(); foreach ($listIdIngred as $idIngredCurrent) { $ing = Ingredient::where('id', '=', $idIngredCurrent)->firstOrFail(); array_push($ingredients, $ing->nom); } $ingredientsFinal = array(); for ($j = 0; $j < sizeof($listIdCategorieIngred); $j++) { $ingredientsArray = array(); $offset = 0; // on a créé un décalage pour parcourir la lsite des ingrédients. if ($j != 0) { $offset = $listNbrIngrParCat[$j - 1]; } for ($i = 0 + $offset; $i < $listNbrIngrParCat[$j] + $offset; $i++) { $ingredientsArray[$i] = array('Ordre' => $listOrdreIngred[$i], 'Ingredient' => $ingredients[$i], 'lien' => ""); } $ingredientsFinal[$j] = array('Titre' => $nomsCatIngredients[$j], 'DetailsIngre' => $ingredientsArray); } $recette['ingredients'] = $ingredientsFinal; // On ajoute la liste de chaque categorie de préparations pour la recette. $recette['preparations'] = array(); $listIdCategoriePrepa = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->distinct()->lists('idCatPrepa'); $listIdPhrasePrepa = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->lists('idPhrasePrepa'); $listOrdrePhrase = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->lists('Ordre'); // On met dans un tableau le nombre de phrase de préparation par categorie $listNbrPhraseParCat = array(); foreach ($listIdCategoriePrepa as $idCatPrepa) { $listNbrPhraseParCat[sizeof($listNbrPhraseParCat)] = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->where('idCatPrepa', '=', $idCatPrepa)->distinct()->count(); } //On récupère le nom des catégories de préparation. $nomsCatPhrase = CategoriePrepa::whereIn('id', $listIdPhrasePrepa)->lists('nom'); $phrases = array(); foreach ($listIdPhrasePrepa as $idPhrasePrepaCurrent) { $phrase = PhrasePrepa::where('id', '=', $idPhrasePrepaCurrent)->firstOrFail(); array_push($phrases, $phrase->phrase); } $phrasesFinal = array(); for ($j = 0; $j < sizeof($listIdCategoriePrepa); $j++) { $phrasesArray = array(); $offset = 0; // on a créé un décalage pour parcourir la lsite des ingrédients. if ($j != 0) { $offset = $listNbrPhraseParCat[$j - 1]; } for ($i = 0 + $offset; $i < $listNbrPhraseParCat[$j] + $offset; $i++) { $phrasesArray[$i] = array('Ordre' => $listOrdrePhrase[$i], 'Phrase' => $phrases[$i]); } $phrasesFinal[$j] = array('Titre' => $nomsCatPhrase[$j], 'Phrases' => $phrasesArray); } $recette['preparations'] = $phrasesFinal; return Response::json($recette); }
/** * Return country by location. * * @param $latitude * @param $longitude * @return mixed */ public function findByLocation($latitude, $longitude) { return Country::where(['latitude' => $latitude, 'longitude' => $longitude])->limit(1)->get(); }
public function postNewCampus() { //verify the user input and create account $validator = Validator::make(Input::all(), array('Country' => 'required|exists:countrys,id')); if ($validator->fails()) { return Redirect::route('newcampus-get')->withErrors($validator)->withInput()->with('global', 'Sorry!! College details were not posted, please retry.'); } else { $countryid = Input::get('Country'); //query the database for colleges in that country $colleges = Institution::where('country_id', '=', $countryid)->get(); if ($colleges->count()) { $countries = Country::where('id', '>', 0)->get(); View::share('countries', $countries); View::share('colleges', $colleges); View::share('countryid', $countryid); return View::make('member.addcampus2'); } else { $countries = Country::where('id', '>', 0)->get(); View::share('countries', $countries); return Redirect::route('newcampus-get')->withInput()->with('global', 'No Colleges were found in this country!'); } return Redirect::route('newcampus-get')->withInput()->with('global', 'Sorry!! Campus details were not posted, please retry.'); } }
public function findCountry() { // if ( Session::token() !== Input::get( '_token' ) ) { // echo "this is not token"; // } $country = Input::get('country'); $result = Country::where('nama', 'LIKE', '%' . $country . '%')->get(); foreach ($result as $row) { echo $row->nama . "<br/>"; } }
public static function getProfileBasicUser($user_id) { $error_code = ApiResponse::OK; $user_login = Session::get('user_id'); if (User::where('user_id', $user_id)->first()) { $users = Profile::orderBy('rate_count', 'desc')->get(); $i = 0; if ($users) { foreach ($users as $key) { $i++; if ($key['user_id'] == $user_id) { break; } } } $profile = Profile::where('user_id', $user_id)->first(); if ($profile->image != null) { $profile->image = URL::asset($profile->image); } if ($profile->country_id != null) { $country = Country::where('id', $profile->country_id)->first(); $profile->country_name = $country->country_name; $profile->country_flag = URL::asset($country->flag_url); } $wishlists = Wishlist::where('user_id', $user_id)->get(); if ($wishlists) { $profile->wishlist_count = count($wishlists); } else { $profile->wishlist_count = 0; } if ($user_id != $user_login) { $follow = Follow::where('from_id', $user_login)->where('to_id', $user_id)->first(); if ($follow) { $profile->is_follow = true; } else { $profile->is_follow = false; } } $profile->user_ranking = $i; $data = $profile->toArray(); } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } return array("code" => $error_code, "data" => $data); }
public function getMoreHomePageSqueeb($lastid) { $campusid = $this->getDevice(); $obj = new BaseController(); $campusid = $this->getDevice(); if ($campusid == 0) { $countryname = $obj->getCountryName(); if ($countryname == 'NONE') { return Redirect::route('selectcampus-get'); } else { //check whether the country name exists inthe db $locationcountry = Country::where('name', '=', $countryname); if ($locationcountry->count()) { $locationcountrycode = $locationcountry->first()->code; $locationcountrycode = strtolower($locationcountrycode); return Redirect::route('selectcountryid', $locationcountrycode); } else { return Redirect::route('selectcampus-get'); } } } $more = true; $college = Institution::whereHas('Branch', function ($query) use($campusid) { $query->where('id', '=', $campusid); })->first(); $collegeid = $college->id; $countryid = Country::where('id', '=', $college->country_id)->first()->id; //get the top squeeb to display $newsqueebs = Squeeb::where('active', '=', TRUE)->where('branch_id', '=', $campusid)->orderBy('id', 'DESC')->take(self::TOP_SQUEEB_LIMIT)->get(); View::share('newsqueebs', $newsqueebs); $squeebs = Notice::whereHas('Squeeb', function ($query) use($campusid, $lastid) { $query->where('branch_id', '=', $campusid)->where('id', '<', $lastid)->where('active', '=', TRUE); })->orwhereHas('Squeeb', function ($query) use($lastid) { $query->where('branch_id', '=', 0)->where('world', '=', TRUE)->where('id', '<', $lastid)->where('active', '=', TRUE); })->orwhereHas('Squeeb', function ($query) use($lastid, $countryid) { $query->where('branch_id', '=', 0)->where('country', '=', $countryid)->where('id', '<', $lastid)->where('active', '=', TRUE); })->orwhereHas('Squeeb', function ($query) use($lastid, $collegeid) { $query->where('branch_id', '=', 0)->where('college', '=', $collegeid)->where('id', '<', $lastid)->where('active', '=', TRUE); }); $last = $squeebs; $squeebs = $squeebs->orderBy('id', 'DESC')->take(self::SQUEEB_LIMIT)->get(); if ($squeebs->count()) { $last_id = $last->orderBy('id', 'DESC')->take(self::SQUEEB_LIMIT)->get()->last()->Squeeb()->first()->id; } View::share('last_id', $last_id); View::share('squeebs', $squeebs); //get the top squeeb to display $topsqueebs = Squeeb::where('active', '=', TRUE)->where('model', '=', 'Notice')->where('branch_id', '=', $campusid)->orderBy('views', 'DESC')->take(self::TOP_SQUEEB_LIMIT)->get(); View::share('topsqueebs', $topsqueebs); if ($lastid <= 0 or $squeebs->count() != self::SQUEEB_LIMIT) { $more = false; } $college = Institution::whereHas('Branch', function ($query) use($campusid) { $query->where('id', '=', $campusid); })->first(); View::share('college', $college); View::share('more', $more); $mycampus = Branch::where('id', '=', $campusid)->first(); View::share('mycampus', $mycampus); return View::make('guest.home'); }
public static function getWineDetail($wine_id) { $user_id = Session::get('user_id'); $wine = Wine::where('wine_id', $wine_id)->with('winery')->first(); $error_code = ApiResponse::OK; if ($wine) { if ($wine->wine_type != null) { $wine->wine_type = Wine::getWineType($wine->wine_type); } $wine->image_url = Wine::getImageWineFromServer($user_id, $wine->wine_unique_id, $wine->image_url); if ($wine->wine_flag != null) { $wine->wine_flag = URL::asset($wine->wine_flag); } $country = Country::where('id', $wine->winery->country_id)->first(); if ($country) { $wine->winery->country_id = $country->country_name; } else { $wine->winery->country_id = null; } $wine_note = Winenote::where('wine_unique_id', $wine->wine_unique_id)->where('user_id', $user_id)->first(); if ($wine_note) { $wine->winenote = $wine_note->note; } else { $wine->winenote = null; } $wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $wine->wine_unique_id)->first(); if ($wishlist) { $wine->is_wishlist = true; } else { $wine->is_wishlist = false; } $all_wines_winery = Wine::where('winery_id', $wine->winery_id)->whereNotIn('wine_id', [$wine_id])->where('year', '>', 0)->where('average_rate', '>', 0)->orderBy('year', 'desc')->take(10)->get(); $wine->winery->count_wine = count($all_wines_winery) + 1; $rate_winery = $wine->rate_count; if (count($all_wines_winery) !== 0) { $sum_rate_winery = $wine->average_rate; foreach ($all_wines_winery as $wine_winery) { $wine_on_winery = Wine::where('wine_id', $wine_winery->wine_id)->first(); $wine_on_winery->image_url = Wine::getImageWineFromServer($user_id, $wine_on_winery->wine_unique_id, $wine_on_winery->image_url); $rate_count = $wine_on_winery->rate_count; $rate_winery = $rate_winery + $rate_count; $average_rate = $wine_on_winery->average_rate; $sum_rate_winery = $sum_rate_winery + $average_rate; } $wine->winery->total_rate = $rate_winery; $wine->winery->average_rate_winery = $sum_rate_winery / count($all_wines_winery); } else { $wine->winery->total_rate = $rate_winery; $wine->winery->average_rate_winery = $wine->average_rate; } $wine->total_like = 0; $rating_user = Rating::where('wine_unique_id', $wine->wine_unique_id)->where('user_id', $user_id)->with('profile')->first(); if (count($rating_user) == 0) { $rating_user = null; } else { if ($rating_user->profile->image != null) { $rating_user->profile->image = URL::asset($rating_user->profile->image); } $wine->total_like = $wine->total_like + $rating_user->like_count; } $ratings = Rating::where('wine_unique_id', $wine->wine_unique_id)->whereNotIn('user_id', [$user_id])->with('profile')->get(); if (count($ratings) == 0) { $ratings = array(); } else { foreach ($ratings as $rating) { if ($rating->profile->image != null) { $rating->profile->image = URL::asset($rating->profile->image); } $follow = Follow::where('from_id', $user_id)->where('to_id', $rating->user_id)->first(); if ($follow) { $rating->is_follow = true; } else { $rating->is_follow = false; } $wine->total_like = $wine->total_like + $rating->like_count; } } $data = array('wine' => $wine, 'rate_user' => $rating_user, 'rate' => $ratings, 'wine_related' => $all_wines_winery); } else { $error_code = ApiResponse::UNAVAILABLE_WINE; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE); } return array("code" => $error_code, "data" => $data); }
public function get_wizard() { $user_id = Auth::user()->id; $user = Auth::user()->email; $user_admin = Neighbors::where('user_id', '=', $user_id)->first(); $code = Auth::user()->confirmation_code; $urbanism_types = UrbanismType::orderBy('id', 'ASC')->lists('type', 'id'); $countries = Country::orderBy('id', 'ASC')->lists('name', 'id'); $states = State::orderBy('id', 'ASC')->lists('name', 'id'); $country_default = 'México'; $selected_country = Country::where('name', '=', $country_default)->first(); return View::make('dashboard.colonies.admin.create_colony', ['urbanism_types' => $urbanism_types, 'user' => $user, 'user_admin' => $user_admin, 'countries' => $countries, 'states' => $states, 'code' => $code, 'selected_country' => [$selected_country->id], 'select' => ['' => 'Seleccione tipo de desarrollo'], 'select_1' => ['' => 'Seleccione País'], 'select_2' => ['' => 'Seleccione Estado'], 'select_3' => ['' => 'Seleccione Ciudad']]); }