<commit_before><?php

namespace DocumentBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use DocumentBundle\Entity\Documento;
use DocumentBundle\Form\Type\DocumentoType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use FOS\UserBundle\Model\UserInterface;
use UserBundle\Entity\Usuario;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;

/**;
 * Documento controller.
 *
 * @Route("/documento")
 */
class DocumentoController extends Controller
{
    /**
     * Lists all Documento entities.
     *
     * @Route("/", name="documento")
     * @Method("GET")
     * @Template()
     */
    public function indexDocumentoAction()
    {
        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('DocumentBundle:Documento')->findAll();

        return [
            'entities' => $entities,
        ];
    }
    /**
     * Creates a new Documento entity.
     *
     * @Route("/",name="documento_create")
     * @Method("POST")
     * @Template("DocumentBundle:Documento:newDocumento.html.twig")
     */
    public function createAction(Request $request)
    {
        $usuario = $this->get('security.token_storage')->getToken()->getUser();
        if (!is_object($usuario) || !$usuario instanceof UserInterface) {
            throw new AccessDeniedException('El usuario no tiene acceso.');
        }
        $entity = new Documento();
        $entity->setUsuario($usuario);
        $form = $this->createCreateForm($entity, $usuario);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            $helper = $this->get('vich_uploader.templating.helper.uploader_helper');
            $path = $helper->asset($entity, 'documentFile');

            $filesystem = $container->get('acme_filesystem');
            $filesystem->write('/', $form['documentFile']);
            
            $em->persist($entity);


            /*
             * El siguiente query sirve para revisar si hay algún documento
             * con el mismo nombre asociado en el mismo curso.
             */<commit_msg>another try of amazon s3<commit_after><?php

namespace DocumentBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use DocumentBundle\Entity\Documento;
use DocumentBundle\Form\Type\DocumentoType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use FOS\UserBundle\Model\UserInterface;
use UserBundle\Entity\Usuario;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;

/**;
 * Documento controller.
 *
 * @Route("/documento")
 */
class DocumentoController extends Controller
{
    /**
     * Lists all Documento entities.
     *
     * @Route("/", name="documento")
     * @Method("GET")
     * @Template()
     */
    public function indexDocumentoAction()
    {
        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('DocumentBundle:Documento')->findAll();

        return [
            'entities' => $entities,
        ];
    }
    /**
     * Creates a new Documento entity.
     *
     * @Route("/",name="documento_create")
     * @Method("POST")
     * @Template("DocumentBundle:Documento:newDocumento.html.twig")
     */
    public function createAction(Request $request)
    {
        $usuario = $this->get('security.token_storage')->getToken()->getUser();
        if (!is_object($usuario) || !$usuario instanceof UserInterface) {
            throw new AccessDeniedException('El usuario no tiene acceso.');
        }
        $entity = new Documento();
        $entity->setUsuario($usuario);
        $form = $this->createCreateForm($entity, $usuario);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            $helper = $this->get('vich_uploader.templating.helper.uploader_helper');
            $path = $helper->asset($entity, 'documentFile');
            $file = $entity->getDocumentFile();
            $filesystem = $container->get('acme_filesystem');
            $stream = fopen($file->getRealPath(), 'r+');
            $filesystem->writeStream('/'.$file->getClientOriginalName(), $stream);
            fclose($stream);
            
            $em->persist($entity);


            /*
             * El siguiente query sirve para revisar si hay algún documento
             * con el mismo nombre asociado en el mismo curso.
             */
{'fraction_non_alphanumeric': 0.13844059887225355, 'fraction_numerical': 0.0021388294769589733, 'mean_word_length': 3.0440251572327046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '1786474', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1475, 'n_words': 256}