<commit_before><?php
namespace Dellaert\KULEducationAPIBundle\Command;

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 Dellaert\KULEducationAPIBundle\Utility\APIUtility;

/**
 * BIG TODO:
 * Everything concerning structure XML
 * Only Courses XML is ready for now!
 **/

class GenerateACCODynamicsImportXMLs extends Command
{
	protected function configure() {
        $this
            ->setName('kulapi:generate-acco-dynamics-import-xmls')
            ->setDescription('Generate the necessary XMLs of either an entire school or a single faculty')
            ->addOption(
                'scid',
                null,
                InputOption::VALUE_REQUIRED,
                'Which school do you want to generate the XMLs for?'
            )
            ->addOption(
                'fid',
                null,
                InputOption::VALUE_REQUIRED,
                'Which faculty do you want to generate the XMLs for?',
                -1
            )
            ->addOption(
                'listid',
                null,
                InputOption::VALUE_REQUIRED,
                'Which Dynamics literature list would you like to generate the XMLs for?'
            )
            ->addOption(
                'locale',
                null,
                InputOption::VALUE_REQUIRED,
                'What locale? nl|en'
            )
            ->addOption(
                'path',
                null,
                InputOption::VALUE_REQUIRED,
                'Where do you want to store the XMLs?'
            )
            ->addOption(
                'showhidden',
                null,
                InputOption::VALUE_NONE,
                'Do you want to show hidden sublevels?'
            )
            ->addOption(
                'debug',
                null,
                InputOption::VALUE_NONE,
                'Do you want to show debug output?'
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output) {
        // Handling options
        $scid = $input->getOption('scid');
        $fid = $input->getOption('fid');
        $listid = $input->getOption('listid');
        $locale = $input->getOption('locale');
        $path = $input->getOption('path');
        $showhidden = $input->getOption('showhidden');
        $debug = $input->getOption('debug');
        $respect_no_show = !$showhidden;

        // Base variables
        $teachers = array();
        $courses = array();
        $stage_none = array('nl'=>'Geen','en'=>'No');
        $xml_cur_level_id = 0;

        // Container
        $container = $this->getApplication()->getKernel()->getContainer();

        // URL Base variables
        $url = APIUtility::getSchoolBaseURL($container,$scid);
        $language = substr($locale,0,1);
        $year = $container->getParameter('dellaert_kul_education_api.baseyear');
        $method = $container->getParameter('dellaert_kul_education_api.method');

        // Structure XML start
        $structure_xml = new \DOMDocument();
        $structure_xml->formatOutput = true;
        // Root element
        $structure_xml_literaturelist = $structure_xml->createElement('literatuurLijst');
        // List id element
        $structure_xml_listid = $structure_xml->createElement('literatuurLijst-ID',$listid);
        $structure_xml_literaturelist->appendChild($structure_xml_listid);

        // Main index XML
        $callUrl = $url.$year.'/opleidingen/n/'.$method.'/index.xml';
        if( $mainXml = simplexml_load_file($callUrl, null, LIBXML_NOCDATA) ) {
            // FACULTY HANDLING
            foreach( $mainXml->xpath("data/instelling/hoofddepartement") as $faculty ) {
                $faculty_id = $faculty['id'];
                $faculty_title = $faculty->xpath("titels/titel[@taal='$language']");
                if( empty($faculty_title) ) {
                    $faculty_title = $faculty->xpath("titels/titel[@taal='".$container->getParameter('dellaert_kul_education_api.fallback_locale')."']");
                }
                $faculty_title = $faculty_title[0];
                $xml_faculty_id = ++$xml_cur_level_id;

                if( $fid != -1 && $faculty['id'] != $fid ) {
                    $this->debugOutput($output,$debug,'Skipping faculty: '.$faculty_id.' - '.$faculty_title);
                    continue;
                }<commit_msg>Allow for multiple faculties at once<commit_after><?php
namespace Dellaert\KULEducationAPIBundle\Command;

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 Dellaert\KULEducationAPIBundle\Utility\APIUtility;

/**
 * BIG TODO:
 * Everything concerning structure XML
 * Only Courses XML is ready for now!
 **/

class GenerateACCODynamicsImportXMLs extends Command
{
	protected function configure() {
        $this
            ->setName('kulapi:generate-acco-dynamics-import-xmls')
            ->setDescription('Generate the necessary XMLs of either an entire school or a single faculty')
            ->addOption(
                'scid',
                null,
                InputOption::VALUE_REQUIRED,
                'Which school do you want to generate the XMLs for?'
            )
            ->addOption(
                'fids',
                null,
                InputOption::VALUE_REQUIRED,
                'Which faculty or faculties do you want to generate the XMLs for? (comma seperated, no spaces)',
                -1
            )
            ->addOption(
                'listid',
                null,
                InputOption::VALUE_REQUIRED,
                'Which Dynamics literature list would you like to generate the XMLs for?'
            )
            ->addOption(
                'locale',
                null,
                InputOption::VALUE_REQUIRED,
                'What locale? nl|en'
            )
            ->addOption(
                'path',
                null,
                InputOption::VALUE_REQUIRED,
                'Where do you want to store the XMLs?'
            )
            ->addOption(
                'showhidden',
                null,
                InputOption::VALUE_NONE,
                'Do you want to show hidden sublevels?'
            )
            ->addOption(
                'debug',
                null,
                InputOption::VALUE_NONE,
                'Do you want to show debug output?'
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output) {
        // Handling options
        $scid = $input->getOption('scid');
        $fids = explode(',',$input->getOption('fids'));
        $listid = $input->getOption('listid');
        $locale = $input->getOption('locale');
        $path = $input->getOption('path');
        $showhidden = $input->getOption('showhidden');
        $debug = $input->getOption('debug');
        $respect_no_show = !$showhidden;

        // Base variables
        $teachers = array();
        $courses = array();
        $stage_none = array('nl'=>'Geen','en'=>'No');
        $xml_cur_level_id = 0;

        // Container
        $container = $this->getApplication()->getKernel()->getContainer();

        // URL Base variables
        $url = APIUtility::getSchoolBaseURL($container,$scid);
        $language = substr($locale,0,1);
        $year = $container->getParameter('dellaert_kul_education_api.baseyear');
        $method = $container->getParameter('dellaert_kul_education_api.method');

        // Structure XML start
        $structure_xml = new \DOMDocument();
        $structure_xml->formatOutput = true;
        // Root element
        $structure_xml_literaturelist = $structure_xml->createElement('literatuurLijst');
        // List id element
        $structure_xml_listid = $structure_xml->createElement('literatuurLijst-ID',$listid);
        $structure_xml_literaturelist->appendChild($structure_xml_listid);

        // Main index XML
        $callUrl = $url.$year.'/opleidingen/n/'.$method.'/index.xml';
        if( $mainXml = simplexml_load_file($callUrl, null, LIBXML_NOCDATA) ) {
            // FACULTY HANDLING
            foreach( $mainXml->xpath("data/instelling/hoofddepartement") as $faculty ) {
                $faculty_id = $faculty['id'];
                $faculty_title = $faculty->xpath("titels/titel[@taal='$language']");
                if( empty($faculty_title) ) {
                    $faculty_title = $faculty->xpath("titels/titel[@taal='".$container->getParameter('dellaert_kul_education_api.fallback_locale')."']");
                }
                $faculty_title = $faculty_title[0];
                $xml_faculty_id = ++$xml_cur_level_id;

                if( $fids[0] != -1 && !in_array($faculty['id'],$fids) ) {
                    $this->debugOutput($output,$debug,'Skipping faculty: '.$faculty_id.' - '.$faculty_title);
                    continue;
                }
{'fraction_non_alphanumeric': 0.12167423750811161, 'fraction_numerical': 0.0014060134112048454, 'mean_word_length': 1.943029917250159, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2638330', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2510, 'n_words': 490}