<commit_before><?php

namespace SMARTASK\HomeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use SMARTASK\HomeBundle\Entity\Contact;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use SMARTASK\HomeBundle\Entity\Groupe;
use SMARTASK\HomeBundle\Entity\Task;
use Symfony\Component\Validator\Constraints\Date;
use Symfony\Component\Validator\Constraints\Time;
use Symfony\Component\HttpFoundation\JsonResponse;
use SMARTASK\UserBundle\Entity\User;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Security;
use SMARTASK\HomeBundle\Form\TaskType;
use SMARTASK\HomeBundle\Form\GroupeType;
use SMARTASK\HomeBundle\Form\ContactType;

class DefaultController extends Controller {
	
	public function findtaskAction(Request $request) {
		$logger = $this->container->get ( 'logger' );
		$logger->info ( 'findtask' );
		// je v�rifie si elle est de type POST
		if ($request->isMethod('POST'))
		{
			$logger->info('findtask POST');
			$keyword = $request->get('keyword');
			$logger->info('findtask $keyword : '.$keyword);			
			$finder = $this->container->get('fos_elastica.finder.app.task');
			$results = $finder->find($keyword);
			
			foreach($results as $task)	{
			    $logger->info('findtask result'.$task->getTitre());
			}
		}

		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$listTasks = $user->getTasks();
		$nbtask = count($listTasks);
		return $this->render('SMARTASKHomeBundle:Default:activity.html.twig',array( 'listTasks' => $listTasks,'nbtask'=>$nbtask ));	
	}
	
