예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Listing::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['listing_id' => $this->listing_id, 'price' => $this->price, 'is_sold' => $this->is_sold, 'pg1_gallery_id' => $this->pg1_gallery_id, 'create_user_id' => $this->create_user_id, 'create_time' => $this->create_time, 'update_user_id' => $this->update_user_id, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'listing_num', $this->listing_num])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'img_path', $this->img_path])->andFilterWhere(['like', 'sm_img_path', $this->sm_img_path]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  * POST /listings
  *
  * @return Response
  */
 public function store()
 {
     $data = Input::all();
     //unset all empty control
     foreach ($data as $key => $value) {
         if ($value == "") {
             unset($data[$key]);
         }
     }
     $listing = new Listing();
     if ($listing->validate($data)) {
         $listing->fill($data);
         $listing->save();
         $user = Auth::user();
         if ($user->seller != null) {
             $listing->seller()->associate($user->seller);
             $listing->save();
         } elseif ($user->broker != null) {
             $listing->broker()->associate($user->broker);
             $listing->save();
         }
         $files = Input::file('photos');
         foreach ($files as $file) {
             if ($file != null && $file->isValid()) {
                 $lp = new ListingPhoto();
                 $lp->photo_url = 'listings/' . $listing->id . '/' . time() . $file->getClientOriginalName();
                 $file->move(public_path('files/listings/' . $listing->id), $lp->photo_url);
                 $lp->listing()->associate($listing);
                 $lp->save();
             }
         }
         return View::make(Auth::user()->role->name . '.listings.add_photos')->withListing($listing)->withSuccess('<strong>Congratulations. Your listing has been created successfully and will be available once verified by admin.</strong>');
     }
     Input::flash();
     return View::make(Auth::user()->role->name . '.listings.create')->withErrors($listing->getValidator());
 }
예제 #3
0
 /**
  * Finds the Listing model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Listing the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Listing::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 /**
  * Unapproves a listing
  * @param  Listing $listing The listing to approve/unapprove
  * @return Response
  */
 public function unapprove($listing)
 {
     $listing->verified = 0;
     $listing->save();
     if (Request::ajax()) {
         return Response::json($listing);
     }
     return View::make('admin.listings')->withUnapprove(true);
 }