Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,33 @@ public function executeCommand(): void
break;

default:
if ($cmd === 'export') {
global $DIC;
$local_dic = LocalDIC::dic();

$builder = new \ILIAS\Questions\ExportImport\Foundation\Builder(
$DIC,
$local_dic
);

$exporter = new \ILIAS\Questions\ExportImport\QuestionsExporter($builder);
$collector = new \ILIAS\Questions\ExportImport\QuestionsDataCollector(
$local_dic[\ILIAS\Questions\Persistence\Repository::class]
);
$serializer = new \ILIAS\Questions\ExportImport\Foundation\Serializing\JSONMemorySerializer();

$importer = new \ILIAS\Questions\ExportImport\QuestionsImporter(
$builder,
$local_dic[\ILIAS\Questions\Persistence\Repository::class]
);
$deserializer = new \ILIAS\Questions\ExportImport\Foundation\Serializing\JSONMemoryDeserializer();

$exported = $exporter->export($collector, $serializer->open('memory'));
$importer->import($deserializer->open($exported), 320);

exit();
}

if ($cmd === null || $cmd === '' || $cmd === 'view') {
$cmd = 'viewQuestions';
}
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/Questions/src/AnswerForm/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace ILIAS\Questions\AnswerForm;

use ILIAS\Questions\ExportImport\Foundation\Contracts\Normalizable;
use ILIAS\Questions\Persistence\Storable;
use ILIAS\Questions\Presentation\Definitions\Environment;
use ILIAS\Data\UUID\Uuid;
Expand All @@ -29,7 +30,7 @@
use ILIAS\UI\Component\Table\Ordering as OrderingTable;
use Psr\Http\Message\ServerRequestInterface;

