Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update create_unique_surveyhero_id_indices.php #15

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion database/migrations/create_unique_surveyhero_id_indices.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function up()
});

Schema::table($tableNames['survey_question_responses']['name'], function (Blueprint $table) {
$table->unique(['survey_response_id', 'survey_question_id', 'survey_answer_id']);
$table->unique(['survey_response_id', 'survey_question_id', 'survey_answer_id'])
->name('survey_question_responses_ternary_ids_idx'); //for some dbs the id name generated by laravel is too long
});
}
}
3 changes: 0 additions & 3 deletions src/Commands/SurveyheroMapperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class SurveyheroMapperCommand extends Command

public $description = 'Map all questions and answers linked to configured surveys.';

/**
* @var \Statikbe\Surveyhero\Services\SurveyMappingService
*/
private SurveyMappingService $mappingService;

public function __construct(SurveyMappingService $surveyMappingService)
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/SurveyheroResponseImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class SurveyheroResponseImportCommand extends Command

public $description = 'Retrieve survey responses from SurveyHero API and save in the database.';

/**
* @var \Statikbe\Surveyhero\Services\SurveyResponseImportService
*/
private SurveyResponseImportService $importService;

public function __construct(SurveyResponseImportService $surveyResponseImportService)
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/SurveyheroSurveyImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class SurveyheroSurveyImportCommand extends Command

public $description = 'Retrieve surveys from SurveyHero API and save in the database.';

/**
* @var \Statikbe\Surveyhero\Services\SurveyImportService
*/
private SurveyImportService $importService;

public function __construct(SurveyImportService $surveyImportService)
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/SurveyheroWebhookAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class SurveyheroWebhookAddCommand extends Command

public $description = 'Automatically generate webhooks for survey responses on your desired URL.';

/**
* @var \Statikbe\Surveyhero\Services\SurveyWebhookService
*/
private SurveyWebhookService $webhookService;

public function __construct(SurveyWebhookService $webhookService)
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/SurveyheroWebhookDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class SurveyheroWebhookDeleteCommand extends Command

public $description = 'Delete Surveyhero webhooks';

/**
* @var \Statikbe\Surveyhero\Services\SurveyWebhookService
*/
private SurveyWebhookService $webhookService;

public function __construct(SurveyWebhookService $webhookService)
Expand Down
7 changes: 2 additions & 5 deletions src/Commands/SurveyheroWebhookListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class SurveyheroWebhookListCommand extends Command

public $description = 'List webhooks for Surveyhero surveys';

/**
* @var \Statikbe\Surveyhero\Services\SurveyWebhookService
*/
private SurveyWebhookService $webhookService;

public function __construct(SurveyWebhookService $webhookService)
Expand All @@ -42,7 +39,7 @@ public function handle(): int
try {
$webhooks = $this->webhookService->listWebhooks($survey);
$webhookData = [];
foreach($webhooks as $webhook) {
foreach ($webhooks as $webhook) {
$webhookData[] = [
$webhook->webhook_id,
$webhook->event_type,
Expand All @@ -52,7 +49,7 @@ public function handle(): int
];
}
$this->table(
['Webhook id','Event type','Url','Status','Created'],
['Webhook id', 'Event type', 'Url', 'Status', 'Created'],
$webhookData
);
} catch (\Exception $e) {
Expand Down
2 changes: 0 additions & 2 deletions src/Contracts/ModelContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public function delete();

/**
* Returns the table name of the model.
*
* @return string
*/
public function getTable(): string;
}
5 changes: 0 additions & 5 deletions src/Contracts/SurveyAnswerContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public function surveyQuestion(): BelongsTo;

/**
* Translate a variable with $key to $locale
*
* @param string $key
* @param string $locale
* @param bool $useFallbackLocale
* @return mixed
*/
public function translate(string $key, string $locale = '', bool $useFallbackLocale = true): mixed;
}
3 changes: 0 additions & 3 deletions src/Contracts/SurveyContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public function getCollectors(): array;

