<commit_before><?php
// src/Blogger/BlogBundle/Controller/BlogController.php

namespace Blogger\BlogBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;

use Blogger\BlogBundle\Entity\Blog;
use Blogger\BlogBundle\Form\BlogType;
use Symfony\Component\Form\Extension\Core\Type\FileType;


/**
 * Blog controller.
 */
class BlogController extends Controller
{
    /**
     * Show a blog entry
     */
    public function showAction($id, $slug)
    {
        $em = $this->getDoctrine()->getManager();
        //выборка из БД по ключу в $blog
        $blog = $em->getRepository('BlogBundle:Blog')
            ->find($id) //метод получает объект по его первичному ключу
        ;

        if (!$blog) {
            throw $this->createNotFoundException('Sorry. Unable to find Blog post.'); //если сущность не найдена -> 404
        }

        $comments = $em->getRepository('BlogBundle:Comment')
            ->getCommentsForBlog($blog->getId());
        
        $countComment = count($em->getRepository('BlogBundle:Comment')
            ->getCommentsForBlog($blog->getId()));

        $user = $this->getUser();

        return $this->render('BlogBundle:Blog:show.html.twig', array( //если сущность найдена - передаем ее во вьюшку
            'user'=>$user,
            'blog' => $blog, //во вьюшке twig-а будет массив blog с данными из $blog
            'comments' => $comments,
//            'b' =>$countComment,
        ));
    }

    public function createAction(Request $request)
    {
        $blog  = new Blog();

        $user = $this->getUser()->getUsername();
        $blog->setAuthor($user);

        $form = $this->createForm(BlogType::class, $blog);
        $form->handleRequest($request);
        
//        $c = $form->getErrors(true, false);

        if ($form->isSubmitted() && $form->isValid()) {

            // $file stores the uploaded image file
            /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
            $file = $blog->getImage();
//            // Generate a unique name for the file before saving it
//            //guessExtension() - Returns the extension based on the mime type.
            $fileName = substr(md5(uniqid()),0 ,14).'.'.$file->guessExtension(); // guessExtension() - Returns the extension based on the mime type.
//            $fileName = substr(md5(uniqid()),0 ,14).'.'.$file->getClientOriginalExtension(); // guessClientExtension() - Returns the extension based on the client mime type.
//
            // Move the file to the directory where brochures are stored
            $file->move(
                $this->getParameter('images_directory'),
                $fileName
            );
//            $fileName = "123";

            $blog->setImage($fileName);

            $em = $this->getDoctrine()
                ->getManager();

            $em->persist($blog);
            $em->flush();
            
            return $this->redirect($this->generateUrl('BloggerBlogBundle_homepage'));
        }

        return $this->render('BlogBundle:Blog:create.html.twig', array(
            'form' => $form->createView()
        ));
    }
    
    public function deleteAction($id)
    {<commit_msg>clear derty<commit_after><?php
// src/Blogger/BlogBundle/Controller/BlogController.php

namespace Blogger\BlogBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;

use Blogger\BlogBundle\Entity\Blog;
use Blogger\BlogBundle\Form\BlogType;
use Symfony\Component\Form\Extension\Core\Type\FileType;


/**
 * Blog controller.
 */
class BlogController extends Controller
{
    /**
     * Show a blog entry
     */
    public function showAction($id, $slug)
    {
        $em = $this->getDoctrine()->getManager();
        //выборка из БД по ключу в $blog
        $blog = $em->getRepository('BlogBundle:Blog')
            ->find($id) //метод получает объект по его первичному ключу
        ;

        if (!$blog) {
            throw $this->createNotFoundException('Sorry. Unable to find Blog post.'); //если сущность не найдена -> 404
        }

        $comments = $em->getRepository('BlogBundle:Comment')
            ->getCommentsForBlog($blog->getId());
        
        $countComment = count($em->getRepository('BlogBundle:Comment')
            ->getCommentsForBlog($blog->getId()));

        $user = $this->getUser();

        return $this->render('BlogBundle:Blog:show.html.twig', array( //если сущность найдена - передаем ее во вьюшку
            'user'=>$user,
            'blog' => $blog, //во вьюшке twig-а будет массив blog с данными из $blog
            'comments' => $comments,
//            'b' =>$countComment,
        ));
    }

    public function createAction(Request $request)
    {
        $blog  = new Blog();

        $user = $this->getUser()->getUsername();
        $blog->setAuthor($user);

        $form = $this->createForm(BlogType::class, $blog);
        $form->handleRequest($request);
        
//        $c = $form->getErrors(true, false);

        if ($form->isSubmitted() && $form->isValid()) {

            // $file stores the uploaded image file
            /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
            $file = $blog->getImage();
//            // Generate a unique name for the file before saving it
//            //guessExtension() - Returns the extension based on the mime type.
            $fileName = substr(md5(uniqid()),0 ,14).'.'.$file->guessExtension();
            
            // Move the file to the directory where brochures are stored
            $file->move(
                $this->getParameter('images_directory'),
                $fileName
            );

            $blog->setImage($fileName);

            $em = $this->getDoctrine()
                ->getManager();

            $em->persist($blog);
            $em->flush();
            
            return $this->redirect($this->generateUrl('BloggerBlogBundle_homepage'));
        }

        return $this->render('BlogBundle:Blog:create.html.twig', array(
            'form' => $form->createView()
        ));
    }
    
    public function deleteAction($id)
    {
{'fraction_non_alphanumeric': 0.14509741802629494, 'fraction_numerical': 0.003326469190559164, 'mean_word_length': 2.2214285714285715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 84, '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': '3221750', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1812, 'n_words': 385}