ynh_extension_meeo/commands/CreateFormsCommand.php

195 lines
8.2 KiB
PHP
Raw Normal View History

2024-07-09 12:13:59 +00:00
<?php
namespace YesWiki\Meeo\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use YesWiki\Wiki;
use YesWiki\Bazar\Service\FormManager;
2024-07-09 13:30:05 +00:00
use YesWiki\Core\Service\PageManager;
use YesWiki\Core\Service\TripleStore;
2024-07-09 12:13:59 +00:00
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class CreateFormsCommand extends Command
{
protected $wiki;
2024-08-02 16:18:15 +00:00
protected $absenceFormId;
2024-08-02 16:24:43 +00:00
protected $notesFormId;
protected $eleveFormId;
2024-08-02 16:06:52 +00:00
protected $yunohostFormId;
2024-07-09 12:13:59 +00:00
public function __construct(Wiki &$wiki)
{
parent::__construct();
$this->wiki = $wiki;
2024-07-21 10:11:46 +00:00
$params = $this->wiki->services->get(ParameterBagInterface::class);
$meeo_config = $params->get('meeo');
2024-08-02 16:18:15 +00:00
$this->absenceFormId = $meeo_config['absencesFormId'];
2024-08-02 16:24:43 +00:00
$this->notesFormId = $meeo_config['notesFormId'];
$this->eleveFormId = $meeo_config['elevesFormId'];
2024-08-02 16:06:52 +00:00
$this->yunohostFormId = $meeo_config['yunohostFormId'];
2024-07-09 12:13:59 +00:00
}
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')
;
}
2024-07-17 07:01:25 +00:00
private function createOrUpdate($formManager, $formId, $data) {
2024-08-02 16:24:43 +00:00
echo $formId.": ".$data['bn_label_nature'];
2024-07-17 07:01:25 +00:00
$existingForm = $formManager->getOne($formId);
if ($existingForm)
return $formManager->update($data);
return $formManager->create($data);
}
2024-07-09 12:13:59 +00:00
private function absencesForm(FormManager $formManager, $meeo_config)
{
$data = [
2024-08-02 16:18:15 +00:00
"bn_id_nature" => $this->absenceFormId,
2024-07-09 12:13:59 +00:00
"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" => <<<EOT
2024-07-21 10:11:46 +00:00
titre***Absence : {{bf_eleve}} - {{bf_date_debut}}***Titre Automatique***
listefiche***$this->eleveFormId***Elève*** *** *** ***bf_eleve*** ***1*** *** *** * *** * *** *** *** ***
2024-07-09 15:31:48 +00:00
listedatedeb***bf_date_debut***Debut*** *** ***today*** *** ***1*** *** *** * *** * *** *** *** ***
listedatedeb***bf_date_fin***Fin*** *** ***today*** *** ***1*** *** *** * *** * *** *** *** ***
2024-07-09 12:13:59 +00:00
textelong***bf_commentaire***Commentaire*** *** *** *** ***wiki***0*** *** *** * *** * *** *** *** ***
EOT,
"bn_ce_i18n" => "fr-FR",
"bn_only_one_entry" => "N",
"bn_only_one_entry_message" => null
];
2024-08-02 16:20:35 +00:00
$this->createOrUpdate($formManager, $this->absenceFormId, $data);
2024-07-09 12:13:59 +00:00
}
2024-07-09 13:30:05 +00:00
private function matiereList()
{
$pageManager = $this->wiki->services->get(PageManager::class);
$tripleStore = $this->wiki->services->get(TripleStore::class);
if (!$pageManager->getOne('ListeMatiere')) {
2024-07-17 07:01:25 +00:00
$pageManager->save('ListeMatiere', '{"label":{"francais":"Français","math":"Math"},"titre_liste":"Matieres"}');
2024-07-09 13:30:05 +00:00
// in case, there is already some triples for 'ListOuinonLms', delete them
2024-07-17 07:01:25 +00:00
$tripleStore->delete('ListeMatiere', 'http://outils-reseaux.org/_vocabulary/type', null);
2024-07-09 13:30:05 +00:00
// create the triple to specify this page is a list
2024-07-17 07:01:25 +00:00
$tripleStore->create('ListeMatiere', 'http://outils-reseaux.org/_vocabulary/type', 'liste', '', '');
2024-07-09 13:30:05 +00:00
}
}
2024-07-09 12:13:59 +00:00
private function notesForm(FormManager $formManager, $meeo_config)
{
2024-07-09 13:30:05 +00:00
$this->matiereList();
2024-07-09 12:13:59 +00:00
$data = [
2024-08-02 16:24:43 +00:00
"bn_id_nature" => $this->notesFormId,
2024-07-09 12:13:59 +00:00
"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" => <<<EOT
2024-07-12 14:49:50 +00:00
titre***Note : {{bf_intitule}} - {{bf_eleve}} - {{bf_matiere}}***Titre Automatique***
texte***bf_intitule***Intitulé*** *** *** *** ***text***1*** *** *** * *** * *** *** *** ***
liste***ListeMatiere***Matière*** *** *** ***bf_matiere*** ***1*** *** *** * *** * *** *** *** ***
listefiche***$this->eleveFormId***Elève*** *** *** ***bf_eleve*** ***1*** *** *** * *** * *** *** *** ***
2024-07-09 13:30:05 +00:00
texte***bf_note***Note***0***20*** *** ***number***1*** *** *** * *** * *** *** *** ***
2024-07-09 12:13:59 +00:00
texte***bf_coef***Coefficient***0.5***10***1*** ***number***0*** *** *** * *** * *** *** *** ***
EOT,
"bn_ce_i18n" => "fr-FR",
"bn_only_one_entry" => "N",
"bn_only_one_entry_message" => null
];
2024-08-02 16:24:43 +00:00
$this->createOrUpdate($formManager, $this->notesFormId, $data);
2024-07-17 07:01:25 +00:00
}
private function classeList()
{
$pageManager = $this->wiki->services->get(PageManager::class);
$tripleStore = $this->wiki->services->get(TripleStore::class);
if (!$pageManager->getOne('ListeClasses')) {
$pageManager->save('ListeClasses', '{"label":{},"titre_liste":"Classe"}');
// in case, there is already some triples for 'ListOuinonLms', delete them
$tripleStore->delete('ListeClasses', 'http://outils-reseaux.org/_vocabulary/type', null);
// create the triple to specify this page is a list
$tripleStore->create('ListeClasses', 'http://outils-reseaux.org/_vocabulary/type', 'liste', '', '');
}
}
private function elevesForms(FormManager $formManager, $meeo_config) {
$this->classeList();
$data = [
2024-08-02 16:18:15 +00:00
"bn_id_nature" => $this->eleveFormId,
2024-07-17 07:01:25 +00:00
"bn_label_nature" => "Eleves",
"bn_description" => "Liste des élèves",
"bn_condition" => "",
"bn_sem_context" => "",
"bn_sem_type" => "",
"bn_sem_use_template" => "1",
"bn_template" => <<<EOT
2024-07-27 13:22:09 +00:00
titre***{{ bf_nom }} - {{ bf_classe }}***Titre Automatique***
listefiche***$this->yunohostFormId***Liste déroulante*** *** *** ***bf_nom*** ***1*** *** *** * *** * *** *** *** ***
2024-07-17 08:42:47 +00:00
liste***ListeClasses***Classe*** *** ***aucune***bf_classe*** ***1*** *** *** * *** * *** *** *** ***
2024-07-17 07:01:25 +00:00
EOT,
"bn_ce_i18n" => "fr-FR",
"bn_only_one_entry" => "N",
"bn_only_one_entry_message" => null
];
2024-08-02 16:20:35 +00:00
$this->createOrUpdate($formManager, $this->eleveFormId, $data);
2024-07-09 12:13:59 +00:00
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$formManager = $this->wiki->services->get(FormManager::class);
$params = $this->wiki->services->get(ParameterBagInterface::class);
2024-07-17 07:01:25 +00:00
$meeo_config = $params->get('meeo');
2024-07-09 12:13:59 +00:00
2024-07-09 13:30:05 +00:00
$this->absencesForm($formManager, $meeo_config);
2024-07-09 12:13:59 +00:00
2024-07-09 13:30:05 +00:00
$this->notesForm($formManager, $meeo_config);
2024-07-09 12:13:59 +00:00
2024-07-17 07:01:25 +00:00
$this->elevesForms($formManager, $meeo_config);
2024-07-09 13:30:05 +00:00
echo 'Succeed\n';
2024-07-09 12:13:59 +00:00
return Command::SUCCESS;
}
}