/** * Display the specified resource. * * @param string $location * @return Response */ public function show() { $location = Input::get('location'); $type = strtolower(Input::get('type')); $wildcardLocation = "%" . $location . "%"; if (Input::has('type')) { $types = array('meeting-room', 'coworking', 'desk'); if (!in_array($type, $types, true)) { return Redirect::to('/')->with('flash_message_404', "Sorry, we don't have that type of space so we brought you back home!"); } $listings = Listing::with('thumbnail')->where('isPublic', '=', 1, "and")->where('space_type', '=', $type)->where('city', 'LIKE', $wildcardLocation)->orWhere('state', 'LIKE', $wildcardLocation)->orWhere('suburb', 'LIKE', $wildcardLocation)->orWhere('country', 'LIKE', $wildcardLocation)->orWhere('postcode', 'LIKE', $wildcardLocation)->get(); } else { $listings = Listing::with('thumbnail')->where('isPublic', '=', 1, "and")->where('space_type', '=', $type)->where('city', 'LIKE', $wildcardLocation)->orWhere('state', 'LIKE', $wildcardLocation)->orWhere('suburb', 'LIKE', $wildcardLocation)->orWhere('country', 'LIKE', $wildcardLocation)->orWhere('postcode', 'LIKE', $wildcardLocation)->get(); } $colNum = Listing::where('city', 'LIKE', $wildcardLocation)->orWhere('state', 'LIKE', $wildcardLocation)->orWhere('suburb', 'LIKE', $wildcardLocation)->orWhere('country', 'LIKE', $wildcardLocation)->where('isPublic', '=', '1')->count(); switch ($colNum) { case 1: $colNum = 12; break; case 2: $colNum = 6; break; case 3: $colNum = 3; break; } $title = ucwords("Search: " . $type . " spaces in " . $location); return View::make('search.results')->with('listings', $listings)->with('title', $title)->with('colNum', $colNum); }
/** * Store a newly created resource in storage. * * @return Response */ public function store($id) { $listing = Listing::where('isPublic', '=', 1)->where('id', '=', $id)->first(); if (!$listing) { throw new \Symfony\Component\Routing\Exception\ResourceNotFoundException(); } $input = Input::all(); //return print_r($input,true); $yesterday = \Carbon\Carbon::now('Australia/Sydney'); $yesterday = $yesterday->format('Y-m-d H:i:s'); // return $yesterday; $rules = array('comments' => array('required', 'min:3'), 'user_phone' => array('required', 'min:9', 'max:30'), 'request_start_datetime' => array('required', 'date', 'dateformat: Y-m-d H:i:s', 'before: ' . $input['request_end_datetime']), 'request_end_datetime' => array('required', 'date', 'dateformat: Y-m-d H:i:s', 'after: ' . $yesterday)); $validator = Validator::make($input, $rules); if ($validator->fails()) { return Redirect::back()->withInput($input)->withErrors($validator); } $comments = $this->sanitizeStringAndParseMarkdown($input['comments']); $authuser = Auth::user(); $name = $authuser->name; $bookings = new Booking(); $bookings->user_id = $authuser->id; $bookings->user_name = $name; $bookings->listing_id = $id; $bookings->user_phone = $input['user_phone']; $bookings->request_start_datetime = $input['request_start_datetime']; $bookings->request_end_datetime = $input['request_end_datetime']; $bookings->status = "Booking request submitted. Awaiting Open Source Collaborative Consumption Marketplace review."; $bookings->user_comments = $comments; $bookings->space_owner_id = $listing->owner_id; $address = $listing->address1 . ", " . $listing->suburb . ", " . $listing->city . " " . $listing->country; $data = $input; $data['address'] = $address; $data['title'] = $listing->title; $data['id'] = $id; $data['type'] = $listing->space_type; $data['user_name'] = $name; $data['status'] = $bookings->status; /* TODO: Make it email the user and space owner */ Mail::send("booking.mail.newbookingfounders", $data, function ($message) { $message->to('*****@*****.**')->subject('New booking on Open Source Collaborative Consumption Marketplace'); }); $email = Auth::user()->email; Mail::send("booking.mail.newbookinguser", $data, function ($message) use($email) { $message->to($email)->subject('Your new booking on Open Source Collaborative Consumption Marketplace!'); }); $bookings->save(); return Redirect::to('dashboard')->with('flash_message_good', "Your booking has been sent. We'll be in touch soon with confirmation or questions!"); }
public function action_deleteExpired() { $date = date("Y-m-d H:i:s"); $date = date('Y-m-d H:i:s', strtotime('-30 day', strtotime($date))); var_dump($date); $listings = Listing::where('date_unavailable', '<', $date)->get(); foreach ($listings as $listing) { $location = Location::find($listing->location_id); $account = Account::find($location->account_id); $email = $account->email; $subject = 'REMARKET: Tell us what happened with your listing.'; $message = "Your posting titled '" . addslashes($listing->title) . "' was recently deleted from market319.tk. \n\n How did it go?" . "\n\n We were wondering if you would fill out our customer survey" . " at market319.tk/survey \n\n Thanks, \n The REMARKET team"; $header = "from: REMARKET <*****@*****.**>"; $sent = mail($email, $subject, $message, $header); $listing->delete(); } }
/** * Toggle the isPublic visibility in storage for a specified ID; * * @param int $id * @return Response */ public function visibility($id) { $listing = Listing::where('id', '=', $id)->first(); /* Check if the user "owns" the space in DB */ if ($listing->owner_id != Auth::user()->id) { return Redirect::back()->with('flash_message_404', 'You do not have permission to change that listing'); } $status = $listing->isPublic; $message = "Visibility for listing: " . $listing->title . " updated!"; if ($status == 1) { $listing->isPublic = 0; $listing->save(); return Redirect::back()->with('flash_message_good', $message); } else { $listing->isPublic = 1; $listing->save(); return Redirect::back()->with('flash_message_good', $message); } }
public function action_sendEmails() { $accounts = Account::where('wishlistEmail', '=', '1')->get(); foreach ($accounts as $account) { $matches = array(); $tags = $account->wishlistitems()->get(); $listings = array(); $tempListings = array(); foreach ($tags as $tag) { $tagListings; $strings = explode(' ', $tag->item); if (sizeof($strings) == 1) { $tagListings = Listing::where('title', 'LIKE', "%{$tag->item}%")->or_where("description", 'LIKE', "%{$tag->item}%")->get(); } else { $string = array_pop($strings); $query = "\tSELECT *\n\t\t\t\t\t\t\t\tFROM listings\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(title LIKE '%{$string}%'\n\t\t\t\t\t\t\t\t\tOR description LIKE '%{$string}%')"; while (!empty($strings)) { $string = array_pop($strings); $query .= " AND (title LIKE '%{$string}%'\n\t\t\t\t\t\t\t\t\tOR description LIKE '%{$string}%')"; } $tagListings = DB::query($query); } foreach ($strings as $string) { } foreach ($tagListings as $listing) { $listing->location = Location::find($listing->location_id); $listing->category = Categorie::find($listing->category_id); } array_push($tempListings, $tagListings); } foreach ($tempListings as $key => $tagListings) { foreach ($tagListings as $listing) { $listings[$listing->id] = $listing; } } var_dump(sizeof($listings)); if (sizeof($listings) > 0) { $email = $account->email; $subject = 'REMARKET: Matches found on your wishlist!'; $message = "There have recently been matches found which match the tags in your wishlist. \n\n" . "Go to market319.tk/ and login to view your wishlist.\n" . "\n\n Happy buying, \n The REMARKET team"; $header = "from: REMARKET <*****@*****.**>"; $sent = mail($email, $subject, $message, $header); } } }