public function actionUpdateAnswer($id) { $btnYes = Yii::$app->request->post('btn-yes'); $btnNo = Yii::$app->request->post('btn-no'); if (isset($btnNo)) { $memberProgress = MembersProgress::find()->where(['member_id' => Yii::$app->user->id, 'category_id' => $id])->one(); if (!$memberProgress) { $memberProgress = new MembersProgress(); $memberProgress->progress = 1; $memberProgress->member_id = Yii::$app->user->id; $memberProgress->category_id = $id; } else { $memberProgress->progress++; } if ($memberProgress->save()) { return Yii::$app->response->redirect(array('members/index')); } } else { $questionsAnswers = new MembersQuestionsAnswers($id); $precessStatus = Yii::$app->MappingComponent->processQuestions($questionsAnswers); if ($precessStatus) { return Yii::$app->response->redirect(array('members/index')); } else { $categoryModel = MappingCategories::findOne($id); $questionsModel = MappingQuestions::find()->where(['category_id' => $id, 'is_active' => 1])->orderBy('order DESC')->with('fieldsTypes')->all(); return $this->render('update_answers', ['categoryModel' => $categoryModel, 'questionsModel' => $questionsModel, 'questionsAnswers' => $questionsAnswers]); } } }
public function getCategoryProgressDate($categoryId, $memberId) { if (!Yii::$app->user->isGuest) { /* initiate members progress data and save to database */ $memberProgress = MembersProgress::find()->where(['category_id' => $categoryId, 'member_id' => $memberId])->one(); $memberProgressTime = 0; //if member progress does not exist if (!empty($memberProgress)) { $memberProgressTime = $memberProgress->updated_at; } return $memberProgressTime; } return false; }