1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 19:22:42 +01:00
phorge-phorge/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php

215 lines
5.8 KiB
PHP
Raw Normal View History

<?php
final class PhabricatorCalendarEventSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Calendar Events');
}
public function getApplicationClassName() {
return 'PhabricatorCalendarApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'rangeStart',
$this->readDateFromRequest($request, 'rangeStart'));
$saved->setParameter(
'rangeEnd',
$this->readDateFromRequest($request, 'rangeEnd'));
$saved->setParameter(
'upcoming',
$this->readBoolFromRequest($request, 'upcoming'));
$saved->setParameter(
'invitedPHIDs',
$this->readUsersFromRequest($request, 'invited'));
$saved->setParameter(
'creatorPHIDs',
$this->readUsersFromRequest($request, 'creators'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorCalendarEventQuery());
$min_range = null;
$max_range = null;
if ($saved->getParameter('rangeStart')) {
$min_range = $saved->getParameter('rangeStart');
}
if ($saved->getParameter('rangeEnd')) {
$max_range = $saved->getParameter('rangeEnd');
}
if ($saved->getParameter('upcoming')) {
if ($min_range) {
$min_range = max(time(), $min_range);
} else {
$min_range = time();
}
}
if ($min_range || $max_range) {
$query->withDateRange($min_range, $max_range);
}
$invited_phids = $saved->getParameter('invitedPHIDs');
if ($invited_phids) {
$query->withInvitedPHIDs($invited_phids);
}
$creator_phids = $saved->getParameter('creatorPHIDs');
if ($creator_phids) {
$query->withCreatorPHIDs($creator_phids);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved) {
$range_start = $saved->getParameter('rangeStart');
$range_end = $saved->getParameter('rangeEnd');
$upcoming = $saved->getParameter('upcoming');
$invited_phids = $saved->getParameter('invitedPHIDs', array());
$creator_phids = $saved->getParameter('creatorPHIDs', array());
$all_phids = array_merge(
$invited_phids,
$creator_phids);
if ($all_phids) {
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->requireViewer())
->withPHIDs($all_phids)
->execute();
} else {
$handles = array();
}
$invited_handles = array_select_keys($handles, $invited_phids);
$creator_handles = array_select_keys($handles, $creator_phids);
$form
->appendChild(
id(new AphrontFormTokenizerControl())
Modernize "users" typeahead datasource Summary: Ref T4420. Modernize users. Test Plan: - Edited "Commit Authors" on Audit search. - Edited "Created By" on calendar search. - Edited "invited" on calendar search. - Edited "To" on "New conpherence message". - Edited user on "Add user to conpherence thread". - Edited "Authors" on countdown search. - Edited "Author" on differential search. - Edited "Responsible users" on differential search. - Edited "Owner" on Diffusion lint search. - Edited "include users" on Feed search. - Edited "Authors" on file search. - Edited "Authors" on Herald rule search. - Edited a couple of user-selecting Herald fields on rules. - Edited "user" on legalpad signature exemption. - Edited "creator" on legalpad search. - Edited "contributors" on legalpad search. - Edited "signers" on legalpad signature search. - Edited "Authors" on macro search. - Edited "Reassign/claim" on task detail. - Edited "assigned to" on task edit. - Edited "assigned to", "users projects", "authors" on task search. - Edited "creators" on oauthserver. - Edited "authors" on paste search. - Edited "actors" and "users" on activity log search. - Edited "authors" on pholio search. - Edited "users" on phrequent search. - Edited "authors", "answered by" on Ponder search. - Edited "add members" on project membership editor. - Edited "members" on project search. - Edited "pushers" on releeph product edit. - Edited "requestors" on releeph request search. - Edited "pushers" on diffusion push log. - Edited "authors", "owners", "subscribers" on global search. - Edited "authors" on slowvote search. - Edited users in custom policy. - Grepped for "common/authors", no hits. - Grepped for "common/users", no (relevant) hits. - Grepped for "common/accounts", no (relevant) hits. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9885
2014-07-18 00:44:18 +02:00
->setDatasource(new PhabricatorPeopleDatasource())
->setName('creators')
->setLabel(pht('Created By'))
->setValue($creator_handles))
->appendChild(
id(new AphrontFormTokenizerControl())
Modernize "users" typeahead datasource Summary: Ref T4420. Modernize users. Test Plan: - Edited "Commit Authors" on Audit search. - Edited "Created By" on calendar search. - Edited "invited" on calendar search. - Edited "To" on "New conpherence message". - Edited user on "Add user to conpherence thread". - Edited "Authors" on countdown search. - Edited "Author" on differential search. - Edited "Responsible users" on differential search. - Edited "Owner" on Diffusion lint search. - Edited "include users" on Feed search. - Edited "Authors" on file search. - Edited "Authors" on Herald rule search. - Edited a couple of user-selecting Herald fields on rules. - Edited "user" on legalpad signature exemption. - Edited "creator" on legalpad search. - Edited "contributors" on legalpad search. - Edited "signers" on legalpad signature search. - Edited "Authors" on macro search. - Edited "Reassign/claim" on task detail. - Edited "assigned to" on task edit. - Edited "assigned to", "users projects", "authors" on task search. - Edited "creators" on oauthserver. - Edited "authors" on paste search. - Edited "actors" and "users" on activity log search. - Edited "authors" on pholio search. - Edited "users" on phrequent search. - Edited "authors", "answered by" on Ponder search. - Edited "add members" on project membership editor. - Edited "members" on project search. - Edited "pushers" on releeph product edit. - Edited "requestors" on releeph request search. - Edited "pushers" on diffusion push log. - Edited "authors", "owners", "subscribers" on global search. - Edited "authors" on slowvote search. - Edited users in custom policy. - Grepped for "common/authors", no hits. - Grepped for "common/users", no (relevant) hits. - Grepped for "common/accounts", no (relevant) hits. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9885
2014-07-18 00:44:18 +02:00
->setDatasource(new PhabricatorPeopleDatasource())
->setName('invited')
->setLabel(pht('Invited'))
->setValue($invited_handles))
->appendChild(
id(new AphrontFormDateControl())
->setLabel(pht('Occurs After'))
->setUser($this->requireViewer())
->setName('rangeStart')
->setAllowNull(true)
->setValue($range_start))
->appendChild(
id(new AphrontFormDateControl())
->setLabel(pht('Occurs Before'))
->setUser($this->requireViewer())
->setName('rangeEnd')
->setAllowNull(true)
->setValue($range_end))
->appendChild(
id(new AphrontFormCheckboxControl())
->addCheckbox(
'upcoming',
1,
pht('Show only upcoming events.'),
$upcoming));
}
protected function getURI($path) {
return '/calendar/event/'.$path;
}
public function getBuiltinQueryNames() {
$names = array(
'upcoming' => pht('Upcoming Events'),
'all' => pht('All Events'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'upcoming':
return $query->setParameter('upcoming', true);
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $events,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($events, 'PhabricatorCalendarEvent');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
foreach ($events as $event) {
if ($event->getUserPHID() == $viewer->getPHID()) {
$href = $this->getApplicationURI('/event/edit/'.$event->getID().'/');
} else {
$from = $event->getDateFrom();
$month = phabricator_format_local_time($from, $viewer, 'm');
$year = phabricator_format_local_time($from, $viewer, 'Y');
$uri = new PhutilURI($this->getApplicationURI());
$uri->setQueryParams(
array(
'month' => $month,
'year' => $year,
));
$href = (string) $uri;
}
$from = phabricator_datetime($event->getDateFrom(), $viewer);
$to = phabricator_datetime($event->getDateTo(), $viewer);
$color = ($event->getStatus() == PhabricatorCalendarEvent::STATUS_AWAY)
? 'red'
: 'yellow';
$item = id(new PHUIObjectItemView())
->setHeader($event->getTerseSummary($viewer))
->setHref($href)
->setBarColor($color)
->addAttribute(pht('From %s to %s', $from, $to))
->addAttribute(
phutil_utf8_shorten($event->getDescription(), 64));
$list->addItem($item);
}
return $list;
}
}