Example #1
0
 /**
  * @param Project $project
  *
  * Temporary function to fill up the rationale for public function table with the relevant data.
  * We will go over each project and find the countries
  */
 public function generateCountryRationaleByProject(Project $project)
 {
     //Get the current (already) present $rationale
     $countriesCollected = new ArrayCollection();
     foreach ($project->getRationale() as $rationale) {
         $countriesCollected->add($rationale->getCountry()->getId());
     }
     $affiliations = $this->getAffiliationService()->findAffiliationByProjectAndWhich($project);
     //Produce an array with unique countries
     foreach ($affiliations as $affiliation) {
         if ($affiliation->getAffiliation()->getOrganisation()->getCountry()->getId() === 0 || $countriesCollected->contains($affiliation->getAffiliation()->getOrganisation()->getCountry()->getId())) {
             continue;
         }
         //Create a new $rationale
         $rationale = new Rationale();
         $rationale->setContact($affiliation->getAffiliation()->getContact());
         $rationale->setCountry($affiliation->getAffiliation()->getOrganisation()->getCountry());
         $rationale->setProject($project);
         $rationale->setRationale(null);
         $this->getEntityManager()->persist($rationale);
         $this->getEntityManager()->flush();
         $countriesCollected->add($affiliation->getAffiliation()->getOrganisation()->getCountry()->getId());
     }
 }