示例#1
0
 public function getMyBookmarks()
 {
     $book = Bookmark::find()->where(['user_id' => 1])->asArray()->all();
     $n = count($book);
     $arr = [];
     for ($i = 0; $i < $n; $i++) {
         $arr[$i] = $book[$i]['advert_id'];
     }
     $query = Advert::find()->andFilterWhere(['IN', 'id', $arr]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Advert::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(['id' => $this->id, 'price' => $this->price, 'fk_agent' => $this->fk_agent, 'bedroom' => $this->bedroom, 'livingroom' => $this->livingroom, 'parking' => $this->parking, 'kitchen' => $this->kitchen, 'hot' => $this->hot, 'sold' => $this->sold, 'recommend' => $this->recommend, 'createAt' => $this->createAt, 'ipdatedAt' => $this->ipdatedAt]);
     $query->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'general_image', $this->general_image])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'type', $this->type]);
     return $dataProvider;
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Advert::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(['id' => $this->id, 'user_id' => $this->user_id, 'region_id' => $this->region_id, 'city_id' => $this->city_id, 'category_id' => $this->category_id, 'subcategory_id' => $this->subcategory_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'views' => $this->views]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
示例#4
0
 public function actionUpload()
 {
     $model = new UploadForm();
     $advert = Advert::find()->where(['user_id' => Yii::$app->user->identity->getId()])->orderBy('id DESC')->asArray()->one();
     $id = $advert['id'];
     if (Yii::$app->request->isPost) {
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         if ($model->upload($id)) {
             return $this->redirect('view?id=' . $id);
         }
     }
     return $this->render('upload', ['model' => $model]);
 }
示例#5
0
文件: try.php 项目: aiskimzhi/advert
use app\models\AdvertSearch;
use app\models\Bookmark;
use app\models\Currency;
use yii\data\ActiveDataProvider;
use yii\helpers\Html;
use yii\helpers\Url;
$columns = [['attribute' => 'price', 'format' => 'html', 'value' => function ($searchModel) {
    $currency = Currency::find()->where(['>', 'date', time()])->asArray()->one();
    $dropDownItems = ['uan' => 'грн.', 'rur' => 'руб.', 'usd' => 'USD', 'eur' => 'EURO'];
    if (isset($_GET['currency']) && $_GET['currency'] !== 'default') {
        $cur = $_GET['currency'];
    } else {
        $cur = $searchModel->currency;
    }
    $price = round($searchModel->price * ($currency[$searchModel->currency] / $currency[$cur]), 2);
    return '<h4><strong>' . $price . ' ' . $dropDownItems[$cur] . '</strong></h4>';
}, 'options' => ['style' => 'width: 130px; max-width: 130px;']], ['attribute' => 'price', 'format' => 'html', 'value' => function ($searchModel) {
    $span = '<span class="glyphicon glyphicon-trash"></span>';
    $url = Url::toRoute(['bookmark/delete-bm', 'advert_id' => $searchModel->id]);
    return Html::a($span, [$url]);
}]];
$searchModel = new AdvertSearch();
$book = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId()])->asArray()->all();
$n = count($book);
$arr = [0];
for ($i = 0; $i < $n; $i++) {
    $arr[$i] = $book[$i]['advert_id'];
}
$query = Advert::find()->andFilterWhere(['IN', 'id', $arr]);
$dataProvider = new ActiveDataProvider(['query' => $query]);
echo $this->render('_try', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'columns' => $columns]);
示例#6
0
 public function lookFor()
 {
     $query = Advert::find()->andFilterWhere(['user_id' => Yii::$app->user->identity->getId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $advert = Advert::find($id);
     if ($advert->author_id == Auth::user()->id) {
         $advert->delete();
         return redirect()->action('Insertions\\AdvertsController@index');
     } else {
         return view('errors.503');
     }
 }