Exemplo n.º 1
0
 /**
  * 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']}");
 }