Ejemplo n.º 1
0
 protected function generateElementXml($elementData, $parent)
 {
     $eleName = $this->getXmlName();
     $data = $this->getElementsIatiData($elementData);
     if (!$this->hasData($data) && empty($this->childElements)) {
         return;
     }
     //Donot generate xml if no iati data and no child
     if ($data['text']) {
         $data['text'] = Iati_Core_Codelist::getCodeByAttrib($this->className, '@xml_lang', $data['text']);
     } else {
         return;
     }
     $xmlObj = $parent->addChild($eleName, preg_replace('/&(?!\\w+;)/', '&', $data['text']));
     if ($this->hasData($data)) {
         $xmlObj = $this->addElementsXmlAttribsFromData($xmlObj, $data);
     }
     return $xmlObj;
 }
Ejemplo n.º 2
0
 protected function prepareReportingOrgSimpleFormat($activityId)
 {
     $returnData = array();
     $element = new Iati_Aidstream_Element_Activity_ReportingOrg();
     $data = $element->fetchData($activityId, true);
     $returnData['reporting-organisation'] = $data['text'];
     $returnData['reporting-organisation-ref'] = $data['@ref'];
     $returnData['reporting-org-type'] = $data['@type'] ? Iati_Core_Codelist::getCodeByAttrib('ReportingOrg', '@type', $data['@type']) : '';
     return $returnData;
 }
Ejemplo n.º 3
0
 /**
  * Loops through the data and adds each attribute to the simpleXmlObject.
  * @param $xmlObj SimpleXMLElement object to which attribute is to be added.
  * @param $data array of attribs with attrib name as key.
  */
 public function addElementsXmlAttribsFromData($xmlObj, $data)
 {
     if (!is_array($data)) {
         return $xmlObj;
     }
     $sectorCode = false;
     foreach ($data as $name => $value) {
         if (in_array($name, $this->iatiAttribs) && $name != 'text') {
             if ($value == "") {
                 continue;
             }
             $name = preg_replace("/^@/", '', $name);
             if ($name == "xml_lang") {
                 $value = Iati_Core_Codelist::getCodeByAttrib($this->className, '@xml_lang', $value);
                 $name = preg_replace('/_/', ':', $name);
                 $xmlObj->addAttribute($name, $value, "http://www.w3.org/XML/1998/namespace");
             } elseif ($name == "currency" || $name == "default_currency") {
                 $value = Iati_Core_Codelist::getCodeByAttrib("Activity_default", '@currency', $value);
                 $name = preg_replace('/_/', '-', $name);
                 $xmlObj->addAttribute($name, $value);
             } elseif ($name == 'last_updated_datetime') {
                 // Convert last updated date to UTC format
                 $name = preg_replace('/_/', '-', $name);
                 $gmDateValue = gmdate('c', strtotime($value));
                 if ($gmDateValue) {
                     $xmlObj->addAttribute($name, $gmDateValue);
                 }
             } elseif ($name == 'vocabulary') {
                 // For DAC vocabulary
                 if ($value == 3) {
                     $sectorCode = true;
                 }
                 $value = Iati_Core_Codelist::getCodeByAttrib($this->className, $name, $value);
                 $name = preg_replace('/_/', '-', $name);
                 $xmlObj->addAttribute($name, $value);
             } elseif ($name == 'code') {
                 if ($this->className == 'Sector') {
                     if ($sectorCode) {
                         $value = Iati_Core_Codelist::getCodeByAttrib($this->className, $name, $value);
                         $name = preg_replace('/_/', '-', $name);
                         $xmlObj->addAttribute($name, $value);
                     } else {
                         $name = preg_replace('/_/', '-', $name);
                         $xmlObj->addAttribute($name, $value);
                     }
                 } else {
                     $value = Iati_Core_Codelist::getCodeByAttrib($this->className, $name, $value);
                     $name = preg_replace('/_/', '-', $name);
                     $xmlObj->addAttribute($name, $value);
                 }
             } else {
                 $value = Iati_Core_Codelist::getCodeByAttrib($this->className, $name, $value);
                 $name = preg_replace('/_/', '-', $name);
                 $xmlObj->addAttribute($name, $value);
             }
         }
     }
     return $xmlObj;
 }
Ejemplo n.º 4
0
 /**
  * 
  * Function to fetch data from the local database and generates array of activities base on segmentation.
  */
 public function getDataToPublish()
 {
     $activityCollection = new Iati_ActivityCollection();
     $activitiesId = $activityCollection->getPublishedActivityCollection($this->publisherOrgId);
     if ($this->segmented) {
         /**
          *Seperate activities by country or region
          *
          *foreach activity
          *if number of country is 1 i.e count of country is one and size is not zero, use country code 
          *else
          *  if number of region is 1 i.e count of region is one and size is not zero, use region code 
          *  else if number of regions is greater than 1 , use 998
          *  else
          *      if number of countries is 0, use 998
          *      else use the country with max percentage, if no percentage use first inserted.
          **/
         $segmentedActivities = array();
         foreach ($activitiesId as $activityId) {
             $recipientCountryObj = new Iati_Aidstream_Element_Activity_RecipientCountry();
             $countries = $recipientCountryObj->fetchData($activityId, true);
             $recipientRegionObj = new Iati_Aidstream_Element_Activity_RecipientRegion();
             $regions = $recipientRegionObj->fetchData($activityId, true);
             if ($countries[0]['@code']) {
                 $countryCode = Iati_Core_Codelist::getCodeByAttrib('RecipientCountry', '@code', $countries[0]['@code']);
             }
             if ($regions[0]['@code']) {
                 $regionCode = Iati_Core_Codelist::getCodeByAttrib('RecipientRegion', '@code', $regions[0]['@code']);
             }
             if (count($countries) == 1) {
                 $segmentedActivities[$countryCode][] = $activityId;
             } else {
                 if (count($regions) == 1) {
                     $segmentedActivities[$regionCode][] = $activityId;
                 } elseif (count($regions) > 1) {
                     $segmentedActivities[998][] = $activityId;
                 } else {
                     if (count($countries) == 0) {
                         $segmentedActivities[998][] = $activityId;
                     } else {
                         $maxPercent = '';
                         foreach ($countries as $country) {
                             $percent = $country['@percentage'];
                             if ($percent > $maxPercent) {
                                 $maxPercent = $percent;
                                 $maxPercentCountry = Iati_Core_Codelist::getCodeByAttrib('RecipientCountry', '@code', $country['@code']);
                             }
                         }
                         if ($maxPercentCountry) {
                             $segmentedActivities[$maxPercentCountry][] = $activityId;
                         } else {
                             $segmentedActivities[$countryCode][] = $activityId;
                         }
                     }
                 }
             }
         }
         return $segmentedActivities;
     } else {
         return $activitiesId;
     }
 }