Exemple #1
0
    <?php 
if (Yii::$app->user->can('surveyCreate')) {
    ?>
        <p>
            <?php 
    echo Html::a('Create Survey', ['create'], ['class' => 'btn btn-success']);
    ?>
        </p>
    <?php 
}
?>

    <?php 
if (!Yii::$app->user->can('surveyEdit')) {
    foreach ($surveys as $row) {
        if (!\app\models\SurveyHasParticipant::checkParticipantHasDone($row['id'])) {
            ?>
                <a href="<?php 
            echo Url::to(['view', 'id' => $row['id']]);
            ?>
">
                    <table class="table">
                        <tr>
                            <td>
                                <h3><?php 
            echo $row['title'];
            ?>
</h3>
                            </td>
                        </tr>
                    </table>
 /**
  * Finds the SurveyHasParticipant model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $Survey_id
  * @param integer $Participant_id
  * @return SurveyHasParticipant the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($Survey_id, $Participant_id)
 {
     if (($model = SurveyHasParticipant::findOne(['Survey_id' => $Survey_id, 'Participant_id' => $Participant_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSurveyHasParticipants()
 {
     return $this->hasMany(SurveyHasParticipant::className(), ['Survey_id' => 'id']);
 }
 public function actionResult($id)
 {
     if (Yii::$app->user->can('surveyResult')) {
         $model = $this->findModel($id);
         $dataProvider = [];
         $questions = Question::getAllQuestionBySurveyId($id);
         foreach ($questions as $row) {
             $result['id'] = $row['id'];
             $result['question'] = Question::getQuestionContentByQuestionId($row['id']);
             if (TextBox::checkIsTextBoxByQuestionId($row['id'])) {
                 $result['type'] = 0;
                 $result['results'] = TextResponse::getResponsesByQuestionId($row['id']);
                 array_push($dataProvider, $result);
                 continue;
             }
             if (Checkbutton::checkIsCheckBoxByQuestionId($row['id'])) {
                 $result['type'] = 1;
                 $result['results'] = Checkbutton::getOptionsStatisticsByQuestionId($row['id']);
                 array_push($dataProvider, $result);
                 continue;
             }
             if (Radiobutton::checkIsRadioButtonByQuestionId($row['id'])) {
                 $result['type'] = 2;
                 $result['results'] = Radiobutton::getOptionsStatisticsByQuestionId($row['id']);
                 array_push($dataProvider, $result);
                 continue;
             }
         }
         return $this->render('result', ['model' => $model, 'dataProvider' => $dataProvider, 'doneCount' => SurveyHasParticipant::getDoneCountBySurveyId($id)]);
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
 public function getDoneCountBySurveyId($id)
 {
     return SurveyHasParticipant::find()->where(['Survey_id' => $id])->count();
 }