/**
* Checks if the response timestamp is more recent than the last updated survey timestamp.
*
* @param string $responseLastUpdatedIsoTimestamp
* @return bool
*/
public function doesResponseNeedsToBeUpdated(string $responseLastUpdatedIsoTimestamp): bool;
}
5 changes: 0 additions & 5 deletions src/Contracts/SurveyQuestionContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public function surveyAnswers(): HasMany;

/**
* Translate a variable with $key to $locale
*
* @param string $key
* @param string $locale
* @param bool $useFallbackLocale
* @return mixed
*/
public function translate(string $key, string $locale = '', bool $useFallbackLocale = true): mixed;
}
3 changes: 1 addition & 2 deletions src/Exports/Sheets/AnswersSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Statikbe\Surveyhero\Contracts\SurveyContract;
use Statikbe\Surveyhero\SurveyheroRegistrar;

class AnswersSheet implements FromQuery, WithTitle, WithHeadings, WithMapping, ShouldAutoSize
class AnswersSheet implements FromQuery, ShouldAutoSize, WithHeadings, WithMapping, WithTitle
{
private SurveyContract $survey;

Expand Down Expand Up @@ -73,7 +73,6 @@ public function headings(): array

/**
* @param SurveyAnswerContract $surveyAnswer
* @return array
*/
public function map($surveyAnswer): array
{
Expand Down
3 changes: 1 addition & 2 deletions src/Exports/Sheets/QuestionsSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Statikbe\Surveyhero\Contracts\SurveyContract;
use Statikbe\Surveyhero\Contracts\SurveyQuestionContract;

class QuestionsSheet implements FromQuery, WithTitle, WithHeadings, WithMapping, ShouldAutoSize
class QuestionsSheet implements FromQuery, ShouldAutoSize, WithHeadings, WithMapping, WithTitle
{
private SurveyContract $survey;

Expand Down Expand Up @@ -63,7 +63,6 @@ public function headings(): array

/**
* @param SurveyQuestionContract $surveyQuestion
* @return array
*/
public function map($surveyQuestion): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exports/Sheets/ResponsesSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Maatwebsite\Excel\Concerns\WithTitle;
use Statikbe\Surveyhero\Contracts\SurveyContract;

class ResponsesSheet implements FromCollection, WithTitle, WithHeadings, ShouldAutoSize
class ResponsesSheet implements FromCollection, ShouldAutoSize, WithHeadings, WithTitle
{
private SurveyContract $survey;

Expand Down
3 changes: 1 addition & 2 deletions src/Exports/SurveyExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Statikbe\Surveyhero\Exports\Sheets\QuestionsSheet;
use Statikbe\Surveyhero\Exports\Sheets\ResponsesSheet;

class SurveyExport implements WithMultipleSheets, ShouldAutoSize
class SurveyExport implements ShouldAutoSize, WithMultipleSheets
{
use Exportable;

Expand Down Expand Up @@ -47,7 +47,6 @@ public function sheets(): array
* Override default worksheets list.
*
* @param array<object> $sheets
* @return void
*/
public function setSheets(array $sheets): void
{
Expand Down
16 changes: 8 additions & 8 deletions src/Http/SurveyheroClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public function getSurveyResponseAnswers(string|int $surveyId, string|int $respo
return $answerData->successful() ? json_decode($answerData->body()) : null;
}

public function getSurveyElements(string|int $surveyId, string $lang = null): array
public function getSurveyElements(string|int $surveyId, ?string $lang = null): array
{
$questionsData = $this->fetchFromSurveyHero(sprintf('surveys/%s/elements%s', $surveyId, $lang ? '?lang='.$lang : null));
$questions = json_decode($questionsData->body());

return $questions ? $questions->elements : [];
}

public function getSurveyQuestions(string|int $surveyId, string $lang = null): array
public function getSurveyQuestions(string|int $surveyId, ?string $lang = null): array
{
$questionsData = $this->fetchFromSurveyHero(sprintf('surveys/%s/questions%s', $surveyId, $lang ? '?lang='.$lang : null));
$questions = json_decode($questionsData->body());
Expand Down Expand Up @@ -120,8 +120,8 @@ private function fetchFromSurveyHero(string $urlPath, array $queryStringArgs = [
$this->preventThrottle();

$response = Http::retry(3, 800)
->withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password'))
->get(config('surveyhero.api_url').$urlPath, $queryStringArgs);
->withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password'))
->get(config('surveyhero.api_url').$urlPath, $queryStringArgs);

$this->updateThrottle();

Expand All @@ -140,8 +140,8 @@ private function postToSurveyHero(string $urlPath, array $queryStringArgs = []):
$this->preventThrottle();

$response = Http::retry(3, 600)
->withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password'))
->post(config('surveyhero.api_url').$urlPath, $queryStringArgs);
->withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password'))
->post(config('surveyhero.api_url').$urlPath, $queryStringArgs);

$this->updateThrottle();

Expand All @@ -160,8 +160,8 @@ private function deleteFromSurveyHero(string $urlPath, array $queryStringArgs =
$this->preventThrottle();

$response = Http::retry(3, 600)
->withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password'))
->delete(config('surveyhero.api_url').$urlPath, $queryStringArgs);
->withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password'))
->delete(config('surveyhero.api_url').$urlPath, $queryStringArgs);

$this->updateThrottle();

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

class Survey extends Model implements SurveyContract
{
use HasCollectors;
use HasFactory;
use HasQuestionMapping;
use HasCollectors;

protected $guarded = [];

Expand Down
3 changes: 0 additions & 3 deletions src/Services/AbstractSurveyheroAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

class AbstractSurveyheroAPIService
{
/**
* @var \Statikbe\Surveyhero\Http\SurveyheroClient
*/
protected SurveyheroClient $client;

public function __construct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
abstract class AbstractQuestionAndAnswerCreator implements QuestionAndAnswerCreator
{
/**
* @param SurveyContract $survey
* @param string $lang
* @param string $questionId
* @param string|null $label
* @param string|null $subquestionId
* @return SurveyQuestionContract
*
* @throws \Statikbe\Surveyhero\Exceptions\QuestionNotMappedException
* @throws \Statikbe\Surveyhero\Exceptions\SurveyNotMappedException
*/
Expand Down Expand Up @@ -57,11 +50,6 @@ protected function getChoiceMapping(string|int $choiceId, string|int $questionId
}

/**
* @param mixed $mappedChoice
* @param string $dataType
* @param array $responseData
* @param \stdClass $surveyheroChoice
*
* @throws AnswerNotMappedException
*/
protected function setChoiceAndConvertToDataType(mixed $mappedChoice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class ChoiceListQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreato
const TYPE = 'choice_list';

/**
* @param \stdClass $question
* @param SurveyContract $survey
* @param string $lang
* @return SurveyQuestionContract|array
*
* @throws \Statikbe\Surveyhero\Exceptions\AnswerNotMappedException
* @throws \Statikbe\Surveyhero\Exceptions\QuestionNotMappedException
* @throws \Statikbe\Surveyhero\Exceptions\SurveyNotMappedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InputQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator
public function updateOrCreateQuestionAndAnswer(\stdClass $question, SurveyContract $survey, string $lang): SurveyQuestionContract|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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
interface QuestionAndAnswerCreator
{
/**
* @param \stdClass $question
* @param SurveyContract $survey
* @param string $lang
* @return SurveyQuestionContract|array
*
* @throws AnswerNotMappedException
*/
public function updateOrCreateQuestionAndAnswer(\stdClass $question, SurveyContract $survey, string $lang): SurveyQuestionContract|array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
abstract class AbstractQuestionMapper implements QuestionMapper
{
/**
* @param int $questionId
* @param string $questionType
* @param string $mappedDataType
* @param int|string $questionFieldSuffix
* @return array{'question_id': int, 'type': string, 'field': string, 'mapped_data_type': string }
*/
public function createQuestionMap(int $questionId, string $questionType, string $mappedDataType, int|string $questionFieldSuffix): array
Expand Down
Loading