Example #1
0
 /**
  * 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();
     }
 }
Example #2
0
 public function updateStatusAction()
 {
     $ids = $this->getRequest()->getParam('ids');
     $state = $this->getRequest()->getParam('status');
     $redirect = $this->getRequest()->getParam('redirect');
     $activity_ids = explode(',', $ids);
     $db = new Model_ActivityStatus();
     if ($state == Iati_WEP_ActivityState::STATUS_PUBLISHED) {
         $identity = Zend_Auth::getInstance()->getIdentity();
         $account_id = $identity->account_id;
         $modelRegistryInfo = new Model_RegistryInfo();
         $registryInfo = $modelRegistryInfo->getOrgRegistryInfo($account_id);
         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. IATI\n                                       Activities files could not be created. Please go to\n                                       <a href='{$this->view->baseUrl()}/wep/settings'>Settings</a>\n                                       to add publisher id."));
             } else {
                 $db->updateActivityStatus($activity_ids, (int) $state);
                 $pub = new Iati_WEP_Publish($account_id, $registryInfo->publisher_id, $registryInfo->publishing_type);
                 $pub->publish();
                 if ($registryInfo->update_registry) {
                     if (!$registryInfo->api_key) {
                         $this->_helper->FlashMessenger->addMessage(array('error' => "Api Key not found.\n                                               Activities could not be registered in\n                                               IATI Registry. Please go to\n                                               <a href='{$this->view->baseUrl()}/wep/settings'>Settings</a>\n                                               to add API key."));
                     } else {
                         $modelPublished = new Model_Published();
                         $files = $modelPublished->getPublishedInfo($account_id);
                         $published = Model_Registry::publish($files, $account_id, $registryInfo);
                         if ($published['error']) {
                             $this->_helper->FlashMessenger->addMessage(array('error' => $published['error']));
                         } else {
                             $this->_helper->FlashMessenger->addMessage(array('message' => "Activities have been\n                                                   registered to IATI registry."));
                         }
                     }
                 } else {
                     $this->_helper->FlashMessenger->addMessage(array('message' => "IATI Activities files\n                                           have been created. <a href='" . $this->view->baseUrl() . "/wep/list-published-files'>View your\n                                           published files</a>"));
                 }
             }
         }
     } else {
         $db->updateActivityStatus($activity_ids, (int) $state);
     }
     if ($redirect) {
         $this->_redirect($redirect, array('prependBase' => false));
     }
     $this->_redirect('wep/view-activities');
 }