Download the PHP package statikbe/laravel-surveyhero without Composer

On this page you can find all versions of the php package statikbe/laravel-surveyhero. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-surveyhero

Import Surveyhero responses into the Laravel database

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package allows you to import Surveyhero survey responses.

Installation

You can install the package via composer:

Please publish the config file with:

Check the configuration options first, in case you want to customise your data model.

Please publish and run the migrations with:

NB: If you want to customise the default data model, first edit the configuration file, see the Data Model Customisation section.

Upgrading to V2

The data model changed in v2, so an upgrade guide is available.

Data model

When a user fills out a survey on Surveyhero, a survey response is available in the API, which contains all question answers. The relational data model implements the same logic. To start importing Surveyhero responses, you should create a Survey record with the survey ID from Surveyhero. The questions and answers (i.e. for multiple choice) with their translated labels can be imported.

Each response contains metadata about the submission and link parameters are stored in JSON but can be mapped to custom data columns. If the response is marked as completed by Surveyhero, we will skip the import.

For each answer, the surveyhero question and answer ID's are stored. The field column is used to store a question identifier to be able to more easily query the answers, e.g. to produce statistics. The answer can be converted to a new value. For instance, this is handy for Likert scales or dropdowns to map to a numeric value or standardised string constants, to make postprocessing easier. Since most surveys are used to run statistics on, we have implemented 2 different column types for now: integer and string to be able to easily run SQL aggregates.

Configuration

Create an API user and password on Surveyhero and set this in the .env file:

You can overwrite the default table names and Eloquent model classes, if needed check the Data Model Customisation section.

Import surveys

This command imports the survey for a given survey ID, the survey IDs in the configuration file or all surveys.

You can import a specific survey with the flag --survey=1234567.

Or you can configure survey IDs in the question_mapping in the surveyhero.php configuration file.

If you want to import all, add the flag --all.

If you want to reimport all surveys you can wipe them by using the flag --fresh.

Question and collector mapping

In order to start importing our survey questions, answers and responses, we need to set up a mapping between the API and our application. The mapping is generated from the Surveyhero API data. When you want to rename questions, answers and convert responses, you can customise this mapping. To make this more flexible, we store this mapping in the Survey data model in the database. You can then change this mapping in the database or you can overwrite the mapping (or only specific questions) by adding the mapping to the configuration file of the question mappings that need to be altered.

This mechanism merges the configuration file mapping into the mapping stored in the database. This allows you to more easily change the survey on Surveyhero and just reimport the mapping without having to change the configuration and have to redeploy your application.

Generate mapping

To automatically generate the mapping using the API, run the following command:

This will generate a default question mapping for your questions and collectors and save them to the surveys data model in the database. The configured collectors on Surveyhero will also be copied to the database and can be changed to your preference.

You should run this command everytime changes are made to questions/answers/collectors in SurveyHero!

Customise mapping

Customise collectors

This is useful when you only want to retrieve responses from a certain collector. For example when you have separate collectors set up for your environments. e.g. by creating a collector per environment you can maintain 1 survey for your local development environment and production deployment. In that case you might add environment vars for the collector ID's in the .env file to ease configuration.

If there are collectors configured in the configuration file, they will be used and will overrule the collectors stored in the survey model.

Collectors in the config file will overwrite the ones automatically imported in the database. When no collectors key is present, we will default to the value in de database.

Customise questions/answers

Customizing the mapping can be useful to decide on your own question identifiers and answer values. To do this, add questions to the question_mapping in your config file and include the questions you want to set up a custom mapping for:

Each question type has different specifications, so the mapping data structure is slightly different:

You can generate the complete question_mapping that you can copy-paste from into your configuration file and further adjust there. Following command generates surveyhero_mapping.phpin the project root. This file contains the PHP array. Run:

Summary of currently supported question types and their mapping structure:

Text input

The field is the identifier in your database to be able to more easily query the responses for a question.

Numeric input

Currently, only integer support is implemented.

Choice list

