Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(StoreAdRequest $request)
 {
     $isFree = $request['is_free'] == 'on';
     $userId = Auth::check() ? Auth::user()->id : null;
     $ad = Ad::create(['title' => $request['title'], 'text' => $request['text'], 'author_name' => $request['name'], 'phone' => $request['phone'], 'category_id' => $request['category_id'], 'city_id' => $request['city_id'], 'price' => $isFree ? 0 : $request['price'], 'is_free' => $isFree, 'author_id' => $userId]);
     /*
      *   Store the ad's images
      */
     if ($request->has('images')) {
         $imagesArr = [];
         foreach ($request['images'] as $image) {
             $imagePaths = explode('|', $image);
             $imagesArr[] = ['ad_id' => $ad->id, 'small' => $imagePaths[0], 'big' => $imagePaths[1]];
         }
         AdImage::insert($imagesArr);
     }
     /*
      *   Store the ad's auto extra properties if received
      */
     if ($request->has('make')) {
         AutoExtraProperties::create(['ad_id' => $ad->id, 'model_id' => $request['model'], 'year' => $request['year'], 'capacity' => $request['capacity'], 'engine_type' => $request['engine_type'], 'transmission' => $request['transmission'], 'mileage' => $request['mileage'], 'power' => $request['power']]);
     }
     /*
      *   Store the ad's realty extra properties if received
      */
     if ($request->has('type_of_ad')) {
         RealtyExtraProperties::create(['ad_id' => $ad->id, 'type' => $request['type_of_ad'], 'lease' => $request['lease'], 'num_of_rooms' => $request['num_of_rooms'], 'square' => $request['square'], 'floor' => $request['floor'], 'num_of_floors' => $request['num_of_floors']]);
     }
     // Ad::createAd($ad); // Auto properties, realty properties
     return redirect('/ad/' . $ad->id);
 }
