From 284646348178e3f2478cc48eb82ae9c663837b0a Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 Sep 2013 16:03:51 -0700 Subject: [PATCH] Implement standard field "bool" type Summary: Depends on D7005. Implements the existing "bool" type. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7006 --- src/__phutil_library_map__.php | 2 + .../PhabricatorStandardCustomField.php | 13 +++ .../PhabricatorStandardCustomFieldBool.php | 95 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b54e8b8625..639d408850 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1636,6 +1636,7 @@ phutil_register_library_map(array( 'PhabricatorSortTableExample' => 'applications/uiexample/examples/PhabricatorSortTableExample.php', 'PhabricatorSourceCodeView' => 'view/layout/PhabricatorSourceCodeView.php', 'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php', + 'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php', 'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php', 'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php', 'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php', @@ -3785,6 +3786,7 @@ phutil_register_library_map(array( 'PhabricatorSortTableExample' => 'PhabricatorUIExample', 'PhabricatorSourceCodeView' => 'AphrontView', 'PhabricatorStandardCustomField' => 'PhabricatorCustomField', + 'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField', 'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField', 'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField', 'PhabricatorStandardPageView' => 'PhabricatorBarePageView', diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php index d30c7f189b..0e9b1a24d6 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php @@ -9,6 +9,7 @@ abstract class PhabricatorStandardCustomField private $fieldDescription; private $fieldConfig; private $applicationField; + private $strings; abstract public function getFieldType(); @@ -84,6 +85,9 @@ abstract class PhabricatorStandardCustomField case 'description': $this->setFieldDescription($value); break; + case 'strings': + $this->setStrings($value); + break; case 'type': // We set this earlier on. break; @@ -119,6 +123,15 @@ abstract class PhabricatorStandardCustomField return coalesce($this->fieldDescription, parent::getFieldDescription()); } + public function setStrings(array $strings) { + $this->strings = $strings; + return; + } + + public function getString($key, $default = null) { + return idx($this->strings, $key, $default); + } + public function shouldUseStorage() { return true; } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php new file mode 100644 index 0000000000..23fad792ae --- /dev/null +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php @@ -0,0 +1,95 @@ +getFieldValue(); + if (strlen($value)) { + $indexes[] = $this->newNumericIndex((int)$value); + } + + return $indexes; + } + + public function getValueForStorage() { + $value = $this->getFieldValue(); + if (strlen($value)) { + return (int)$value; + } else { + return null; + } + } + + public function setValueFromStorage($value) { + if (strlen($value)) { + $value = (bool)$value; + } else { + $value = null; + } + return $this->setFieldValue($value); + } + + public function readApplicationSearchValueFromRequest( + PhabricatorApplicationSearchEngine $engine, + AphrontRequest $request) { + + return $request->getStr($this->getFieldKey()); + } + + public function applyApplicationSearchConstraintToQuery( + PhabricatorApplicationSearchEngine $engine, + PhabricatorCursorPagedPolicyAwareQuery $query, + $value) { + if ($value == 'require') { + $query->withApplicationSearchContainsConstraint( + $this->newNumericIndex(null), + 1); + } + } + + public function appendToApplicationSearchForm( + PhabricatorApplicationSearchEngine $engine, + AphrontFormView $form, + $value, + array $handles) { + + $form->appendChild( + id(new AphrontFormSelectControl()) + ->setLabel($this->getFieldName()) + ->setName($this->getFieldKey()) + ->setValue($value) + ->setOptions( + array( + '' => $this->getString('search.default', pht('(Any)')), + 'require' => $this->getString('search.require', pht('Require')), + ))); + } + + public function renderEditControl() { + return id(new AphrontFormCheckboxControl()) + ->setLabel($this->getFieldName()) + ->addCheckbox( + $this->getFieldKey(), + 1, + $this->getString('edit.checkbox'), + (bool)$this->getFieldValue()); + } + + public function renderPropertyViewValue() { + $value = $this->getFieldValue(); + if ($value) { + return $this->getString('view.yes', pht('Yes')); + } else { + return null; + } + } + + +}