Differential D18957 Diff 45481 src/applications/search/controller/PhabricatorApplicationSearchController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/controller/PhabricatorApplicationSearchController.php
| Show First 20 Lines • Show All 415 Lines • ▼ Show 20 Lines | if ($named_query) { | ||||
| $sheet_title = $engine->getResultTypeDescription(); | $sheet_title = $engine->getResultTypeDescription(); | ||||
| } | } | ||||
| $filename = phutil_utf8_strtolower($filename); | $filename = phutil_utf8_strtolower($filename); | ||||
| $filename = PhabricatorFile::normalizeFileName($filename); | $filename = PhabricatorFile::normalizeFileName($filename); | ||||
| $formats = PhabricatorExportFormat::getAllEnabledExportFormats(); | $formats = PhabricatorExportFormat::getAllEnabledExportFormats(); | ||||
| $format_options = mpull($formats, 'getExportFormatName'); | $format_options = mpull($formats, 'getExportFormatName'); | ||||
| // Try to default to the format the user used last time. If you just | |||||
| // exported to Excel, you probably want to export to Excel again. | |||||
| $format_key = $this->readExportFormatPreference(); | |||||
| if (!isset($formats[$format_key])) { | |||||
| $format_key = head_key($format_options); | |||||
| } | |||||
| $errors = array(); | $errors = array(); | ||||
| $e_format = null; | $e_format = null; | ||||
| if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
| $format_key = $request->getStr('format'); | $format_key = $request->getStr('format'); | ||||
| $format = idx($formats, $format_key); | $format = idx($formats, $format_key); | ||||
| if (!$format) { | if (!$format) { | ||||
| $e_format = pht('Invalid'); | $e_format = pht('Invalid'); | ||||
| $errors[] = pht('Choose a valid export format.'); | $errors[] = pht('Choose a valid export format.'); | ||||
| } | } | ||||
| if (!$errors) { | if (!$errors) { | ||||
| $this->writeExportFormatPreference($format_key); | |||||
| $query = $engine->buildQueryFromSavedQuery($saved_query); | $query = $engine->buildQueryFromSavedQuery($saved_query); | ||||
| // NOTE: We aren't reading the pager from the request. Exports always | // NOTE: We aren't reading the pager from the request. Exports always | ||||
| // affect the entire result set. | // affect the entire result set. | ||||
| $pager = $engine->newPagerForSavedQuery($saved_query); | $pager = $engine->newPagerForSavedQuery($saved_query); | ||||
| $pager->setPageSize(0x7FFFFFFF); | $pager->setPageSize(0x7FFFFFFF); | ||||
| $objects = $engine->executeQuery($query, $pager); | $objects = $engine->executeQuery($query, $pager); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | private function processExportRequest() { | ||||
| $export_form = id(new AphrontFormView()) | $export_form = id(new AphrontFormView()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->appendControl( | ->appendControl( | ||||
| id(new AphrontFormSelectControl()) | id(new AphrontFormSelectControl()) | ||||
| ->setName('format') | ->setName('format') | ||||
| ->setLabel(pht('Format')) | ->setLabel(pht('Format')) | ||||
| ->setError($e_format) | ->setError($e_format) | ||||
| ->setValue($format_key) | |||||
| ->setOptions($format_options)); | ->setOptions($format_options)); | ||||
| return $this->newDialog() | return $this->newDialog() | ||||
| ->setTitle(pht('Export Results')) | ->setTitle(pht('Export Results')) | ||||
| ->setErrors($errors) | ->setErrors($errors) | ||||
| ->appendForm($export_form) | ->appendForm($export_form) | ||||
| ->addCancelButton($cancel_uri) | ->addCancelButton($cancel_uri) | ||||
| ->addSubmitButton(pht('Continue')); | ->addSubmitButton(pht('Continue')); | ||||
| ▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | private function canExport() { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| if (!$viewer->getPHID()) { | if (!$viewer->getPHID()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| private function readExportFormatPreference() { | |||||
| $viewer = $this->getViewer(); | |||||
| $export_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY; | |||||
| return $viewer->getUserSetting($export_key); | |||||
| } | |||||
| private function writeExportFormatPreference($value) { | |||||
| $viewer = $this->getViewer(); | |||||
| $request = $this->getRequest(); | |||||
| if (!$viewer->isLoggedIn()) { | |||||
| return; | |||||
| } | |||||
| $export_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY; | |||||
| $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); | |||||
| $editor = id(new PhabricatorUserPreferencesEditor()) | |||||
| ->setActor($viewer) | |||||
| ->setContentSourceFromRequest($request) | |||||
| ->setContinueOnNoEffect(true) | |||||
| ->setContinueOnMissingFields(true); | |||||
| $xactions = array(); | |||||
| $xactions[] = $preferences->newTransaction($export_key, $value); | |||||
| $editor->applyTransactions($preferences, $xactions); | |||||
| } | |||||
| } | } | ||||