Ejemplo n.º 2
0
 public function run()
 {
     DB::table('ads')->delete();
     $imgs = array('2015-06-09-06-45-14-465.png', '2015-06-09-11-42-59-111.png', '2015-06-09-11-43-32-544.png', '2015-06-09-12-02-11-636.png', '2015-06-09-12-02-26-650.png', '2015-06-09-12-02-42-669.png', '2015-06-09-12-03-02-88.png', '2015-06-09-12-03-18-933.gif');
     for ($i = 1; $i <= 5000; $i++) {
         Ad::create(['uid' => $i % 200 + 1, 'title' => 'Title (' . $i . ')', 'type' => $i % 2, 'img_path' => $imgs[$i % 8], 'content' => 'Content (' . $i . ')', 'uname' => 'Uname (' . ($i % 200 + 1) . ')', 'longitude' => 113.398238 + ($i % 200 + 1) / 5000, 'latitude' => 23.06668 + ($i % 200 + 1) / 5000, 'begin_at' => '2015-07-' . ($i % 31 + 1), 'end_at' => '2015-08-' . ($i % 31 + 1), 'status' => $i % 4, 'page_view' => 0, 'page_click' => 0]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(AdminAdCreateRequest $request)
 {
     $ad = Ad::create($request->all());
     $ad->slug = str_slug($ad->nombre);
     $ad->save();
     if ($ad->save()) {
         notify()->flash('Ad created correctly', 'success', ['timer' => 3000, 'text' => '']);
     } else {
         notify()->flash('There was a problem creating the advert', 'error', ['timer' => 3000, 'text' => '']);
     }
     return redirect()->to("admin/ad");
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $ad = Ad::create($request->all());
     return $ad;
 }
Ejemplo n.º 5
0
 public function doNewAd()
 {
     $input = \Input::all();
     //input 'corrections'
     if (isset($input['door'])) {
         if ($input['door'] == '0') {
             $input['door'] = $input['door_letter'];
         } else {
             if ($input['door'] == '1') {
                 $input['door'] = $input['door_number'];
             }
         }
     }
     if (isset($input['has_booking'])) {
         if ($input['has_booking'] == '1') {
             $input['booking'] = $input['booking-percentage'];
         } else {
             if ($input['has_booking'] == '2') {
                 $input['booking'] = $input['booking-euros'];
             }
         }
     }
     if (isset($input['has_deposit'])) {
         if ($input['has_deposit'] == '1') {
             $input['deposit'] = $input['deposit-percentage'];
         } else {
             if ($input['has_deposit'] == '2') {
                 $input['deposit'] = $input['deposit-euros'];
             }
         }
     }
     //create new Ad ID
     $newAd = Ad::create();
     $input['ad_id'] = $newAd->id;
     //associate pictures to the new Ad ID
     foreach ($input as $key => $value) {
         $exp_key = explode('_', $key);
         if ($exp_key[0] == 'pictures') {
             $pictures[] = ['filename' => $value];
         }
     }
     if (isset($pictures)) {
         foreach ($pictures as $picture) {
             AdPic::create(['filename' => $picture['filename'], 'ad_id' => $input['ad_id']]);
         }
     }
     //save all the details of the ad in its specific table
     switch ($input['operation']) {
         case '0':
             //sell
             switch ($input['typology']) {
                 case '0':
                     //apartment
                     $new = SellApartment::create($input);
                     $table = 'sell_apartment';
                     break;
                 case '1':
                     //house
                     $new = SellHouse::create($input);
                     $table = 'sell_house';
                     break;
                 case '2':
                     //country house
                     $new = SellCountryHouse::create($input);
                     $table = 'sell_country_house';
                     break;
                 case '3':
                     //office
                     $new = SellOffice::create($input);
                     $table = 'sell_office';
                     break;
                 case '4':
                     //business
                     $new = SellBusiness::create($input);
                     $table = 'sell_business';
                     break;
                 case '5':
                     //garage
                     $new = SellGarage::create($input);
                     $table = 'sell_garage';
                     break;
                 case '6':
                     //land
                     $new = SellLand::create($input);
                     $table = 'sell_land';
                     break;
             }
             break;
         case '1':
             //rent
             switch ($input['typology']) {
                 case '0':
                     //apartment
                     $new = RentApartment::create($input);
                     $table = 'rent_apartment';
                     break;
                 case '1':
                     //house
                     $new = RentHouse::create($input);
                     $table = 'rent_house';
                     break;
                 case '2':
                     //country house
                     $new = RentCountryHouse::create($input);
                     $table = 'rent_country_house';
                     break;
                 case '3':
                     //office
                     $new = RentOffice::create($input);
                     $table = 'rent_office';
                     break;
                 case '4':
                     //business
                     $new = RentBusiness::create($input);
                     $table = 'rent_business';
                     break;
                 case '5':
                     //garage
                     $new = RentGarage::create($input);
                     $table = 'rent_garage';
                     break;
                 case '6':
                     //land
                     $new = RentLand::create($input);
                     $table = 'rent_land';
                     break;
                 case '7':
                     //vacation (lodging)
                     $new = Lodging::create($input);
                     $table = 'rent_vacation';
                     //associate prices to new lodging
                     foreach ($input as $key => $value) {
                         $exp_key = explode('-', $key);
                         if ($exp_key[0] == 'n_season') {
                             SeasonPrice::create(['n_season' => $value, 'from_date' => Carbon::createFromFormat('d/m/Y', $input['from_date-' . $value]), 'to_date' => Carbon::createFromFormat('d/m/Y', $input['to_date-' . $value]), 'p_one_night' => $input['p_one_night-' . $value], 'p_weekend_night' => $input['p_weekend_night-' . $value], 'p_one_week' => $input['p_one_week-' . $value], 'p_half_month' => $input['p_half_month-' . $value], 'p_one_month' => $input['p_one_month-' . $value], 'p_extra_guest_per_night' => $input['p_extra_guest_per_night-' . $value], 'n_min_nights' => $input['n_min_nights-' . $value], 'rent_vacation_id' => $new->id]);
                         }
                     }
                     break;
                 case '8':
                     //room
                     $new = Room::create($input);
                     $table = 'rent_room';
                     break;
             }
             break;
     }
     //save local table and ID as ad fields
     if (isset($new) && isset($table)) {
         $newAd->local_table = $table;
         $newAd->local_id = $new->id;
         $newAd->save();
     }
     //return success to admin dashboard
     if (isset($new->id)) {
         return redirect('dashboard')->with('success', ['Stitle' => 'Nuevo anuncio', 'Smsg' => 'Su nuevo anuncio ha sido creado satisfactoriamente.']);
     }
     return redirect('dashboard')->with('error', ['Etitle' => 'Nuevo anuncio', 'Emsg' => 'Se produjo un error al tratar de crear un nuevo anuncio. Si el problema persiste póngase en contacto con el Servicio Técnico de la aplicación.']);
 }
Ejemplo n.º 6
0
 public function postPublish(Request $request)
 {
     $rules = ['ad_title' => 'required|max:255', 'category_id' => 'required|integer|not_in:0', 'ad_description' => 'required|min:50', 'type_id' => 'required|integer|not_in:0', 'ad_image' => 'require_one_of_array', 'ad_image.*' => 'mimes:jpeg,bmp,png|max:300', 'location_id' => 'required|integer|not_in:0', 'ad_puslisher_name' => 'required|string|max:255', 'ad_email' => 'required|email|max:255', 'policy_agree' => 'required'];
     $messages = ['require_one_of_array' => 'You need to upload at least one ad pic.'];
     $validator = Validator::make($request->all(), $rules, $messages);
     /**
      * type 1 common ads validation
      */
     $validator->sometimes(['ad_price_type_1'], 'required|numeric|not_in:0', function ($input) {
         if ($input->category_type == 1 && $input->price_radio == 1) {
             return true;
         }
         return false;
     });
     $validator->sometimes(['condition_id_type_1'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 1 ? 1 : 0;
     });
     /**
      * type 2 estate ads validation
      */
     $validator->sometimes(['ad_price_type_2'], 'required|numeric|not_in:0', function ($input) {
         if ($input->category_type == 2) {
             return true;
         }
         return false;
     });
     $validator->sometimes(['estate_type_id'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 2 ? 1 : 0;
     });
     $validator->sometimes(['estate_sq_m'], 'required|numeric|not_in:0', function ($input) {
         return $input->category_type == 2 ? 1 : 0;
     });
     /**
      * type 3 cars ads validation
      */
     $validator->sometimes(['car_brand_id'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['car_model_id'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['car_engine_id'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['car_transmission_id'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['car_modification_id'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['car_year'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['car_kilometeres'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['car_condition_id'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['condition_id_type_3'], 'required|integer|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     $validator->sometimes(['ad_price_type_3'], 'required|numeric|not_in:0', function ($input) {
         return $input->category_type == 3 ? 1 : 0;
     });
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $ad_data = $request->all();
     //get user info by ad email or create new user
     $current_user_id = 0;
     if (Auth::check()) {
         $current_user_id = Auth::user()->user_id;
         $user = Auth::user();
     } else {
         //check this mail for registered user
         try {
             $user = User::where('email', $ad_data['ad_email'])->firstOrFail();
         } catch (\Exception $e) {
             //no user create one
             //generate password
             $password = str_random(10);
             $user = new User();
             $user->name = $ad_data['ad_puslisher_name'];
             $user->email = $ad_data['ad_email'];
             $user->user_phone = $ad_data['ad_phone'];
             $user->user_skype = $ad_data['ad_skype'];
             $user->user_site = $ad_data['ad_link'];
             $user->user_location_id = $ad_data['location_id'];
             $user->user_address = $ad_data['ad_address'];
             $user->user_lat_lng = $ad_data['ad_lat_lng'];
             $user->password = bcrypt($password);
             $user->user_activation_token = str_random(30);
             $user->save();
             //send activation mail
             Mail::send('emails.activation', ['user' => $user, 'password' => $password], function ($m) use($user) {
                 $m->from('*****@*****.**', 'dclassifieds activation');
                 $m->to($user->email)->subject('Activate your account!');
             });
         }
         $current_user_id = $user->user_id;
     }
     //fill aditional fields
     $ad_data['user_id'] = $current_user_id;
     $ad_data['ad_publish_date'] = date('Y-m-d H:i:s');
     $ad_data['ad_valid_until'] = date('Y-m-d', mktime(null, null, null, date('m') + 1, date('d'), date('Y')));
     $ad_data['ad_ip'] = Util::getRemoteAddress();
     $ad_data['ad_description'] = Util::nl2br(strip_tags($ad_data['ad_description']));
     switch ($ad_data['category_type']) {
         case 1:
             if ($ad_data['price_radio'] == 1) {
                 $ad_data['ad_price'] = $ad_data['ad_price_type_1'];
                 $ad_data['ad_free'] = 0;
             } else {
                 $ad_data['ad_price'] = 0;
                 $ad_data['ad_free'] = 1;
             }
             $ad_data['condition_id'] = $ad_data['condition_id_type_1'];
             break;
         case 2:
             $ad_data['ad_price'] = $ad_data['ad_price_type_2'];
             $ad_data['condition_id'] = $ad_data['condition_id_type_2'];
             break;
         case 3:
             $ad_data['ad_price'] = $ad_data['ad_price_type_3'];
             $ad_data['condition_id'] = $ad_data['condition_id_type_3'];
             break;
     }
     $ad_data['ad_description_hash'] = md5($ad_data['ad_description']);
     //generate ad unique code
     do {
         $ad_data['code'] = str_random(30);
     } while (Ad::where('code', $ad_data['code'])->first());
     //create ad
     $ad = Ad::create($ad_data);
     //upload and fix ad images
     $ad_image = Input::file('ad_image');
     $destination_path = public_path('uf/adata/');
     $first_image_uploaded = 0;
     foreach ($ad_image as $k) {
         if (!empty($k) && $k->isValid()) {
             $file_name = $ad->ad_id . '_' . md5(time() + rand(0, 9999)) . '.' . $k->getClientOriginalExtension();
             $k->move($destination_path, $file_name);
             $img = Image::make($destination_path . $file_name);
             $width = $img->width();
             $height = $img->height();
             if ($width == $height || $width > $height) {
                 $img->heighten(1000, function ($constraint) {
                     $constraint->upsize();
                 })->save($destination_path . '1000_' . $file_name);
             } else {
                 $img->widen(1000, function ($constraint) {
                     $constraint->upsize();
                 })->save($destination_path . '1000_' . $file_name);
             }
             if (!$first_image_uploaded) {
                 $img->resizeCanvas(740, 740, 'top')->save($destination_path . '740_' . $file_name);
                 $ad->ad_pic = $file_name;
                 $ad->save();
                 $first_image_uploaded = 1;
             } else {
                 $adPic = new AdPic();
                 $adPic->ad_id = $ad->ad_id;
                 $adPic->ad_pic = $file_name;
                 $adPic->save();
             }
             @unlink($destination_path . $file_name);
         }
     }
     $ad->ad_category_info = $this->category->getParentsByIdFlat($ad->category_id);
     $ad->ad_location_info = $this->location->getParentsByIdFlat($ad->location_id);
     $ad->pics = AdPic::where('ad_id', $ad->ad_id)->get();
     $ad->same_ads = Ad::where([['ad_description_hash', $ad->ad_description_hash], ['ad_id', '<>', $ad->ad_id]])->get();
     //send info and activation mail
     Mail::send('emails.ad_activation', ['user' => $user, 'ad' => $ad], function ($m) use($user) {
         $m->from('*****@*****.**', 'dclassifieds ad activation');
         $m->to($user->email)->subject('Activate your ad!');
     });
     //send control mail
     Mail::send('emails.control_ad_activation', ['user' => $user, 'ad' => $ad], function ($m) {
         $m->from('*****@*****.**', '[CONTROL] dclassifieds');
         $m->to('*****@*****.**')->to('*****@*****.**')->subject('[CONTROL] dclasssifieds new ad');
     });
     //set flash message and return
     session()->flash('message', 'Your ad is in moderation mode, please activate it.');
     return redirect()->back();
 }