/**
  * findAmbassadorByContact returns a generator with only elements of ambassadors
  * based on the country.
  */
 public function testfindAmbassadorByCountry()
 {
     $country = new Country();
     $country->setId(1);
     $ambassadorCollection = $this->ambassadorService->findAmbassadorByCountry($country);
     foreach ($ambassadorCollection as $ambassador) {
         $this->assertInstanceOf('Ambassador', $ambassador);
         // and all the ambassadors have the Country
         $this->assertEquals($ambassador->getCountry(), $country);
     }
 }
示例#2
0
 /**
  * Tests the Country.
  */
 public function testCountry()
 {
     $ambassador = new Ambassador();
     $this->assertInstanceOf("General\\Entity\\Country", $ambassador->getCountry());
     // check if ambassador is initialized with an empty country
     $this->assertNull($ambassador->getCountry()->getId());
     // if a new country is set check if it is set correctly
     $country = new Country();
     $country->setId(rand(1, 10000));
     $ambassador->setCountry($country);
     $this->assertEquals($country, $ambassador->getCountry());
 }
示例#3
0
 /**
  * @param Country $country
  * @param int     $width
  *
  * @return string
  */
 public function __invoke(Country $country, $width = 20)
 {
     $flag = $country->getFlag();
     if (is_null($flag)) {
         return '';
     }
     /*
      * Reset the classes
      */
     $this->setClasses([]);
     $this->setRouter('assets/country-flag');
     $this->addRouterParam('iso3', strtolower($country->getIso3()));
     $this->addRouterParam('ext', 'png');
     $this->setImageId('country_flag_' . $country->getIso3());
     $this->setWidth($width);
     return $this->createImageUrl();
 }
示例#4
0
 /**
  * @param         $name
  * @param Country $country
  *
  * @return Entity\Organisation|null
  */
 public function findOrganisationByNameCountry($name, Country $country)
 {
     $qb = $this->_em->createQueryBuilder();
     $qb->select('o');
     $qb->distinct('o.id');
     $qb->from('Organisation\\Entity\\Organisation', 'o');
     /*
      * Limit on the country
      */
     $qb->andWhere('o.country = ?3');
     $qb->setParameter(3, $country->getId());
     /*
      * Do a filter based on the organisation name
      */
     $qb->andWhere('o.organisation LIKE :searchItem');
     $qb->setParameter('searchItem', "%" . $name . "%");
     $qb->setMaxResults(1);
     return $qb->getQuery()->getOneOrNullResult();
 }
示例#5
0
 /**
  * Needed for the hydration of form elements
  *
  * @return array
  */
 public function getArrayCopy()
 {
     return ['country' => $this->country->getIso3(), 'type' => $this->type, 'address' => $this->address, 'city' => $this->city, 'zipCode' => $this->zipCode];
 }
示例#6
0
 public function testToString()
 {
     $country = new Country();
     $country->setCountry('test');
     $this->assertEquals((string) $country, 'test');
 }
 /**
  * @param Country $country
  * @param Project $project
  *
  * @return array
  */
 private function parseCostAndEffortBreakdownPerCountryAndProject(Country $country, Project $project)
 {
     $affiliations = $this->getAffiliationService()->findAffiliationByProjectPerCountryAndWhich($project);
     $rows = [];
     $headerRow = [];
     $cols = [];
     $cols['d_affiliation'] = ['width' => 1500, 'align' => ''];
     $headerRow['d_affiliation'] = 'Organisation';
     $amountOfWorkPackages = $project->getWorkpackage()->count();
     $widthPerCell = ($this->tableWidth - 1500) / ($amountOfWorkPackages + 2);
     foreach ($project->getWorkpackage() as $workPackage) {
         if (!is_null($workPackage->getDateEnd())) {
             continue;
         }
         $cols['wp_' . $workPackage->getId()] = ['width' => $widthPerCell, 'align' => ''];
         $headerRow['wp_' . $workPackage->getId()] = 'WP' . $workPackage->getSequence();
     }
     $cols['total_effort'] = ['width' => $widthPerCell, 'align' => ''];
     $headerRow['total_effort'] = 'Total effort (PY)';
     $cols['total_cost'] = ['width' => $widthPerCell, 'align' => ''];
     $headerRow['total_cost'] = 'Total cost (k€)';
     //We always create the merged document from the draft
     $rows[] = $headerRow;
     $totals = ['d_affiliation' => 'Totals'];
     foreach ($affiliations[$country->getId()] as $affiliationService) {
         $totalEffortPerAffiliation = 0;
         $rowContent = ['d_affiliation' => $affiliationService->getAffiliation()->getOrganisation()->getOrganisation()];
         foreach ($project->getWorkpackage() as $workPackage) {
             if (!is_null($workPackage->getDateEnd())) {
                 continue;
             }
             $key = 'wp_' . $workPackage->getId();
             if (!array_key_exists($key, $totals)) {
                 $totals[$key] = 0;
             }
             switch ($this->documentType) {
                 case self::DOCUMENT_TYPE_PROPOSAL:
                     $effortPerAffiliationAndWorkpackage = $this->getProjectService()->findTotalEffortByWorkpackageAndAffiliation($workPackage, $affiliationService->getAffiliation());
                     break;
                 case self::DOCUMENT_TYPE_VERSION:
                     $effortPerAffiliationAndWorkpackage = $this->getVersionService()->findTotalEffortVersionByWorkpackageAndAffiliationAndProjectVersion($workPackage, $affiliationService->getAffiliation(), $this->getVersionService()->getVersion());
                     break;
             }
             $rowContent[$key] = $this->formatEffort($effortPerAffiliationAndWorkpackage);
             $totalEffortPerAffiliation += $effortPerAffiliationAndWorkpackage;
             $totals[$key] += $this->formatEffort($effortPerAffiliationAndWorkpackage);
         }
         $rowContent['total_effort'] = $this->formatEffort($totalEffortPerAffiliation);
         switch ($this->documentType) {
             case self::DOCUMENT_TYPE_PROPOSAL:
                 $totalCostPerAffiliation = $this->getProjectService()->findTotalCostByAffiliation($affiliationService->getAffiliation());
                 break;
             case self::DOCUMENT_TYPE_VERSION:
                 $totalCostPerAffiliation = $this->getProjectService()->findTotalCostByAffiliation($affiliationService->getAffiliation());
                 break;
         }
         $rowContent['total_cost'] = $this->formatCost($totalCostPerAffiliation);
         if (!array_key_exists('total_effort', $totals)) {
             $totals['total_effort'] = 0;
         }
         if (!array_key_exists('total_cost', $totals)) {
             $totals['total_cost'] = 0;
         }
         //Add the totals to the totalColumn
         $totals['total_effort'] += $totalEffortPerAffiliation;
         $totals['total_cost'] += $totalCostPerAffiliation;
         $rows[] = $rowContent;
     }
     /***
      * Apply the formatting
      */
     $totals['total_effort'] = $this->formatEffort($totals['total_effort']);
     $totals['total_cost'] = $this->formatCost($totals['total_cost']);
     $rows[] = $totals;
     return ['cols' => $cols, 'rows' => $rows];
 }