From 1e4bdc39a11beb2fe39a53e13d35773786ef0306 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 5 Dec 2018 12:40:59 -0800 Subject: [PATCH] Add an "availaiblity" attachment for user.search Summary: Ref T13222. See PHI990. The older `user.query` supports availability information, but it isn't currently available in a modern way. Make it available. Test Plan: {F6048126} Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13222 Differential Revision: https://secure.phabricator.com/D19851 --- src/__phutil_library_map__.php | 2 + ...opleAvailabilitySearchEngineAttachment.php | 46 +++++++++++++++++++ .../people/storage/PhabricatorUser.php | 5 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/applications/people/engineextension/PhabricatorPeopleAvailabilitySearchEngineAttachment.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index aeba5e18ae..cd260f497d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3761,6 +3761,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleAnyOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleAnyOwnerDatasource.php', 'PhabricatorPeopleApplication' => 'applications/people/application/PhabricatorPeopleApplication.php', 'PhabricatorPeopleApproveController' => 'applications/people/controller/PhabricatorPeopleApproveController.php', + 'PhabricatorPeopleAvailabilitySearchEngineAttachment' => 'applications/people/engineextension/PhabricatorPeopleAvailabilitySearchEngineAttachment.php', 'PhabricatorPeopleBadgesProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleBadgesProfileMenuItem.php', 'PhabricatorPeopleCommitsProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleCommitsProfileMenuItem.php', 'PhabricatorPeopleController' => 'applications/people/controller/PhabricatorPeopleController.php', @@ -9640,6 +9641,7 @@ phutil_register_library_map(array( 'PhabricatorPeopleAnyOwnerDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorPeopleApplication' => 'PhabricatorApplication', 'PhabricatorPeopleApproveController' => 'PhabricatorPeopleController', + 'PhabricatorPeopleAvailabilitySearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 'PhabricatorPeopleBadgesProfileMenuItem' => 'PhabricatorProfileMenuItem', 'PhabricatorPeopleCommitsProfileMenuItem' => 'PhabricatorProfileMenuItem', 'PhabricatorPeopleController' => 'PhabricatorController', diff --git a/src/applications/people/engineextension/PhabricatorPeopleAvailabilitySearchEngineAttachment.php b/src/applications/people/engineextension/PhabricatorPeopleAvailabilitySearchEngineAttachment.php new file mode 100644 index 0000000000..f61ebe7f01 --- /dev/null +++ b/src/applications/people/engineextension/PhabricatorPeopleAvailabilitySearchEngineAttachment.php @@ -0,0 +1,46 @@ +needAvailability(true); + } + + public function getAttachmentForObject($object, $data, $spec) { + + $until = $object->getAwayUntil(); + if ($until) { + $until = (int)$until; + } else { + $until = null; + } + + $value = $object->getDisplayAvailability(); + if ($value === null) { + $value = PhabricatorCalendarEventInvitee::AVAILABILITY_AVAILABLE; + } + + $name = PhabricatorCalendarEventInvitee::getAvailabilityName($value); + $color = PhabricatorCalendarEventInvitee::getAvailabilityColor($value); + + $event_phid = $object->getAvailabilityEventPHID(); + + return array( + 'value' => $value, + 'until' => $until, + 'name' => $name, + 'color' => $color, + 'eventPHID' => $event_phid, + ); + } + +} diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index 651d1b75a6..7717fbf18c 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -1466,7 +1466,10 @@ final class PhabricatorUser } public function getConduitSearchAttachments() { - return array(); + return array( + id(new PhabricatorPeopleAvailabilitySearchEngineAttachment()) + ->setAttachmentKey('availability'), + ); }