public function duplicateActivityAction() { $identity = Zend_Auth::getInstance()->getIdentity(); $activityId = $this->_getParam('activity_id'); if (!$activityId) { $this->_helper->FlashMessenger->addMessage(array('error' => "No id provided.")); $this->_redirect('wep/view-activities'); } $activityClassObj = new Iati_Aidstream_Element_Activity(); $activityModel = new Model_Activity(); $wepModel = new Model_Wep(); $activities = $wepModel->listAll('iati_activities', 'account_id', $identity->account_id); $activities_id = $activities[0]['id']; $activityData = $activityClassObj->fetchData($activityId, false); $form = new Form_Wep_IatiIdentifier('add', $identity->account_id); $form->add('add', $identity->account_id); $form->populate(array('reporting_org' => $activityData['Activity']['ReportingOrg']['@ref'])); if ($data = $this->getRequest()->getPost()) { if (!$form->isValid($data)) { $form->populate($data); } else { $iatiIdentifier = array(); $iatiIdentifier['iati_identifier'] = $data['iati_identifier_text']; $iatiIdentifier['activity_identifier'] = $data['activity_identifier']; $newActivityId = $activityModel->duplicateActivity($activities_id, $activityId, $activityData['Activity'], $iatiIdentifier); } if ($newActivityId) { $this->_helper->FlashMessenger->addMessage(array('message' => "Activity duplication successful. View duplicated \n <a href='{$this->view->baseUrl()}/activity/view-activity-info/?activity_id={$newActivityId}'>activity</a>.")); $this->_redirect('/wep/view-activities'); } else { $this->_helper->FlashMessenger->addMessage(array('error' => 'Activity duplication failed.')); $this->_redirect('/wep/view-activities'); } } $this->view->form = $form; $this->view->activity_info = $activityData['Activity']; }
public function addActivityAction() { $identity = Zend_Auth::getInstance()->getIdentity(); if ($_GET) { $activities_id = $this->getRequest()->getParam('activities_id'); $wepModel = new Model_Wep(); $exists = $wepModel->getRowById('iati_activities', 'id', $_GET['activities_id']); if (!$exists) { $this->_helper->FlashMessenger->addMessage(array('message' => "Invalid Id.")); $this->_redirect('/user/user/login'); } } else { $wepModel = new Model_Wep(); $activities = $wepModel->listAll('iati_activities', 'account_id', $identity->account_id); $activities_id = $activities[0]['id']; } $model = new Model_Viewcode(); $rowSet = $model->getRowsByFields('default_field_values', 'account_id', $identity->account_id); $defaultValues = unserialize($rowSet[0]['object']); $default = $defaultValues->getDefaultFields(); $wepModel = new Model_Wep(); $activity_info['@xml_lang'] = $wepModel->fetchValueById('Language', $default['language'], 'Code'); $activity_info['@default_currency'] = $wepModel->fetchValueById('Currency', $default['currency'], 'Code'); $activity_info['@hierarchy'] = $default['hierarchy']; $activity_info['@linked_data_uri'] = $default['linked_data_default']; $activity_info['@last_updated_datetime'] = date('Y-m-d H:i:s'); $activity_info['activities_id'] = $activities_id; $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'], 'Name'); $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\n activity data you need to add some default\n values that will automatically be filled in for\n each activity you report.")); $this->_redirect('wep/settings'); } else { // For other user redirect to dashboard. $this->_helper->FlashMessenger->addMessage(array('message' => "All information for Reporting\n Organisation is not provided .Please contact\n your organisation admin")); $this->_redirect('wep/dashborad'); } } $activityDefaults['@collaboration_type'] = $wepModel->fetchValueById('CollaborationType', $default['collaboration_type'], 'Name'); $activityDefaults['@flow_type'] = $wepModel->fetchValueById('FlowType', $default['flow_type'], 'Name'); $activityDefaults['@finance_type'] = $wepModel->fetchValueById('FinanceType', $default['finance_type'], 'Name'); $activityDefaults['@aid_type'] = $wepModel->fetchValueById('AidType', $default['aid_type'], 'Name'); $activityDefaults['@tied_status'] = $wepModel->fetchValueById('TiedStatus', $default['tied_status'], 'Name'); $form = new Form_Wep_IatiIdentifier('add', $identity->account_id); $form->add('add', $identity->account_id); $form->populate(array('reporting_org' => $default['reporting_org_ref'])); if ($_POST) { try { $data = $this->getRequest()->getPost(); if (!$form->isValid($data)) { $form->populate($data); } else { $iatiIdentifier = array(); $iatiIdentifier['iati_identifier'] = $data['iati_identifier_text']; $iatiIdentifier['activity_identifier'] = $data['activity_identifier']; $activityModel = new Model_Activity(); $activity_id = $activityModel->createActivity($activities_id, $default, $iatiIdentifier); //Create Activity Hash $activityHashModel = new Model_ActivityHash(); $updated = $activityHashModel->updateActivityHash($activity_id); $this->_helper->FlashMessenger->addMessage(array('message' => "Congratulations! You have\n successfully created an activity.")); $this->_redirect('activity/view-activity-info/?activity_id=' . $activity_id); } } catch (Exception $e) { print $e; } } $this->view->activities_id = $activities_id; $this->view->activity_info = $activity_info; $this->view->reporting_org_info = $reporting_org_info; $this->view->activityDefaults = $activityDefaults; $this->view->form = $form; }