Exemple #1
0
 public function deleteOrganisationById($orgId)
 {
     $wepModel = new Model_Wep();
     // Delete Activities
     $actCollModel = new Model_ActivityCollection();
     $activities = $actCollModel->getActivityIdsByAccount($orgId);
     $activityModel = new Model_Activity();
     foreach ($activities as $activity) {
         $activityModel->deleteActivityById($activity['id']);
     }
     // Delete Defaults
     $wepModel->deleteRow('default_field_groups', 'account_id', $orgId);
     $wepModel->deleteRow('default_field_values', 'account_id', $orgId);
     // Delete registry info
     $regModel = new Model_RegistryInfo();
     $regModel->deleteRegistryInfo($orgId);
     // Delete Users
     $userModel = new Model_User();
     $users = $userModel->getAllUsersByAccountId($orgId);
     foreach ($users as $user) {
         $this->deleteUserById($user['user_id']);
     }
     // Delete account
     $wepModel->deleteRow('iati_activities', 'account_id', $orgId);
     $wepModel->deleteRow('account', 'id', $orgId);
 }
Exemple #2
0
 /**
 Add the activity results to the table;
 */
 function after()
 {
     if (!empty($this->_activity_result)) {
         foreach ($this->_activity_result as $result) {
             $activity = new Model_Activity();
             $activity->create_activity($result);
         }
     }
 }
Exemple #3
0
 public function organisationAction()
 {
     if ($_GET['reporting_org']) {
         $reportingOrg = $this->_request->getParam('reporting_org');
     } else {
         $this->_redirect('organisation?reporting_org=all');
     }
     !$reportingOrg ? $handler = new Iati_Snapshot_Lib_DataHandler() : ($handler = new Iati_Snapshot_Lib_DataHandler($reportingOrg));
     $accountModel = new User_Model_DbTable_Account();
     $userModel = new Model_User();
     $publishModel = new Model_Published();
     $wepModel = new Model_Wep();
     $regInfoModel = new Model_RegistryInfo();
     $result = $accountModel->getAccountByOrganisation($reportingOrg);
     if (count($result)) {
         // Get Account Id
         $accountId = $result['id'];
         $user = $userModel->getUserByAccountId($accountId);
         $regInfo = $regInfoModel->getOrgRegistryInfo($accountId);
         // Get Organisation Info
         $organisation_array['name'] = $result['name'];
         $organisation_array['image'] = $result['file_name'];
         $organisation_array['address'] = $result['address'];
         $organisation_array['email'] = $user['email'];
         $organisation_array['telephone'] = $result['telephone'] ? $result['telephone'] : 'Not Available';
         $organisation_array['website'] = $result['url'] ? $result['url'] : 'Not Available';
         $organisation_array['twitter'] = $result['twitter'] ? $result['twitter'] : 'Not Available';
         $organisation_array['prefix'] = $result['username'];
         $organisation_array['disqus_comments'] = $result['disqus_comments'];
         $this->view->organisation_array = $organisation_array;
         $this->view->publisher_id = $regInfo->publisher_id;
     } else {
         // For all organisations: snapshot
         if ($reportingOrg == 'all' || $reportingOrg == '') {
             $activityModel = new Model_Activity();
             $orgData = $activityModel->allOrganisationsActivityStates();
             foreach ($orgData as $key => $row) {
                 $total['activities'] += array_sum($row['states']);
                 $total['published'] += $row['registry_published_count'];
             }
             $accountModel = new User_Model_DbTable_Account();
             $count = $accountModel->getAccountCount();
             $total['organisations'] = $count['total'];
             $this->view->total = $total;
         } else {
             $this->_redirect('organisation?reporting_org=all');
         }
     }
     // end if
     $this->view->handler = $handler;
 }
Exemple #4
0
 public function get_by_subject($subject_id)
 {
     $data = Model_Activity::find('all', array('where' => array(array('subject_id', $subject_id))));
     $data_array = array();
     foreach ($data as $key => $value) {
         if (!isset($data_array[$value['date']])) {
             $data_array[$value['date']] = array();
         }
         array_push($data_array[$value['date']], $value);
     }
     $success = false;
     if ($data_array) {
         $success = true;
     }
     return $this->response(['data' => $data_array, 'success' => $success]);
 }
