mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Support exporting custom "Options/Select" fields to Excel/JSON/CSV/etc
Summary: See <https://discourse.phabricator-community.org/t/exporting-custom-select-fields-as-part-of-query-exports/2466/>. In JSON, export both the internal key and the visible value. For other formats, export the visible label. Test Plan: - Added a custom options/select field. - Exported CSV, JSON, Text, got sensible output. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D20316
This commit is contained in:
parent
a5226366d3
commit
917fedafe6
3 changed files with 54 additions and 0 deletions
|
@ -3692,6 +3692,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorOlderInlinesSetting' => 'applications/settings/setting/PhabricatorOlderInlinesSetting.php',
|
'PhabricatorOlderInlinesSetting' => 'applications/settings/setting/PhabricatorOlderInlinesSetting.php',
|
||||||
'PhabricatorOneTimeTriggerClock' => 'infrastructure/daemon/workers/clock/PhabricatorOneTimeTriggerClock.php',
|
'PhabricatorOneTimeTriggerClock' => 'infrastructure/daemon/workers/clock/PhabricatorOneTimeTriggerClock.php',
|
||||||
'PhabricatorOpcodeCacheSpec' => 'applications/cache/spec/PhabricatorOpcodeCacheSpec.php',
|
'PhabricatorOpcodeCacheSpec' => 'applications/cache/spec/PhabricatorOpcodeCacheSpec.php',
|
||||||
|
'PhabricatorOptionExportField' => 'infrastructure/export/field/PhabricatorOptionExportField.php',
|
||||||
'PhabricatorOptionGroupSetting' => 'applications/settings/setting/PhabricatorOptionGroupSetting.php',
|
'PhabricatorOptionGroupSetting' => 'applications/settings/setting/PhabricatorOptionGroupSetting.php',
|
||||||
'PhabricatorOwnerPathQuery' => 'applications/owners/query/PhabricatorOwnerPathQuery.php',
|
'PhabricatorOwnerPathQuery' => 'applications/owners/query/PhabricatorOwnerPathQuery.php',
|
||||||
'PhabricatorOwnersApplication' => 'applications/owners/application/PhabricatorOwnersApplication.php',
|
'PhabricatorOwnersApplication' => 'applications/owners/application/PhabricatorOwnersApplication.php',
|
||||||
|
@ -9687,6 +9688,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorOlderInlinesSetting' => 'PhabricatorSelectSetting',
|
'PhabricatorOlderInlinesSetting' => 'PhabricatorSelectSetting',
|
||||||
'PhabricatorOneTimeTriggerClock' => 'PhabricatorTriggerClock',
|
'PhabricatorOneTimeTriggerClock' => 'PhabricatorTriggerClock',
|
||||||
'PhabricatorOpcodeCacheSpec' => 'PhabricatorCacheSpec',
|
'PhabricatorOpcodeCacheSpec' => 'PhabricatorCacheSpec',
|
||||||
|
'PhabricatorOptionExportField' => 'PhabricatorExportField',
|
||||||
'PhabricatorOptionGroupSetting' => 'PhabricatorSetting',
|
'PhabricatorOptionGroupSetting' => 'PhabricatorSetting',
|
||||||
'PhabricatorOwnerPathQuery' => 'Phobject',
|
'PhabricatorOwnerPathQuery' => 'Phobject',
|
||||||
'PhabricatorOwnersApplication' => 'PhabricatorApplication',
|
'PhabricatorOwnersApplication' => 'PhabricatorApplication',
|
||||||
|
|
|
@ -153,4 +153,9 @@ final class PhabricatorStandardCustomFieldSelect
|
||||||
->setOptions($this->getOptions());
|
->setOptions($this->getOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function newExportFieldType() {
|
||||||
|
return id(new PhabricatorOptionExportField())
|
||||||
|
->setOptions($this->getOptions());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorOptionExportField
|
||||||
|
extends PhabricatorExportField {
|
||||||
|
|
||||||
|
private $options;
|
||||||
|
|
||||||
|
public function setOptions(array $options) {
|
||||||
|
$this->options = $options;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOptions() {
|
||||||
|
return $this->options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNaturalValue($value) {
|
||||||
|
if ($value === null) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strlen($value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = $this->getOptions();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'value' => (string)$value,
|
||||||
|
'name' => (string)idx($options, $value, $value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTextValue($value) {
|
||||||
|
$natural_value = $this->getNaturalValue($value);
|
||||||
|
if ($natural_value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $natural_value['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPHPExcelValue($value) {
|
||||||
|
return $this->getTextValue($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue