Exemplo n.º 1
0
 /**
  *Function to save activity
  *
  * @todo break this function to smaller functions.
  */
 public function addActivity($data, $default)
 {
     $this->defaults = $default;
     $identity = Zend_Auth::getInstance()->getIdentity();
     //var_dump($data);exit;
     $model = $this->model;
     $modelActivity = new Model_Activity();
     $activitiesId = $model->getIdByField('iati_activities', 'account_id', $identity->account_id);
     //Create activity and its defaults
     $iatiIdentifier['activity_identifier'] = $data['identifier'];
     $iatiIdentifier['iati_identifier'] = $default['reporting_org_ref'] . "-" . trim($data['identifier']);
     $activityId = $modelActivity->createActivity($activitiesId, $default, $iatiIdentifier);
     $this->activityId = $activityId;
     //Create Recipient Organisation( this is set to nepal)
     $recOrg = array();
     $recOrg['@code'] = 156;
     $recOrg['activity_id'] = $activityId;
     $model->insertRowsToTable('iati_recipient_country', $recOrg);
     //Create title
     $title['text'] = $data['title'];
     $title['@xml_lang'] = $default['language'];
     $title['activity_id'] = $activityId;
     $model->insertRowsToTable('iati_title', $title);
     //Create Description
     $description['@type'] = 1;
     //@todo check.
     $description['@xml_lang'] = $default['language'];
     $description['text'] = $data['description'];
     $description['activity_id'] = $activityId;
     $model->insertRowsToTable('iati_description', $description);
     //Create funding org
     // Funding org data is received as a comma seperated value
     if ($data['funding_org']) {
         $fundingOrgs = explode(',', $data['funding_org']);
         foreach ($fundingOrgs as $fundingOrg) {
             $funding = array();
             $funding['@role'] = 1;
             $funding['text'] = $fundingOrg;
             $funding['@xml_lang'] = $default['language'];
             $funding['activity_id'] = $activityId;
             $model->insertRowsToTable('iati_participating_org', $funding);
         }
     }
     //Create Start date
     if ($data['start_date']) {
         $startDate['@iso_date'] = $data['start_date'];
         $startDate['@type'] = 3;
         $startDate['@xml_lang'] = $default['language'];
         $startDate['text'] = '';
         $startDate['activity_id'] = $activityId;
         $model->insertRowsToTable('iati_activity_date', $startDate);
     }
     //Create End date
     if ($data['end_date']) {
         $endDate['@iso_date'] = $data['end_date'];
         $endDate['@type'] = 4;
         $endDate['@xml_lang'] = $default['language'];
         $endDate['text'] = '';
         $endDate['activity_id'] = $activityId;
         $model->insertRowsToTable('iati_activity_date', $endDate);
     }
     //Create Sector
     if ($this->hasValue($data['sector'])) {
         foreach ($data['sector'] as $sectorData) {
             $sector['@code'] = $sectorData;
             $sector['@vocabulary'] = 3;
             // @todo check
             $sector['activity_id'] = $activityId;
             $model->insertRowsToTable('iati_sector', $sector);
         }
     }
     //Create Status
     $this->saveStatus($data);
     //Create Document
     $this->addDocument($data['document_wrapper']['document']);
     //Create Location
     $this->addLocation($data['location_wrapper']['location']);
     //Create Budget
     $this->addBudget($data['budget_wrapper']['budget']);
     //Incomming Fund
     $this->addIncommingFund($data['incomming_fund_wrapper']['incommingFund']);
     //Expenditure
     $this->addExpenditure($data['expenditure_wrapper']['expenditure']);
     //Result
     $this->saveResult($data['result_wrapper']['result']);
     return $activityId;
 }
