<commit_before><?php

namespace Sio\SemiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sio\SemiBundle\Entity\Registration as Registration;
Use Symfony\Component\HttpFoundation\JsonResponse;
Use Sio\SemiBundle\SioSemiConstants;
/**
 * @Route("/seminar")
 */
class SeminarController extends Controller {

  
  /**
   * Show recorded meetings for a seminar and user given
   * 
   * @Route("/mymeetings/{id}", name="_semi_seminar_my_meetings")
   */
  public function myMeetingsAction(Request $request, $id) {
    if ($id) { 
      return $this->getMeetings($request, $id, true);
    } else {
      // TODO throw new ;
      return $this->redirect($this->generateUrl('_semi_default_index'));
    }
  }
  
  /**
   * Show seminars list or direct meetings for a seminar given
   * 
   * @Route("/", name="_semi_seminar_index")
   * @Route("/{id}", name="_semi_seminar_index_seminar")
   * @Template()
   */
  public function indexAction(Request $request, $id = null) {
    if ($id) {
      // idSeminar ok
      return $this->getMeetings($request, $id, false);      
    } else {
      $user = $this->getUser();
      $em = $this->getDoctrine()->getManager();
      // TODO à revoir cette section (recup directe des seminaires d'un user)
      $query = $em->createQuery(
          'SELECT userseminar
                FROM SioSemiBundle:StatusUserSeminar userseminar
                WHERE userseminar.user = ' . $user->getId() . '
                ORDER BY userseminar.id'
      );

      $userSeminar = $query->getResult();
      $repoSeminar = $this->getDoctrine()->getRepository("SioSemiBundle:Seminar");
      /*
       * $seminars = array();
       
      foreach ($userSeminar as $seminarUser) {
        $seminars[] = $repoSeminar->findBy(array("id" => $seminarUser->getSeminar()->getId()));
      }
      
      */
/** TODO not work below...
      
      if (count($seminars) == 1 ){
        // direct seminar meeting 
        return $this->getMeetings($request, $seminars[0]->getId(), false);
      }
 * 
 */
      $seminars = $repoSeminar->getStatusSeminarsOfUser($user);
      // go to seminars list
      return array('seminars' => $seminars);  
    }
  }

  private function getMeetings($request, $idSeminar, $isOnlyMyRegistrations) {
    $user = $this->getUser();
    $manager = $this->getDoctrine()->getManager();
    $repoMeeting = $manager->getRepository('Sio\SemiBundle\Entity\Meeting');

    $seminar = $this->getDoctrine()->getRepository("SioSemiBundle:Seminar")->findOneBy(array("id" => $idSeminar));
    if (!$seminar) {
      // TODO throw exception ? 
      return $this->redirect($this->generateUrl('_semi_default_index'));
    }
    
    // user can go on this seminar ? (if hack url :)
    $seminarStatus = $this->getDoctrine()
        ->getRepository('SioSemiBundle:StatusUserSeminar')
        ->findOneBy(array('user' => $user,
                          'seminar' => $seminar));
    if (!$seminarStatus) {
      // TODO throw exception ? 
      return $this->redirect($this->generateUrl('_semi_default_index'));
    }
    
    // set idSeminar in session
    $request->getSession()->set(SioSemiConstants::SEMINAR_ID, $idSeminar);<commit_msg>Menage dans indexAction de SeminarController...<commit_after><?php

namespace Sio\SemiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sio\SemiBundle\Entity\Registration as Registration;
Use Symfony\Component\HttpFoundation\JsonResponse;
Use Sio\SemiBundle\SioSemiConstants;
/**
 * @Route("/seminar")
 */
class SeminarController extends Controller {

  
  /**
   * Show recorded meetings for a seminar and user given
   * 
   * @Route("/mymeetings/{id}", name="_semi_seminar_my_meetings")
   */
  public function myMeetingsAction(Request $request, $id) {
    if ($id) { 
      return $this->getMeetings($request, $id, true);
    } else {
      // TODO throw new ;
      return $this->redirect($this->generateUrl('_semi_default_index'));
    }
  }
  
  /**
   * Show seminars list or direct meetings for a seminar given
   * 
   * @Route("/", name="_semi_seminar_index")
   * @Route("/{id}", name="_semi_seminar_index_seminar")
   * @Template()
   */
  public function indexAction(Request $request, $id = null) {
    if ($id) {
      // idSeminar ok
      return $this->getMeetings($request, $id, false);      
    } else {
      $user = $this->getUser();
      $repoSeminar = $this->getDoctrine()->getRepository("SioSemiBundle:Seminar");   
      $seminars = $repoSeminar->getStatusSeminarsOfUser($user);
      
      /** TODO to test !
      if (count($seminars) == 1 ){
        // direct seminar meeting 
        return $this->getMeetings($request, $seminars[0]->getSeminar()->getId(), false);
      }
 * 
 */
      // go to seminars list
      return array('seminars' => $seminars);  
    }
  }

  private function getMeetings($request, $idSeminar, $isOnlyMyRegistrations) {
    $user = $this->getUser();
    $manager = $this->getDoctrine()->getManager();
    $repoMeeting = $manager->getRepository('Sio\SemiBundle\Entity\Meeting');

    $seminar = $this->getDoctrine()->getRepository("SioSemiBundle:Seminar")->findOneBy(array("id" => $idSeminar));
    if (!$seminar) {
      // TODO throw exception ? 
      return $this->redirect($this->generateUrl('_semi_default_index'));
    }
    
    // user can go on this seminar ? (if hack url :)
    $seminarStatus = $this->getDoctrine()
        ->getRepository('SioSemiBundle:StatusUserSeminar')
        ->findOneBy(array('user' => $user,
                          'seminar' => $seminar));
    if (!$seminarStatus) {
      // TODO throw exception ? 
      return $this->redirect($this->generateUrl('_semi_default_index'));
    }
    
    // set idSeminar in session
    $request->getSession()->set(SioSemiConstants::SEMINAR_ID, $idSeminar);
{'fraction_non_alphanumeric': 0.14976, 'fraction_numerical': 0.00064, 'mean_word_length': 3.192488262910798, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, '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': '5825780', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1921, 'n_words': 361}