*/ declare(strict_types=1); namespace oat\taoQtiItem\install\scripts; use oat\oatbox\extension\script\ScriptAction; use oat\oatbox\reporting\Report; use oat\taoQtiItem\model\QtiCreator\ExtendedTextInteractionConfigurationRegistry; /** * Run the following to enable Math Entry format option * php index.php 'oat\taoQtiItem\install\scripts\SetupExtendedTextInteractionConfigurationRegistry' -m 1 * * Run the following to disable Math Entry format option * php index.php 'oat\taoQtiItem\install\scripts\SetupExtendedTextInteractionConfigurationRegistry' -m 0 */ class SetupExtendedTextInteractionConfigurationRegistry extends ScriptAction { public const HAS_MATH = 'math'; /** @var ExtendedTextInteractionConfigurationRegistry */ private $registry; protected function provideOptions(): array { return [ self::HAS_MATH => [ 'prefix' => 'm', 'longPrefix' => self::HAS_MATH, 'description' => 'Enables / disables Math entry on extended text interactions', ], ]; } protected function provideDescription(): string { return sprintf('Sets `%s` values.', ExtendedTextInteractionConfigurationRegistry::class); } protected function run(): Report { $this->registry = $this->propagate(new ExtendedTextInteractionConfigurationRegistry()); if ($this->hasOption(self::HAS_MATH)) { $this->registry->setHasMath( (bool)$this->getOption(self::HAS_MATH) ); } return $this->createReport(); } private function createReport(): Report { $setValues = $this->registry->get(ExtendedTextInteractionConfigurationRegistry::ID); return $setValues ? Report::createSuccess( sprintf( "Applied the following configuration to `%s`\n%s", ExtendedTextInteractionConfigurationRegistry::class, json_encode($setValues) ) ) : Report::createError( sprintf('No values set to `%s`', ExtendedTextInteractionConfigurationRegistry::class) ); } }