/** * Check Presence of an organisation for a login user * If present, redirect to view-elements of an organisation * Else, redirect to add new organisation */ public function organisationDataAction() { $identity = Zend_Auth::getInstance()->getIdentity(); // Check organisation is present or not for a login user $organisationModelObj = new Model_Organisation(); $organisationId = $organisationModelObj->checkOrganisationPresent($identity->account_id); // Fetch default value for an organisation $model = new Model_Viewcode(); $rowSet = $model->getRowsByFields('default_field_values', 'account_id', $identity->account_id); $defaultValues = unserialize($rowSet[0]['object']); $default = $defaultValues->getDefaultFields(); // Check default value exist or not $wepModel = new Model_Wep(); $reporting_org_info['@reporting_org_name'] = $default['reporting_org']; $reporting_org_info['@reporting_org_ref'] = $default['reporting_org_ref']; $reporting_org_info['@reporting_org_type'] = $wepModel->fetchValueById('OrganisationType', $default['reporting_org_type'], 'Code'); $reporting_org_info['@reporting_org_lang'] = $wepModel->fetchValueById('Language', $default['reporting_org_lang'], 'Name'); $incomplete = false; foreach ($reporting_org_info as $key => $reportingOrgValue) { if (!$reportingOrgValue && $key != '@reporting_org_lang') { $incomplete = true; break; } } if ($incomplete) { //For admin user redirect to defaults page. if ($identity->role_id == 1) { $this->_helper->FlashMessenger->addMessage(array('message' => "Before you start entering organisation data\n you need to add some default values that will\n automatically be filled in for\n each organisation you report.")); $this->_redirect('wep/settings'); } else { // For other user redirect to dashboard. $this->_helper->FlashMessenger->addMessage(array('message' => "All information for Reporting Organisation\n is not provided .Please contact you organisation admin")); $this->_redirect('wep/dashborad'); } } if (!$organisationId) { $this->_redirect("organisation/add-organisation"); } $this->_redirect("organisation/view-elements/?parentId={$organisationId}"); }
/** * Update all reporting org values in activities and organisation data if changed in settings. */ public function settingsChange() { $identity = Zend_Auth::getInstance()->getIdentity(); //Get Activities $activities = $this->listAll('iati_activities', 'account_id', $identity->account_id); $activities_id = $activities[0]['id']; $activityArray = $this->listAll('iati_activity', 'activities_id', $activities_id); //Update Each Activity Reporting Org $activityReportingOrg = new Model_ReportingOrg(); $activityHashModel = new Model_ActivityHash(); $activityModel = new Model_Activity(); foreach ($activityArray as $key => $activity) { $activityReportingOrg->updateReportingOrg($activity['id']); $updated = $activityHashModel->updateActivityHash($activity['id']); if ($updated) { //Update each activity: last updated time $wepModel = new Model_Wep(); $activityData['id'] = $activity['id']; $activityData['@last_updated_datetime'] = date('Y-m-d H:i:s'); $wepModel->updateRowsToTable('iati_activity', $activityData); } } //Get Organisation Id $organisationModelObj = new Model_Organisation(); $organisationId = $organisationModelObj->checkOrganisationPresent($identity->account_id); // If organisation exists if ($organisationId) { //Update Organisation Reporting Org $organisationReportingOrg = new Model_OrganisationDefaultElement(); $organisationReportingOrg->updateElementData('ReportingOrg', $organisationId); //Update Organisation Hash $organisationHashModel = new Model_OrganisationHash(); $update = $organisationHashModel->updateHash($organisationId); if ($update) { //Update organisation: last updated time $wepModel = new Model_Wep(); $organisationData['id'] = $organisationId; $organisationData['@last_updated_datetime'] = date('Y-m-d h:i:s'); $wepModel->updateRowsToTable('iati_organisation', $organisationData); } } $modelRegistryInfo = new Model_RegistryInfo(); $registryInfo = $modelRegistryInfo->getOrgRegistryInfo($identity->account_id); if ($registryInfo && $registryInfo->publisher_id) { $pub = new Iati_WEP_Publish($identity->account_id, $registryInfo->publisher_id, $registryInfo->publishing_type); $pub->publish(); } }
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; }