<commit_before><?php

namespace Etu\Module\ForumBundle\Controller;

use Doctrine\ORM\EntityRepository;

use Etu\Core\CoreBundle\Framework\Definition\Controller;
use Etu\Core\CoreBundle\Twig\Extension\StringManipulationExtension;
use Etu\Core\CoreBundle\Util\RedactorJsEscaper;
use Etu\Core\CoreBundle\Entity\Notification;

use Etu\Module\ForumBundle\Entity\Category;
use Etu\Module\ForumBundle\Entity\Thread;
use Etu\Module\ForumBundle\Entity\Message;
use Etu\Module\ForumBundle\Entity\View;
use Etu\Module\ForumBundle\Form\ThreadType;
use Etu\Module\ForumBundle\Form\MessageEditType;
use Etu\Module\ForumBundle\Form\MessageType;
use Etu\Module\ForumBundle\Model\PermissionsChecker;

// Import annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class MainController extends Controller
{
	/**
	 * @Route("/forum", name="forum_index")
	 * @Template()
	 */
	public function indexAction()
	{
		$em = $this->getDoctrine()->getManager();
		$categories = $em->createQueryBuilder()
			->select('c')
			->from('EtuModuleForumBundle:Category', 'c')
			->where('c.depth <= 1')
			->orderBy('c.left')
			->getQuery()
			->getResult();

		return array('categories' => $categories);
	}

	/**
	 * @Route("/forum/{id}-{slug}/{page}", defaults={"page" = 1}, requirements={"page" = "\d+"}, name="forum_category")
	 * @Template()
	 */
	public function categoryAction($id, $slug, $page)
	{
		$em = $this->getDoctrine()->getManager();

		/** @var Category $category */
		$category = $em->getRepository('EtuModuleForumBundle:Category')
			->find($id);

		$checker = new PermissionsChecker($this->getUser());

		if (!$checker->canRead($category)) {
			return $this->createAccessDeniedResponse();
		}

		$parents = $em->createQueryBuilder()
			->select('c')
			->from('EtuModuleForumBundle:Category', 'c')
			->where('c.left <= :left')
			->andWhere('c.right >= :right')
			->andWhere('c.id != :id')
			->setParameter('left', $category->getLeft())
			->setParameter('right', $category->getRight())
			->setParameter('id', $category->getId())
			->orderBy('c.depth')
			->getQuery()
			->getResult();

		$subCategories = $em->createQueryBuilder()
			->select('c')
			->from('EtuModuleForumBundle:Category', 'c')
			->where('c.left > :left')
			->andWhere('c.right < :right')
			->setParameter('left', $category->getLeft())
			->setParameter('right', $category->getRight())
			->orderBy('c.left')
			->getQuery()
			->getResult();
<commit_msg>Fix a minor depth bug<commit_after><?php

namespace Etu\Module\ForumBundle\Controller;

use Doctrine\ORM\EntityRepository;

use Etu\Core\CoreBundle\Framework\Definition\Controller;
use Etu\Core\CoreBundle\Twig\Extension\StringManipulationExtension;
use Etu\Core\CoreBundle\Util\RedactorJsEscaper;
use Etu\Core\CoreBundle\Entity\Notification;

use Etu\Module\ForumBundle\Entity\Category;
use Etu\Module\ForumBundle\Entity\Thread;
use Etu\Module\ForumBundle\Entity\Message;
use Etu\Module\ForumBundle\Entity\View;
use Etu\Module\ForumBundle\Form\ThreadType;
use Etu\Module\ForumBundle\Form\MessageEditType;
use Etu\Module\ForumBundle\Form\MessageType;
use Etu\Module\ForumBundle\Model\PermissionsChecker;

// Import annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class MainController extends Controller
{
	/**
	 * @Route("/forum", name="forum_index")
	 * @Template()
	 */
	public function indexAction()
	{
		$em = $this->getDoctrine()->getManager();
		$categories = $em->createQueryBuilder()
			->select('c')
			->from('EtuModuleForumBundle:Category', 'c')
			->where('c.depth <= 1')
			->orderBy('c.left')
			->getQuery()
			->getResult();

		return array('categories' => $categories);
	}

	/**
	 * @Route("/forum/{id}-{slug}/{page}", defaults={"page" = 1}, requirements={"page" = "\d+"}, name="forum_category")
	 * @Template()
	 */
	public function categoryAction($id, $slug, $page)
	{
		$em = $this->getDoctrine()->getManager();

		/** @var Category $category */
		$category = $em->getRepository('EtuModuleForumBundle:Category')
			->find($id);

		$checker = new PermissionsChecker($this->getUser());

		if (!$checker->canRead($category)) {
			return $this->createAccessDeniedResponse();
		}

		$parents = $em->createQueryBuilder()
			->select('c')
			->from('EtuModuleForumBundle:Category', 'c')
			->where('c.left <= :left')
			->andWhere('c.right >= :right')
			->andWhere('c.id != :id')
			->setParameter('left', $category->getLeft())
			->setParameter('right', $category->getRight())
			->setParameter('id', $category->getId())
			->orderBy('c.depth')
			->getQuery()
			->getResult();

		$depth = count($parents)+1;

		$subCategories = $em->createQueryBuilder()
			->select('c')
			->from('EtuModuleForumBundle:Category', 'c')
			->where('c.left > :left')
			->andWhere('c.right < :right')
			->andWhere('c.depth = :depth')
			->setParameter('left', $category->getLeft())
			->setParameter('right', $category->getRight())
			->setParameter('depth', $depth)
			->orderBy('c.left')
			->getQuery()
			->getResult();

{'fraction_non_alphanumeric': 0.19327073552425664, 'fraction_numerical': 0.0009780907668231612, 'mean_word_length': 4.870264064293915, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 97, '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': '4226724', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1693, 'n_words': 256}