/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ip::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, 'product_id' => $this->product_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
<?php use yii\helpers\Html; use kartik\rating\StarRating; use yii\widgets\ActiveForm; use backend\models\Ip; use backend\models\Product; use frontend\helpers\ProductHelper; $this->title = $model->title; /* @var $this yii\web\View */ $ip = Yii::$app->request->userIP; $ipModel = Ip::find()->where(['name' => $ip, 'product_id' => $model->id])->one(); if ($ipModel) { $isRatingDisabled = true; } ?> <div class="row"> <div class="col-sm-4"> <?php require Yii::getAlias('@partials') . '/_slider.php'; echo $slider; ?> </div> <div class="col-sm-8"> <article> <h2 class="product-view"><?php echo $model->title; ?> </h2> <p><?php
/** * */ public function actionCharge($ip) { $model = Charge::find()->where(['ip' => $ip])->one(); $ipModel = Ip::find()->where(['ip' => $ip])->one(); if (!$model) { $model = new Charge(); $model->ip = $ip; } if ($model->load(Yii::$app->request->post())) { if ($model->state != 'state_normal') { $telnet = new Telnet(); $telnet->signin(); $telnet->rebind($ip, $ipModel->mac); $telnet->close(); $model->state = "state_normal"; } $model->save(); return $this->redirect(['index']); } else { return $this->render('charge', ['model' => $model]); } }
public function actionProductRating() { if (Yii::$app->request->isAjax and $rating = Yii::$app->request->post('rating') and $id = Yii::$app->request->post('id')) { if ($product = Product::findOne($id)) { $ip = Yii::$app->request->userIP; $ipModel = Ip::find()->where(['name' => $ip, 'product_id' => $id])->one(); if ($ipModel === null) { $currentRating = $product->rating; $currentRatingCount = $product->rating_count; $resultRating = round(($currentRating + $rating) / 2, 1); $product->rating = $resultRating; $product->rating_count = $currentRatingCount + 1; $product->save(); $model = new Ip(); $model->name = $ip; $model->product_id = $id; $model->save(); return true; } else { return 'forbidden'; // $this->refresh(); } } else { return false; } // return json_encode([$rating, $id]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } }