From 62b35014275ec553ab1218711062eec3538667a0 Mon Sep 17 00:00:00 2001 From: mckmonster Date: Tue, 9 Jul 2024 14:13:59 +0200 Subject: [PATCH] Add command to create Forms --- commands/CreateFormsCommand.php | 137 ++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 commands/CreateFormsCommand.php diff --git a/commands/CreateFormsCommand.php b/commands/CreateFormsCommand.php new file mode 100644 index 0000000..0870da9 --- /dev/null +++ b/commands/CreateFormsCommand.php @@ -0,0 +1,137 @@ +wiki = $wiki; + } + + protected function configure() + { + $this + // the name of the command : ./yeswicli helloworld:hello" + ->setName('meeo:createforms') + // the short description shown while running "./yeswicli list" + ->setDescription('Permet de créer les formulaires pour ') + + // the full command description shown when running the command with + // the "--help" option + // ->setHelp("This command display the message \"Hello !\" with options for uppercase of add a username.\n" . + // "The argument \"username\" can be used to add a username. Example : \n" . + // "Command line'./yeswicli helloworld:hello \"John Smith\"' gives \"Hello John Smith !\"") + + // add argument for username + // second parameter could be InputArgument::OPTIONAL <=> null, InputArgument::REQUIRED, InputArgument::IS_ARRAY + // third parameter is the description + // forth parameter is default value + // ->addArgument('username', InputArgument::OPTIONAL, 'Username') + + // add option to display output as UPPERCASE + // second parameter null|string is shortcut + // third parameter null|int could be InputOption::VALUE_NONE <=> null, InputOption::VALUE_REQUIRED + // , InputOption::VALUE_OPTIONAL, InputOption::VALUE_IS_ARRAY, InputOption::VALUE_NEGATABLE + // forth parameter is the description + // ->addOption('uppercase', 'u', InputOption::VALUE_NONE, 'Display output in UPPERCASE') + ; + } + + private function absencesForm(FormManager $formManager, $meeo_config) + { + $existingForm = $formManager->getOne($meeo_config['absences']['formId']); + if ($existingForm) + return false; + + $data = [ + "bn_id_nature" => $meeo_config['absences']['formId'], + "bn_label_nature" => "Absences", + "bn_description" => "Absences des élèves", + "bn_condition" => "", + "bn_sem_context" => "", + "bn_sem_type" => "", + "bn_sem_use_template" => "1", + "bn_template" => << "fr-FR", + "bn_only_one_entry" => "N", + "bn_only_one_entry_message" => null + ]; + + return $formManager->create($data); + } + + private function notesForm(FormManager $formManager, $meeo_config) + { + $existingForm = $formManager->getOne($meeo_config['notes']['formId']); + if ($existingForm) + return false; + + $data = [ + "bn_id_nature" => $meeo_config['notes']['formId'], + "bn_label_nature" => "Notes", + "bn_description" => "Notes des élèves", + "bn_condition" => "", + "bn_sem_context" => "", + "bn_sem_type" => "", + "bn_sem_use_template" => "1", + "bn_template" => << "fr-FR", + "bn_only_one_entry" => "N", + "bn_only_one_entry_message" => null + ]; + + return $formManager->create($data); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + + $formManager = $this->wiki->services->get(FormManager::class); + $params = $this->wiki->services->get(ParameterBagInterface::class); + if (!$params->has('meeo')) { + $result = $formManager->getAll(); + $lastFormId = array_key_last($result); + $meeo_config = [ + 'absences' => [ + 'formId' => $lastFormId, + ], + 'notes' => [ + 'formId' => $lastFormId + 1, + ] + ]; + } else { + $meeo_config = $params->get('meeo'); + } + + if (!$this->absencesForm($formManager, $meeo_config)) + return Command::FAILURE; + + if (!$this->notesForm($formManager, $meeo_config)) + return Command::FAILURE; + + return Command::SUCCESS; + } +}