Beispiel #1
0
 public function upload(Request $request)
 {
     $listing = new Listing();
     $listing->fill($request->all());
     if ($request->hasFile('file')) {
         $file = $request->file('file');
         $filename = date('U') . $file->getClientOriginalName();
         $file->move(public_path('uploads/'), $filename);
         $listing->image = $filename;
     }
     $listing->user_id = Auth::user()->id;
     // $user = Auth::user
     // $listing->fill
     $listing->save();
     return redirect('/');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ListingRequest $request)
 {
     //
     /** save data from Landlord form to database **/
     $model = new Listing();
     $model->address = $request->get('address');
     $model->cross_street = $request->get('cross_street');
     $model->square_feet = $request->get('square_feet');
     $model->price = $request->get('price');
     $model->deposit_price = $request->get('deposit_price');
     $model->last_price = $request->get('last_price');
     $model->type_of_dwelling = $request->get('type_of_dwelling');
     $model->lease = $request->get('lease');
     $model->bedroom = $request->get('bedroom');
     $model->bathroom = $request->get('bathroom');
     $model->carport = $request->get('carport');
     $model->garage = $request->get('garage');
     $model->furnished = $request->get('furnished');
     $model->pets = $request->get('pets');
     $model->features = $request->get('features');
     $model->schools = $request->get('schools');
     $model->map = $request->get('map');
     $model->description = $request->get('description');
     $model->owner_name = $request->get('owner_name');
     $model->contact_number = $request->get('contact_number');
     $model->status = $request->get('status');
     $model->save();
     /* save photo and file details to database via Update */
     $listing = Listing::findOrFail($model->id);
     if ($request->file('photo') != NULL) {
         $imageName = $model->id . '-listing-photo.' . $request->file('photo')->getClientOriginalExtension();
         $request->file('photo')->move(base_path() . '/public/images/catalog/', $imageName);
         $listing->photos = base_path() . '/public/images/catalog/' . $imageName;
     }
     if ($request->file('file') != NULL) {
         $fileName = $model->id . '-listing-file.' . $request->file('file')->getClientOriginalExtension();
         $request->file('file')->move(base_path() . '/public/images/catalog/', $fileName);
         $listing->file = base_path() . '/public/images/catalog/' . $fileName;
     }
     $listing->save();
     return redirect('listing');
 }
    public function addListing(Request $request)
    {
        //needs login to add session id
        if (!Auth::check()) {
            //This should not be possible
            //But in the case the user SOMEHOW is not logged in, redirect
            return redirect('signIn');
        }
        $v = Validator::make($request->all(), ['title_name' => 'bail|required', 'location_name' => 'bail|required|numeric', 'floorNum_name' => 'bail|alpha_num', 'unitNum_name' => 'bail|alpha_num', 'dateFrom_name' => 'bail|required', 'dateTo_name' => 'bail', 'rent_name' => 'bail|required|numeric|min:0', 'rentalLength_name' => 'bail|numeric|min:0', 'priceDescription_name' => '', 'sqft_name' => 'min:0', 'bedrooms_name' => 'bail|numeric|min:0', 'bathrooms_name' => 'bail|numeric|min:0', 'sqftSize_name' => 'bail|numeric|min:0', 'image.*' => 'required|image', 'mls' => 'alpha_num']);
        //Check if validation passes. If not, redirect.
        if ($v->fails()) {
            return redirect('addListing')->withErrors($v)->withInput();
        }
        $listing = new Listing();
        $listing->location_id = Input::get('location_name');
        $listing->save();
        $listingInfo = new Listing_Info();
        $listingInfo->listing_id = $listing->listing_id;
        $listingInfo->date_created = Carbon::now();
        $listingInfo->is_active = true;
        $listingInfo->listing_title = ucwords(Input::get('title_name'));
        $listingInfo->listing_description = Input::get('description_name', 'No Description');
        $listingInfo->price_monthly = Input::get('rent_name');
        $listingInfo->price_description = Input::get('priceDescription_name', 'No Description');
        $listingInfo->unit = Input::get('unitNum_name');
        $listingInfo->room_level = Input::get('floorNum_name');
        $listingInfo->num_bedrooms_total = Input::get('bedrooms_name');
        $listingInfo->num_bathrooms_total = Input::get('bathrooms_name');
        $listingInfo->num_roommates_max = Input::get('roommatesNum_name');
        $listingInfo->room_size_sqft = Input::get('sqft_name', 0);
        //Booleans
        $listingInfo->has_kitchen = Input::has('kitchen_name') ? true : false;
        $listingInfo->has_laundry = Input::has('laundry_name') ? true : false;
        $listingInfo->has_yard = Input::has('yard_name') ? true : false;
        $listingInfo->has_furnishings = Input::has('furnishing_name') ? true : false;
        $listingInfo->owner_pays_internet = Input::has('internet_name') ? true : false;
        $listingInfo->owner_pays_water = Input::has('water_name') ? true : false;
        $listingInfo->owner_pays_electricity = Input::has('electricity_name') ? true : false;
        $listingInfo->owner_has_pets = Input::has('allergy_name') ? true : false;
        $listingInfo->allowed_dogs = Input::has('dogs_name') ? true : false;
        $listingInfo->allowed_cats = Input::has('cats_name') ? true : false;
        $listingInfo->allowed_other_pets = Input::has('otherPets_name') ? true : false;
        $listingInfo->smoke_free = Input::has('smoke_name') ? true : false;
        $listingInfo->details_pets = Input::get('petDescription_name');
        $listingInfo->mls_number = Input::get('mls', 'N/A');
        $listingInfo->rental_length_months_min = Input::get('rentalLength_name');
        $listingInfo->rental_available_from = Input::get('dateFrom_name');
        $listingInfo->rental_available_to = Input::get('dateTo_name', NULL);
        $listingInfo->save();
        $imageNum = 0;
        foreach ($request->file('image') as $file) {
            $imageNum = $imageNum + 1;
            $file_prefix = 'images/listing_photos/';
            $img = Image::make($file);
            $img_t = Image::make($file);
            $img_t->resize(600, null, function ($constraint) {
                $constraint->aspectRatio();
            });
            $filename = $file_prefix . time() . '_imgNum' . $imageNum . '_' . $listing->listing_id;
            $img->save($filename);
            $img_t->save($filename . '_thumb', 100);
            $lis_img = new Listing_Image();
            $lis_img->listing_id = $listing->listing_id;
            $lis_img->image_filename = $filename;
            $lis_img->image_filename_thumbnail = $filename . '_thumb';
            $lis_img->save();
        }
        /* Scan new listing for saved searches match, and send SMS message */
        $dbg = false;
        //set to true for testing
        $query = <<<SQL
\t\t\tSELECT \t*
\t\t\tFROM \thomestead.saved_searches AS SEARCH
\t\t\tINNER \tJOIN homestead.users AS USER ON SEARCH.user_id = USER.user_id
SQL;
        $searches = DB::select($query);
        foreach ($searches as $s) {
            $match = true;
            if ($dbg) {
                print "User {$s->first_name} has a search<br>";
            }
            $str = $s->phone;
            $ph = "";
            for ($i = 0; $i < strlen($str); $i++) {
                if (is_numeric($str[$i])) {
                    $ph = $ph . $str[$i];
                }
            }
            if ($ph[0] == 1) {
                $ph = substr($ph, 0, 11);
            } else {
                $ph = substr($ph, 0, 10);
            }
            if ($dbg) {
                printf("The phone is : " . $ph . "<br>");
            }
            /* Check price range if max pricing is not in saved search */
            if ($s->price_monthly_max < 2000) {
                if ($listingInfo->price_monthly >= $s->price_monthly_min && $listingInfo->price_monthly <= $s->price_monthly_max) {
                    if ($dbg) {
                        print "Price matches search criteria<br>";
                    }
                } else {
                    $match = false;
                }
            }
            if ($listingInfo->num_bedrooms_total < $s->num_bedrooms_total) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 1<br>";
                }
            }
            if ($listingInfo->num_bathrooms_total < $s->num_bathrooms_total) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 2<br>";
                }
            }
            if ($listingInfo->num_roommates_max > $s->num_roommates_max) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 3<br>";
                }
            }
            if (($s->has_kitchen == 1 ? true : false) && !$listingInfo->has_kitchen) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 4 {$listingInfo->has_kitchen} {$listingInfo->has_kitchen} " . (Input::has('kitchen_name') ? "A" : "B") . "<br>";
                }
            }
            if (($s->has_laundry == 1 ? true : false) && !$listingInfo->has_laundry) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 5<br>";
                }
            }
            if (($s->has_yard == 1 ? true : false) && !$listingInfo->has_yard) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 6<br>";
                }
            }
            if (($s->has_furnishings == 1 ? true : false) && !$listingInfo->has_furnishings) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 7<br>";
                }
            }
            if (($s->owner_pays_internet == 1 ? true : false) && !$listingInfo->owner_pays_internet) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 8<br>";
                }
            }
            if (($s->owner_pays_water == 1 ? true : false) && !$listingInfo->owner_pays_water) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 9<br>";
                }
            }
            if (!($s->owner_has_pets == 1 ? true : false) && $listingInfo->owner_has_pets) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 10<br>";
                }
            }
            if (($s->allowed_dogs == 1 ? true : false) && !$listingInfo->allowed_dogs) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 11<br>";
                }
            }
            if (($s->allowed_cats == 1 ? true : false) && !$listingInfo->allowed_cats) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 12<br>";
                }
            }
            if (($s->allowed_other_pets == 1 ? true : false) && !$listingInfo->allowed_other_pets) {
                $match = false;
            }
            if ($dbg) {
                if (!$match) {
                    print "No match 13<br>";
                }
            }
            if ($match && strlen($ph) == 10) {
                if ($dbg) {
                    print "This listing matches your search criteria<br>";
                }
                $msg = <<<MSG
Hello {$s->first_name}!
Homestead has found a {$listingInfo->num_bedrooms_total} bedroom,{$listingInfo->num_bathrooms_total} bathroom property that matches the criteria in your saved search #{$s->saved_search_id}.

Please visit our website to check out the listing for more details!

Regards,
 The Homestead Team

MSG;
                $em = $s->email;
                Mail::raw($msg, function ($message) use($ph, $msg) {
                    $message->from('*****@*****.**', 'Homestead');
                    $message->to('*****@*****.**');
                    $message->subject($ph);
                });
                Mail::raw($msg, function ($message) use($ph, $msg, $em) {
                    $message->from('*****@*****.**', 'Homestead');
                    $message->to($em);
                    $message->subject('Homestead listing search results');
                    //print "SMS sent to $ph<br>";
                });
            } else {
                if ($dbg) {
                    print "This listing does not match your search criteria<br>";
                }
            }
        }
        if ($dbg) {
            return var_dump($searches) . var_dump($listingInfo);
        }
        return redirect('houseTemplate/' . $listing->listing_id);
    }
 public function postListing(Request $request, $slug)
 {
     if (Auth::guest()) {
         flash()->error("You need to be logged in to post.");
         return redirect()->back();
     }
     if (!Auth::user()->contact_number) {
         flash()->error("Enter your contact number in the settings to post.");
         return redirect()->back();
     }
     $game = Game::where('slug', $slug)->first();
     if (!$game) {
         flash("Something's wrong with your posting");
         return redirect()->back();
     }
     $listing = new Listing();
     $listing->price = (double) $request->input('price');
     if ($request->input('condition') == "Excellent" || $request->input('condition') == "Good" || $request->input('condition') == "Disc Only") {
         $listing->condition = $request->input('condition');
     } else {
         flash("Something's wrong with your input");
         return redirect()->back();
     }
     $list_of_cities = ['Abra', 'Agusan del Norte', 'Agusan del Sur', 'Aklan', 'Albay', 'Antique', 'Apayao', 'Aurora', 'Basilan', 'Bataan', 'Batanes', 'Batangas', 'Benguet', 'Biliran', 'Bohol', 'Bukidnon', 'Bulacan', 'Cagayan', 'Camarines Norte', 'Camarines Sur', 'Camiguin', 'Capiz', 'Catanduanes', 'Cavite', 'Cebu', 'Compostela Valley', 'Cotabato', 'Davao del Norte', 'Davao del Sur', 'Davao Oriental', 'Eastern Samar', 'Guimaras', 'Ifugao', 'Ilocos Norte', 'Ilocos Sur', 'Iloilo', 'Isabela', 'Kalinga', 'La Union', 'Laguna', 'Lanao del Norte', 'Lanao del Sur', 'Leyte', 'Maguindanao', 'Marinduque', 'Masbate', 'Metro Manila', 'Misamis Occidental', 'Misamis Oriental', 'Mountain Province', 'Negros Occidental', 'Negros Oriental', 'Northern Samar', 'Nueva Ecija', 'Nueva Vizcaya', 'Occidental Mindoro', 'Oriental Mindoro', 'Palawan', 'Pampanga', 'Pangasinan', 'Quezon', 'Quirino', 'Rizal', 'Romblon', 'Samar', 'Sarangani', 'Siquijor', 'Sorsogon', 'South Cotabato', 'Southern Leyte', 'Sultan Kudarat', 'Sulu', 'Surigao del Norte', 'Surigao del Sur', 'Tarlac', 'Tawi-Tawi', 'Zambales', 'Zamboanga del Norte', 'Zamboanga del Sur', 'Zamboanga Sibugay'];
     if (in_array($request->input('location'), $list_of_cities)) {
         $listing->location = $request->input('location');
     }
     $listing->game_id = $game->id;
     $listing->user_id = (int) Auth::user()->id;
     $listing->save();
     return redirect()->back();
 }