Ejemplo n.º 1
0
 public function run()
 {
     parent::run();
     $products = ViewedProduct::find()->where(['user_id' => \Yii::$app->user->id])->limit($this->num)->all();
     if (!empty($products)) {
         return $this->render('last-viewed-products', ['products' => $products]);
     } else {
         return false;
     }
 }
 /**
  * Deletes an existing ViewedProduct model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     if (!Yii::$app->user->isGuest) {
         if (!empty($id)) {
             $viewedProduct = ViewedProduct::find()->where(['product_id' => $id, 'user_id' => Yii::$app->user->id])->one();
             if ($viewedProduct->user_id == Yii::$app->user->id) {
                 $viewedProduct->delete();
                 return $this->redirect(['list']);
             }
         }
     } else {
         throw new NotFoundHttpException();
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ViewedProduct::find()->where(['user_id' => \Yii::$app->user->id]);
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'product_id' => $this->product_id, 'user_id' => $this->user_id, 'creation_time' => $this->creation_time, 'update_time' => $this->update_time]);
     return $dataProvider;
 }