interface Properties extends Storable
interface Properties extends Storable, Normalizable
{
public function getAnswerFormId(): Uuid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,31 @@ function (array $matches) use (&$new_gaps): string {
return $clone;
}

public function replaceGapsWithIds(
array $gaps_to_replace
): self {
if ($gaps_to_replace === []) {
return $this;
}

$clone = clone $this;
$clone->cloze_text = $this->text_factory->markdown(
mb_ereg_replace_callback(
'{{' . Gap::GAP_PLACEHOLDER_NAME . '_([0-9a-fA-F-]+)}}',
function (array $matches) use ($gaps_to_replace): string {
$old_id = $matches[1];
if (!isset($gaps_to_replace[$old_id]) || $gaps_to_replace[$old_id] === null) {
return $matches[0];
}

return '{{' . Gap::GAP_PLACEHOLDER_NAME . '_' . $gaps_to_replace[$old_id] . '}}';
},
$this->cloze_text->getRawRepresentation()
)
);
return $clone;
}

private function hasAtLeastOneGap(): bool
{
if ($this->cloze_text->getRawRepresentation() === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
namespace ILIAS\Questions\AnswerFormTypes\Cloze\Properties\Combinations;

use ILIAS\Questions\AnswerFormTypes\Cloze\Persistence;
use ILIAS\Questions\ExportImport\Foundation\Contracts\Normalizable;
use ILIAS\Questions\ExportImport\Foundation\Contracts\Transformations;
use ILIAS\Questions\Persistence\Manipulate;
use ILIAS\Questions\Persistence\TableNameBuilder;
use ILIAS\Data\UUID\Uuid;
use ILIAS\Language\Language;
use ILIAS\HTTP\Services as HttpServices;
use ILIAS\Refinery\Factory as Refinery;
use ILIAS\Refinery\Transformation;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Component\Table\DataRowBuilder;

class Combinations
class Combinations implements Normalizable
{
private array $combinations;

Expand Down Expand Up @@ -173,4 +176,16 @@ public function getNumberOfCombinations(): int
{
return count($this->combinations);
}

public function toNormalized(Transformations $tt): Transformation
{
//TODO
return $tt->custom()->transformation(fn() => []);
}

public function fromNormalized(Transformations $tt): Transformation
{
//TODO
return $tt->custom()->transformation(fn() => $this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

namespace ILIAS\Questions\AnswerFormTypes\Cloze\Properties\Gaps\AnswerOptions;

use ILIAS\Questions\ExportImport\Foundation\Contracts\Normalizable;
use ILIAS\Questions\ExportImport\Foundation\Contracts\Transformations;
use ILIAS\Questions\Persistence\Replace;
use ILIAS\Questions\Persistence\Value;
use ILIAS\Data\UUID\Uuid;
use ILIAS\Refinery\Transformation;

class AnswerOption
class AnswerOption implements Normalizable
{
public const string FORM_KEY_ID = 'id';
public const string FORM_KEY_POSITION = 'position';
Expand Down Expand Up @@ -166,4 +169,35 @@ private function buildValuesForGapReplace(): array

];
}

/**
* @inheritDoc
*/
public function toNormalized(Transformations $tt): Transformation
{
return $tt->custom()->transformation(fn(): array => [
'answer_option_id' => $tt->normalize($this->answer_option_id),
'answer_input_id' => $tt->normalize($this->answer_input_id),
'position' => $this->position,
'text_value' => $this->text_value,
'lower_limit' => $this->lower_limit,
'upper_limit' => $this->upper_limit,
'available_points' => $this->available_points,
]);
}

/**
* @inheritDoc
*/
public function fromNormalized(Transformations $tt): Transformation
{
return $tt->custom()->transformation(function (array $normalized) use ($tt): AnswerOption {
$clone = clone $this;
$clone->text_value = $tt->string($normalized['text_value']);
$clone->lower_limit = $tt->nullableFloat($normalized['lower_limit']);
$clone->upper_limit = $tt->nullableFloat($normalized['upper_limit']);
$clone->available_points = $tt->float($normalized['available_points']);
return $clone;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*N
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Questions\AnswerFormTypes\Cloze\Properties\Gaps\AnswerOptions;

use ILIAS\Questions\ExportImport\Foundation\Contracts\Normalizable;
use ILIAS\Questions\ExportImport\Foundation\Contracts\Transformations;
use ILIAS\Questions\Persistence\Delete;
use ILIAS\Questions\Persistence\Replace;
use ILIAS\Questions\Persistence\TableNameBuilder;
Expand All @@ -32,7 +34,7 @@
use ILIAS\Refinery\Transformation;
use ILIAS\UI\Component\Input\Field\Factory as FieldFactory;

class AnswerOptions
class AnswerOptions implements Normalizable
{
private array $answer_options_awarding_points;

Expand Down Expand Up @@ -310,4 +312,34 @@ private function retrieveAnswerOptionByTextValue(
);
return array_shift($filtered_array) ?? null;
}

/**
* @inheritDoc
*/
public function toNormalized(Transformations $tt): Transformation
{
return $tt->custom()->transformation(fn(): array => [
'options' => $tt->normalize($this->answer_options),
]);
//TODO: answer_options_awarding_points
}

/**
* @inheritDoc
*/
public function fromNormalized(Transformations $tt): Transformation
{
return $tt->custom()->transformation(function (array $normalized) use ($tt): AnswerOptions {
$clone = clone $this;
foreach ($normalized['options'] as $option_data) {
$answer_option = $this->factory->getDefaultAnswerOptionForPosition(
$this->answer_input_id,
$tt->int($option_data['position'])
);
$clone->answer_options[] = $tt->denormalize($option_data, $answer_option);
}
return $clone;
});
//TODO: answer_options_awarding_points
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use ILIAS\Questions\AnswerForm\Persistence;
use ILIAS\Questions\AnswerFormTypes\Cloze\Properties\Gaps\AnswerOptions\AnswerOptions;
use ILIAS\Questions\Definitions\TextMatchingOptions;
use ILIAS\Questions\ExportImport\Foundation\Contracts\Normalizable;
use ILIAS\Questions\ExportImport\Foundation\Contracts\Transformations;
use ILIAS\Questions\Persistence\Replace;
use ILIAS\Questions\Persistence\TableNameBuilder;
use ILIAS\Questions\Persistence\TableTypes;
Expand All @@ -38,7 +40,7 @@
use ILIAS\UI\Component\Table\DataRowBuilder;
use ILIAS\Refinery\Transformation;

class Gap
class Gap implements Normalizable
{
public const string GAP_PLACEHOLDER_NAME = 'GAP';

Expand All @@ -50,9 +52,6 @@ class Gap
private const string FORM_KEY_SHUFFLE_ANSWER_OPTIONS = 'shuffle';
private const string FORM_KEY_ANSWER_OPTIONS = 'answer_options';

/**
* @param array<ILIAS\Questions\AnswerFormTypes\Cloze\Properties\Gaps\AnswerOptions\AnswerOption> $answer_options
*/
public function __construct(
private readonly Uuid $answer_input_id,
private readonly Uuid $answer_form_id,
Expand Down Expand Up @@ -476,4 +475,42 @@ private function getShortenedAnswerInputId(): string
{
return mb_substr($this->answer_input_id->toString(), 0, 4);
}

/**
* @inheritDoc
*/
public function toNormalized(Transformations $tt): Transformation
{
return $tt->custom()->transformation(fn(): array => [
'answer_input_id' => $tt->normalize($this->answer_input_id),
'answer_form_id' => $tt->normalize($this->answer_form_id),
'position' => $this->position,
'type' => $this->type?->getIdentifier(),
'max_chars' => $this->max_chars,
'step_size' => $this->step_size,
'text_matching_method' => $this->text_matching_method?->value,
'min_autocomplete' => $this->min_autocomplete,
'shuffle_answer_options' => $this->shuffle_answer_options,
'answer_options' => $tt->normalize($this->answer_options),
]);
}

/**
* @inheritDoc
*/
public function fromNormalized(Transformations $tt): Transformation
{
// Answer Input Id, Answer Form Id, Position, Type will be set in Gaps::fromNormalized

return $tt->custom()->transformation(function (array $normalized) use ($tt): Gap {
$clone = clone $this;
$clone->max_chars = $tt->nullableInt($normalized['max_chars']);
$clone->step_size = $tt->nullableFloat($normalized['step_size']);
$clone->text_matching_method = $normalized['text_matching_method'] !== null ? TextMatchingOptions::tryFrom($normalized['text_matching_method']) : $this->getTextMatchingMethod();
$clone->min_autocomplete = $tt->nullableInt($normalized['min_autocomplete']);
$clone->shuffle_answer_options = $tt->nullableBool($normalized['shuffle_answer_options']);
$clone->answer_options = $tt->denormalize($normalized['answer_options'], $this->answer_options);
return $clone;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace ILIAS\Questions\AnswerFormTypes\Cloze\Properties\Gaps;

use ILIAS\Questions\ExportImport\Foundation\Contracts\Transformations;
use ILIAS\Questions\ExportImport\Foundation\Contracts\Normalizable;
use ILIAS\Questions\Persistence\Delete;
use ILIAS\Questions\Persistence\Junctor;
use ILIAS\Questions\Persistence\Manipulate;
Expand All @@ -40,7 +42,7 @@
use ILIAS\UI\Component\Input\Field\MultiSelect;
use ILIAS\UI\Component\Table\DataRowBuilder;

class Gaps
class Gaps implements Normalizable
{
/**
* @var array<string, \ILIAS\Questions\AnswerFormTypes\Cloze\Properties\Gaps\Gap>
Expand Down Expand Up @@ -486,4 +488,29 @@ private function filterGapsBySelected(
ARRAY_FILTER_USE_KEY
);
}

/**
* @inheritDoc
*/
public function toNormalized(Transformations $tt): Transformation
{
return $tt->custom()->transformation(fn(): array => $tt->normalize($this->gaps));
}

/**
* @inheritDoc
*/
public function fromNormalized(Transformations $tt): Transformation
{
return $tt->custom()->transformation(function (array $normalized) use ($tt): Gaps {
$clone = clone $this;
foreach ($normalized as $gap_data) {
$gap = $this->factory->getNewGap($this->answer_form_id, $tt->int($gap_data['position']))
->withType($this->factory->getGapTypeByIdentifier($gap_data['type']));

$clone = $clone->withGap($tt->denormalize($gap_data, $gap));
}
return $clone;
});
}
}
Loading