/** * Displays a single Activity model. * @param integer $id * @return mixed */ public function actionView($id) { $rate = new \app\models\Rating(); $activityProvider = new ActiveDataProvider(['query' => \app\models\Rating::find()->where(['activity_id' => $id]), 'pagination' => ['pageSize' => 8]]); Yii::$app->notification->viewer($id); return $this->render('view', ['model' => $this->findModel($id), 'rate' => $rate, 'activityProvider' => $activityProvider]); }
public function findUniqueRatings($dvds) { $added = []; $ratings = []; foreach ($dvds as $dvd) { if (!array_key_exists($dvd->rating_id, $added)) { $added[$dvd->rating_id] = true; $ratings[] = Rating::find($dvd->rating_id); } } return $ratings; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $rating = Rating::find($id); if ($rating) { if ($rating->update($request->all())) { return response(['message' => 'successfull']); } else { return $this->errorUpdated(); } } else { return $this->store($request); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Rating::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, 'activity_id' => $this->activity_id, 'user_id' => $this->user_id, 'rate' => $this->rate]); return $dataProvider; }
public function countEntered($id, $aid) { return count(Rating::find()->where(['user_id' => $id, 'activity_id' => $aid])->all()) > 0 ? true : false; }