auto fixes + some impl.

This commit is contained in:
Dennis Eichhorn 2024-01-26 22:54:00 +00:00
parent 2f51284d29
commit 486dd41c9c
26 changed files with 210 additions and 453 deletions

View File

@ -18,7 +18,7 @@ use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^.*/survey.*$' => [
'^.*/survey(\?.*$|$)' => [
[
'dest' => '\Modules\Surveys\Controller\BackendController:setUpBackend',
'verb' => RouteVerb::GET,
@ -29,7 +29,7 @@ return [
],
],
],
'^.*/survey/list.*$' => [
'^.*/survey/list(\?.*$|$)' => [
[
'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysList',
'verb' => RouteVerb::GET,
@ -40,7 +40,7 @@ return [
],
],
],
'^.*/survey/create.*$' => [
'^.*/survey/create(\?.*$|$)' => [
[
'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysCreate',
'verb' => RouteVerb::GET,
@ -51,7 +51,7 @@ return [
],
],
],
'^.*/survey/edit.*$' => [
'^.*/survey/edit(\?.*$|$)' => [
[
'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysEdit',
'verb' => RouteVerb::GET,
@ -62,7 +62,7 @@ return [
],
],
],
'^.*/survey(\?.*|$)$' => [
'^.*/survey(\?.*$|$)' => [
[
'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysSurvey',
'verb' => RouteVerb::GET,

View File

@ -26,9 +26,7 @@ use Modules\Surveys\Models\SurveyTemplateElementMapper;
use Modules\Surveys\Models\SurveyTemplateL11n;
use Modules\Surveys\Models\SurveyTemplateLabelL11n;
use Modules\Surveys\Models\SurveyTemplateMapper;
use Modules\Tag\Models\NullTag;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
@ -105,38 +103,20 @@ final class ApiController extends Controller
$template = new SurveyTemplate();
$template->start = $request->getDataDateTime('start');
$template->end = $request->getDataDateTime('end');
$template->status = $request->getDataInt('status') ?? SurveyStatus::ACTIVE;
$template->status = SurveyStatus::tryFromValue($request->getDataInt('status')) ?? SurveyStatus::ACTIVE;
$template->createdBy = new NullAccount($request->header->account);
$l11n = new SurveyTemplateL11n(
$request->getDataString('title') ?? '',
Markdown::parse($request->getDataString('description') ?? ''),
$request->getDataString('description') ?? '',
$request->getDataString('language') ?? ISO639x1Enum::_EN
ISO639x1Enum::tryFromValue($request->getDataString('language')) ?? ISO639x1Enum::_EN
);
$template->setL11n($l11n);
if (!empty($tags = $request->getDataJson('tags'))) {
foreach ($tags as $tag) {
if (!isset($tag['id'])) {
$request->setData('title', $tag['title'], true);
$request->setData('color', $tag['color'], true);
$request->setData('icon', $tag['icon'] ?? null, true);
$request->setData('language', $tag['language'], true);
$internalResponse = new HttpResponse();
$this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse);
if (!\is_array($data = $internalResponse->getDataArray($request->uri->__toString()))) {
continue;
}
$template->addTag($data['response']);
} else {
$template->addTag(new NullTag((int) $tag['id']));
}
}
if ($request->hasData('tags')) {
$template->tags = $this->app->moduleManager->get('Tag', 'Api')->createTagsFromRequest($request);
}
if (!empty($uploadedFiles = $request->files)) {
@ -150,13 +130,13 @@ final class ApiController extends Controller
);
foreach ($uploaded as $media) {
$template->addMedia($media);
$template->files[] = $media;
}
}
if (!empty($mediaFiles = $request->getDataJson('media'))) {
foreach ($mediaFiles as $media) {
$template->addMedia(new NullMedia($media));
$template->files[] = new NullMedia($media);
}
}
@ -235,7 +215,7 @@ final class ApiController extends Controller
$request->getDataString('text') ?? '',
Markdown::parse($request->getDataString('description') ?? ''),
$request->getDataString('description') ?? '',
$request->getDataString('language') ?? ISO639x1Enum::_EN
ISO639x1Enum::tryFromValue($request->getDataString('language')) ?? ISO639x1Enum::_EN
);
$element->setL11n($l11n);
@ -244,7 +224,7 @@ final class ApiController extends Controller
foreach ($labels as $text) {
$label = new SurveyTemplateLabelL11n(
$text,
$request->getDataString('language') ?? ISO639x1Enum::_EN
ISO639x1Enum::tryFromValue($request->getDataString('language')) ?? ISO639x1Enum::_EN
);
$element->addLabel($label);

View File

@ -131,7 +131,7 @@ final class BackendController extends Controller
->with('elements')
->with('elements/l11n')
->with('elements/labels')
->with('media')
->with('files')
->with('l11n')
->with('tags')
->with('tags/title')

View File

@ -31,25 +31,4 @@ final class SurveyAnswer
* @since 1.0.0
*/
public int $id = 0;
/**
* Constructor
*
* @since 1.0.0
*/
public function __construct()
{
}
/**
* Get id.
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
}

View File

@ -15,8 +15,6 @@ declare(strict_types=1);
namespace Modules\Surveys\Models;
use Modules\Admin\Models\Account;
use Modules\Media\Models\Media;
use Modules\Tag\Models\NullTag;
use Modules\Tag\Models\Tag;
use phpOMS\Localization\ISO639x1Enum;
@ -120,14 +118,6 @@ class SurveyTemplate
*/
public array $elements = [];
/**
* Media files
*
* @var Media[]
* @since 1.0.0
*/
public array $media = [];
/**
* Constructor.
*
@ -138,18 +128,6 @@ class SurveyTemplate
$this->createdAt = new \DateTimeImmutable('now');
}
/**
* Get id.
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* @return SurveyTemplateL11n
*
@ -175,104 +153,6 @@ class SurveyTemplate
$this->l11n = $l11n;
}
/**
* Get tags
*
* @return array
*
* @since 1.0.0
*/
public function getTags() : array
{
return $this->tags;
}
/**
* Get tag.
*
* @param int $id Element id
*
* @return Tag
*
* @since 1.0.0
*/
public function getTag(int $id) : Tag
{
return $this->tags[$id] ?? new NullTag();
}
/**
* Add tag
*
* @param Tag $tag Tag
*
* @return void
*
* @since 1.0.0
*/
public function addTag(Tag $tag) : void
{
$this->tags[] = $tag;
}
/**
* Remove Tag from list.
*
* @param int $id Tag
*
* @return bool
*
* @since 1.0.0
*/
public function removeTag($id) : bool
{
if (isset($this->tags[$id])) {
unset($this->tags[$id]);
return true;
}
return false;
}
/**
* Get all media
*
* @return Media[]
*
* @since 1.0.0
*/
public function getMedia() : array
{
return $this->media;
}
/**
* Add media
*
* @param Media $media Media to add
*
* @return void
*
* @since 1.0.0
*/
public function addMedia(Media $media) : void
{
$this->media[] = $media;
}
/**
* Get elements
*
* @return array
*
* @since 1.0.0
*/
public function getElements() : array
{
return $this->elements;
}
/**
* Add element
*
@ -302,7 +182,7 @@ class SurveyTemplate
'virtualPath' => $this->virtualPath,
'tags' => $this->tags,
'elements' => $this->elements,
'media' => $this->media,
'media' => $this->files,
];
}
@ -313,4 +193,6 @@ class SurveyTemplate
{
return $this->toArray();
}
use \Modules\Media\Models\MediaListTrait;
}

View File

@ -90,18 +90,6 @@ class SurveyTemplateElement
*/
public array $values = [];
/**
* Get id.
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* @return SurveyTemplateElementL11n
*
@ -177,13 +165,13 @@ class SurveyTemplateElement
public function toArray() : array
{
return [
'id' => $this->id,
'type' => $this->type,
'isOptional' => $this->isOptional,
'order' => $this->order,
'template' => $this->template,
'labels' => $this->labels,
'values' => $this->values,
'id' => $this->id,
'type' => $this->type,
'isOptional' => $this->isOptional,
'order' => $this->order,
'template' => $this->template,
'labels' => $this->labels,
'values' => $this->values,
];
}

View File

@ -124,12 +124,12 @@ class SurveyTemplateElementL11n implements \JsonSerializable
public function toArray() : array
{
return [
'id' => $this->id,
'text' => $this->text,
'description' => $this->description,
'descriptionPlain' => $this->descriptionPlain,
'element' => $this->element,
'language' => $this->language,
'id' => $this->id,
'text' => $this->text,
'description' => $this->description,
'descriptionPlain' => $this->descriptionPlain,
'element' => $this->element,
'language' => $this->language,
];
}

View File

@ -33,12 +33,12 @@ final class SurveyTemplateElementL11nMapper extends DataMapperFactory
* @since 1.0.0
*/
public const COLUMNS = [
'survey_template_element_l11n_id' => ['name' => 'survey_template_element_l11n_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_element_l11n_text' => ['name' => 'survey_template_element_l11n_text', 'type' => 'string', 'internal' => 'text', 'autocomplete' => true],
'survey_template_element_l11n_description' => ['name' => 'survey_template_element_l11n_description', 'type' => 'string', 'internal' => 'description'],
'survey_template_element_l11n_description_plain' => ['name' => 'survey_template_element_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'],
'survey_template_element_l11n_element' => ['name' => 'survey_template_element_l11n_element', 'type' => 'int', 'internal' => 'element'],
'survey_template_element_l11n_language' => ['name' => 'survey_template_element_l11n_language', 'type' => 'string', 'internal' => 'language'],
'survey_template_element_l11n_id' => ['name' => 'survey_template_element_l11n_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_element_l11n_text' => ['name' => 'survey_template_element_l11n_text', 'type' => 'string', 'internal' => 'text', 'autocomplete' => true],
'survey_template_element_l11n_description' => ['name' => 'survey_template_element_l11n_description', 'type' => 'string', 'internal' => 'description'],
'survey_template_element_l11n_description_plain' => ['name' => 'survey_template_element_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'],
'survey_template_element_l11n_element' => ['name' => 'survey_template_element_l11n_element', 'type' => 'int', 'internal' => 'element'],
'survey_template_element_l11n_language' => ['name' => 'survey_template_element_l11n_language', 'type' => 'string', 'internal' => 'language'],
];
/**

View File

@ -36,12 +36,12 @@ final class SurveyTemplateElementMapper extends DataMapperFactory
* @since 1.0.0
*/
public const COLUMNS = [
'survey_template_element_id' => ['name' => 'survey_template_element_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_element_type' => ['name' => 'survey_template_element_type', 'type' => 'int', 'internal' => 'type'],
'survey_template_element_order' => ['name' => 'survey_template_element_order', 'type' => 'int', 'internal' => 'order'],
'survey_template_element_optional' => ['name' => 'survey_template_element_optional', 'type' => 'bool', 'internal' => 'isOptional'],
'survey_template_element_values' => ['name' => 'survey_template_element_values', 'type' => 'Json', 'internal' => 'values'],
'survey_template_element_template' => ['name' => 'survey_template_element_template', 'type' => 'int', 'internal' => 'template'],
'survey_template_element_id' => ['name' => 'survey_template_element_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_element_type' => ['name' => 'survey_template_element_type', 'type' => 'int', 'internal' => 'type'],
'survey_template_element_order' => ['name' => 'survey_template_element_order', 'type' => 'int', 'internal' => 'order'],
'survey_template_element_optional' => ['name' => 'survey_template_element_optional', 'type' => 'bool', 'internal' => 'isOptional'],
'survey_template_element_values' => ['name' => 'survey_template_element_values', 'type' => 'Json', 'internal' => 'values'],
'survey_template_element_template' => ['name' => 'survey_template_element_template', 'type' => 'int', 'internal' => 'template'],
];
/**
@ -52,17 +52,17 @@ final class SurveyTemplateElementMapper extends DataMapperFactory
*/
public const HAS_MANY = [
'l11n' => [
'mapper' => SurveyTemplateElementL11nMapper::class,
'table' => 'survey_template_element_l11n',
'self' => 'survey_template_element_l11n_element',
'conditional' => true,
'external' => null,
'mapper' => SurveyTemplateElementL11nMapper::class,
'table' => 'survey_template_element_l11n',
'self' => 'survey_template_element_l11n_element',
'conditional' => true,
'external' => null,
],
'labels' => [
'mapper' => SurveyTemplateLabelL11nMapper::class,
'table' => 'survey_template_element_label_l11n',
'self' => 'survey_template_element_label_l11n_element',
'external' => null,
'mapper' => SurveyTemplateLabelL11nMapper::class,
'table' => 'survey_template_element_label_l11n',
'self' => 'survey_template_element_label_l11n_element',
'external' => null,
],
];

View File

@ -140,12 +140,12 @@ class SurveyTemplateL11n implements \JsonSerializable
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'descriptionPlain' => $this->descriptionPlain,
'template' => $this->template,
'language' => $this->language,
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'descriptionPlain' => $this->descriptionPlain,
'template' => $this->template,
'language' => $this->language,
];
}

View File

@ -36,14 +36,14 @@ final class SurveyTemplateL11nMapper extends DataMapperFactory
* @since 1.0.0
*/
public const COLUMNS = [
'survey_template_l11n_id' => ['name' => 'survey_template_l11n_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_l11n_title' => ['name' => 'survey_template_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'survey_template_l11n_description' => ['name' => 'survey_template_l11n_description', 'type' => 'string', 'internal' => 'description'],
'survey_template_l11n_description_plain' => ['name' => 'survey_template_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'],
'survey_template_l11n_footer' => ['name' => 'survey_template_l11n_footer', 'type' => 'string', 'internal' => 'footer'],
'survey_template_l11n_footer_plain' => ['name' => 'survey_template_l11n_footer_plain', 'type' => 'string', 'internal' => 'footerPlain'],
'survey_template_l11n_template' => ['name' => 'survey_template_l11n_template', 'type' => 'int', 'internal' => 'template'],
'survey_template_l11n_language' => ['name' => 'survey_template_l11n_language', 'type' => 'string', 'internal' => 'language'],
'survey_template_l11n_id' => ['name' => 'survey_template_l11n_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_l11n_title' => ['name' => 'survey_template_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'survey_template_l11n_description' => ['name' => 'survey_template_l11n_description', 'type' => 'string', 'internal' => 'description'],
'survey_template_l11n_description_plain' => ['name' => 'survey_template_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'],
'survey_template_l11n_footer' => ['name' => 'survey_template_l11n_footer', 'type' => 'string', 'internal' => 'footer'],
'survey_template_l11n_footer_plain' => ['name' => 'survey_template_l11n_footer_plain', 'type' => 'string', 'internal' => 'footerPlain'],
'survey_template_l11n_template' => ['name' => 'survey_template_l11n_template', 'type' => 'int', 'internal' => 'template'],
'survey_template_l11n_language' => ['name' => 'survey_template_l11n_language', 'type' => 'string', 'internal' => 'language'],
];
/**

View File

@ -112,11 +112,11 @@ class SurveyTemplateLabelL11n implements \JsonSerializable
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'element' => $this->element,
'order' => $this->order,
'language' => $this->language,
'id' => $this->id,
'title' => $this->title,
'element' => $this->element,
'order' => $this->order,
'language' => $this->language,
];
}

View File

@ -36,11 +36,11 @@ final class SurveyTemplateLabelL11nMapper extends DataMapperFactory
* @since 1.0.0
*/
public const COLUMNS = [
'survey_template_element_label_l11n_id' => ['name' => 'survey_template_element_label_l11n_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_element_label_l11n_title' => ['name' => 'survey_template_element_label_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'survey_template_element_label_l11n_element' => ['name' => 'survey_template_element_label_l11n_element', 'type' => 'int', 'internal' => 'element'],
'survey_template_element_label_l11n_order' => ['name' => 'survey_template_element_label_l11n_order', 'type' => 'int', 'internal' => 'order'],
'survey_template_element_label_l11n_language' => ['name' => 'survey_template_element_label_l11n_language', 'type' => 'string', 'internal' => 'language'],
'survey_template_element_label_l11n_id' => ['name' => 'survey_template_element_label_l11n_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_element_label_l11n_title' => ['name' => 'survey_template_element_label_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'survey_template_element_label_l11n_element' => ['name' => 'survey_template_element_label_l11n_element', 'type' => 'int', 'internal' => 'element'],
'survey_template_element_label_l11n_order' => ['name' => 'survey_template_element_label_l11n_order', 'type' => 'int', 'internal' => 'order'],
'survey_template_element_label_l11n_language' => ['name' => 'survey_template_element_label_l11n_language', 'type' => 'string', 'internal' => 'language'],
];
/**

View File

@ -40,14 +40,14 @@ final class SurveyTemplateMapper extends DataMapperFactory
* @since 1.0.0
*/
public const COLUMNS = [
'survey_template_id' => ['name' => 'survey_template_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_status' => ['name' => 'survey_template_status', 'type' => 'int', 'internal' => 'status'],
'survey_template_public_result' => ['name' => 'survey_template_public_result', 'type' => 'bool', 'internal' => 'hasPublicResult'],
'survey_template_start' => ['name' => 'survey_template_start', 'type' => 'DateTime', 'internal' => 'start'],
'survey_template_end' => ['name' => 'survey_template_end', 'type' => 'DateTime', 'internal' => 'end'],
'survey_template_virtual' => ['name' => 'survey_template_virtual', 'type' => 'string', 'internal' => 'virtualPath'],
'survey_template_created_by' => ['name' => 'survey_template_created_by', 'type' => 'int', 'internal' => 'createdBy'],
'survey_template_created_at' => ['name' => 'survey_template_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'],
'survey_template_id' => ['name' => 'survey_template_id', 'type' => 'int', 'internal' => 'id'],
'survey_template_status' => ['name' => 'survey_template_status', 'type' => 'int', 'internal' => 'status'],
'survey_template_public_result' => ['name' => 'survey_template_public_result', 'type' => 'bool', 'internal' => 'hasPublicResult'],
'survey_template_start' => ['name' => 'survey_template_start', 'type' => 'DateTime', 'internal' => 'start'],
'survey_template_end' => ['name' => 'survey_template_end', 'type' => 'DateTime', 'internal' => 'end'],
'survey_template_virtual' => ['name' => 'survey_template_virtual', 'type' => 'string', 'internal' => 'virtualPath'],
'survey_template_created_by' => ['name' => 'survey_template_created_by', 'type' => 'int', 'internal' => 'createdBy'],
'survey_template_created_at' => ['name' => 'survey_template_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'],
];
/**
@ -58,17 +58,17 @@ final class SurveyTemplateMapper extends DataMapperFactory
*/
public const HAS_MANY = [
'elements' => [
'mapper' => SurveyTemplateElementMapper::class,
'table' => 'survey_template_element',
'self' => 'survey_template_element_template',
'external' => null,
'mapper' => SurveyTemplateElementMapper::class,
'table' => 'survey_template_element',
'self' => 'survey_template_element_template',
'external' => null,
],
'l11n' => [
'mapper' => SurveyTemplateL11nMapper::class,
'table' => 'survey_template_l11n',
'self' => 'survey_template_l11n_template',
'conditional' => true,
'external' => null,
'mapper' => SurveyTemplateL11nMapper::class,
'table' => 'survey_template_l11n',
'self' => 'survey_template_l11n_template',
'conditional' => true,
'external' => null,
],
'tags' => [
'mapper' => TagMapper::class,
@ -76,7 +76,7 @@ final class SurveyTemplateMapper extends DataMapperFactory
'self' => 'survey_template_tag_dst',
'external' => 'survey_template_tag_src',
],
'media' => [
'files' => [
'mapper' => MediaMapper::class,
'table' => 'survey_template_media',
'external' => 'survey_template_media_dst',
@ -92,8 +92,8 @@ final class SurveyTemplateMapper extends DataMapperFactory
*/
public const BELONGS_TO = [
'createdBy' => [
'mapper' => AccountMapper::class,
'external' => 'survey_template_created_by',
'mapper' => AccountMapper::class,
'external' => 'survey_template_created_by',
],
];

View File

@ -49,8 +49,8 @@ return ['Surveys' => [
'Type' => 'Typ',
'User' => 'Nutzer',
'UserGroup' => 'Benutzergruppe',
'Headline' => 'Headline',
'Textfield' => 'Textfeld',
'Textarea' => 'Textblock',
'Numeric' => 'Zahl',
'Headline' => 'Headline',
'Textfield' => 'Textfeld',
'Textarea' => 'Textblock',
'Numeric' => 'Zahl',
]];

View File

@ -49,8 +49,8 @@ return ['Surveys' => [
'Type' => 'Type',
'User' => 'User',
'UserGroup' => 'User/Group',
'Headline' => 'Headline',
'Textfield' => 'Textfield',
'Textarea' => 'Textarea',
'Numeric' => 'Numeric',
'Headline' => 'Headline',
'Textfield' => 'Textfield',
'Textarea' => 'Textarea',
'Numeric' => 'Numeric',
]];

View File

@ -106,14 +106,14 @@ echo $this->data['nav']->render(); ?>
<div class="form-group">
<label for="iSType"><?= $this->getHtml('Type'); ?></label>
<select id="iSType" name="stype">
<option value="<?= SurveyElementType::HEADLINE; ?>"><?= $this->getHtml('Headline') ?>
<option value="<?= SurveyElementType::DROPDOWN; ?>"><?= $this->getHtml('Dropdown') ?>
<option value="<?= SurveyElementType::CHECKBOX; ?>"><?= $this->getHtml('Checkbox') ?>
<option value="<?= SurveyElementType::RADIO; ?>"><?= $this->getHtml('Radio') ?>
<option value="<?= SurveyElementType::TEXTFIELD; ?>"><?= $this->getHtml('Textfield') ?>
<option value="<?= SurveyElementType::TEXTAREA; ?>"><?= $this->getHtml('Textarea') ?>
<option value="<?= SurveyElementType::NUMERIC; ?>"><?= $this->getHtml('Numeric') ?>
<option value="<?= SurveyElementType::DATE; ?>"><?= $this->getHtml('Date') ?>
<option value="<?= SurveyElementType::HEADLINE; ?>"><?= $this->getHtml('Headline'); ?>
<option value="<?= SurveyElementType::DROPDOWN; ?>"><?= $this->getHtml('Dropdown'); ?>
<option value="<?= SurveyElementType::CHECKBOX; ?>"><?= $this->getHtml('Checkbox'); ?>
<option value="<?= SurveyElementType::RADIO; ?>"><?= $this->getHtml('Radio'); ?>
<option value="<?= SurveyElementType::TEXTFIELD; ?>"><?= $this->getHtml('Textfield'); ?>
<option value="<?= SurveyElementType::TEXTAREA; ?>"><?= $this->getHtml('Textarea'); ?>
<option value="<?= SurveyElementType::NUMERIC; ?>"><?= $this->getHtml('Numeric'); ?>
<option value="<?= SurveyElementType::DATE; ?>"><?= $this->getHtml('Date'); ?>
</select>
</div>
</div>
@ -136,8 +136,8 @@ echo $this->data['nav']->render(); ?>
<?php if (!empty($survey->getL11n()->description)) : ?>
<article class="survey-description"><?= $survey->getL11n()->description; ?></article>
<?php endif; ?>
<?php $elements = $survey->getElements();
foreach ($elements as $element) {
<?php
foreach ($survey->elements as $element) {
if ($element->type === SurveyElementType::HEADLINE) {
echo '<h1>' . $this->printHtml($element->getL11n()->text) . '</h1>';

View File

@ -109,7 +109,7 @@ echo $this->data['nav']->render(); ?>
<td>
<td><a href="<?= $url; ?>"><?= $value->getL11n()->title; ?></a>
<td>
<td><a class="content" href="<?= UriFactory::build('{/base}/profile/single?{?}&for=' . $value->createdBy->id); ?>"><?= $this->printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->createdBy->name1, $value->createdBy->name2, $value->createdBy->name3, $value->createdBy->login ?? ''])); ?></a>
<td><a class="content" href="<?= UriFactory::build('{/base}/profile/view?{?}&for=' . $value->createdBy->id); ?>"><?= $this->printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->createdBy->name1, $value->createdBy->name2, $value->createdBy->name3, $value->createdBy->login ?? ''])); ?></a>
<td><a href="<?= $url; ?>"><?= $value->createdAt->format('Y-m-d'); ?></a>
<?php endforeach; ?>
<?php if ($count === 0) : ?>

View File

@ -75,8 +75,8 @@ final class Autoloader
*/
public static function defaultAutoloader(string $class) : void
{
$class = \ltrim($class, '\\');
$class = \strtr($class, '_\\', '//');
$class = \ltrim($class, '\\');
$class = \strtr($class, '_\\', '//');
if (\stripos($class, 'Web/Backend') !== false || \stripos($class, 'Web/Api') !== false) {
$class = \is_dir(__DIR__ . '/Web') ? $class : \str_replace('Web/', 'MainRepository/Web/', $class);

View File

@ -1,4 +1,15 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Surveys\tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
\ini_set('memory_limit', '2048M');
@ -67,10 +78,10 @@ $GLOBALS['is_github'] = $IS_GITHUB;
$tmp = FileLogger::getInstance(__DIR__ . '/../Logs');
$CONFIG = [
'db' => [
'db' => [
'core' => [
'masters' => [
'admin' => [
'admin' => [
'db' => 'mysql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '3306', /* db host port */
@ -80,7 +91,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'insert' => [
'insert' => [
'db' => 'mysql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '3306', /* db host port */
@ -90,7 +101,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'select' => [
'select' => [
'db' => 'mysql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '3306', /* db host port */
@ -100,7 +111,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'update' => [
'update' => [
'db' => 'mysql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '3306', /* db host port */
@ -110,7 +121,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'delete' => [
'delete' => [
'db' => 'mysql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '3306', /* db host port */
@ -120,7 +131,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'schema' => [
'schema' => [
'db' => 'mysql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '3306', /* db host port */
@ -132,7 +143,7 @@ $CONFIG = [
],
],
'postgresql' => [
'admin' => [
'admin' => [
'db' => 'pgsql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '5432', /* db host port */
@ -142,7 +153,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'insert' => [
'insert' => [
'db' => 'pgsql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '5432', /* db host port */
@ -152,7 +163,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'select' => [
'select' => [
'db' => 'pgsql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '5432', /* db host port */
@ -162,7 +173,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'update' => [
'update' => [
'db' => 'pgsql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '5432', /* db host port */
@ -172,7 +183,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'delete' => [
'delete' => [
'db' => 'pgsql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '5432', /* db host port */
@ -182,7 +193,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'schema' => [
'schema' => [
'db' => 'pgsql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '5432', /* db host port */
@ -194,37 +205,37 @@ $CONFIG = [
],
],
'sqlite' => [
'admin' => [
'admin' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'insert' => [
'insert' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'select' => [
'select' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'update' => [
'update' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'delete' => [
'delete' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'schema' => [
'schema' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
@ -232,7 +243,7 @@ $CONFIG = [
],
],
'mssql' => [
'admin' => [
'admin' => [
'db' => 'mssql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '1433', /* db host port */
@ -242,7 +253,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'insert' => [
'insert' => [
'db' => 'mssql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '1433', /* db host port */
@ -252,7 +263,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'select' => [
'select' => [
'db' => 'mssql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '1433', /* db host port */
@ -262,7 +273,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'update' => [
'update' => [
'db' => 'mssql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '1433', /* db host port */
@ -272,7 +283,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'delete' => [
'delete' => [
'db' => 'mssql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '1433', /* db host port */
@ -282,7 +293,7 @@ $CONFIG = [
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'schema' => [
'schema' => [
'db' => 'mssql', /* db type */
'host' => '127.0.0.1', /* db host address */
'port' => '1433', /* db host port */
@ -322,16 +333,16 @@ $CONFIG = [
'password' => '123456',
],
],
'log' => [
'log' => [
'file' => [
'path' => __DIR__ . '/Logs',
],
],
'page' => [
'page' => [
'root' => '/',
'https' => false,
],
'app' => [
'app' => [
'path' => __DIR__,
'default' => [
'app' => 'Backend',
@ -350,7 +361,7 @@ $CONFIG = [
],
],
],
'socket' => [
'socket' => [
'master' => [
'host' => '127.0.0.1',
'limit' => 300,
@ -360,7 +371,7 @@ $CONFIG = [
'language' => [
'en',
],
'apis' => [
'apis' => [
],
];

View File

@ -32,7 +32,6 @@ use phpOMS\Module\ModuleAbstract;
use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter;
use phpOMS\System\MimeType;
use phpOMS\Uri\HttpUri;
use phpOMS\Utils\TestUtils;
/**
@ -59,13 +58,13 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
protected string $appName = 'Api';
};
$this->app->dbPool = $GLOBALS['dbpool'];
$this->app->unitId = 1;
$this->app->accountManager = new AccountManager($GLOBALS['session']);
$this->app->appSettings = new CoreSettings();
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
$this->app->dispatcher = new Dispatcher($this->app);
$this->app->eventManager = new EventManager($this->app->dispatcher);
$this->app->dbPool = $GLOBALS['dbpool'];
$this->app->unitId = 1;
$this->app->accountManager = new AccountManager($GLOBALS['session']);
$this->app->appSettings = new CoreSettings();
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
$this->app->dispatcher = new Dispatcher($this->app);
$this->app->eventManager = new EventManager($this->app->dispatcher);
$this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php');
$this->app->sessionManager = new HttpSession(36000);
$this->app->l11nManager = new L11nManager();
@ -101,7 +100,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testApiSurveyTemplateCreate() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('title', 'TestSurvey');
@ -136,7 +135,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testApiSurveyTemplateCreateInvalidData() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('invalid', '1');
@ -152,7 +151,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testApiSurveyTemplateElementCreate() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('survey', '1');
@ -177,7 +176,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testApiSurveyTemplateElementCreateInvalidData() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('invalid', '1');
@ -193,7 +192,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testApiSurveyAnswerCreate() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('survey', '1');
@ -211,7 +210,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testApiSurveyAnswerCreateInvalidData() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('invalid', '1');

View File

@ -65,16 +65,6 @@ final class SurveyTemplateElementL11nTest extends \PHPUnit\Framework\TestCase
self::assertEquals('TestContent', $this->l11n->description);
}
/**
* @covers Modules\Surveys\Models\SurveyTemplateElementL11n
* @group module
*/
public function testLanguageInputOutput() : void
{
$this->l11n->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(ISO639x1Enum::_DE, $this->l11n->language);
}
/**
* @covers Modules\Surveys\Models\SurveyTemplateElementL11n
* @group module
@ -85,16 +75,16 @@ final class SurveyTemplateElementL11nTest extends \PHPUnit\Framework\TestCase
$this->l11n->description = 'Content';
$this->l11n->descriptionPlain = 'ContentPlain';
$this->l11n->element = 2;
$this->l11n->setLanguage(ISO639x1Enum::_DE);
$this->l11n->language = ISO639x1Enum::_DE;
self::assertEquals(
[
'id' => 0,
'text' => 'Title',
'description' => 'Content',
'descriptionPlain' => 'ContentPlain',
'element' => 2,
'language' => ISO639x1Enum::_DE,
'id' => 0,
'text' => 'Title',
'description' => 'Content',
'descriptionPlain' => 'ContentPlain',
'element' => 2,
'language' => ISO639x1Enum::_DE,
],
$this->l11n->jsonSerialize()
);

View File

@ -84,21 +84,21 @@ final class SurveyTemplateElementTest extends \PHPUnit\Framework\TestCase
*/
public function testSerialize() : void
{
$this->element->isOptional = true;
$this->element->order = 3;
$this->element->template = 2;
$this->element->isOptional = true;
$this->element->order = 3;
$this->element->template = 2;
$serialized = $this->element->jsonSerialize();
self::assertEquals(
[
'id' => 0,
'type' => SurveyElementType::CHECKBOX,
'isOptional' => true,
'order' => 3,
'template' => 2,
'labels' => [],
'values' => [],
'id' => 0,
'type' => SurveyElementType::CHECKBOX,
'isOptional' => true,
'order' => 3,
'template' => 2,
'labels' => [],
'values' => [],
],
$serialized
);

View File

@ -65,16 +65,6 @@ final class SurveyTemplateL11nTest extends \PHPUnit\Framework\TestCase
self::assertEquals('TestContent', $this->l11n->description);
}
/**
* @covers Modules\Surveys\Models\SurveyTemplateL11n
* @group module
*/
public function testLanguageInputOutput() : void
{
$this->l11n->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(ISO639x1Enum::_DE, $this->l11n->language);
}
/**
* @covers Modules\Surveys\Models\SurveyTemplateL11n
* @group module
@ -85,16 +75,16 @@ final class SurveyTemplateL11nTest extends \PHPUnit\Framework\TestCase
$this->l11n->description = 'Content';
$this->l11n->descriptionPlain = 'ContentPlain';
$this->l11n->template = 2;
$this->l11n->setLanguage(ISO639x1Enum::_DE);
$this->l11n->language = ISO639x1Enum::_DE;
self::assertEquals(
[
'id' => 0,
'title' => 'Title',
'description' => 'Content',
'descriptionPlain' => 'ContentPlain',
'template' => 2,
'language' => ISO639x1Enum::_DE,
'id' => 0,
'title' => 'Title',
'description' => 'Content',
'descriptionPlain' => 'ContentPlain',
'template' => 2,
'language' => ISO639x1Enum::_DE,
],
$this->l11n->jsonSerialize()
);

View File

@ -53,34 +53,24 @@ final class SurveyTemplateLabelL11nTest extends \PHPUnit\Framework\TestCase
self::assertEquals('TestName', $this->l11n->title);
}
/**
* @covers Modules\Surveys\Models\SurveyTemplateLabelL11n
* @group module
*/
public function testLanguageInputOutput() : void
{
$this->l11n->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(ISO639x1Enum::_DE, $this->l11n->language);
}
/**
* @covers Modules\Surveys\Models\SurveyTemplateLabelL11n
* @group module
*/
public function testSerialize() : void
{
$this->l11n->title = 'Title';
$this->l11n->element = 2;
$this->l11n->order = 3;
$this->l11n->setLanguage(ISO639x1Enum::_DE);
$this->l11n->title = 'Title';
$this->l11n->element = 2;
$this->l11n->order = 3;
$this->l11n->language = ISO639x1Enum::_DE;
self::assertEquals(
[
'id' => 0,
'title' => 'Title',
'element' => 2,
'order' => 3,
'language' => ISO639x1Enum::_DE,
'id' => 0,
'title' => 'Title',
'element' => 2,
'order' => 3,
'language' => ISO639x1Enum::_DE,
],
$this->l11n->jsonSerialize()
);

View File

@ -14,12 +14,9 @@ declare(strict_types=1);
namespace Modules\Surveys\tests\Models;
use Modules\Media\Models\Media;
use Modules\Surveys\Models\SurveyStatus;
use Modules\Surveys\Models\SurveyTemplate;
use Modules\Surveys\Models\SurveyTemplateElement;
use Modules\Surveys\Models\SurveyTemplateL11n;
use Modules\Tag\Models\Tag;
/**
* @internal
@ -45,58 +42,9 @@ final class SurveyTemplateTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $this->survey->id);
$date = new \DateTime('now');
self::assertEquals([], $this->survey->getElements());
self::assertEquals([], $this->survey->getTags());
self::assertEquals([], $this->survey->getMedia());
}
/**
* @covers Modules\Surveys\Models\SurveyTemplate
* @group module
*/
public function testTagInputOutput() : void
{
$tag = new Tag();
$tag->setL11n('Tag');
$this->survey->addTag($tag);
self::assertEquals($tag, $this->survey->getTag(0));
self::assertCount(1, $this->survey->getTags());
}
/**
* @covers Modules\Surveys\Models\SurveyTemplate
* @group module
*/
public function testTagRemove() : void
{
$tag = new Tag();
$tag->setL11n('Tag');
$this->survey->addTag($tag);
self::assertTrue($this->survey->removeTag(0));
self::assertCount(0, $this->survey->getTags());
self::assertFalse($this->survey->removeTag(0));
}
/**
* @covers Modules\Surveys\Models\SurveyTemplate
* @group module
*/
public function testMediaInputOutput() : void
{
$this->survey->addMedia(new Media());
self::assertCount(1, $this->survey->getMedia());
}
/**
* @covers Modules\Surveys\Models\SurveyTemplate
* @group module
*/
public function testElementInputOutput() : void
{
$this->survey->addElement(new SurveyTemplateElement());
self::assertCount(1, $this->survey->getElements());
self::assertEquals([], $this->survey->elements);
self::assertEquals([], $this->survey->tags);
self::assertEquals([], $this->survey->files);
}
/**
@ -115,10 +63,10 @@ final class SurveyTemplateTest extends \PHPUnit\Framework\TestCase
*/
public function testSerialize() : void
{
$this->survey->hasPublicResult = false;
$this->survey->start = new \DateTime('now');
$this->survey->end = new \DateTime('now');
$this->survey->virtualPath = 'test/path';
$this->survey->hasPublicResult = false;
$this->survey->start = new \DateTime('now');
$this->survey->end = new \DateTime('now');
$this->survey->virtualPath = 'test/path';
$serialized = $this->survey->jsonSerialize();
unset($serialized['createdAt']);