<commit_before><?php

namespace EZ\CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\HttpFoundation\Request;
use EZ\CoreBundle\Form\TemplateType;
use ZipArchive;

class TemplateController extends Controller
{
    public function templateAction(Request $request){

        $template_used = Yaml::parse(file_get_contents(__DIR__ . '/../../CoreBundle/Resources/config/parameters.yml'));
        $template_used = $template_used['template'];

        $templates_dir = __DIR__.'/../Resources/views/layout/office';
        $templates_dir = array_diff(scandir($templates_dir), array('..', '.'));

        foreach ($templates_dir as $template){
            if(preg_match('#.html.twig$#',$template)){
                $template =str_replace('.html.twig', '', $template);
                $templates[$template] = $template;
            }
        }
        $form = $this->createForm(TemplateType::class);
        $form->handleRequest($request);

        if($form->isSubmitted() && $form->isValid())
        {
            $task = $form->getData();

            $file = $task['theme'];
            if( $file->getClientOriginalExtension() === 'zip')
            {

                $file_name = $file->getClientOriginalName();
                $file->move(__DIR__.'/../Resources/views/Layout/office',$file_name);

                $zip = new ZipArchive();
                if($zip->open(__DIR__.'/../Resources/views/Layout/office/'.$file_name) === TRUE )
                {
                    $zip->extractTo( __DIR__.'/../Resources/views/Layout/office');
                    $zip->close();
                    unlink(__DIR__.'/../Resources/views/Layout/office/'.$file_name);

                    if(is_dir(__DIR__.'/../../../../web/img/template'))
                    {
                        $template_img = str_replace('.zip', '.png', $file_name);
                        rename(__DIR__.'/../Resources/views/Layout/office/'.$template_img ,__DIR__.'/../../../../web/img/template/'.$template_img);
                    }
                    else
                    {
                        mkdir(__DIR__.'/../../../../web/img/template');
                        $template_img = str_replace('.zip', '.png', $file_name);
                        rename(__DIR__.'/../Resources/views/Layout/office/'.$template_img,__DIR__.'/../../../../web/img/template/'.$template_img);

                    }

                    $this->get('session')->getFlashBag()->set('success', 'Theme telecharge avec succes !');
                }

                return $this->redirect($this->generateUrl('ez_core_template'));
            }
            else
            {
                die('It must be a zip file');
            }



        }

        return $this->render('EZCoreBundle:template:index.html.twig', array(
            'template_used' => $template_used,
            'templates' => $templates,<commit_msg>Template small change<commit_after><?php

namespace EZ\CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\HttpFoundation\Request;
use EZ\CoreBundle\Form\TemplateType;
use ZipArchive;

class TemplateController extends Controller
{
    public function templateAction(Request $request){

        $template_used = Yaml::parse(file_get_contents(__DIR__ . '/../../CoreBundle/Resources/config/parameters.yml'));
        $template_used = $template_used['template'];

        $templates_dir = __DIR__.'/../Resources/views/layout/office';
        $templates_dir = array_diff(scandir($templates_dir), array('..', '.'));

        foreach ($templates_dir as $template){
            if(preg_match('#.html.twig$#',$template)){
                $template =str_replace('.html.twig', '', $template);
                $templates[$template] = $template;
            }
        }
        $form = $this->createForm(TemplateType::class);
        $form->handleRequest($request);

        if($form->isSubmitted() && $form->isValid())
        {
            $task = $form->getData();

            $file = $task['theme'];
            if( $file->getClientOriginalExtension() === 'zip')
            {

                $file_name = $file->getClientOriginalName();
                $file->move(__DIR__.'/../Resources/views/Layout/office',$file_name);

                $zip = new ZipArchive();
                if($zip->open(__DIR__.'/../Resources/views/Layout/office/'.$file_name) === TRUE )
                {
                    $zip->extractTo( __DIR__.'/../Resources/views/Layout/office');
                    $zip->close();
                    unlink(__DIR__.'/../Resources/views/Layout/office/'.$file_name);

                    if(is_dir(__DIR__.'/../../../../web/img/template'))
                    {
                        $template_img = str_replace('.zip', '.png', $file_name);
                        rename(__DIR__.'/../Resources/views/Layout/office/'.$template_img ,__DIR__.'/../../../../web/img/template/'.$template_img);
                    }
                    else
                    {
                        mkdir(__DIR__.'/../../../../web/img/template');
                        $template_img = str_replace('.zip', '.png', $file_name);
                        rename(__DIR__.'/../Resources/views/Layout/office/'.$template_img,__DIR__.'/../../../../web/img/template/'.$template_img);

                    }

                    $this->get('session')->getFlashBag()->set('success', 'Theme telecharge avec succes !');
                }

                return $this->redirect($this->generateUrl('ez_core_template'));
            }
            else
            {
                $this->get('session')->getFlashBag()->set('error', 'Le fichier doit tre un zip !');
                return $this->redirect($this->generateUrl('ez_core_template'));
            }



        }

        return $this->render('EZCoreBundle:template:index.html.twig', array(
            'template_used' => $template_used,
            'templates' => $templates,
{'fraction_non_alphanumeric': 0.17326732673267325, 'fraction_numerical': 0.0, 'mean_word_length': 1.8034227567067531, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6535428', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1600, 'n_words': 204}