<commit_before><?php

namespace Etu\Module\TrombiBundle\Controller;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Etu\Core\CoreBundle\Framework\Definition\Controller;
use Etu\Core\UserBundle\Entity\User;

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

class MainController extends Controller
{
	/**
	 * @Route("/trombi/{page}", defaults={"page" = 1}, requirements={"page" = "\d+"}, name="trombi_index")
	 * @Template()
	 */
	public function indexAction($page)
	{
		if (! $this->getUserLayer()->isStudent() && ! $this->getUserLayer()->isOrga()) {
			return $this->createAccessDeniedResponse();
		}

		$user = new User();
		$search = false;
		$users = array();

		$form = $this->createFormBuilder($user)
			->add('fullName', null, array('required' => false))
			->add('studentId', null, array('required' => false))
			->add('phoneNumber', null, array('required' => false))
			->add('uvs', null, array('required' => false))
			->add('branch', 'choice', array('choices' => User::$branches, 'required' => false))
			->add('niveau', 'choice', array('choices' => User::$levels, 'required' => false))
			->add('personnalMail', null, array('required' => false))
			->getForm();

		if ($this->getRequest()->query->has('form') && $form->submit($this->getRequest())->isValid()) {
			$search = true;

			/** @var $em EntityManager */
			$em = $this->getDoctrine()->getManager();

			/** @var $users QueryBuilder */
			$users = $em->createQueryBuilder()
				->select('u')
				->from('EtuUserBundle:User', 'u')
				->where('u.isStudent = 1')
				->orderBy('u.lastName');

			if (! $user->getFullName() && ! $user->getStudentId() && ! $user->getPhoneNumber() && ! $user->getUvs() &&
				! $user->getBranch() && ! $user->getNiveau() && ! $user->getPersonnalMail())
			{
				return $this->redirect($this->generateUrl('trombi_index'));
			}

			if ($user->getFullName()) {
				$where = 'u.login = :login ';
				$users->setParameter('login', $user->getFullName());

				$where .= 'OR u.surnom = :surnom OR (';
				$users->setParameter('surnom', '%'.$user->getFullName().'%');

				$terms = explode(' ', $user->getFullName());

				foreach ($terms as $key => $term) {
					$where .= 'u.fullName LIKE :name_'.$key.' AND ';
					$users->setParameter('name_'.$key, '%'.$term.'%');
				}

				$where = substr($where, 0, -5).')';

				$users->andWhere($where);
			}

			if ($user->getStudentId()) {
				$users->andWhere('u.studentId = :id')
					->setParameter('id', $user->getStudentId());
			}

			if ($user->getPhoneNumber()) {
				$phone = $user->getPhoneNumber();
				$parts = array();

				if (strpos($phone, '.') !== false) {
					$parts = explode('.', $phone);
				} elseif (strpos($phone, '-') !== false) {<commit_msg>Bugfix #213<commit_after><?php

namespace Etu\Module\TrombiBundle\Controller;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Etu\Core\CoreBundle\Framework\Definition\Controller;
use Etu\Core\UserBundle\Entity\User;

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

class MainController extends Controller
{
	/**
	 * @Route("/trombi/{page}", defaults={"page" = 1}, requirements={"page" = "\d+"}, name="trombi_index")
	 * @Template()
	 */
	public function indexAction($page)
	{
		if (! $this->getUserLayer()->isStudent() && ! $this->getUserLayer()->isOrga()) {
			return $this->createAccessDeniedResponse();
		}

		$user = new User();
		$search = false;
		$users = array();

		$form = $this->createFormBuilder($user)
			->add('fullName', null, array('required' => false))
			->add('studentId', null, array('required' => false))
			->add('phoneNumber', null, array('required' => false))
			->add('uvs', null, array('required' => false))
			->add('branch', 'choice', array('choices' => User::$branches, 'required' => false))
			->add('niveau', 'choice', array('choices' => User::$levels, 'required' => false))
			->add('personnalMail', null, array('required' => false))
			->getForm();

		if ($this->getRequest()->query->has('form') && $form->submit($this->getRequest())->isValid()) {
			$search = true;

			/** @var $em EntityManager */
			$em = $this->getDoctrine()->getManager();

			/** @var $users QueryBuilder */
			$users = $em->createQueryBuilder()
				->select('u')
				->from('EtuUserBundle:User', 'u')
				->where('u.isStudent = 1')
				->orderBy('u.lastName');

			if (! $user->getFullName() && ! $user->getStudentId() && ! $user->getPhoneNumber() && ! $user->getUvs() &&
				! $user->getBranch() && ! $user->getNiveau() && ! $user->getPersonnalMail())
			{
				return $this->redirect($this->generateUrl('trombi_index'));
			}

			if ($user->getFullName()) {
				$where = 'u.login = :login ';
				$users->setParameter('login', $user->getFullName());

				$where .= 'OR u.surnom LIKE :surnom OR (';
				$users->setParameter('surnom', '%'.$user->getFullName().'%');

				$terms = explode(' ', $user->getFullName());

				foreach ($terms as $key => $term) {
					$where .= 'u.fullName LIKE :name_'.$key.' AND ';
					$users->setParameter('name_'.$key, '%'.$term.'%');
				}

				$where = substr($where, 0, -5).')';

				$users->andWhere($where);
			}

			if ($user->getStudentId()) {
				$users->andWhere('u.studentId = :id')
					->setParameter('id', $user->getStudentId());
			}

			if ($user->getPhoneNumber()) {
				$phone = $user->getPhoneNumber();
				$parts = array();

				if (strpos($phone, '.') !== false) {
					$parts = explode('.', $phone);
				} elseif (strpos($phone, '-') !== false) {
{'fraction_non_alphanumeric': 0.23348095659875998, 'fraction_numerical': 0.0019486271036315323, 'mean_word_length': 4.0500894454382825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 123, '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': '3869014', 'n_tokens_mistral': 2168, 'n_tokens_neox': 1879, 'n_words': 330}