Exemple #5
0
 /**
  * 活动详情
  * @return array
  */
 static function activity_detail($id)
 {
     $activity_info = Model_Activity::detail_info($id);
     return $activity_info;
 }
 function view_detail($id)
 {
     $info = Model_Activity::detail_info($id);
     foreach ($info['styles'] as $product_id => $styles) {
         foreach ($styles as $style_key => $style) {
             $style_id = $style['product_style_id'];
             $info["styles"][$product_id][$style_key]["sizes"] = self::_db()->select_rows("select\n                        goods.pro_size,sum(goods.quantity) as quantity,brand.name as brand_name ,product.name as product_name\n                        from et_order_goods as goods\n                        left join et_product_style as style on style.id = goods.style_id\n                        left join et_product as product on product.id = style.product_id\n                        left join et_product_brand as brand on brand.id = product.brand_id\n                        where goods.activity_id = ? and goods.style_id = ?  group by goods.pro_size ", $id, $style_id);
         }
     }
     $manufacturers = self::_db()->select_rows("select * from et_product_manufacturer");
     $produce = self::_db()->select_row("select\n              produce.*,m.name as m_name\n              from et_activity_produce as produce\n              left join et_product_manufacturer as m on m.id = produce.man_id\n              where produce.id = ?", $id);
     $res = array("produce" => $produce, "info" => $info, "manufacturers" => $manufacturers);
     //print_r($res);exit;
     return $res;
 }
Exemple #7
0
 public static function all_activities_day()
 {
     $activies_today = Model_Activity::count(array('where' => array('created_at' => Date::time())));
     return $activies_today;
 }
Exemple #8
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;
 }
 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'];
 }
Exemple #10
0
 public function prepareDataForSimpleFormat($activitiesId)
 {
     if (empty($activitiesId)) {
         return;
     }
     $csvData = array();
     foreach ($activitiesId as $activityId) {
         $actModel = new Model_Activity();
         $actInfo = $actModel->getActivityInfo($activityId);
         $act['default-language'] = $actInfo['@xml_lang'];
         $act['default-currency'] = $actInfo['@default_currency'];
         $act['last-updated-datetime'] = $actInfo['@last_updated_datetime'];
         $reportOrg = $this->prepareReportingOrgSimpleFormat($activityId);
         $act = array_merge($act, $reportOrg);
         $act['iati-identifier'] = $actInfo['iati_identifier'];
         $act['title'] = $actInfo['iati_title'];
         $desc = $this->prepareDescriptionSimpleFormat($activityId);
         $status = $this->prepareActivityStatusSimpleFormat($activityId);
         $date = $this->prepareActivityDateSimpleFormat($activityId);
         $transaction = $this->prepareTransactionSimpleFormat($activityId);
         $participatingOrg = $this->prepareParticipatingOrgSimpleFormat($activityId);
         $recptCountry = $this->prepareRecipientCountrySimpleFormat($activityId);
         $recptRegion = $this->prepareRecipientRegionSimpleFormat($activityId);
         $sector = $this->prepareSectorSimpleFormat($activityId);
         $activityData = array_merge($act, $desc, $status, $date, $transaction, $participatingOrg, $recptCountry, $recptRegion, $sector);
         $csvData[] = $activityData;
     }
     return $csvData;
 }
Exemple #11
0
 public function action_delete($id = null)
 {
     $where = ['id' => $id];
     if (Model_User::is_current_user('teacher')) {
         $where['subject.user_id'] = Auth::get('id');
     }
     if ($activity = Model_Activity::find('first', ['where' => $where, 'related' => ['subject']])) {
         $activity->delete();
         Session::set_flash('success', e('Deleted activity #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete activity #' . $id));
     }
     Response::redirect('site/activities');
 }
Exemple #12
0
 public function listActivityStatesAction()
 {
     $activityModel = new Model_Activity();
     $orgData = $activityModel->allOrganisationsActivityStates();
     $this->view->orgs = $orgData;
 }
