<commit_before><?php

namespace Project\AppBundle\Controller;

use Project\AppBundle\Entity\StudentEvaluation;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Project\AppBundle\Entity\Evaluation;
use Project\AppBundle\Entity\Criterion;
use Symfony\Component\HttpFoundation\Request;
use Project\AppBundle\Form\EvaluationType;
use Project\AppBundle\Form\ValidateEvaluationType;
use Project\AppBundle\Entity\Speaker;
use Symfony\Component\Process\Exception\InvalidArgumentException;
/**
 * Criterion controller.
 *
 * @Route("/evaluation")
 */
class EvaluationController extends Controller
{

    /**
     * Lists all Evaluation entities.
     *
     * @Route("/", name="evaluation")
     * @Secure(roles={"ROLE_SPEAKER", "ROLE_MANAGER", "ROLE_STUDENT"})
     * @Method("GET")
     * @Template("ProjectAppBundle:Evaluation:index.html.twig")
     */
    public function indexAction()
    {
        // Get user logged in
        $user = $this->getUser();
        $userRoles = $user->getRoles();

        // init database
        $em = $this->getDoctrine()->getManager();
        $repoStudentEval = $em->getRepository('ProjectAppBundle:StudentEvaluation');
        $repoEval = $em->getRepository('ProjectAppBundle:Evaluation');
        $repoStudent = $em->getRepository('ProjectAppBundle:Student');
        $repoCrit = $em->getRepository('ProjectAppBundle:Criterion');
        $repoStudentEvalCrit = $em->getRepository('ProjectAppBundle:StudentEvaluationCriterion');
        
        // Si l'utilisateur est MANAGER ou SPEAKER
        if(in_array('ROLE_MANAGER', $userRoles)){
            $evals = $repoEval->findAllUnvalidatedByPromotion($this->get('session')->get('promotion'));

            if(!empty($evals)) {
                foreach($evals as $eval) {
                    $entities[] = array(
                            'evaluation' => $eval,
                            'criterions' => $repoCrit->findByEvaluation($eval)
                    );
                }
            } else {
                $entities = array();
            }


        } else if (in_array('ROLE_STUDENT', $userRoles)) {

            $student = $repoStudent->findOneByUser($user);
            $studentEvals = $repoStudentEval->findByStudent($student);
            $studentCritScores = array();

            if(!empty($studentEvals)) {
                foreach($studentEvals as $studentEval) {
                    $criterions = $repoCrit->findByEvaluation($studentEval->getEvaluation());

                    foreach ( $criterions as $criterion ) {
                        $critEval = $repoStudentEvalCrit->findOneByCritEval($criterion, $studentEval);<commit_msg>Correct criterion score array reseting<commit_after><?php

namespace Project\AppBundle\Controller;

use Project\AppBundle\Entity\StudentEvaluation;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Project\AppBundle\Entity\Evaluation;
use Project\AppBundle\Entity\Criterion;
use Symfony\Component\HttpFoundation\Request;
use Project\AppBundle\Form\EvaluationType;
use Project\AppBundle\Form\ValidateEvaluationType;
use Project\AppBundle\Entity\Speaker;
use Symfony\Component\Process\Exception\InvalidArgumentException;
/**
 * Criterion controller.
 *
 * @Route("/evaluation")
 */
class EvaluationController extends Controller
{

    /**
     * Lists all Evaluation entities.
     *
     * @Route("/", name="evaluation")
     * @Secure(roles={"ROLE_SPEAKER", "ROLE_MANAGER", "ROLE_STUDENT"})
     * @Method("GET")
     * @Template("ProjectAppBundle:Evaluation:index.html.twig")
     */
    public function indexAction()
    {
        // Get user logged in
        $user = $this->getUser();
        $userRoles = $user->getRoles();

        // init database
        $em = $this->getDoctrine()->getManager();
        $repoStudentEval = $em->getRepository('ProjectAppBundle:StudentEvaluation');
        $repoEval = $em->getRepository('ProjectAppBundle:Evaluation');
        $repoStudent = $em->getRepository('ProjectAppBundle:Student');
        $repoCrit = $em->getRepository('ProjectAppBundle:Criterion');
        $repoStudentEvalCrit = $em->getRepository('ProjectAppBundle:StudentEvaluationCriterion');
        
        // Si l'utilisateur est MANAGER ou SPEAKER
        if(in_array('ROLE_MANAGER', $userRoles)){
            $evals = $repoEval->findAllUnvalidatedByPromotion($this->get('session')->get('promotion'));

            if(!empty($evals)) {
                foreach($evals as $eval) {
                    $entities[] = array(
                            'evaluation' => $eval,
                            'criterions' => $repoCrit->findByEvaluation($eval)
                    );
                }
            } else {
                $entities = array();
            }


        } else if (in_array('ROLE_STUDENT', $userRoles)) {

            $student = $repoStudent->findOneByUser($user);
            $studentEvals = $repoStudentEval->findByStudent($student);


            if(!empty($studentEvals)) {
                foreach($studentEvals as $studentEval) {
                    $criterions = $repoCrit->findByEvaluation($studentEval->getEvaluation());

                    $studentCritScores = array();
                    foreach ( $criterions as $criterion ) {
                        $critEval = $repoStudentEvalCrit->findOneByCritEval($criterion, $studentEval);
{'fraction_non_alphanumeric': 0.12832011038289065, 'fraction_numerical': 0.0, 'mean_word_length': 2.876336898395722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '3747268', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1559, 'n_words': 239}