Exemplo n.º 2
0
 public function editActivityAction()
 {
     $identity = Zend_Auth::getInstance()->getIdentity();
     if ($_GET) {
         $wepModel = new Model_Wep();
         if (isset($_GET['activities_id'])) {
             $exists = $wepModel->getRowById('iati_activities', 'id', $_GET['activities_id']);
             if (!$exists) {
                 $this->_helper->FlashMessenger->addMessage(array('message' => "Activities does not exist."));
                 $this->_redirect('/user/user/login');
             }
             $activities_id = $this->getRequest()->getParam('activities_id');
             $rowSet = $wepModel->getRowsByFields('default_field_values', 'account_id', $identity->account_id);
             $defaultValues = unserialize($rowSet[0]['object']);
             $default = $defaultValues->getDefaultFields();
             $activity['xml_lang'] = $default['language'];
             $activity['default_currency'] = $default['currency'];
             $activity['hierarchy'] = $default['hierarchy'];
             $activity['linked_data_uri'] = $default['linked_data_default'];
             $form = new Form_Wep_IatiActivity();
             $form->add('add', $identity->account_id);
             $form->populate(array('reporting_org' => $default['reporting_org_ref']));
         }
         if (isset($_GET['activity_id'])) {
             $exists = $wepModel->getRowById('iati_activity', 'id', $_GET['activity_id']);
             if (!$exists) {
                 $this->_helper->FlashMessenger->addMessage(array('warning' => "Activity does not exist."));
                 $this->_redirect('/user/user/login');
             }
             $activity_id = $this->getRequest()->getParam('activity_id');
             $rowSet = $wepModel->getRowsByFields('iati_activity', 'id', $activity_id);
             $activity['xml_lang'] = $rowSet[0]['@xml_lang'];
             $activity['default_currency'] = $rowSet[0]['@default_currency'];
             $activity['hierarchy'] = $rowSet[0]['@hierarchy'];
             $activity['activities_id'] = $rowSet[0]['activities_id'];
             $activity['linked_data_uri'] = $rowSet[0]['@linked_data_uri'];
             $form = new Form_Wep_EditIatiActivity();
             $form->edit($identity->account_id);
             $aActivityInfo = $wepModel->listAll('iati_activity', 'id', $activity_id);
             $activityInfo = $aActivityInfo[0];
             $iati_identifier_row = $wepModel->getRowById('iati_identifier', 'activity_id', $activity_id);
             $activityInfo['iati_identifier'] = $iati_identifier_row['text'];
             $title_row = $wepModel->getRowById('iati_title', 'activity_id', $activity_id);
             $activityInfo['iati_title'] = $title_row['text'];
             $this->view->activityInfo = $activityInfo;
         }
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             if (!$form->isValid($formData)) {
                 $form->populate($formData);
             } else {
                 if (isset($_GET['activities_id'])) {
                     $default['language'] = $formData['xml_lang'];
                     $default['currency'] = $formData['default_currency'];
                     $default['hierarchy'] = $formData['hierarchy'];
                     $default['linked_data_default'] = $formData['linked_data_uri'];
                     $iatiIdentifier = array();
                     $iatiIdentifier['iati_identifier'] = $formData['iati_identifier_text'];
                     $iatiIdentifier['activity_identifier'] = $formData['activity_identifier'];
                     $activityModel = new Model_Activity();
                     $activityId = $activityModel->createActivity($activities_id, $default, $iatiIdentifier);
                     //Create Activity Hash
                     $activityHashModel = new Model_ActivityHash();
                     $updated = $activityHashModel->updateActivityHash($activityId);
                     $this->_helper->FlashMessenger->addMessage(array('message' => "Activity Sucessfully Created."));
                     $this->_redirect('activity/view-activity-info/?activity_id=' . $activityId);
                 }
                 if (isset($_GET['activity_id'])) {
                     //$data['activities_id'] = $rowSet[0]['activities_id'];
                     $data['id'] = $activity_id;
                     $data['@xml_lang'] = $formData['xml_lang'];
                     $data['@default_currency'] = $formData['default_currency'];
                     $data['@hierarchy'] = $formData['hierarchy'];
                     $data['@linked_data_uri'] = $formData['linked_data_uri'];
                     $result = $wepModel->updateRowsToTable('iati_activity', $data);
                     $wepModel = new Model_Wep();
                     $activityHashModel = new Model_ActivityHash();
                     $updated = $activityHashModel->updateActivityHash($activity_id);
                     if (!$updated) {
                         $type = 'info';
                         $message = 'No Changes Made';
                     } else {
                         //change state to editing
                         $db = new Model_ActivityStatus();
                         $db->updateActivityStatus($activity_id, Iati_WEP_ActivityState::STATUS_DRAFT);
                         $type = 'message';
                         $message = "Activity overridden";
                     }
                     $this->_helper->FlashMessenger->addMessage(array($type => $message));
                 }
                 $this->_redirect('activity/view-activity-info/?activity_id=' . $activity_id);
             }
             //end of inner if
         } else {
             $form->populate($activity);
         }
         $this->view->form = $form;
         $this->view->activity_id = $activity_id;
     }
 }