Exemplo n.º 1
0
 /**
  * Displays a single SptTask model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     if (isset($_POST['progress'])) {
         $model->progress = $_POST['progress'];
         $model->save();
         \Yii::$app->session->setFlash('success', 'Save progress success');
     }
     $comment = new \ivoglent\simpletask\models\SptComment(['task_id' => $model->id, 'user_id' => \Yii::$app->user->identity->id]);
     if ($comment->load(\Yii::$app->request->post())) {
         if ($comment->save()) {
             \Yii::$app->session->setFlash('success', 'Comment success');
         } else {
             print_r($model->getErrors());
         }
     }
     $commentProvider = new ActiveDataProvider(['query' => SptComment::find()->where(['task_id' => $id])]);
     return $this->render('view', ['model' => $model, 'commentProvider' => $commentProvider, 'comment' => $comment]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SptComment::find();
     // 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, 'task_id' => $this->task_id, 'user_id' => $this->user_id, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
 /**
  * Finds the SptComment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SptComment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SptComment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComments0()
 {
     return $this->hasMany(SptComment::className(), ['user_id' => 'created_by']);
 }