Example #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;
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Bookmark::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, 'advert_id' => $this->advert_id]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Displays a single Advert model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     if (Currency::find()->where(['>', 'date', time()])->orderBy(['date' => SORT_DESC])->asArray()->one() == null) {
         $currency = new Currency();
         if ($currency->exchangeRates()) {
             Yii::$app->session->setFlash('warning', 'Exchange rates might differ from actual ones');
         }
     }
     $model = $this->findModel($id);
     $pic = new Pictures();
     $imgModel = new UploadForm();
     $n = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId(), 'advert_id' => $id])->all();
     if ($model->user_id == Yii::$app->user->identity->getId()) {
         if (isset($_POST['delete'])) {
             $model->deletePic();
         }
         if (!empty($n)) {
             $value = 'Delete ' . 'from bookmarks';
         } else {
             $value = 'Add to bookmarks';
         }
         if (Yii::$app->request->isPost) {
             $imgModel->imageFiles = UploadedFile::getInstances($imgModel, 'imageFiles');
             if ($imgModel->upload($id)) {
                 return $this->render('view-my-advert', ['model' => $this->findModel($id), 'imgModel' => $imgModel, 'pic' => $pic]);
             }
         }
         return $this->render('view-my-advert', ['model' => $this->findModel($id), 'imgModel' => $imgModel, 'pic' => $pic, 'value' => $value]);
     } else {
         $views = new Views();
         $n = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId(), 'advert_id' => $id])->all();
         if (!empty($n)) {
             $value = 'Delete ' . 'from bookmarks';
         } else {
             $value = 'Add to bookmarks';
         }
         if (!$views->countViews($id)) {
             if ($model->user_id !== Yii::$app->user->identity->getId()) {
                 $advert = new Advert();
                 $advert->countViews($id);
                 $views->advert_id = $id;
                 $views->user_id = Yii::$app->user->identity->getId();
                 $views->save();
             }
         }
         return $this->render('view-adv', ['model' => $this->findModel($id), 'pic' => $pic, 'imgModel' => $imgModel, 'value' => $value]);
     }
 }
Example #4
0
 public function actionDeleteBm($advert_id)
 {
     Bookmark::findOne(['advert_id' => $advert_id, 'user_id' => Yii::$app->user->identity->getId()])->delete();
     return $this->redirect(['my-bookmarks']);
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBookmarks()
 {
     return $this->hasMany(Bookmark::className(), ['user_id' => 'id']);
 }
Example #6
0
 function bookmark_store(Request $request)
 {
     if ($request->job_id) {
         $user_id = $this->user->id;
         //当前用户的id
         $data = [];
         foreach ($request->job_id as $job_id) {
             $bookmark = Bookmark::where('user_id', $user_id)->where('job_id', $job_id)->first();
             if ($bookmark) {
                 continue;
             }
             $data['user_id'] = $user_id;
             $data['job_id'] = $job_id;
             Bookmark::create($data);
         }
     }
     return redirect('/my/regist/rireki');
 }
Example #7
0
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]);
Example #8
0
 public function getMyBookmarks()
 {
     $query = Bookmark::find()->andFilterWhere(['user_id' => Yii::$app->user->identity->getId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
Example #9
0
 /**
  * Finds the Bookmark model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Bookmark the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Bookmark::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #10
0
 public function actionAddToBookmarks($id)
 {
     $bookmark = new Bookmark();
     $n = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId(), 'advert_id' => $id])->all();
     //        var_dump(!empty($n)); die;
     if (!empty($n)) {
         echo Json::encode([]);
     } else {
         $bookmark->user_id = Yii::$app->user->identity->getId();
         $bookmark->advert_id = $id;
         $bookmark->save();
         echo Json::encode([]);
     }
 }