Exemplo n.º 1
0
 /**
  * Remove schedule
  *
  * @param \Proethos2\ModelBundle\Entity\SubmissionTask $schedule
  */
 public function removeSchedule(\Proethos2\ModelBundle\Entity\SubmissionTask $schedule)
 {
     $this->schedule->removeElement($schedule);
 }
Exemplo n.º 2
0
 /**
  * @Route("/submission/new/{submission_id}/fourth", name="submission_new_fourth_step")
  * @Template()
  */
 public function FourthStepAction($submission_id)
 {
     $output = array();
     $request = $this->getRequest();
     $session = $request->getSession();
     $translator = $this->get('translator');
     $em = $this->getDoctrine()->getManager();
     $submission_repository = $em->getRepository('Proethos2ModelBundle:Submission');
     $submission_cost_repository = $em->getRepository('Proethos2ModelBundle:SubmissionCost');
     $submission_task_repository = $em->getRepository('Proethos2ModelBundle:SubmissionTask');
     $user_repository = $em->getRepository('Proethos2ModelBundle:User');
     $submission_clinical_trial_repository = $em->getRepository('Proethos2ModelBundle:SubmissionClinicalTrial');
     $clinical_trial_name_repository = $em->getRepository('Proethos2ModelBundle:ClinicalTrialName');
     // getting the current submission
     $submission = $submission_repository->find($submission_id);
     $output['submission'] = $submission;
     $clinical_trial_names = $clinical_trial_name_repository->findByStatus(true);
     $output['clinical_trial_names'] = $clinical_trial_names;
     if (!$submission or $submission->getIsSended()) {
         throw $this->createNotFoundException($translator->trans('No submission found'));
     }
     $allow_to_edit_submission = true;
     $user = $this->get('security.token_storage')->getToken()->getUser();
     // if current user is not owner, check the team
     if ($user != $submission->getOwner()) {
         $allow_to_edit_submission = false;
         foreach ($submission->getTeam() as $team_member) {
             // if current user = some team member, than it allows to edit
             if ($user == $team_member) {
                 $allow_to_edit_submission = true;
             }
         }
     }
     if (!$allow_to_edit_submission) {
         throw $this->createNotFoundException($translator->trans('No submission found'));
     }
     // checking if was a post request
     if ($this->getRequest()->isMethod('POST')) {
         // getting post data
         $post_data = $request->request->all();
         // checking required files
         $required_fields = array('funding-source', 'primary-sponsor');
         foreach ($required_fields as $field) {
             if (!isset($post_data[$field]) or empty($post_data[$field])) {
                 $session->getFlashBag()->add('error', $translator->trans("Field '%field%' is required.", array("%field%" => $field)));
                 return $output;
             }
         }
         // removing all clinical_trial to rewrite
         foreach ($submission->getClinicalTrial() as $trial) {
             $submission->removeClinicalTrial($trial);
             $em->remove($trial);
             $em->flush();
         }
         if (isset($post_data['clinical-trial'])) {
             $submission->setClinicalTrialSecondary($post_data['clinical-trial-second']);
             foreach ($post_data['clinical-trial'] as $key => $trial_data) {
                 $trial_name = $clinical_trial_name_repository->find($trial_data['name-id']);
                 $date = NULL;
                 if (!empty($trial_data['date'])) {
                     $date = new \DateTime($trial_data['date']);
                 }
                 // check if exists
                 $trial = $submission_clinical_trial_repository->findOneBy(array('submission' => $submission, 'name' => $trial_name, 'date' => $date, 'number' => $trial_data['number']));
                 if (!$trial) {
                     $trial = new SubmissionClinicalTrial();
                     $trial->setSubmission($submission);
                     $trial->setName($trial_name);
                     $trial->setNumber($trial_data['number']);
                     $trial->setDate($date);
                 }
                 $em->persist($trial);
                 $em->flush();
                 // add in submission
                 $submission->addClinicalTrial($trial);
             }
         }
         // removing all team to readd
         foreach ($submission->getBudget() as $budget) {
             $submission->removeBudget($budget);
             $em->remove($budget);
             $em->flush();
         }
         if (isset($post_data['budget'])) {
             foreach ($post_data['budget'] as $key => $cost) {
                 // check if exists
                 $submission_cost = $submission_cost_repository->findOneBy(array('submission' => $submission, 'description' => $cost['description'], 'quantity' => $cost['quantity'], 'unit_cost' => $cost['unit_cost']));
                 // if not exists, create the new submission_cost
                 if (!$submission_cost) {
                     $submission_cost = new SubmissionCost();
                     $submission_cost->setSubmission($submission);
                     $submission_cost->setDescription($cost['description']);
                     $submission_cost->setQuantity($cost['quantity']);
                     $submission_cost->setUnitCost($cost['unit_cost']);
                 }
                 $em->persist($submission_cost);
                 $em->flush();
                 // add in submission
                 $submission->addBudget($submission_cost);
             }
         }
         $submission->setFundingSource($post_data['funding-source']);
         $submission->setPrimarySponsor($post_data['primary-sponsor']);
         $submission->setSecondarySponsor($post_data['secondary-sponsor']);
         // removing all schedule to readd
         foreach ($submission->getSchedule() as $schedule) {
             $submission->removeSchedule($schedule);
             $em->remove($schedule);
             $em->flush();
         }
         if (isset($post_data['schedule'])) {
             foreach ($post_data['schedule'] as $key => $task) {
                 // check if exists
                 $submission_task = $submission_task_repository->findOneBy(array('submission' => $submission, 'description' => $task['description'], 'init' => new \DateTime($task['init']), 'end' => new \DateTime($task['end'])));
                 // if not exists, create the new submission_task
                 if (!$submission_task) {
                     $submission_task = new SubmissionTask();
                     $submission_task->setSubmission($submission);
                     $submission_task->setDescription($task['description']);
                     $submission_task->setInit(new \DateTime($task['init']));
                     $submission_task->setEnd(new \DateTime($task['end']));
                 }
                 $em->persist($submission_task);
                 $em->flush();
                 // add in submission
                 $submission->addSchedule($submission_task);
             }
         }
         $em->persist($submission);
         $em->flush();
         $session->getFlashBag()->add('success', $translator->trans("Fourth step saved with sucess."));
         return $this->redirectToRoute('submission_new_fifth_step', array('submission_id' => $submission->getId()), 301);
     }
     return $output;
 }