A choice list requires an answer_mapping, where you can map the Surveyhero choice ID's to the converted values that you want to use in your statistics. You should also set mapped_data_type to int or string depending on the values data type of answer_mapping.

Choice table

A choice table is a Likert scale type of question with a set of rows or subquestions. You need to map each row to a subquestion with its own question_id and field. So each subquestion will become a SurveyQuestionResponse record. The answer_mapping operates identically to Choice List. You can also specify an answer_mapping for a specific question, in case the mapping differs for that question, see question_id 13509165.

Import questions and answers

This command imports all survey questions and answers associated with their (translated) label for a given survey ID or all surveys. You can schedule this for continuous updates.

You can configure a specific survey with the flag --survey=22333. If you want to reimport all survey responses you can wipe the SurveyQuestions and SurveyAnswers by using the flag --fresh.

Import responses

This command imports all survey responses for a given survey ID or all surveys. You can schedule this for continuous updates. First you need to create at least one Survey record with a Surveyhero ID.

You can configure a specific survey with the flag --survey=22333. If you want to reimport all survey responses you can wipe the SurveyResponses and SurveyQuestionResponses by using the flag --fresh.

Link parameters mapping

Surveyhero allows to pass parameters in the query string of the share URL, see docs.

These parameters are often used to send the same survey URL to different types or participants that you want to be able to identify in your survey responses. Surveyhero returns these parameters as link-parameters through the response API. By default, the library stores the link parameters as JSON in the surveyhero_link_parameters column.

The library also allows you to map these link parameters to variables on the SurveyReponse model. To do this you need to create a new migration in your project to add the new columns to the survey_response table, and then configure surveyhero_link_parameters_mapping in the configuration file.

There are 2 options to map link parameters.

Option 1: Map directly to a database column

The key is the name of the Surveyhero link parameter

Option 2: Map to the foreign key of a model

Following parameters are optional in case you want to evaluate the link_parameters value on the database

Data Model Customisation

If you want to add extra variables, functions or relationships to the Eloquent models of this package, you might want to extend the model classes or implement your own.

Note: If you implement your own data models without subclassing the default models, you need to implement the Contract interfaces in Statikbe\Surveyhero\Contracts. The package expects certain column names (check the migrations and contracts for details), however you can configure the table names and foreign keys in the configuration, see below.

Customising the Eloquent models

You can set your own Eloquent models in the configuration file under the variable models.

Customising the table names

You can change the table names by editing the table_names variable in the config file:

The foreign_key is the column name of the foreign keys used to refer the table name.

Surveyhero webhooks

We have implemented part of the Surveyhero webhook options into this package.

Create a webhook

With the command below you can add a webhook to your Survey:

List webhooks

With the command below you can list all the webhooks of your Survey:

Delete a webhook

With the command below you can delete a webhook from your Survey:

Webhook handlers

We have also implemented a default controller (SurveyheroWebhookController.php) to handle the webhook responses. Currently, it only supports the response.completed type.

You can add this in a route to your api.php file, like so:

There is also a convenience function on the facade so you can also just include this in your api.php:

Data export

You can export the responses to a spreadsheet with questions, answers and responses worksheets by default. For example, you can execute:

You can pass the survey to be exported and then customise the export by adding columns to the responses sheet, from the link parameters that were passed to Surveyhero or extra columns from the survey responses table.

Customisation

You can extend SurveyExportService, SurveyExport and the sheet implementations.

In the SurveyExportService you can change the createSurveyExport() function to change the SurveyExport implementation. If you want to add more sheets, you can set the sheets by setting setSheets() on SurveyExport. If you want to change the work sheets, you can change the queries in query(), the title in setTitle(), etc.

Events

The following events are implemented:

Ideas for future improvements

Testing

Currently, no tests are implemented :-(.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

You can post an issue and provide a pull request. Thanks!

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-surveyhero with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
illuminate/contracts Version ^10.0|^11.0
maatwebsite/excel Version ^3.1
spatie/laravel-package-tools Version ^1.9.2
spatie/laravel-translatable Version ^5.0|^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package statikbe/laravel-surveyhero contains the following files

Loading the files please wait ....