add filters, refactoring
This commit is contained in:
@ -62,11 +62,16 @@ class AnswerController extends Controller
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
public function actionCreate($question_id = null)
|
||||
{
|
||||
$model = new Answer();
|
||||
$model->question_id = $question_id;
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if ($question_id !== null)
|
||||
{
|
||||
return $this->redirect(['question/view', 'id' => $question_id]);
|
||||
}
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@ -82,11 +87,15 @@ class AnswerController extends Controller
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
public function actionUpdate($id, $question_id = null)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if ($question_id !== null)
|
||||
{
|
||||
return $this->redirect(['question/view', 'id' => $question_id]);
|
||||
}
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@ -102,9 +111,13 @@ class AnswerController extends Controller
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
public function actionDelete($id, $question_id = null)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
if ($question_id !== null)
|
||||
{
|
||||
return $this->redirect(['question/view', 'id' => $question_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace backend\modules\questionnaire\controllers;
|
||||
|
||||
use backend\modules\questionnaire\models\AnswerSearch;
|
||||
use Yii;
|
||||
use backend\modules\questionnaire\models\Question;
|
||||
use backend\modules\questionnaire\models\QuestionSearch;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
@ -52,8 +54,19 @@ class QuestionController extends Controller
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$answerSearchModel = new AnswerSearch();
|
||||
$answerDataProvider = new ActiveDataProvider([
|
||||
'query' => $model->getAnswers(),
|
||||
'pagination' => [
|
||||
'pageSize' => 20,
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
'model' => $model,
|
||||
'answerSearchModel' => $answerSearchModel,
|
||||
'answerDataProvider' => $answerDataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -62,11 +75,23 @@ class QuestionController extends Controller
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
public function actionCreate($questionnaire_id = null, $question_type_id = null)
|
||||
{
|
||||
$model = new Question();
|
||||
$model->questionnaire_id = $questionnaire_id;
|
||||
$model->question_type_id = $question_type_id;
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
|
||||
if ($questionnaire_id !== null )
|
||||
{
|
||||
return $this->redirect(['questionnaire/view', 'id' => $questionnaire_id]);
|
||||
}
|
||||
elseif ($question_type_id !== null)
|
||||
{
|
||||
return $this->redirect(['question-type/view', 'id' => $question_type_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@ -82,11 +107,21 @@ class QuestionController extends Controller
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
public function actionUpdate(int $id, $questionnaire_id = null, $question_type_id = null)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
|
||||
if ($questionnaire_id !== null)
|
||||
{
|
||||
return $this->redirect(['questionnaire/view', 'id' => $questionnaire_id]);
|
||||
}
|
||||
elseif ($question_type_id !== null)
|
||||
{
|
||||
return $this->redirect(['question-type/view', 'id' => $question_type_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@ -102,10 +137,20 @@ class QuestionController extends Controller
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
public function actionDelete(int $id, $questionnaire_id = null, $question_type_id = null)
|
||||
{
|
||||
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
if ($questionnaire_id !== null)
|
||||
{
|
||||
return $this->redirect(['questionnaire/view', 'id' => $questionnaire_id]);
|
||||
}
|
||||
elseif ($question_type_id !== null)
|
||||
{
|
||||
return $this->redirect(['question-type/view', 'id' => $question_type_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace backend\modules\questionnaire\controllers;
|
||||
|
||||
use backend\modules\questionnaire\models\QuestionSearch;
|
||||
use Yii;
|
||||
use backend\modules\questionnaire\models\QuestionType;
|
||||
use backend\modules\questionnaire\models\QuestionTypeSearch;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
@ -52,8 +54,19 @@ class QuestionTypeController extends Controller
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$questionSearchModel = new QuestionSearch();
|
||||
$questionDataProvider = new ActiveDataProvider([
|
||||
'query' => $model->getQuestions(),
|
||||
'pagination' => [
|
||||
'pageSize' => 20,
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
'questionDataProvider' => $questionDataProvider,
|
||||
'questionSearchModel' => $questionSearchModel,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace backend\modules\questionnaire\controllers;
|
||||
|
||||
use backend\modules\questionnaire\models\QuestionnaireSearch;
|
||||
use Yii;
|
||||
use backend\modules\questionnaire\models\QuestionnaireCategory;
|
||||
use backend\modules\questionnaire\models\QuestionnaireCategorySearch;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
@ -52,8 +54,20 @@ class QuestionnaireCategoryController extends Controller
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$questionnaireSearchModel = new QuestionnaireSearch();
|
||||
$questionnaireDataProvider = new ActiveDataProvider([
|
||||
'query' => $model->getQuestionnaires(),
|
||||
'pagination' => [
|
||||
'pageSize' => 20,
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
'model' => $model,
|
||||
'questionnaireDataProvider' => $questionnaireDataProvider,
|
||||
'questionnaireSearchModel' => $questionnaireSearchModel,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -76,11 +76,16 @@ class QuestionnaireController extends Controller
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
public function actionCreate($category_id = null)
|
||||
{
|
||||
$model = new Questionnaire();
|
||||
$model->category_id = $category_id;
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if ($category_id !== null)
|
||||
{
|
||||
return $this->redirect(['questionnaire-category/view', 'id' => $model->category_id]);
|
||||
}
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@ -96,11 +101,15 @@ class QuestionnaireController extends Controller
|
||||
* @return string|Response
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate(int $id)
|
||||
public function actionUpdate(int $id, $category_id = null)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if ($category_id !== null)
|
||||
{
|
||||
return $this->redirect(['questionnaire-category/view', 'id' => $category_id]);
|
||||
}
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@ -116,10 +125,15 @@ class QuestionnaireController extends Controller
|
||||
* @return Response
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionDelete(int $id)
|
||||
public function actionDelete(int $id, $category_id = null)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
if ($category_id !== null)
|
||||
{
|
||||
return $this->redirect(['questionnaire-category/view', 'id' => $category_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace backend\modules\questionnaire\controllers;
|
||||
|
||||
use backend\modules\questionnaire\models\Questionnaire;
|
||||
use backend\modules\questionnaire\models\QuestionnaireCategory;
|
||||
use common\helpers\ScoreCalculatorHelper;
|
||||
use Yii;
|
||||
use backend\modules\questionnaire\models\UserQuestionnaire;
|
||||
use backend\modules\questionnaire\models\UserQuestionnaireSearch;
|
||||
@ -11,7 +12,7 @@ use yii\data\ActiveDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
use yii\web\Response;
|
||||
|
||||
|
||||
/**
|
||||
@ -144,16 +145,22 @@ class UserQuestionnaireController extends Controller
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
public function actionQuestionnaire() {
|
||||
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||
public function actionQuestionnaire(): array
|
||||
{
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
|
||||
if (isset($_POST['depdrop_parents'])) {
|
||||
$parents = $_POST['depdrop_parents'];
|
||||
if ($parents != null) {
|
||||
$cat_id = $parents[0];
|
||||
$categories = Questionnaire::getQuestionnaireByCategory($cat_id);
|
||||
$categories = Questionnaire::questionnairesOfCategoryArr($cat_id);
|
||||
|
||||
return ['output'=>$categories, 'selected'=>''];
|
||||
$formattedCatArr = array();
|
||||
foreach ($categories as $key => $value){
|
||||
$formattedCatArr[] = array('id' => $key, 'name' => $value);
|
||||
}
|
||||
|
||||
return ['output'=>$formattedCatArr, 'selected'=>''];
|
||||
}
|
||||
}
|
||||
return ['output'=>'', 'selected'=>''];
|
||||
@ -161,15 +168,16 @@ class UserQuestionnaireController extends Controller
|
||||
|
||||
public function actionRateResponses($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$model->rateResponses();
|
||||
$user_questionnaire = $this->findModel($id);
|
||||
ScoreCalculatorHelper::rateResponses($user_questionnaire);
|
||||
|
||||
return $this->actionView($id);
|
||||
}
|
||||
|
||||
public function actionCalculateScore($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$model->getScore();
|
||||
$user_questionnaire = $this->findModel($id);
|
||||
ScoreCalculatorHelper::calculateScore($user_questionnaire);
|
||||
|
||||
return $this->actionView($id);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace backend\modules\questionnaire\controllers;
|
||||
|
||||
use backend\modules\questionnaire\models\Questionnaire;
|
||||
use backend\modules\questionnaire\models\User;
|
||||
use backend\modules\questionnaire\models\UserQuestionnaire;
|
||||
use Yii;
|
||||
use backend\modules\questionnaire\models\UserResponse;
|
||||
@ -91,11 +90,16 @@ class UserResponseController extends Controller
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
public function actionUpdate(int $id, $user_questionnaire_id = null)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if ($user_questionnaire_id !== null)
|
||||
{
|
||||
return $this->redirect(['user-questionnaire/view', 'id' => $user_questionnaire_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user