/**
  * Check the user's drop to see if he has corrected enought copy and if his copy is fully corrected
  * in order to notify him that his grade is available.
  *
  * */
 private function checkUserGradeAvailable(Dropzone $dropzone, Drop $drop, $user)
 {
     // notification only in the PeerReview mode.
     $em = $this->getDoctrine()->getManager();
     $event = new LogDropGradeAvailableEvent($dropzone, $drop);
     if ($dropzone->getPeerReview() == 1) {
         // copy corrected by user
         // corrections on the user's copy
         $nbCorrectionByOthersOnUsersCopy = $em->getRepository('InnovaCollecticielBundle:Correction')->getCorrectionsIds($dropzone, $drop);
         //Expected corrections
         $expectedCorrections = $dropzone->getExpectedTotalCorrection();
         /**
          * $nbCorrectionByUser = $em->getRepository('InnovaCollecticielBundle:Correction')->getAlreadyCorrectedDropIds($dropzone, $user);
          * if(count($nbCorrectionByUser) >=  $expectedCorrections && count($nbCorrectionByOthersOnUsersCopy) >= $expectedCorrections  )
          **/
         // corrected copy only instead of corrected copy AND given corrections.
         if (count($nbCorrectionByOthersOnUsersCopy) >= $expectedCorrections) {
             //dispatchEvent.
             $this->get('event_dispatcher')->dispatch('log', $event);
         }
     } else {
         $nbCorrectionByOthersOnUsersCopy = $em->getRepository('InnovaCollecticielBundle:Correction')->getCorrectionsIds($dropzone, $drop);
         if ($nbCorrectionByOthersOnUsersCopy > 0) {
             $this->get('event_dispatcher')->dispatch('log', $event);
         }
     }
 }
 /**
  *
  * STATES  FOR NORMAL ARE :
  *  0 : not started
  *  1 : Waiting for drop
  *  2 : Drop received, waiting for correction
  *  3 : Copy corrected , Evaluation end.
  *
  * STATES FOR PEERREVIEW (for X correction ):
  *  0 : notStarted
  *  1 : Waiting for drop
  *  2 : Drop received
  *  3 : Correction 1/x
  *  4 : Correction 2/X
  *  5 : Correction X/X
  *  6 : Waiting for correction
  *  7 : copy corrected, Evaluation End.
  *
  * WARNING : if a drop has the 'unlockedDrop' property, it will make the drop being at the last state.
  *  currentstate : index of the current state  in the stateArray
  *  percent : rounded progress in percent
  *  nbCorrection : corrections made by the user in this evaluation.
  *
  * @param  \Innova\CollecticielBundle\Entity\Dropzone                                     $dropzone
  * @param  \Innova\CollecticielBundle\Entity\Drop|\Innova\CollecticielBundle\Manager\Drop $drop
  * @param  int                                                                            $nbCorrection number of correction the user did.
  * @return array                                                                          (states, currentState,percent,nbCorrection)
  */
 public function getDrozponeProgress(Dropzone $dropzone, Drop $drop = null, $nbCorrection = 0)
 {
     $begin_states = array('Evaluation not started', 'awaiting for drop', 'drop provided');
     $end_states = array('waiting for correction', 'corrected copy');
     $states = array();
     $states = array_merge($states, $begin_states);
     $expectedCorrections = $dropzone->getExpectedTotalCorrection();
     $currentState = 0;
     // set the states of the dropzone.
     if ($dropzone->getPeerReview()) {
         // case of peerReview
         /*
          * --------------------- SPECIAL CASE  BEGIN ------------------------------
          *  particular case where the peerReview end whereas the user didnt
          *  had time to make all the expected corrections.
          *  so we make a hack to allow them to see their note and simulate that
          *  they did the expected corrections.
          */
         $allow_user_to_not_have_expected_corrections = $this->isPeerReviewEndedOrManualStateFinished($dropzone, $nbCorrection);
         /* --------------------- SPECIAL CASE  END ------------------------------*/
         if (!$allow_user_to_not_have_expected_corrections && $drop != null && !$drop->isUnlockedDrop()) {
             for ($i = 0; $i < $expectedCorrections; $i++) {
                 array_push($states, 'correction n°%nb_correction%/%expected_correction%');
             }
         }
         $states = array_merge($states, $end_states);
         // getting the current state.
         // if no drop, state is 0 as default.
         if (!empty($drop)) {
             $currentState++;
             if ($drop->getFinished()) {
                 $currentState++;
             }
             // @TODO manage invalidated corrections.
             //  update the state with the correction number.
             if ($nbCorrection > $expectedCorrections) {
                 $nbCorrection = $expectedCorrections;
             }
             if (!$allow_user_to_not_have_expected_corrections && !$drop->isUnlockedDrop()) {
                 $currentState += $nbCorrection;
                 if ($nbCorrection >= $expectedCorrections) {
                     $currentState++;
                 }
             } else {
                 $currentState++;
             }
             if ($drop->countFinishedCorrections() >= $expectedCorrections) {
                 $currentState++;
                 if ($allow_user_to_not_have_expected_corrections) {
                     $currentState++;
                 }
             } elseif ($drop->isUnlockedDrop()) {
                 $currentState++;
             }
             // admin case ( can correct more than expected )
             if ($currentState >= count($states)) {
                 $currentState = count($states) - 1;
             }
         }
     } else {
         // case of normal correction.
         $states = array_merge($states, $end_states);
         // if no drop, state is 0 as default.
         if (!empty($drop)) {
             $currentState++;
             if ($drop->getFinished()) {
                 $currentState += 2;
             }
             if ($drop->countFinishedCorrections() >= $expectedCorrections) {
                 $currentState++;
             }
         }
     }
     $percent = round($currentState * 100 / (count($states) - 1));
     return array('states' => $states, 'currentState' => $currentState, 'percent' => $percent, 'nbCorrection' => $nbCorrection);
 }