Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
sten authored and github-actions[bot] committed Sep 2, 2022
1 parent 53289aa commit 01b99fa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 60 deletions.
18 changes: 9 additions & 9 deletions src/Exceptions/QuestionNotMappedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Statikbe\Surveyhero\Exceptions;

class QuestionNotMappedException extends \Exception
{
public int $questionId;
class QuestionNotMappedException extends \Exception
{
public int $questionId;

public static function create(int $questionId, string $message): self
{
$ex = new self($message);
$ex->questionId = $questionId;
public static function create(int $questionId, string $message): self
{
$ex = new self($message);
$ex->questionId = $questionId;

return $ex;
}
return $ex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@

namespace Statikbe\Surveyhero\Services\Factories\QuestionAndAnswerCreator;

use Statikbe\Surveyhero\Models\Survey;
use Statikbe\Surveyhero\Models\SurveyAnswer;
use Statikbe\Surveyhero\Models\SurveyQuestion;
use Statikbe\Surveyhero\Services\SurveyMappingService;
use Statikbe\Surveyhero\Models\Survey;
use Statikbe\Surveyhero\Models\SurveyAnswer;
use Statikbe\Surveyhero\Models\SurveyQuestion;
use Statikbe\Surveyhero\Services\SurveyMappingService;

class ChoiceTableQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator
class ChoiceTableQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator
{
const TYPE = 'choice_table';

public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array
{
const TYPE = 'choice_table';

public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array
{
$questions = [];
foreach ($question->question->choice_table->rows as $rowQuestion) {
$surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $rowQuestion->label, $rowQuestion->row_id);

foreach ($question->question->choice_table->choices as $choice) {
$responseData = [
'survey_question_id' => $surveyQuestion->id,
'surveyhero_answer_id' => $choice->choice_id,
'label' => [
$lang => $choice->label,
],
];

$questionMapping = (new SurveyMappingService())->getQuestionMappingForSurvey($survey, $question->element_id);
$mappedChoice = $this->getChoiceMapping($choice->choice_id, $questionMapping);

$this->setChoiceAndConvertToDataType($mappedChoice, $questionMapping['mapped_data_type'], $responseData, $choice);

SurveyAnswer::updateOrCreate([
'survey_question_id' => $surveyQuestion->id,
'surveyhero_answer_id' => $choice->choice_id,
], $responseData);
}

$questions[] = $surveyQuestion;
$questions = [];
foreach ($question->question->choice_table->rows as $rowQuestion) {
$surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $rowQuestion->label, $rowQuestion->row_id);

foreach ($question->question->choice_table->choices as $choice) {
$responseData = [
'survey_question_id' => $surveyQuestion->id,
'surveyhero_answer_id' => $choice->choice_id,
'label' => [
$lang => $choice->label,
],
];

$questionMapping = (new SurveyMappingService())->getQuestionMappingForSurvey($survey, $question->element_id);
$mappedChoice = $this->getChoiceMapping($choice->choice_id, $questionMapping);

$this->setChoiceAndConvertToDataType($mappedChoice, $questionMapping['mapped_data_type'], $responseData, $choice);

SurveyAnswer::updateOrCreate([
'survey_question_id' => $surveyQuestion->id,
'surveyhero_answer_id' => $choice->choice_id,
], $responseData);
}

return $questions;
$questions[] = $surveyQuestion;
}

return $questions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace Statikbe\Surveyhero\Services\Factories\QuestionAndAnswerCreator;

use Statikbe\Surveyhero\Models\Survey;
use Statikbe\Surveyhero\Models\SurveyQuestion;
use Statikbe\Surveyhero\Models\Survey;
use Statikbe\Surveyhero\Models\SurveyQuestion;

class InputQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator
{
const TYPE = 'input';
class InputQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator
{
const TYPE = 'input';

/**
* @throws \Statikbe\Surveyhero\Exceptions\SurveyNotMappedException
* @throws \Statikbe\Surveyhero\Exceptions\QuestionNotMappedException
*/
public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array
{
$surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $question->question->question_text);
//the answer is different for each user entry, so we cannot save answers for this type of question.
return $surveyQuestion;
}
/**
* @throws \Statikbe\Surveyhero\Exceptions\SurveyNotMappedException
* @throws \Statikbe\Surveyhero\Exceptions\QuestionNotMappedException
*/
public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array
{
$surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $question->question->question_text);
//the answer is different for each user entry, so we cannot save answers for this type of question.
return $surveyQuestion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Statikbe\Surveyhero\Services\Factories\ResponseCreator;

use Statikbe\Surveyhero\Exceptions\AnswerNotMappedException;
use Statikbe\Surveyhero\Models\SurveyQuestionResponse;
use Statikbe\Surveyhero\Models\SurveyResponse;

Expand Down

0 comments on commit 01b99fa

Please sign in to comment.