Esempio n. 1
0
 /**
  * @return string
  */
 public function parseInvoiceName()
 {
     return sprintf("%s %s", $this->call, $this->program->getProgram());
 }
Esempio n. 2
0
 /**
  * @param Program $program
  *
  * @return string
  */
 public function __invoke(Program $program)
 {
     set_time_limit(0);
     $document = new DOMDocument('1.0', 'UTF-8');
     $eureka = $document->createElement('EurekaCluster');
     $eureka->setAttribute('version', '1.0');
     $eureka->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:noNamespaceSchemaLocation', 'http://clusters.eurekanetwork.org/resources/xsd/EurekaCluster.xsd');
     $document->appendChild($eureka);
     /*
      * Add the status of the export
      */
     $status = $document->createElement('status', 'OK');
     $status->setAttribute('code', '200');
     $eureka->appendChild($status);
     /*
      * Append the result of the export itself
      */
     $result = $document->createElement('result');
     /*
      * Add the details of the request
      */
     $request = $document->createElement('request');
     $request->appendChild($document->createElement('type', 'rest'));
     $request->appendChild($document->createElement('url', 'https://itea3.org'));
     $request->appendChild($document->createElement('query', ''));
     $result->appendChild($request);
     /*
      * Add the cluster details
      */
     $cluster = $document->createElement('cluster', $program->getProgram());
     $cluster->setAttribute('cluster_id', $program->getNumber());
     $result->appendChild($cluster);
     /*
      * Add the projects
      */
     $projects = $document->createElement('projects');
     /*
      * Add each project.
      *
      * @var Project
      */
     foreach ($this->getProjectService()->findProjectByProgram($program, ProjectService::WHICH_LABELLED)->getQuery()->getResult() as $project) {
         $projectService = $this->getProjectService()->setProject($project);
         //Get some required versions
         $fpp = $this->getVersionService()->findLatestVersionByType($projectService->getProject(), $this->getVersionService()->findEntityById('Version\\Type', Type::TYPE_FPP));
         /*
          * Find the latest version which was approved
          */
         $version = $this->getProjectService()->getLatestProjectVersion(null, null, false, true);
         $this->getVersionService()->setVersion($version);
         /*
          * Keep local variables with heavy database intensive numbers
          */
         $totalCost = $this->getVersionService()->findTotalCostVersionByProjectVersion($version);
         $totalEffort = $this->getVersionService()->findTotalEffortVersionByProjectVersion($version);
         $projectElement = $document->createElement('project');
         /*
          * Go over the project information
          */
         $projectElement->appendChild($document->createElement('project_id', $projectService->getProject()->getNumber()));
         $projectElement->appendChild($document->createElement('title', $this->xmlEntities($projectService->getProject()->getTitle())));
         $summary = $document->createElement('summary');
         $summary->appendChild($document->createCDATASection($this->xmlEntities($projectService->getProject()->getSummary())));
         $projectElement->appendChild($summary);
         $projectElement->appendChild($document->createElement('acronym', substr($this->xmlEntities($projectService->getProject()->getProject()), 0, 20)));
         $projectElement->appendChild($document->createElement('label_date', $fpp->getDateReviewed()->format('Y-m-d')));
         if (!is_null($projectService->parseOfficialDateStart())) {
             $projectElement->appendChild($document->createElement('start_date', $projectService->parseOfficialDateStart()->format('Y-m-d')));
         } else {
             /*
              * @todo, the XSD needs an upgrade to have these values passed correctly
              */
             $projectElement->appendChild($document->createElement('start_date', '1970-01-01'));
         }
         if (!is_null($version->getDateStart()) and !is_null($version->getDateEnd())) {
             $projectElement->appendChild($document->createElement('duration', $this->getVersionService()->parseDuration()));
         } else {
             $projectElement->appendChild($document->createElement('duration', 0));
         }
         $projectElement->appendChild($document->createElement('total_cost', ceil($totalCost)));
         $projectElement->appendChild($document->createElement('total_man_year', ceil($totalEffort)));
         if (!is_null($projectService->parseOfficialDateEnd())) {
             $projectElement->appendChild($document->createElement('end_date', $projectService->parseOfficialDateEnd()->format('Y-m-d')));
         } else {
             /*
              * @todo, the XSD needs an upgrade to have these values passed correctly
              */
             $projectElement->appendChild($document->createElement('end_date', '1970-01-01'));
         }
         /*
          * Include an element to indicate the the project is withdrawn (cancelled)
          */
         if ($projectService->isCancelled()) {
             $projectElement->appendChild($document->createElement('withdrawal_date', $version->getDateReviewed()->format('Y-m-d')));
         } else {
             $projectElement->appendChild($document->createElement('withdrawal_date', null));
         }
         /*
          * Do a very simple mapping of the status of the project
          */
         switch (strtolower($projectService->parseStatus())) {
             case 'labelled':
                 $status = 'LAB';
                 break;
             case 'running':
                 $status = 'RUN';
                 break;
             case 'cancelled':
                 $status = 'FIN';
                 break;
             default:
                 $status = 'FIN';
         }
         /*
          * Define the role in the project (Main or Partner)
          */
         $statusName = $document->createElement('status_name');
         $statusName->setAttribute('status_id', $status);
         $projectElement->appendChild($statusName);
         //Add now the organisations.
         $organisationElement = $document->createElement('organisations');
         /*
          * @var Affiliation
          */
         foreach ($this->getAffiliationService()->findAffiliationByProjectVersionAndWhich($version, AffiliationService::WHICH_ALL) as $affiliation) {
             $affiliationElement = $document->createElement('prj_organisation');
             $affiliationElement->setAttribute('org_id', $affiliation->getOrganisation()->getId());
             /*
              * Go over the partner information
              */
             $affiliationElement->appendChild($document->createElement('org_name', $this->xmlEntities($affiliation->getOrganisation()->getOrganisation())));
             /*
              * Mapping of the organisation type on the EUREKA values
              */
             $orgType = $document->createElement('org_type');
             switch ($affiliation->getOrganisation()->getType()->getId()) {
                 case OrganisationType::TYPE_SME:
                     $typeNumber = 'S';
                     break;
                 case OrganisationType::TYPE_LARGE_INDUSTRY:
                 case OrganisationType::TYPE_IFC:
                     $typeNumber = 'I';
                     break;
                 case OrganisationType::TYPE_RESEARCH:
                     $typeNumber = 'R';
                     break;
                 case OrganisationType::TYPE_UNIVERSITY:
                     $typeNumber = 'U';
                     break;
                 case OrganisationType::TYPE_GOVERNMENT:
                     $typeNumber = 'A';
                     break;
                 case OrganisationType::TYPE_OTHER:
                 default:
                     $typeNumber = 'O';
             }
             $orgType->setAttribute('org_type_id', $typeNumber);
             $affiliationElement->appendChild($orgType);
             /*
              * Define the role in the project (Main or Partner)
              */
             $role = $document->createElement('role');
             $role->setAttribute('role_id', $affiliation->getContact()->getId() === $project->getContact()->getId() ? 'M' : 'P');
             $affiliationElement->appendChild($role);
             /*
              * Add the country
              */
             $country = $document->createElement('country', $affiliation->getOrganisation()->getCountry()->getIso3());
             $country->setAttribute('code', $affiliation->getOrganisation()->getCountry()->getCd());
             $affiliationElement->appendChild($country);
             /*
              * Add the country
              */
             $contactService = $this->getContactService()->setContact($affiliation->getContact());
             $affiliationElement->appendChild($document->createElement('zip_code', !is_null($contactService->getMailAddress()) ? $contactService->getMailAddress()->getAddress()->getZipCode() : '0000'));
             $affiliationElement->appendChild($document->createElement('contact_email', $this->xmlEntities($contactService->getContact()->getEmail())));
             $affiliationElement->appendChild($document->createElement('contribution_cost', ceil($this->getVersionService()->findTotalCostVersionByAffiliationAndVersion($affiliation, $version))));
             $affiliationElement->appendChild($document->createElement('contribution_man_year', $this->getVersionService()->findEffortVersionByAffiliationAndVersion($affiliation, $version)));
             $affiliationElement->appendChild($document->createElement('VAT_number', !is_null($affiliation->getOrganisation()->getFinancial()) ? $affiliation->getOrganisation()->getFinancial()->getVat() : null));
             $affiliationElement->appendChild($document->createElement('partner_withdrawn_date', !is_null($affiliation->getDateEnd()) ? $affiliation->getdateEnd()->format('Y-m-d') : null));
             $organisationElement->appendChild($affiliationElement);
         }
         $projectElement->appendChild($organisationElement);
         $projects->appendChild($projectElement);
     }
     $result->appendChild($projects);
     $eureka->appendChild($result);
     return $document->saveXML();
 }