public function allAcomByCity($city) { $am = new AccommodationModel(); $accomm = null; $accommodations = []; try { $accomm = DB::table('accommodations')->where('province', $city)->orWhere('city', $city)->paginate(5); if (count($accomm) == 0) { return null; } foreach ($accomm as $ac) { $a = new Accommodation(); $a->setID($ac->id); $a->setBaths($ac->bathrooms); $a->setBeds($ac->beds); $a->setCapacity($ac->capacity); $a->setCity($ac->city); $a->setDesc($ac->desc); $a->setInside($ac->inside); $a->setOutside($ac->outside); $a->setPhotos($am->allPhotos($ac->id)); $a->setPrice($ac->price_per_person); $a->setProvince($ac->province); $a->setTitle($ac->title); $a->setInitialDesc($ac->desc); $accommodations[] = $a; } } catch (QueryException $ex) { return null; } return $accommodations; }
public function accommodationByOwner($owner_id) { $accomm = null; $accommodations = []; try { $accomm = AccommodationModel::all()->where('user_id', $owner_id); if ($accomm->count() == 0) { return null; } foreach ($accomm as $ac) { $a = new Accommodation(); $a->setID($ac->id); $a->setBaths($ac->bathrooms); $a->setBeds($ac->beds); $a->setCapacity($ac->capacity); $a->setCity($ac->city); $a->setDesc($ac->desc); $a->setInside($ac->inside); $a->setOutside($ac->outside); $a->setPhotos($this->allPhotos($ac->id)); $a->setPrice($ac->price_per_person); $a->setProvince($ac->province); $a->setTitle($ac->title); $a->setInitialDesc($ac->desc); $accommodations[] = $a; } } catch (QueryException $ex) { return null; } return $accommodations; }
/** * Escenario: Buscar los alojamientos de una ciudad que sí tiene resultados desde página de búsqueda * Dado que soy un usuario del sistema y pretendo buscar los alojamientos de una determinada ciudad desde la página de búsqueda * Si escribo dicha ciudad en el buscador y sí se encuentran resultados * El sistema deberá redireccionar a la dirección 'search/accommodations/City/page/1' * Y mostrar los alojamientos disponibles * * @return void * @group searchAcceptance * @test */ public function try_search() { $am = new AccommodationModel(); $a1 = new Accommodation(); $p1 = new Photo(); $p2 = new Photo(); $owner = new Owner(); $um = new UserModel(); $arrayPhoto = []; $owner->setName("Norman"); $owner->setEmail("*****@*****.**"); $owner->setSurname("Coloma"); $owner->setPhone("654987321"); $owner->setPassword("prueba"); $um->createUser($owner); $p1->setUrl('url/photo1'); $p1->setMain(1); $p2->setUrl('url/photo2'); $p2->setMain(0); $arrayPhoto[] = $p1; $arrayPhoto[] = $p2; $a1->setBaths(2); $a1->setBeds(3); $a1->setCapacity(5); $a1->setCity('Madrid'); $a1->setDesc('Alojamiento de lujo.'); $a1->setInside('Descripción del interior del alojamiento.'); $a1->setOutside('Descripción del exterior del alojamiento.'); $a1->setPhotos($arrayPhoto); $a1->setPrice(50); $a1->setProvince('Madrid'); $a1->setTitle('Casa rural'); $am->createAccom($a1, $um->getID($owner->getEmail())); $this->visit('/')->see('Destacados')->type('Elche', 'city')->press('BUSCAR')->seePageIs('search/accommodations/Elche/page/1')->see('No hay resultados para la búsqueda introducida!')->type('Madrid', 'city')->press('Buscar')->seePageIs('/search/accommodations/Madrid/page/1')->see('Madrid'); }
/** * Testeamos que el método devuelva null si no existe el id del owner * * @return void * @group getAccommByOwnerFail */ public function testFailGetAccommByOwnerID() { $am = new AccommodationModel(); $this->assertNull($am->accommodationByOwner(100)); }
/** * Recuperamos los alojamientos de una determinada ciudad de la BD * * @return void * @group getAccomByCity */ public function testgetAllAccommByCity() { $this->notSeeInDatabase('accommodations', ['title' => 'Casa rural']); $am = new AccommodationModel(); $a1 = new Accommodation(); $a2 = new Accommodation(); $p1 = new Photo(); $p3 = new Photo(); $p2 = new Photo(); $p4 = new Photo(); $owner = new Owner(); $owner2 = new Owner(); $um = new UserModel(); $sm = new \App\Models\SystemModel(); $arrayPhoto = []; $arrayPhoto2 = []; $arrayAcomm = []; $owner->setName("Norman"); $owner->setEmail("*****@*****.**"); $owner->setSurname("Coloma"); $owner->setPhone("654987321"); $owner->setPassword("prueba"); $owner2->setName("Norman"); $owner2->setEmail("*****@*****.**"); $owner2->setSurname("Coloma"); $owner2->setPhone("654987321"); $owner2->setPassword("prueba"); $um->createUser($owner); $um->createUser($owner2); $p1->setUrl('url/photo1'); $p1->setMain(1); $p2->setUrl('url/photo2'); $p2->setMain(0); $p3->setUrl('url/photo3'); $p3->setMain(1); $p4->setUrl('url/photo4'); $p4->setMain(0); $arrayPhoto[] = $p1; $arrayPhoto[] = $p2; $arrayPhoto2[] = $p3; $arrayPhoto2[] = $p4; $a1->setBaths(2); $a1->setBeds(3); $a1->setCapacity(5); $a1->setCity('Elche'); $a1->setDesc('Alojamiento de lujo.'); $a1->setInside('Descripción del interior del alojamiento.'); $a1->setOutside('Descripción del exterior del alojamiento.'); $a1->setPhotos($arrayPhoto); $a1->setPrice(number_format((double) 50, 2, '.', '')); $a1->setProvince('Alicante'); $a1->setTitle('Casa rural'); $a1->setInitialDesc($a1->getDesc()); $a2->setBaths(4); $a2->setBeds(5); $a2->setCapacity(20); $a2->setCity('Elche'); $a2->setDesc('Alojamiento de caca.'); $a2->setInside('Descripción del interior del alojamiento2.'); $a2->setOutside('Descripción del exterior del alojamiento2.'); $a2->setPhotos($arrayPhoto2); $a2->setPrice(number_format((double) 150, 2, '.', '')); $a2->setProvince('Alicante'); $a2->setTitle('Casa rural2'); $a2->setInitialDesc($a2->getDesc()); $accom = $am->createAccom($a1, $um->getID($owner->getEmail())); $accom2 = $am->createAccom($a2, $um->getID($owner2->getEmail())); $a1->setID($accom['id']); $a2->setID($accom2['id']); $arrayAcomm[] = $a1; $arrayAcomm[] = $a2; $this->SeeInDatabase('accommodations', ['title' => 'Casa rural']); $this->SeeInDatabase('photos', ['url' => 'url/photo1']); $this->SeeInDatabase('photos', ['url' => 'url/photo2']); $this->SeeInDatabase('accommodations', ['title' => 'Casa rural2']); $this->SeeInDatabase('photos', ['url' => 'url/photo3']); $this->SeeInDatabase('photos', ['url' => 'url/photo4']); //Testeamos el método allAccomByCity $this->assertEquals($arrayAcomm, $sm->allAcomByCity("Elche")); }
/** * Recibimos por parámetro los datos para insertar un nuevo alojamiento. * * @param Request $request * @return Response */ public function addAccommodation(Request $request) { $am = new AccommodationModel(); $accom = new Accommodation(); $file = null; $files = null; $photos = []; $size = 0; if ($request->hasFile('new-accom-main-img')) { $file = $request->file('new-accom-main-img'); $photo = new Photo(); $photo->setUrl($file->getClientOriginalName()); $photo->setMain(true); $photos[] = $photo; if ($request->hasFile('galery')) { $files = $request->file('galery'); foreach ($files as $f) { $size = $size + $f->getClientSize(); $photo = new Photo(); $photo->setUrl($f->getClientOriginalName()); $photo->setMain(false); $photos[] = $photo; } } } if ($size > 30720000) { return redirect('/manage/owner#newAccom')->withErrors(['galery' => 'La galería no puede pesar más de 30mb'])->withInput(); } else { $validator = Validator::make($request->all(), ['new-accom-title' => 'required|regex:/^[A-Z]+[a-zA-ZÁÉÍÓÚáéíóuñÑ\\s\']+$/', 'new-accom-city' => 'required|regex:/^[A-Z]+[a-zA-ZÁÉÍÓÚáéíóuñÑ\\s\']+$/', 'new-accom-desc' => 'required', 'new-accom-price' => 'required|numeric', 'new-accom-main-img' => 'required|image|mimes:jpeg,jpg,bmp,png,gif|max:5120'], $this->messages); if ($validator->fails()) { return redirect('/manage/owner#newAccom')->withErrors($validator)->withInput(); } else { $accom->setTitle($request->input('new-accom-title')); $accom->setCity($request->input('new-accom-city')); $accom->setProvince($request->input('new-accom-province')); $accom->setBaths($request->input('new-accom-baths')); $accom->setBeds($request->input('new-accom-beds')); $accom->setCapacity($request->input('new-accom-capacity')); $accom->setPrice($request->input('new-accom-price')); if ($request->has('new-accom-inside')) { $accom->setInside($request->input('new-accom-inside')); } if ($request->has('new-accom-outside')) { $accom->setOutside($request->input('new-accom-outside')); } $accom->setDesc($request->input('new-accom-desc')); $accom->setPhotos($photos); echo "good"; try { $am->createAccom($accom, Auth::user()->id); if ($this->uploadPhoto($file)) { if ($files != null) { foreach ($files as $file) { $this->uploadPhoto($file); } } } flash()->overlay('Tu alojamiento se ha anunciado correctamente. Puedes comprobarlo desde tu panel de control.', 'Publicado'); return redirect("/manage/owner"); } catch (QueryException $ex) { echo $ex; } } } }