sst/survey-lib-bundle
Composer 安装命令:
composer require sst/survey-lib-bundle
包简介
Symfony Bundle For Surveys
README 文档
README
This bundle provides a library of survey-related Entities and Services for Symfony projects.
License
This bundle is developed by SST Software, see LICENSE for more details.
Installation
- Run
composer require sst/survey-lib-bundle - Create Entities, based on the interfaces in
Interfaces/Entity(see below)
Contents
Entities
This bundle provides interfaces and traits to fulfill these, for a general Survey application.
The bundle assumes that these entities are stored in the App\Entity\Survey namespace, if this is not the case, you can change this in the configuration (see below).
Available Entities with their Traits and Interfaces are:
- Survey: The basis of a survey, contains a list of containers
- Trait:
Sst\SurveyLibBundle\Entity\Traits\SurveyTrait - Interface:
Sst\SurveyLibBundle\Interfaces\Entity\SurveyInterface
- Trait:
- Container: A container for one or more element-usages or one or more child-containers (use either one, combinations of child-containers and element-usages are not allowed)
- Trait:
Sst\SurveyLibBundle\Entity\Traits\ContainerTrait - Interface:
Sst\SurveyLibBundle\Interfaces\Entity\ContainerInterface
- Trait:
- Element: The basis of a survey-element, which can be e.g. a question, or a piece of text.
- Trait:
Sst\SurveyLibBundle\Entity\Traits\ElementTrait - Interface:
Sst\SurveyLibBundle\Interfaces\Entity\ElementInterface
- Trait:
- ElementUsage: An element-usage is a reference to an element, which can be used in a container.
- Trait:
Sst\SurveyLibBundle\Entity\Traits\ElementUsageTrait - Interface:
Sst\SurveyLibBundle\Interfaces\Entity\ElementUsageInterface
- Trait:
- SurveyResponse: A group of answers, which is the result of a survey being filled in.
- Trait:
Sst\SurveyLibBundle\Entity\Traits\SurveyResponseTrait - Interface:
Sst\SurveyLibBundle\Interfaces\Entity\SurveyResponseInterface
- Trait:
- Answer: Contains the given answer to an ElementUsage
- Trait:
Sst\SurveyLibBundle\Entity\Traits\AnswerTrait - Interface:
Sst\SurveyLibBundle\Interfaces\Entity\AnswerInterface
- Trait:
Datamodel
The Element entity and ElementData
The Element entity has a parameter elementData, in which all data regarding the element can be stored.
ElementData matches the type of the Element, so make sure you set a valid combination of type and ElementDatawhen creating an Element
This bundle provides several default ElementData types:
| ElementType | ElementData | Description |
|---|---|---|
| TEXT | TextQuestionElementDataInterface | Question which can be answered with a text |
| NUMBER | NumberQuestionElementDataInterface | Question which can be answered with a number |
| DATETIME | DateTimeQuestionElementDataInterface | Question which can be answered with a date or datetime |
| MULTIPLE_CHOICE | MultipleChoiceQuestionElementDataInterface | Multiple choice question |
| MULTIPLE_CHOICE_GRID | MultipleChoiceGridQuestionElementDataInterface | Question providing a grid of multiple multiple-choice-questions |
| SCALE | ScaleQuestionElementDataInterface | Question that can be shown as scale |
| INFO | ElementDataInterface | Info-text, to be shown during a survey |
| CUSTOM | CustomElementDataInterface | Custom ElementData, to allow for project-specific implementations |
You can extend or overwrite these, as long as your ElementData implements the correct interface, matching the type of the Element.
Display conditions
This bundle provides a service to check if a given ElementUsage should be displayed, based on a given SurveyResponse.
To identify elements, it uses the code parameter of the ElementUsage.
The provided displayConditionService assumes that ElementUsage->display_condition contains a valid expression, see Symfony Expression Language.
So make sure, this code is unique in the set you are checking, usually this means, that it should be unique in the related survey.
Services
This bundle contains several services to use in your survey-project. These are injected automatically when using their interfaces. This can be overridden by providing a configuration file (see below).
createSurveyResponseService: Creates a new SurveyResponse, linked to the given survey, with stored start-date and shuffled element-order (if applicable)displayConditionService: Checks if the given ElementUsage should be displayed, based on a given SurveyResponse, also provided functions to get the condition as php or as javascriptastToJavascriptService: Converts an AST to javascriptnextElementService: Gets the next ElementUsage to display for a SurveyResponse, can also be used to get the previous item, by setting$reverseto trueaddAnswerService: Adds one or more answers to a SurveyResponse, based on the given ElementUsage and the given rawAnswervalidateAnswerService: Validates the given answer for a given ElementUsage
Customization
You can customize which class implements which interface by providing a configuration file in your project.
If you want to do so, create a file config/packages/sst_survey_lib.yaml with the following contents:
sst_survey_lib: services: createSurveyResponseService: Sst\SurveyLibBundle\Service\CreateSurveyResponseService displayConditionService: Sst\SurveyLibBundle\Service\DisplayConditionService astToJavascriptService: Sst\SurveyLibBundle\Service\AstToJavascriptService nextElementService: Sst\SurveyLibBundle\Service\NextElementService addAnswerService: Sst\SurveyLibBundle\Service\AddAnswerService validateAnswerService: Sst\SurveyLibBundle\Service\ValidateAnswerService entities: survey: App\Entity\Survey container: App\Entity\Container element: App\Entity\Element elementOverride: Sst\SurveyLibBundle\Entity\ElementOverride elementUsage: App\Entity\ElementUsage surveyResponse: App\Entity\SurveyResponse answer: App\Entity\Answer typeMappings: elementData: Sst\SurveyLibBundle\Types\ElementDataType rawAnswer: Sst\SurveyLibBundle\Types\RawAnswerType elementOverride: Sst\SurveyLibBundle\Types\ElementOverrideType
These are the default values, if these are the values you need, you don't need to create the file. If you need to change this, copy (parts of) above code into this file.
Events
This bundle provides a few events, which you can listen to.
-
SurveyResponseCreate::PRE_CREATEis dispatched before a survey-response is created -
SurveyResponseCreate::POST_CREATEis dispatched after a survey-response is created -
AnswerCreate::PRE_CREATEis dispatched before an answer is created -
AnswerCreate::POST_CREATEis dispatched after an answer is created -
AnswerCreate::PRE_UPDATEis dispatched before an answer is updated -
AnswerCreate::POST_UPDATEis dispatched after an answer is updated -
AnswerCreate::PRE_VALIDATEis dispatched before an answer is validated -
AnswerCreate::POST_VALIDATEis dispatched after an answer is validated
sst/survey-lib-bundle 适用场景与选型建议
sst/survey-lib-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 977 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「survey」 「lib」 「sst」 「survey lib」 「surveylib」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sst/survey-lib-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sst/survey-lib-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sst/survey-lib-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Laravel wrapper for surveyjs library
Package for create surveys in laravel
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
Optical Mark Recognition from PHP
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 977
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-01
