示例#1
0
 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'];
 }
示例#2
0
 public function add($status = "add", $account_id = '')
 {
     $form = array();
     $model = new Model_Wep();
     $language = $model->getCodeArray('Language', null, '1');
     $currency = $model->getCodeArray('Currency', null, '1');
     if ($status != 'edit') {
         $rowSet = $model->getRowsByFields('default_field_values', 'account_id', $account_id);
         $defaultValues = unserialize($rowSet[0]['object']);
         $default = $defaultValues->getDefaultFields();
     }
     $form['xml_lang'] = new Zend_Form_Element_Select('xml_lang');
     $form['xml_lang']->setLabel('Language')->setAttrib('class', 'form-select')->setRequired()->addMultiOption('', 'Select anyone');
     if ($status != 'edit') {
         $form['xml_lang']->setValue($default['language']);
     }
     foreach ($language as $key => $eachLanguage) {
         $form['xml_lang']->addMultiOption($key, $eachLanguage);
     }
     $form['default_currency'] = new Zend_Form_Element_Select('default_currency');
     $form['default_currency']->setLabel('Default Currency')->setRequired()->setAttrib('class', 'form-select')->addMultiOption('', 'Select anyone');
     if ($status != 'edit') {
         $form['default_currency']->setValue($default['currency']);
     }
     foreach ($currency as $key => $eachCurrency) {
         $form['default_currency']->addMultiOption($key, $eachCurrency);
     }
     $form['hierarchy'] = new Zend_Form_Element_Text('hierarchy');
     $form['hierarchy']->setAttrib('class', 'form-text')->setLabel('Hierarchy');
     $form['linked_data_uri'] = new Zend_Form_Element_text('linked_data_uri');
     $form['linked_data_uri']->setLabel('Linked Data Uri')->setAttrib('class', 'form-text');
     if ($status != 'edit') {
         $form['linked_data_uri']->setValue($default['linked_data_default']);
     }
     //This code is used to append a <div> with help class for all form elements, used for displaying help
     foreach ($form as $item_name => $element) {
         $form[$item_name]->setDecorators(array('ViewHelper', 'Errors', 'Label', array('HtmlTag', array('tag' => '<div>', 'placement' => 'PREPEND', 'class' => 'help activity-' . $item_name)), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'clearfix form-item'))));
     }
     $this->addElements($form);
     $this->addDisplayGroup(array('xml_lang', 'default_currency', 'hierarchy', 'linked_data_uri'), 'field1', array('legend' => 'Activity'));
     $activity = $this->getDisplayGroup('field1');
     $activity->addDecorators(array(array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'default-activity-list'))));
     /*
     $form1 = new Form_Wep_ReportingOrganisation();
     $form1->add('add', $account_id);
     $this->addSubForm($form1, 'Reporting Organisation');
     
     $iati_identifier = new Zend_Form_Element_Text('iati_identifier_text');
     $iati_identifier->setLabel('Iati Identifier')->setAttrib('class', 'form-text')
                             ->setRequired()
                             ->setDecorators( array(
                                                         'ViewHelper',
                                                         'Errors',
                                                         'Label',
                                                         array('HtmlTag', array(
                                                                                'tag'        =>'<div>',
                                                                                'placement'  =>'APPEND',
                                                                                'class'      =>'help identifier-text'
                                                                                )
                                                             ),
                                                         array(array( 'wrapperAll' => 'HtmlTag' ), array( 'tag' => 'div','class'=>'clearfix form-element'))
                                                     )
                                             );
     
     $this->addElement($iati_identifier);
     
     
     $this->addDisplayGroup(array('iati_identifier_text'), 'field',array('legend'=>'Iati Identifier'));
     $identifier = $this->getDisplayGroup('field');
     $identifier->addDecorators( array(
             array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'default-activity-list'))
         )
     );
     */
     $form1 = new Form_Wep_IatiIdentifier();
     $form1->add('add', $account_id);
     $form1->removeElement('save');
     $this->addSubForm($form1, 'IATI Identifier');
     $save = new Zend_Form_Element_Submit('save');
     $save->setValue('Save')->setAttrib('class', 'form-submit');
     $this->addElement($save);
     $this->setMethod('post');
 }
示例#3
0
 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;
 }