コード例 #1
0
 public function savePublishedDataInActivityRegistry($publishedFile)
 {
     $files = $publishedFile->published_activities;
     foreach ($files as $xmlFile) {
         $activityId = array_last(explode('-', explode('.', $xmlFile)[0]), function ($value) {
             return true;
         });
         $transaction = [];
         $recipientCountry = [];
         $recipientRegion = [];
         $title = [];
         $filePath = sprintf('%s%s%s', public_path('files'), config('filesystems.xml'), $xmlFile);
         if (file_exists($filePath)) {
             $xml = simplexml_load_string(file_get_contents($filePath));
             $xml = json_decode(json_encode($xml), true);
             if (isset($xml['iati-activity']['transaction'])) {
                 $xmlTransaction = $xml['iati-activity']['transaction'];
                 $transaction = $this->activityManager->getTransactionForBulk($xmlTransaction);
             }
             if (isset($xml['iati-activity']['recipient-country'])) {
                 $xmlRecipientCountry = $xml['iati-activity']['recipient-country'];
                 $recipientCountry = $this->activityManager->getRecipientCountryForBulk($xmlRecipientCountry);
             }
             $activityStatus = '';
             if (is_array($xml['iati-activity']['activity-status'])) {
                 $activityStatus = $xml['iati-activity']['activity-status']['@attributes']['code'];
             }
             $identifier = $xml['iati-activity']['iati-identifier'];
             if (is_array($xml['iati-activity']['title'])) {
                 if (count($xml['iati-activity']['title']['narrative']) == 1) {
                     $title = $xml['iati-activity']['title']['narrative'];
                 } elseif (count($xml['iati-activity']['title']['narrative']) > 1) {
                     $title = $xml['iati-activity']['title']['narrative'][0];
                 }
             }
             $xmlSector = is_array($xml['iati-activity']['sector']) ? $xml['iati-activity']['sector'] : [];
             $sector = $this->activityManager->getSectorForBulk($xmlSector);
             $jsonData = $this->activityManager->convertIntoJson($transaction, $activityStatus, $recipientRegion, $recipientCountry, $sector, $title, $identifier);
             $this->activityManager->saveBulkPublishDataInActivityRegistry($activityId, $jsonData);
         }
     }
 }