OpHandlerQuestionCreate
in package
implements
OpHandlerInterface
Uses
OpHandlerSurveyTrait, OpHandlerExceptionTrait, OpHandlerQuestionTrait, OpHandlerValidationTrait
Table of Contents
Interfaces
Properties
- $entity : string
- $model : Question
- $transformer : TransformerInputQuestionAggregate
Methods
- __construct() : mixed
- addErrorToValidationData() : array<string|int, mixed>
- Adds the error message to the validationData array
- canHandle() : bool
- extractTempId() : int|mixed
- returns and removes tempId from dataset
- getSurveyIdFromContext() : int
- Extracts and returns surveyId from context
- getValidationReturn() : array<string|int, mixed>|array<string|int, array<string|int, ValidationErrorItem>>
- handle() : array<string|int, mixed>
- For a valid creation of a question you need at least question and questionL10n entities within the patch.
- validateCollection() : array<string|int, mixed>
- checks incoming props if it's a collection otherwise adds error to validationData.
- validateCollectionIndex() : array<string|int, mixed>
- validates for collection first and then checks the indexes to be numeric or alphabetic dependent on the alphabetic flag
- validateEntityId() : array<string|int, mixed>
- checks for entity id being there, otherwise adds error to validationData
- validateOperation() : array<string|int, mixed>
- Checks if patch is valid for this operation.
- getSubQuestionNewIdMapping() : array<string|int, mixed>
- Maps the tempIds of new subquestions or answers to the real ids.
- throwNoValuesException() : void
Properties
$entity
protected
string
$entity
$model
protected
Question
$model
$transformer
protected
TransformerInputQuestionAggregate
$transformer
Methods
__construct()
public
__construct(Question $model, TransformerInputQuestionAggregate $transformer) : mixed
Parameters
- $model : Question
- $transformer : TransformerInputQuestionAggregate
addErrorToValidationData()
Adds the error message to the validationData array
public
addErrorToValidationData(string $error, array<string|int, mixed> $validationData) : array<string|int, mixed>
Parameters
- $error : string
- $validationData : array<string|int, mixed>
Return values
array<string|int, mixed>canHandle()
public
canHandle(OpInterface $op) : bool
Parameters
- $op : OpInterface
Return values
boolextractTempId()
returns and removes tempId from dataset
public
extractTempId(array<string|int, mixed> &$dataSet) : int|mixed
Parameters
- $dataSet : array<string|int, mixed>
Return values
int|mixedgetSurveyIdFromContext()
Extracts and returns surveyId from context
public
getSurveyIdFromContext(OpInterface $op) : int
Parameters
- $op : OpInterface
Tags
Return values
intgetValidationReturn()
public
getValidationReturn(string $error, array<string|int, mixed> $validationData, OpInterface $op) : array<string|int, mixed>|array<string|int, array<string|int, ValidationErrorItem>>
Parameters
- $error : string
- $validationData : array<string|int, mixed>
- $op : OpInterface
Return values
array<string|int, mixed>|array<string|int, array<string|int, ValidationErrorItem>>handle()
For a valid creation of a question you need at least question and questionL10n entities within the patch.
public
handle(OpInterface $op) : array<string|int, mixed>
An example patch with all(!) possible entities:
{ "patch": [ { "entity": "question", "op": "create", "id": "0", "props": { "question": { "qid": "0", "title": "G01Q06", "type": "1", "questionThemeName": "arrays/dualscale", "gid": "1", "mandatory": false, "relevance": "1", "encrypted": false, "saveAsDefault": false, "tempId": "XXX321" }, "questionL10n": { "en": { "question": "Array Question", "help": "Help text" }, "de": { "question": "Array ger", "help": "help ger" } }, "attributes": { "dualscale_headerA": { "de": "A ger", "en": "A" }, "dualscale_headerB": { "de": "B ger", "en": "B" }, "public_statistics": { "": "1" } }, "answers": { "0": { "code": "AO01", "sortOrder": 0, "assessmentValue": 0, "scaleId": 0, "tempId": "111", "l10ns": { "de": { "answer": "antwort1", "language": "de" }, "en": { "answer": "answer1", "language": "en" } } }, "1": { "code": "AO02", "sortOrder": 1, "assessmentValue": 0, "scaleId": 0, "tempId": "112", "l10ns": { "de": { "answer": "antwort1.2", "language": "de" }, "en": { "answer": "answer1.2", "language": "en" } } } }, "subquestions": { "0": { "title": "SQ001", "sortOrder": 0, "relevance": "1", "tempId": "113", "l10ns": { "de": { "question": "subger1", "language": "de" }, "en": { "question": "sub1", "language": "en" } } }, "1": { "title": "SQ002", "sortOrder": 1, "relevance": "1", "tempId": "114", "l10ns": { "de": { "question": "subger2", "language": "de" }, "en": { "question": "sub2", "language": "en" } } } } } } ] }
Parameters
- $op : OpInterface
Tags
Return values
array<string|int, mixed>validateCollection()
checks incoming props if it's a collection otherwise adds error to validationData.
public
validateCollection(OpInterface $op, array<string|int, mixed> $validationData) : array<string|int, mixed>
Basically this only check for the incoming props being a multidimensional array.
Parameters
- $op : OpInterface
- $validationData : array<string|int, mixed>
Return values
array<string|int, mixed>validateCollectionIndex()
validates for collection first and then checks the indexes to be numeric or alphabetic dependent on the alphabetic flag
public
validateCollectionIndex(OpInterface $op, array<string|int, mixed> $validationData[, bool $alphabetic = true ]) : array<string|int, mixed>
Parameters
- $op : OpInterface
- $validationData : array<string|int, mixed>
- $alphabetic : bool = true
Return values
array<string|int, mixed>validateEntityId()
checks for entity id being there, otherwise adds error to validationData
public
validateEntityId(OpInterface $op, array<string|int, mixed> $validationData) : array<string|int, mixed>
Parameters
- $op : OpInterface
- $validationData : array<string|int, mixed>
Return values
array<string|int, mixed>validateOperation()
Checks if patch is valid for this operation.
public
validateOperation(OpInterface $op) : array<string|int, mixed>
Parameters
- $op : OpInterface
Return values
array<string|int, mixed>getSubQuestionNewIdMapping()
Maps the tempIds of new subquestions or answers to the real ids.
private
getSubQuestionNewIdMapping(Question $question, array<string|int, mixed> $data[, bool $answers = false ]) : array<string|int, mixed>
Parameters
- $question : Question
- $data : array<string|int, mixed>
- $answers : bool = false
Return values
array<string|int, mixed>throwNoValuesException()
private
throwNoValuesException(OpInterface $op[, string $name = '' ]) : void
Parameters
- $op : OpInterface
- $name : string = ''