/** * * Function to get the activity status and activity sectors information for dashboard. * @param Array $activities */ public function getActivityAttribs($activities) { $model = new Model_Wep(); $sectors = array(); $iatiStatuses = $model->getRowsByFields('ActivityStatus', 'lang_id', 1); $status = array(); foreach ($activities as $activity) { //Preapare sector data. $sectorData = $model->listAll('iati_sector', 'activity_id', $activity['id']); if ($sectorData) { foreach ($sectorData as $sectorValue) { if (!$sectorValue['@vocabulary'] || $sectorValue['@vocabulary'] == 3) { if (!$sectorValue['@code']) { continue; } $sectorName = $model->fetchValueById('Sector', $sectorValue['@code'], 'Name'); if (strlen($sectorName) > 35) { $sectorName = substr($sectorName, 0, 32) . "..."; } } else { $sectorName = $sectorValue['text']; if (strlen($sectorName) > 35) { $sectorName = preg_replace('/ \\w+$/', '', substr($sectorName, 0, 32)); $sectorName .= "…"; } } if ($sectorName) { $sectors[] = $sectorName; } } } //Prepare activity status data. $statusData = $model->listAll('iati_activity_status', 'activity_id', $activity['id']); if ($statusData) { foreach ($statusData as $statusValue) { $status[$statusValue['@code']] += 1; } } else { $status['unknown'] += 1; } } foreach ($iatiStatuses as $iatiStatus) { $iatiStatus['count'] = $status[$iatiStatus['Code']]; $activityStatus[] = $iatiStatus; } if ($status['unknown']) { $activityStatus[] = array('Name' => 'Status Unspecified', 'count' => $status['unknown']); } $output = array(); $output['status'] = $activityStatus; $output['sector'] = array_unique($sectors); return $output; }
public static function getActivityInfo($activityId) { $model = new Model_Wep(); $activityInfo = $model->listAll('iati_activity', 'id', $activityId); if (empty($activityInfo)) { return false; } $activity = $activityInfo[0]; $activity['@xml_lang'] = $model->fetchValueById('Language', $activityInfo[0]['@xml_lang'], 'Code'); $activity['@default_currency'] = $model->fetchValueById('Currency', $activityInfo[0]['@default_currency'], 'Code'); $iati_identifier_row = $model->getRowById('iati_identifier', 'activity_id', $activityId); $activity['iati_identifier'] = $iati_identifier_row['text']; $activity['activity_identifier'] = $iati_identifier_row['activity_identifier']; $title_row = $model->getRowById('iati_title', 'activity_id', $activityId); $activity['iati_title'] = $title_row['text']; return $activity; }
public function getCountryAction() { $code = $this->_getParam('code'); $id = $this->_getParam('id'); if ($code) { $model = new Model_Wep(); $country = $model->findIdByFieldData('Country', $code, 1); echo $country[0]['id']; exit; } else { if ($id) { $model = new Model_Wep(); $country = $model->fetchValueById('Country', $id, 'Name'); echo strtolower($country); exit; } else { echo "Unknown"; exit; } } }
/** * Check Presence of an organisation for a login user * If present, redirect to view-elements of an organisation * Else, redirect to add new organisation */ public function organisationDataAction() { $identity = Zend_Auth::getInstance()->getIdentity(); // Check organisation is present or not for a login user $organisationModelObj = new Model_Organisation(); $organisationId = $organisationModelObj->checkOrganisationPresent($identity->account_id); // Fetch default value for an organisation $model = new Model_Viewcode(); $rowSet = $model->getRowsByFields('default_field_values', 'account_id', $identity->account_id); $defaultValues = unserialize($rowSet[0]['object']); $default = $defaultValues->getDefaultFields(); // Check default value exist or not $wepModel = new Model_Wep(); $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'], 'Code'); $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 organisation data\n you need to add some default values that will\n automatically be filled in for\n each organisation you report.")); $this->_redirect('wep/settings'); } else { // For other user redirect to dashboard. $this->_helper->FlashMessenger->addMessage(array('message' => "All information for Reporting Organisation\n is not provided .Please contact you organisation admin")); $this->_redirect('wep/dashborad'); } } if (!$organisationId) { $this->_redirect("organisation/add-organisation"); } $this->_redirect("organisation/view-elements/?parentId={$organisationId}"); }
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; }