/**
  * it validates activity schema according to version standard
  * @param      $id
  * @param null $version
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function validateActivity($id, $version = null)
 {
     $activityData = $this->activityManager->getActivityData($id);
     $settings = $this->settingsManager->getSettings($activityData['organization_id']);
     $transactionData = $this->activityManager->getTransactionData($id);
     $resultData = $this->activityManager->getResultData($id);
     $organization = $this->organizationManager->getOrganization($activityData->organization_id);
     $orgElem = $this->organizationManager->getOrganizationElement();
     $activityElement = $this->activityManager->getActivityElement();
     if ($version == null) {
         $version = config('app.default_version_name');
     }
     return $this->validateCompletedActivity($activityData, $transactionData, $resultData, $settings, $activityElement, $orgElem, $organization, $version);
 }
 /**
  * generate new xml files with published activities
  * @param $newPublishingType
  * @param $activities
  */
 protected function generateNewFiles($newPublishingType, $activities)
 {
     $activityElement = $this->activityManager->getActivityElement();
     $xmlService = $activityElement->getActivityXmlService();
     $orgIdentifier = $this->organization->reporting_org[0]['reporting_organization_identifier'];
     $publisherId = $this->settings->registry_info[0]['publisher_id'];
     if ($newPublishingType == "unsegmented") {
         $filename = $publisherId . '-activities.xml';
         $activitiesXml = [];
         foreach ($activities as $activity) {
             if ($activity->activity_workflow == 3) {
                 $publishedActivity = sprintf('%s-%s.xml', $publisherId, $activity->id);
                 $this->generateXmlIfDoesNotExist($publishedActivity, $activity);
                 $activitiesXml[] = $publishedActivity;
             }
         }
         $xmlService->getMergeXml($activitiesXml, $filename);
         $xmlService->savePublishedFiles($filename, Session::get('org_id'), $activitiesXml);
     } elseif ($newPublishingType == "segmented") {
         $activitiesXml = [];
         foreach ($activities as $activity) {
             if ($activity->activity_workflow == 3) {
                 $filename = sprintf('%s-%s.xml', $publisherId, $xmlService->segmentedXmlFile($activity));
                 $publishedActivity = sprintf('%s-%s.xml', $publisherId, $activity->id);
                 $this->generateXmlIfDoesNotExist($publishedActivity, $activity);
                 $activitiesXml[$filename][] = $publishedActivity;
             }
         }
         foreach ($activitiesXml as $filename => $xmlFiles) {
             $xmlService->getMergeXml($xmlFiles, $filename);
             $xmlService->savePublishedFiles($filename, Session::get('org_id'), $xmlFiles);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * generate activity xml
  * @param Activity $activity
  */
 public function generateXml(Activity $activity)
 {
     $activity_id = $activity->id;
     $org_id = $activity->organization_id;
     $settings = $this->getSettings($org_id);
     $transactionData = $this->activityManager->getTransactionData($activity_id);
     $resultData = $this->activityManager->getResultData($activity_id);
     $organization = $this->organizationManager->getOrganization($org_id);
     $orgElem = $this->organizationManager->getOrganizationElement();
     $activityElement = $this->activityManager->getActivityElement();
     $xmlService = $activityElement->getActivityXmlService();
     $xmlService->generateActivityXml($activity, $transactionData, $resultData, $settings, $activityElement, $orgElem, $organization);
 }
 /** Returns the filename that is generated when activity is published based on publishing type.
  * @param $organization_id
  * @param $activity
  * @return string
  */
 public function getPublishedActivityFilename($organization_id, $activity)
 {
     $settings = $this->settings->where('organization_id', $organization_id)->first();
     $publisherId = $settings->registry_info[0]['publisher_id'];
     $publishingType = $settings->publishing_type;
     if ($publishingType != "segmented") {
         $endName = 'activities';
     } else {
         $activityElement = $this->activityManager->getActivityElement();
         $xmlService = $activityElement->getActivityXmlService();
         $endName = $xmlService->segmentedXmlFile($activity);
     }
     $filename = sprintf('%s' . '-' . '%s.xml', $publisherId, $endName);
     return $filename;
 }
Ejemplo n.º 5
0
 /**
  * Publish an Activity.
  *
  * If the auto-publish option is set, the Activity data is published into the IATI Registry.
  * @param $activity
  * @param $details
  * @return bool
  */
 public function publish($activity, array $details)
 {
     try {
         $organization = $activity->organization;
         $settings = $organization->settings;
         $version = $settings->version;
         $this->xmlServiceProvider->initializeGenerator($version)->generate($activity, $this->organizationManager->getOrganizationElement(), $this->activityManager->getActivityElement());
         if (getVal($settings['registry_info'], [0, 'publish_files']) == 'yes') {
             $this->publisher->publishFile($organization->settings['registry_info'], $this->organizationDataProvider->fileBeingPublished($activity->id), $organization, $organization->settings->publishing_type);
             $this->activityManager->activityInRegistry($activity);
             $this->twitter->post($organization->settings, $organization);
         }
         $this->update($details, $activity);
         return true;
     } catch (\ErrorException $exception) {
         $this->logger->error($exception);
         return null;
     } catch (Exception $exception) {
         $this->logger->error($exception);
         return array_first(explode("\n", $exception->getMessage()), function () {
             return true;
         });
     }
 }