From 611567061551310c66bf58aeaf5fb2796d400cca Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 Sep 2013 16:04:31 -0700 Subject: [PATCH] Add a "date" standard custom field Summary: See previous revisions. As maniphest. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7009 --- src/__phutil_library_map__.php | 2 + ...PhabricatorPeopleProfileEditController.php | 4 +- .../field/PhabricatorCustomFieldList.php | 7 ++ .../PhabricatorStandardCustomFieldDate.php | 76 +++++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index dee462fe3c..73708a72f5 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1637,6 +1637,7 @@ phutil_register_library_map(array( 'PhabricatorSourceCodeView' => 'view/layout/PhabricatorSourceCodeView.php', 'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php', 'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php', + 'PhabricatorStandardCustomFieldDate' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php', 'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php', 'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php', 'PhabricatorStandardCustomFieldRemarkup' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php', @@ -3789,6 +3790,7 @@ phutil_register_library_map(array( 'PhabricatorSourceCodeView' => 'AphrontView', 'PhabricatorStandardCustomField' => 'PhabricatorCustomField', 'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField', + 'PhabricatorStandardCustomFieldDate' => 'PhabricatorStandardCustomField', 'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField', 'PhabricatorStandardCustomFieldRemarkup' => 'PhabricatorStandardCustomField', 'PhabricatorStandardCustomFieldSelect' => 'PhabricatorStandardCustomField', diff --git a/src/applications/people/controller/PhabricatorPeopleProfileEditController.php b/src/applications/people/controller/PhabricatorPeopleProfileEditController.php index 675512c63b..d7a059603a 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfileEditController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileEditController.php @@ -35,7 +35,9 @@ final class PhabricatorPeopleProfileEditController $field_list = PhabricatorCustomField::getObjectFields( $user, PhabricatorCustomField::ROLE_EDIT); - $field_list->readFieldsFromStorage($user); + $field_list + ->setViewer($user) + ->readFieldsFromStorage($user); if ($request->isFormPost()) { $xactions = $field_list->buildFieldTransactionsFromRequest( diff --git a/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php b/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php index 2a8a9b8341..74889698f5 100644 --- a/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php +++ b/src/infrastructure/customfield/field/PhabricatorCustomFieldList.php @@ -20,6 +20,13 @@ final class PhabricatorCustomFieldList extends Phobject { return $this->fields; } + public function setViewer(PhabricatorUser $viewer) { + foreach ($this->getFields() as $field) { + $field->setViewer($viewer); + } + return $this; + } + /** * Read stored values for all fields which support storage. * diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php new file mode 100644 index 0000000000..2e089e75a5 --- /dev/null +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php @@ -0,0 +1,76 @@ +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 = (int)$value; + } else { + $value = null; + } + return $this->setFieldValue($value); + } + + public function renderEditControl() { + return $this->newDateControl(); + } + + public function readValueFromRequest(AphrontRequest $request) { + $control = $this->newDateControl(); + $control->setUser($request->getUser()); + $value = $control->readValueFromRequest($request); + + $this->setFieldValue($value); + } + + public function renderPropertyViewValue() { + $value = $this->getFieldValue(); + if (!$value) { + return null; + } + + return phabricator_datetime($value, $this->getViewer()); + } + + private function newDateControl() { + $control = id(new AphrontFormDateControl()) + ->setLabel($this->getFieldName()) + ->setName($this->getFieldKey()) + ->setUser($this->getViewer()) + ->setAllowNull(true); + + $control->setValue($this->getFieldValue()); + + return $control; + } + + // TODO: Support ApplicationSearch for these fields. We build indexes above, + // but don't provide a UI for searching. To do so, we need a reasonable date + // range control and the ability to add a range constraint. + +}