public function downloadXmlAction() { $name = $this->_getParam('name'); $identity = Zend_Auth::getInstance()->getIdentity(); $obj = new Iati_Core_Xml(); if ($name == 'Activity') { $wepModel = new Model_Wep(); $activities = $wepModel->listAll('iati_activities', 'account_id', $identity->account_id); $activities_id = $activities[0]['id']; $activityArray = $wepModel->listAll('iati_activity', 'activities_id', $activities_id); $index = 0; foreach ($activityArray as $key => $activity) { $activity_array[$index] = $activity['id']; $index++; } $xmlOutput = $obj->generateXml($name, $activity_array); $filename = 'iati_activity'; } elseif ($name == 'Organisation') { $organisationModelObj = new Model_Organisation(); $organisationId = $organisationModelObj->checkOrganisationPresent($identity->account_id); $organisationIds = explode(',', $organisationId); $xmlOutput = $obj->generateXml($name, $organisationIds); $filename = 'iati_organisation_data'; } else { exit('Invalid name for download.'); } header('Content-Type: text/xml'); header('Content-Disposition: attachment;filename=' . $filename . '.xml'); echo $xmlOutput; exit; }
/** * Update State Of An Organisation */ public function updateStateAction() { $ids = $this->getRequest()->getParam('ids'); $state = $this->getRequest()->getParam('status'); $organisationIds = explode(',', $ids); $db = new Model_OrganisationState(); $not_valid = false; if ($not_valid) { $this->_helper->FlashMessenger->addMessage(array('warning' => "The organisation cannot be changed\n to the state. Please check that a state to be\n changed is valid for all selected organisations")); } else { if ($state == Iati_WEP_ActivityState::STATUS_PUBLISHED) { $identity = Zend_Auth::getInstance()->getIdentity(); $accountId = $identity->account_id; $modelRegistryInfo = new Model_RegistryInfo(); $registryInfo = $modelRegistryInfo->getOrgRegistryInfo($accountId); if (!$registryInfo) { $this->_helper->FlashMessenger->addMessage(array('error' => "Registry information not found.\n Please go to\n <a href='{$this->view->baseUrl()}/wep/settings'>Settings</a>\n to add registry info.")); } else { if (!$registryInfo->publisher_id) { $this->_helper->FlashMessenger->addMessage(array('error' => "Publisher Id not found.\n Xml files could not be created.\n Please go to\n <a href='{$this->view->baseUrl()}/wep/settings'>Settings</a>\n to add publisher id.")); } else { $db->updateOrganisationState($organisationIds, (int) $state); // Generate Xml $obj = new Iati_Core_Xml(); $fileName = $obj->generateFile('organisation', $organisationIds, $registryInfo->publisher_id); // Fetch last updated data's datetime $wepModel = new Model_Wep(); $organsationInfo = $wepModel->getRowsByFields('iati_organisation', 'id', $organisationIds[0]); $lastUpdateDatetime = $organsationInfo[0]['@last_updated_datetime']; //Set all status to 0 $modelPublished = new Model_OrganisationPublished(); $modelPublished->resetPublishedInfo($accountId); $organisationpublishedModel = new Model_OrganisationPublished(); $publishedData['publishing_org_id'] = $accountId; $publishedData['filename'] = $fileName; $publishedData['organisation_count'] = count($organisationIds); $publishedData['data_updated_datetime'] = $lastUpdateDatetime; $publishedData['published_date'] = date('Y-m-d H:i:s'); $publishedData['status'] = 1; $organisationpublishedModel->savePublishedInfo($publishedData); if ($registryInfo->update_registry) { if (!$registryInfo->api_key) { $this->_helper->FlashMessenger->addMessage(array('error' => "Api Key not found.\n Activities could not be registered\n in IATI Registry. Please go to\n <a href='{$this->view->baseUrl()}/wep/settings'>Settings</a>\n to add API key.")); } else { $reg = new Iati_Registry($registryInfo->publisher_id, $registryInfo->api_key); $organisationpublishedModel = new Model_OrganisationPublished(); $files = $organisationpublishedModel->getPublishedInfo($accountId); $published = Model_Registry::publish($files, $accountId, $registryInfo, true); if ($published['error']) { $this->_helper->FlashMessenger->addMessage(array('error' => $published['error'])); } else { $this->_helper->FlashMessenger->addMessage(array('message' => "Organisation\n published to IATI registry.")); } } } else { $this->_helper->FlashMessenger->addMessage(array('message' => "Organisation xml files created.")); } } } } else { $db->updateOrganisationState($organisationIds, (int) $state); } } $this->_redirect("organisation/view-elements/?parentId={$organisationIds['0']}"); }
/** * * Creates xml file using Iati_Core_Xml and saves them to local directory. * @param Array $activities Array of activities to be published. */ public function saveActivityXml($activitiesIdArray) { $file = strtolower($this->publisherId); if ($this->segmented) { $file .= "-" . strtolower($this->recipient); } else { $file .= "-activities"; } $file = preg_replace('/ /', '_', $file); $file = preg_replace('/,/', '', $file); $fileName = $file . ".xml"; $obj = new Iati_Core_Xml(); $fp = fopen($this->filePath . $fileName, 'w'); fwrite($fp, $obj->generateXml('Activity', $activitiesIdArray)); fclose($fp); return $fileName; }