	public function comments_groupAction($groupId){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $groupId );
		return $this->render('SMARTASKHomeBundle:Default:commentsGroup.html.twig',array('group' => $group));
	}
	
	public function deleteTaskGroupAction($taskId, $groupId){
		$em =$this->getDoctrine()->getManager();
		$task = $em->getRepository('SMARTASKHomeBundle:Task')->find($taskId);
		$em->remove($task);
		$em->flush();
		$this->activity_groupAction($groupId);
	}
	
	public function activity_groupAction($id){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		$listTasks = $em->getRepository('SMARTASKHomeBundle:Task')->findBy(array('group' => $group));
		$nbtask = count($listTasks);
		return $this->render('SMARTASKHomeBundle:Default:listTaskGroup.html.twig',array('listTasks' => $listTasks,'group' => $group,'nbtask'=>$nbtask));
	}
	public function remove_person_from_groupAction($userId, $groupId){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $groupId );
		$user=$em->getRepository('SMARTASKUserBundle:User')->findOneBy(array('id' => $userId));
		$user->removeGroupe($group);
		$em->flush();
		return $this->redirectToRoute('list_members_group',array('id' => $groupId));
	}
	public function listMembersGroupAction($id){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		return $this->render('SMARTASKHomeBundle:Default:listMembersGroup.html.twig',array('group' => $group));
	}
	
	public function addcontactgroupAction (Request $request, $id){
		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		
		if ($request->isMethod('POST')){
			$emailcontact = $request->get('email');
			$logger = $this->container->get('logger');
			$logger->info('addcontactgroupAction email :'.$emailcontact);
			$addeduser = $em->getRepository('SMARTASKUserBundle:User')->findOneBy(array('email' => $emailcontact));
			if ($addeduser){
			    $addeduser->getGroupes()->add($group);
			    $logger->info('addcontactgroupAction user ajout�');
			    $em->persist($group);
			    $em->persist($addeduser);
			    $em->flush();
			    return $this->redirectToRoute('add_contact_group',array('id' => $id));
			}else{
				return $this->render('SMARTASKHomeBundle:Default:error.html.twig',array('msg' => "L'utilisateur n'est pas encore enregistre"));
			}
		}
		return $this->render('SMARTASKHomeBundle:Default:addperson.html.twig',array('group' => $group,'list_contact' => $user->getContacts()));
	}
	
	
	public function open_group_detailAction($id){ 
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		return $this->render('SMARTASKHomeBundle:Default:detailgroup.html.twig',array('group' => $group));
	}
	/**
	 * @Route("/")
	 * @Template()
	 */
	public function accueilAction(Request $request){
		
		// envoie de mail pour les fans
		$logger = $this->container->get('logger');
		$logger->info('sendmailAction');
				
		// je v�rifie si elle est de type POST
		if($request->isMethod('POST'))
		{
			$logger->info('sendmailAction POST');
			$name = $request->get('name');
			$comments = $request->get('comments');
			$mail = $request->get('email');
		
			$logger->info('sendmailAction $$name : '.$name);
			$logger->info('sendmailAction $$mail  : '.$mail);
		
			$message = \Swift_Message::newInstance()
			->setContentType('text/html')
			->setSubject("Messag from Fan of SmarTask")
			->setFrom($mail)
			->setTo("<EMAIL>")
			->setBody($comments);
			
			$this->get('mailer')->send($message);
		
		}
		// gere la connection 
		$session = $request->getSession();
	
		$authErrorKey = Security::AUTHENTICATION_ERROR;
		$lastUsernameKey = Security::LAST_USERNAME;
	
		// get the error if any (works with forward and redirect -- see below)
		if ($request->attributes->has($authErrorKey)) {
			$error = $request->attributes->get($authErrorKey);
		} elseif (null !== $session && $session->has($authErrorKey)) {
			$error = $session->get($authErrorKey);
			$session->remove($authErrorKey);
		} else {
			$error = null;
		}
	
		if (!$error instanceof AuthenticationException) {
			$error = null; // The value does not come from the security component.
		}
	
		// last username entered by the user
		$lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey);
	
		$csrfToken = $this->has('security.csrf.token_manager') ? $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue(): null;

		//add cache
		$response = $this->render('SMARTASKHomeBundle:Default:accueil.html.twig',array('last_username' => $lastUsername,'error' => $error,'csrf_token' => $csrfToken));
		
		$response->setSharedMaxAge(3600);
		
		return  $response ;
		
		//return $this->render('SMARTASKHomeBundle:Default:accueil.html.twig',array('last_username' => $lastUsername,'error' => $error,'csrf_token' => $csrfToken));
		
	}
	

	public function activityAction(Request $request)
	{
		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$listTasks = $user->getTasks();
		$nbtask = count($listTasks);
		return $this->render('SMARTASKHomeBundle:Default:activity.html.twig',array( 'listTasks' => $listTasks,'nbtask'=>$nbtask ));
	}
	
	
	public function taskAction(Request $request)
	{
		$logger = $this->container->get('logger');
		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$task = new Task();
		$task->setManager($user);
		$task->setIsalarmeon(1);
		$task->setDate(new \DateTime("now"));
		$task->setTime(new \DateTime("now"));
		$form   = $this->get('form.factory')->create(TaskType::class, $task);
	
		if ($request->isMethod('POST')){//s'il l'utilisateur veut enregistrer sa tache
			$form->handleRequest($request);
			if($form->isValid()){<commit_msg>add homepage on cache with reverse proxy 2<commit_after><?php

namespace SMARTASK\HomeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use SMARTASK\HomeBundle\Entity\Contact;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use SMARTASK\HomeBundle\Entity\Groupe;
use SMARTASK\HomeBundle\Entity\Task;
use Symfony\Component\Validator\Constraints\Date;
use Symfony\Component\Validator\Constraints\Time;
use Symfony\Component\HttpFoundation\JsonResponse;
use SMARTASK\UserBundle\Entity\User;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Security;
use SMARTASK\HomeBundle\Form\TaskType;
use SMARTASK\HomeBundle\Form\GroupeType;
use SMARTASK\HomeBundle\Form\ContactType;

class DefaultController extends Controller {
	
	public function findtaskAction(Request $request) {
		$logger = $this->container->get ( 'logger' );
		$logger->info ( 'findtask' );
		// je v�rifie si elle est de type POST
		if ($request->isMethod('POST'))
		{
			$logger->info('findtask POST');
			$keyword = $request->get('keyword');
			$logger->info('findtask $keyword : '.$keyword);			
			$finder = $this->container->get('fos_elastica.finder.app.task');
			$results = $finder->find($keyword);
			
			foreach($results as $task)	{
			    $logger->info('findtask result'.$task->getTitre());
			}
		}

		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$listTasks = $user->getTasks();
		$nbtask = count($listTasks);
		return $this->render('SMARTASKHomeBundle:Default:activity.html.twig',array( 'listTasks' => $listTasks,'nbtask'=>$nbtask ));	
	}
	
	public function comments_groupAction($groupId){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $groupId );
		return $this->render('SMARTASKHomeBundle:Default:commentsGroup.html.twig',array('group' => $group));
	}
	
	public function deleteTaskGroupAction($taskId, $groupId){
		$em =$this->getDoctrine()->getManager();
		$task = $em->getRepository('SMARTASKHomeBundle:Task')->find($taskId);
		$em->remove($task);
		$em->flush();
		$this->activity_groupAction($groupId);
	}
	
	public function activity_groupAction($id){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		$listTasks = $em->getRepository('SMARTASKHomeBundle:Task')->findBy(array('group' => $group));
		$nbtask = count($listTasks);
		return $this->render('SMARTASKHomeBundle:Default:listTaskGroup.html.twig',array('listTasks' => $listTasks,'group' => $group,'nbtask'=>$nbtask));
	}
	public function remove_person_from_groupAction($userId, $groupId){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $groupId );
		$user=$em->getRepository('SMARTASKUserBundle:User')->findOneBy(array('id' => $userId));
		$user->removeGroupe($group);
		$em->flush();
		return $this->redirectToRoute('list_members_group',array('id' => $groupId));
	}
	public function listMembersGroupAction($id){
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		return $this->render('SMARTASKHomeBundle:Default:listMembersGroup.html.twig',array('group' => $group));
	}
	
	public function addcontactgroupAction (Request $request, $id){
		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		
		if ($request->isMethod('POST')){
			$emailcontact = $request->get('email');
			$logger = $this->container->get('logger');
			$logger->info('addcontactgroupAction email :'.$emailcontact);
			$addeduser = $em->getRepository('SMARTASKUserBundle:User')->findOneBy(array('email' => $emailcontact));
			if ($addeduser){
			    $addeduser->getGroupes()->add($group);
			    $logger->info('addcontactgroupAction user ajout�');
			    $em->persist($group);
			    $em->persist($addeduser);
			    $em->flush();
			    return $this->redirectToRoute('add_contact_group',array('id' => $id));
			}else{
				return $this->render('SMARTASKHomeBundle:Default:error.html.twig',array('msg' => "L'utilisateur n'est pas encore enregistre"));
			}
		}
		return $this->render('SMARTASKHomeBundle:Default:addperson.html.twig',array('group' => $group,'list_contact' => $user->getContacts()));
	}
	
	
	public function open_group_detailAction($id){ 
		$em =$this->getDoctrine()->getManager();
		$group= $em->getRepository('SMARTASKHomeBundle:Groupe')->find( $id );
		return $this->render('SMARTASKHomeBundle:Default:detailgroup.html.twig',array('group' => $group));
	}
	/**
	 * @Route("/")
	 * @Template()
	 */
	public function accueilAction(Request $request){
		
		// envoie de mail pour les fans
		$logger = $this->container->get('logger');
		$logger->info('sendmailAction');
				
		// je v�rifie si elle est de type POST
		if($request->isMethod('POST'))
		{
			$logger->info('sendmailAction POST');
			$name = $request->get('name');
			$comments = $request->get('comments');
			$mail = $request->get('email');
		
			$logger->info('sendmailAction $$name : '.$name);
			$logger->info('sendmailAction $$mail  : '.$mail);
		
			$message = \Swift_Message::newInstance()
			->setContentType('text/html')
			->setSubject("Messag from Fan of SmarTask")
			->setFrom($mail)
			->setTo("<EMAIL>")
			->setBody($comments);
			
			$this->get('mailer')->send($message);
		
		}
		// gere la connection 
		$session = $request->getSession();
	
		$authErrorKey = Security::AUTHENTICATION_ERROR;
		$lastUsernameKey = Security::LAST_USERNAME;
	
		// get the error if any (works with forward and redirect -- see below)
		if ($request->attributes->has($authErrorKey)) {
			$error = $request->attributes->get($authErrorKey);
		} elseif (null !== $session && $session->has($authErrorKey)) {
			$error = $session->get($authErrorKey);
			$session->remove($authErrorKey);
		} else {
			$error = null;
		}
	
		if (!$error instanceof AuthenticationException) {
			$error = null; // The value does not come from the security component.
		}
	
		// last username entered by the user
		$lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey);
	
		$csrfToken = $this->has('security.csrf.token_manager') ? $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue(): null;

		//add cache
		$response = $this->render('SMARTASKHomeBundle:Default:accueil.html.twig',array('last_username' => $lastUsername,'error' => $error,'csrf_token' => $csrfToken));
		
		$response->setSharedMaxAge(3600);
		
		return  $response ;		
	}
	

	public function activityAction(Request $request)
	{
		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$listTasks = $user->getTasks();
		$nbtask = count($listTasks);
		return $this->render('SMARTASKHomeBundle:Default:activity.html.twig',array( 'listTasks' => $listTasks,'nbtask'=>$nbtask ));
	}
	
	
	public function taskAction(Request $request)
	{
		$logger = $this->container->get('logger');
		$user = $this->getUser();// Pour r�cup�rer le service UserManager du bundle
		$task = new Task();
		$task->setManager($user);
		$task->setIsalarmeon(1);
		$task->setDate(new \DateTime("now"));
		$task->setTime(new \DateTime("now"));
		$form   = $this->get('form.factory')->create(TaskType::class, $task);
	
		if ($request->isMethod('POST')){//s'il l'utilisateur veut enregistrer sa tache
			$form->handleRequest($request);
			if($form->isValid()){
{'fraction_non_alphanumeric': 0.1851803789255126, 'fraction_numerical': 0.0007137295613807423, 'mean_word_length': 5.366377529946303, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 295, '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': '1368497', 'n_tokens_mistral': 5437, 'n_tokens_neox': 4939, 'n_words': 821}