New proper types

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2020-04-10 15:50:39 +02:00 committed by Jonas Rittershofer
parent 0961fbfdd7
commit 7aa3f7ace0
4 changed files with 31 additions and 10 deletions

View file

@ -27,9 +27,9 @@ return [
// Before /{hash} to avoid conflict
['name' => 'page#createForm', 'url' => '/new', 'verb' => 'GET'],
['name' => 'page#editForm', 'url' => '/{hash}/edit/', 'verb' => 'GET'],
['name' => 'page#cloneForm', 'url' => '/{hash}/clone/', 'verb' => 'GET'],
['name' => 'page#getResult', 'url' => '/{hash}/results/', 'verb' => 'GET'],
['name' => 'page#editForm', 'url' => '/{hash}/edit', 'verb' => 'GET'],
['name' => 'page#cloneForm', 'url' => '/{hash}/clone', 'verb' => 'GET'],
['name' => 'page#getResult', 'url' => '/{hash}/results', 'verb' => 'GET'],
['name' => 'page#goto_form', 'url' => '/{hash}', 'verb' => 'GET'],
['name' => 'page#insert_submission', 'url' => '/insert/submission', 'verb' => 'POST'],
@ -39,11 +39,11 @@ return [
['name' => 'api#getForm', 'url' => 'api/v1/form/{id}', 'verb' => 'GET'],
['name' => 'api#updateForm', 'url' => 'api/v1/form/update/', 'verb' => 'POST'],
['name' => 'api#deleteForm', 'url' => 'api/v1/form/{id}', 'verb' => 'DELETE'],
['name' => 'api#updateQuestion', 'url' => 'api/v1/question/update/', 'verb' => 'POST'],
['name' => 'api#reorderQuestions', 'url' => 'api/v1/question/reorder/', 'verb' => 'POST'],
['name' => 'api#newQuestion', 'url' => 'api/v1/question/', 'verb' => 'POST'],
['name' => 'api#updateQuestion', 'url' => 'api/v1/question/update', 'verb' => 'POST'],
['name' => 'api#reorderQuestions', 'url' => 'api/v1/question/reorder', 'verb' => 'POST'],
['name' => 'api#newQuestion', 'url' => 'api/v1/question', 'verb' => 'POST'],
['name' => 'api#deleteQuestion', 'url' => 'api/v1/question/{id}', 'verb' => 'DELETE'],
['name' => 'api#newOption', 'url' => 'api/v1/option/', 'verb' => 'POST'],
['name' => 'api#newOption', 'url' => 'api/v1/option', 'verb' => 'POST'],
['name' => 'api#deleteOption', 'url' => 'api/v1/option/{id}', 'verb' => 'DELETE'],
['name' => 'api#getSubmissions', 'url' => 'api/v1/submissions/{hash}', 'verb' => 'GET'],

View file

@ -256,11 +256,16 @@ class ApiController extends Controller {
'text' => $text,
]);
if (array_search($type, Question::TYPES) === false) {
$this->logger->debug('Invalid type');
return new Http\JSONResponse(['message' => 'Invalid type'], Http::STATUS_BAD_REQUEST);
}
try {
$form = $this->formMapper->findById($formId);
} catch (IMapperException $e) {
$this->logger->debug('Could not find form');
return new Http\JSONResponse([], Http::STATUS_BAD_REQUEST);
return new Http\JSONResponse(['message' => 'Could not find form'], Http::STATUS_BAD_REQUEST);
}
if ($form->getOwnerId() !== $this->userId) {

View file

@ -43,6 +43,13 @@ class Question extends Entity {
protected $mandatory;
protected $text;
const TYPES = [
'short',
'long',
'multiple',
'multiple_unique'
];
public function __construct() {
$this->addType('formId', 'integer');
$this->addType('order', 'integer');

View file

@ -39,7 +39,7 @@ use \DateTime;
* Installation class for the forms app.
* Initial db creation
*/
class Version010200Date2020323141300 extends SimpleMigrationStep {
class Version010200Date20200323141300 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
@ -47,6 +47,15 @@ class Version010200Date2020323141300 extends SimpleMigrationStep {
/** @var IConfig */
protected $config;
/** Map of questionTypes to change */
private $questionTypeMap = [
'radiogroup' => 'multiple_unique',
'checkbox' => 'multiple',
'text' => 'short',
'comment' => 'long',
'dropdown' => 'multiple_unique'
];
/**
* @param IDBConnection $connection
* @param IConfig $config
@ -257,7 +266,7 @@ class Version010200Date2020323141300 extends SimpleMigrationStep {
->values([
'form_id' => $qb_restore->createNamedParameter($id_mapping['events'][$question['form_id']]['newId'], IQueryBuilder::PARAM_INT),
'order' => $qb_restore->createNamedParameter($id_mapping['events'][$question['form_id']]['nextQuestionOrder']++, IQueryBuilder::PARAM_INT),
'type' => $qb_restore->createNamedParameter($question['form_question_type'], IQueryBuilder::PARAM_STR),
'type' => $qb_restore->createNamedParameter($this->questionTypeMap[$question['form_question_type']], IQueryBuilder::PARAM_STR),
'text' => $qb_restore->createNamedParameter($question['form_question_text'], IQueryBuilder::PARAM_STR)
]);
$qb_restore->execute();