Пример #1
0
 /**
  * Remove country
  *
  * @param \Proethos2\ModelBundle\Entity\SubmissionCountry $country
  */
 public function removeCountry(\Proethos2\ModelBundle\Entity\SubmissionCountry $country)
 {
     $this->country->removeElement($country);
 }
Пример #2
0
 /**
  * @Route("/submission/new/{submission_id}/third", name="submission_new_third_step")
  * @Template()
  */
 public function ThirdStepAction($submission_id)
 {
     $output = array();
     $request = $this->getRequest();
     $session = $request->getSession();
     $translator = $this->get('translator');
     $em = $this->getDoctrine()->getManager();
     $submission_repository = $em->getRepository('Proethos2ModelBundle:Submission');
     $user_repository = $em->getRepository('Proethos2ModelBundle:User');
     $submission_country_repository = $em->getRepository('Proethos2ModelBundle:SubmissionCountry');
     $gender_repository = $em->getRepository('Proethos2ModelBundle:Gender');
     $recruitment_status_repository = $em->getRepository('Proethos2ModelBundle:RecruitmentStatus');
     $country_repository = $em->getRepository('Proethos2ModelBundle:Country');
     // getting the current submission
     $submission = $submission_repository->find($submission_id);
     $output['submission'] = $submission;
     // getting gender list
     $genders = $gender_repository->findByStatus(true);
     $output['genders'] = $genders;
     // getting recruitment_statuses list
     $recruitment_statuses = $recruitment_status_repository->findByStatus(true);
     $output['recruitment_statuses'] = $recruitment_statuses;
     $countries = $country_repository->findBy(array(), array('name' => 'asc'));
     $output['countries'] = $countries;
     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('study-design', 'gender', 'sample-size', 'minimum-age', 'maximum-age', 'inclusion-criteria', 'exclusion-criteria', 'recruitment-init-date', 'recruitment-status', 'interventions', 'primary-outcome');
         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;
             }
         }
         $recruitment_init_date = new \DateTime($post_data['recruitment-init-date']);
         if (new \DateTime('NOW') > $recruitment_init_date) {
             $session->getFlashBag()->add('error', $translator->trans("The recruitment start date has to be subsequent to the date of protocol submission."));
             return $output;
         }
         // adding fields to model
         $submission->setStudyDesign($post_data['study-design']);
         $submission->setHealthCondition($post_data['health-condition']);
         $submission->setSampleSize($post_data['sample-size']);
         $submission->setMinimumAge($post_data['minimum-age']);
         $submission->setMaximumAge($post_data['maximum-age']);
         $submission->setInclusionCriteria($post_data['inclusion-criteria']);
         $submission->setExclusionCriteria($post_data['exclusion-criteria']);
         $submission->setRecruitmentInitDate(new \DateTime($post_data['recruitment-init-date']));
         // gender
         $selected_gender = $gender_repository->find($post_data['gender']);
         $submission->setGender($selected_gender);
         // recruitment status
         $selected_recruitment_status = $recruitment_status_repository->find($post_data['recruitment-status']);
         $submission->setRecruitmentStatus($selected_recruitment_status);
         // removing all team to readd
         foreach ($submission->getCountry() as $country) {
             $submission->removeCountry($country);
             $em->remove($country);
             $em->flush();
         }
         if (isset($post_data['country'])) {
             foreach ($post_data['country'] as $key => $country) {
                 $country_obj = $country_repository->find($country['country_id']);
                 // check if exists
                 $submission_country = $submission_country_repository->findOneBy(array('submission' => $submission, 'country' => $country_obj));
                 // var_dump($post_data);die;
                 // if not exists, create the new submission_country
                 if (!$submission_country) {
                     $submission_country = new SubmissionCountry();
                     $submission_country->setSubmission($submission);
                     $submission_country->setCountry($country_obj);
                     $submission_country->setParticipants($country['participants']);
                 } else {
                     $submission_country->setParticipants($country['participants']);
                 }
                 $em = $this->getDoctrine()->getManager();
                 $em->persist($submission_country);
                 $em->flush();
                 // add in submission
                 $submission->addCountry($submission_country);
             }
         }
         $submission->setInterventions($post_data['interventions']);
         $submission->setPrimaryOutcome($post_data['primary-outcome']);
         $submission->setSecondaryOutcome($post_data['secondary-outcome']);
         $submission->setGeneralProcedures($post_data['general-procedures']);
         $submission->setAnalysisPlan($post_data['analysis-plan']);
         $submission->setEthicalConsiderations($post_data['ethical-considerations']);
         $em = $this->getDoctrine()->getManager();
         $em->persist($submission);
         $em->flush();
         $session->getFlashBag()->add('success', $translator->trans("Third step saved with sucess."));
         return $this->redirectToRoute('submission_new_fourth_step', array('submission_id' => $submission->getId()), 301);
     }
     return $output;
 }