/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Listing(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Listing'])) { $model->attributes = $_POST['Listing']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->listing_id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Listing(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Listing'])) { $model->attributes = $_POST['Listing']; if (!Yii::app()->user->isGuest) { $user_email = Yii::app()->user->name; $userModel = User::model()->findByAttributes(array('user_email' => $user_email)); $model->listing_owner_user_id = $userModel->user_id; } if ($model->save()) { $this->redirect(array('view', 'id' => $model->listing_id)); } } $this->render('create', array('model' => $model)); }
/** * Make changes to the database. * * @return void */ public function up() { // $locations = Location::all(); foreach ($locations as $loc) { for ($i = 0; $i < 2; $i++) { $l = new Listing(); $l->title = $i; $l->description = "THSI IFS AWIFAWOEIJFAWIEJFWEIFJ"; $l->category_id = "1"; $l->price = 123.12; $l->date_available = "2013-07-27 00:00:00"; $l->date_unavailable = "2013-08-05 00:00:00"; $l->location_id = $loc->id; $l->save(); } } }
/** * Make changes to the database. * * @return void */ public function up() { // $locations = Location::all(); foreach ($locations as $location) { for ($i = 1; $i <= 2; $i++) { $listing = new Listing(); $listing->title = "{$i}"; $listing->description = "description {$i}"; $listing->category = "wood"; $listing->quantity = "{$i}"; $listing->price = "\$" . $i; $listing->date_expiry = "2013-03-19 11:33:22"; $listing->date_available = "2013-03-19 11:33:22"; $listing->date_unavailable = "2013-03-19 11:33:22"; $listing->location_id = $location->id; $listing->save(); } } }
public function action_create() { if (Session::has('id')) { $account = Account::find(Session::get('id')); if (Input::has('title') && Input::has('category_id') && Input::has('price') && Input::has('date_available') && Input::has('date_unavailable')) { $location; if (Input::has('location_id')) { $location = Location::find(Input::get('location_id')); } if (Input::has('address') || Input::has('city') || Input::has('postal_code')) { $location = new Location(); Input::has('address') ? $location->address = Input::get('address') : ($location->address = ''); Input::has('city') ? $location->city = Input::get('city') : ($location->city = ''); Input::has('postal_code') ? $location->postal_code = Input::get('postal_code') : ($location->postal_code = ''); // $location->address = Input::get('address'); // $location->city = Input::get('city'); // $location->postal_code = Input::get('postal_code'); $location->account_id = $account->id; $location->save(); $location = Location::where_address_and_city_and_postal_code(Input::get('address'), Input::get('city'), Input::get('postal_code'))->first(); } else { Session::put('alert', 'Incomplete Location Data'); // $view = View::make('') } $listing = new Listing(); $listing->title = strip_tags(Input::get('title')); $listing->description = Input::has('description') ? strip_tags(Input::get('description')) : ''; $listing->category_id = Input::get('category_id'); $listing->price = Input::get('price'); $date_available = Input::get('date_available'); $date_unavailable = Input::get('date_unavailable'); $listing->date_available = $date_available . "-00-00-00"; $listing->date_unavailable = $date_unavailable . "-00-00-00"; $listing->location_id = $location->id; $listing->save(); $listing = Listing::order_by('id', 'desc')->first(); return Redirect::to('/listing/addimages/' . $listing->id); } else { $categories = Categorie::all(); $locations = $account->locations()->get(); $view = View::make('listing.create.index')->with('title', 'Create a Posting')->with('locations', $locations)->with('categories', $categories); // var_dump($_POST); return $view; } } else { return Redirect::to('/account'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { /* $input = array('name' => 'r'); $rules = array('name' => 'min:5'); dd($coreValidator->messages()); */ /* Validation */ $input = Input::all(); $rules = array('title' => array('required', 'min:3', 'unique:listings'), 'elevator_pitch' => array('required', 'min:3'), 'extended_desc' => 'max:999999', 'faqs' => array('required', 'min:3'), 'address1' => array('required', 'min:4', 'max:255'), 'city' => array('required', 'alpha_num', 'min:3', 'max:255'), 'suburb' => array('required', 'min:3', 'max:255'), 'state' => array('required', 'min:4', 'max:255'), 'country' => array('required', 'min:4', 'max:255'), 'postcode' => array('required', 'numeric', 'min:0000', 'max:9999'), 'daily_rate' => array('required', 'numeric', 'min:0', 'max:9999'), 'weekly_rate' => array('required', 'numeric', 'min:0', 'max:99999'), 'monthly_rate' => array('required', 'numeric', 'min:0', 'max:99999'), 'space_type' => array('required', 'alpha', 'exists:spacetypes,type')); /* Check to see if data is valid */ $coreValidator = Validator::make($input, $rules); if ($coreValidator->fails()) { return Redirect::back()->withErrors($coreValidator)->withInput(); } else { //Check if the images are legit if (!$this->didPassImageValidation()) { return Redirect::back()->with('flash_message_404', 'Sorry, the image(s) you uploaded is not a supported file type'); } //Add new listing to DB. $listing = new Listing(); $listing->owner_id = Auth::user()->id; //Key info $listing->title = $input['title']; $listing->elevator_pitch = $input['elevator_pitch']; $listing->extended_desc = $this->sanitizeStringAndParseMarkdown($input['extended_desc']); $listing->faqs = $this->sanitizeStringAndParseMarkdown($input['faqs']); $listing->space_type = $input['space_type']; //Location $listing->address1 = $input['address1']; $listing->city = $input['city']; $listing->suburb = $input['suburb']; $listing->state = $input['state']; $listing->country = $input['country']; $listing->postcode = $input['postcode']; //Rates $listing->daily_rate = $input['daily_rate']; $listing->weekly_rate = $input['weekly_rate']; $listing->monthly_rate = $input['monthly_rate']; $listing->currency = 'AUD'; $listing->isPublic = 1; //Amenities if (isset($input['wifi'])) { $listing->wifi = 1; } else { $listing->wifi = 0; } if (isset($input['coffee'])) { $listing->coffee_machine = 1; } else { $listing->coffee_machine = 0; } if (isset($input['heating'])) { $listing->heating = 1; } else { $listing->heating = 0; } if (isset($input['parking'])) { $listing->parking = 1; } else { $listing->parking = 0; } if (isset($input['aircon'])) { $listing->aircon = 1; } else { $listing->aircon = 0; } if (isset($input['couches'])) { $listing->couches = 1; } else { $listing->couches = 0; } $listing->save(); /* Image Business */ //Handle thumbnail upload $unique = uniqid("aimg", true); $path = 'images/listing_thumbnails/' . $unique . '.jpg'; $thumb = Input::file('thumbnail')->getRealPath(); $thumb = Image::make($thumb)->resize(300, 200, true, true); $thumb->encode('jpg', 60); $thumb->save($path); if (isset($thumb)) { unset($thumb); } $thumbnail = new Thumbnail(); $thumbnail->listing_id = $listing->id; $thumbnail->url = $path; $thumbnail->alt_text = 'Thumbnail image for ' . $input['title'] . ' space listing'; $thumbnail->save(); $counter = 1; foreach (Input::file('photos') as $photo) { $unique = uniqid("gallery", true); $path = 'images/listing_images/' . $unique . '.jpg'; $photo = $photo->getRealPath(); $photo = Image::make($photo)->resize(800, 450, true, true); $photo->encode('jpg', 60); $photo->save($path); if (isset($photo)) { unset($photo); } $photo = new Photo(); $photo->listing_id = $listing->id; $photo->url = $path; $photo->alt_text = 'Gallery image ' . $counter . "for " . $input['title'] . ' space listing'; $photo->size = "800x450"; $photo->save(); $counter = $counter + 1; } return Redirect::to('/')->with('flash_message_good', 'Successfully listed'); } }