Exemple #13
0
 function action_detail($app_id, $activity_id, $time, $sign)
 {
     $app = self::_db()->select_row("select id,app_secret from et_application where app_id = ?", $app_id);
     if (!$app) {
         throw new Exception("app 不存在");
     }
     $request = array("model" => "open/activity", "action" => "detail", "app_id" => $app_id, "activity_id" => $activity_id, "time" => $time);
     $_sign = md5(http_build_query($request) . $app['app_secret']);
     if ($_sign != $sign) {
         throw new Exception("签名不正确");
     }
     return Model_Activity::detail_info($activity_id, $app['id']);
 }
Exemple #14
0
 public function uploadTransactionAction()
 {
     $activityId = $this->_getParam('activity_id');
     $form = new Form_Wep_UploadTransaction();
     if ($data = $this->getRequest()->getPost()) {
         if ($form->isValid($data)) {
             $uploadDir = Zend_Registry::get('config')->public_folder . "/files/csv/uploads";
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->setDestination($uploadDir);
             $source = $upload->getFileName();
             try {
                 $upload->receive();
                 $csvHandler = new Model_CsvUpload();
                 $csvHandler->setInputFile($source);
                 $csvHandler->readCsv();
                 $headerCount = $csvHandler->countHeader();
                 if ($headerCount == 34) {
                     $count = $csvHandler->uploadDetailDataToTransaction($activityId);
                 } elseif ($headerCount == 11) {
                     $count = $csvHandler->uploadSimpleDataToTransaction($activityId);
                 }
                 if (!$count) {
                     $messanger = $this->_helper->FlashMessenger;
                     $messanger->addMessage(array('trans-error' => 'You have
                                                      following errors. Please correct the errors.'));
                     if ($csvHandler->getErrors()) {
                         foreach ($csvHandler->getErrors() as $tranCount => $error) {
                             $tranNo = $tranCount + 1;
                             if (!empty($error)) {
                                 $messanger->addMessage(array('trans-error' => "<div class='tran-no'>\n                                                      Transaction no: {$tranNo}</div>"));
                                 foreach ($error as $errormessage) {
                                     $messanger->addMessage(array('trans-error' => " # " . $errormessage['message']));
                                 }
                             }
                         }
                     } else {
                         $messanger->addMessage(array('trans-error' => "<div class='tran-no'>\n                                                    Something went wrong. Please check your csv file.</div>"));
                     }
                 } else {
                     $activityHashModel = new Model_ActivityHash();
                     $updated = $activityHashModel->updateActivityHash($activityId);
                     if (!$updated) {
                         // Update hash and status
                         $type = 'message';
                         $message = 'No Changes Made';
                     } else {
                         $oldState = Model_Activity::getActivityStatus($activityId);
                         Model_Activity::updateActivityUpdatedInfo($activityId);
                     }
                     if ($updated && $oldState != Iati_WEP_ActivityState::STATUS_DRAFT) {
                         // In case of update notify the user about state change.
                         $this->_helper->FlashMessenger->addMessage(array('state-change-flash-message' => "The\n                                                    activity state is changed back to Draft.\n                                                    You must complete and verify in order\n                                                    to publish the activity."));
                     }
                     $this->_helper->FlashMessenger->addMessage(array('message' => "{$count['add']} transaction(s) added. {$count['update']} transaction(s) updated."));
                     $this->_redirect("/activity/list-elements/?activity_id=" . $activityId . "&classname=Activity_Transaction");
                 }
             } catch (Zend_File_Transfer_Exception $e) {
                 $e->getMessage();
             }
         } else {
             $form->populate($data);
         }
     }
     $this->view->form = $form;
     $this->view->activityId = $activityId;
     $this->view->blockManager()->enable('partial/override-activity.phtml');
     $this->view->blockManager()->enable('partial/activitymenu.phtml');
     $this->view->blockManager()->disable('partial/primarymenu.phtml');
     $this->view->blockManager()->disable('partial/add-activity-menu.phtml');
     $this->view->blockManager()->disable('partial/usermgmtmenu.phtml');
     $this->view->blockManager()->disable('partial/published-list.phtml');
     $this->view->blockManager()->disable('partial/organisation-data.phtml');
     $this->view->blockManager()->disable('partial/uploaded-docs.phtml');
     $this->view->blockManager()->disable('partial/download-my-data.phtml');
 }