Path: blob/master/src/applications/differential/query/DifferentialRevisionRequiredActionResultBucket.php
12256 views
<?php12final class DifferentialRevisionRequiredActionResultBucket3extends DifferentialRevisionResultBucket {45const BUCKETKEY = 'action';67const KEY_MUSTREVIEW = 'must-review';8const KEY_SHOULDREVIEW = 'should-review';910private $objects;1112public function getResultBucketName() {13return pht('Bucket by Required Action');14}1516protected function buildResultGroups(17PhabricatorSavedQuery $query,18array $objects) {1920$this->objects = $objects;2122$phids = $query->getEvaluatedParameter('responsiblePHIDs');23if (!$phids) {24throw new Exception(25pht(26'You can not bucket results by required action without '.27'specifying "Responsible Users".'));28}29$phids = array_fuse($phids);3031// Before continuing, throw away any revisions which responsible users32// have explicitly resigned from.3334// The goal is to allow users to resign from revisions they don't want to35// review to get these revisions off their dashboard, even if there are36// other project or package reviewers which they have authority over.37$this->filterResigned($phids);3839// We also throw away draft revisions which you aren't the author of.40$this->filterOtherDrafts($phids);4142$groups = array();4344$groups[] = $this->newGroup()45->setName(pht('Must Review'))46->setKey(self::KEY_MUSTREVIEW)47->setNoDataString(pht('No revisions are blocked on your review.'))48->setObjects($this->filterMustReview($phids));4950$groups[] = $this->newGroup()51->setName(pht('Ready to Review'))52->setKey(self::KEY_SHOULDREVIEW)53->setNoDataString(pht('No revisions are waiting on you to review them.'))54->setObjects($this->filterShouldReview($phids));5556$groups[] = $this->newGroup()57->setName(pht('Ready to Land'))58->setNoDataString(pht('No revisions are ready to land.'))59->setObjects($this->filterShouldLand($phids));6061$groups[] = $this->newGroup()62->setName(pht('Ready to Update'))63->setNoDataString(pht('No revisions are waiting for updates.'))64->setObjects($this->filterShouldUpdate($phids));6566$groups[] = $this->newGroup()67->setName(pht('Drafts'))68->setNoDataString(pht('You have no draft revisions.'))69->setObjects($this->filterDrafts($phids));7071$groups[] = $this->newGroup()72->setName(pht('Waiting on Review'))73->setNoDataString(pht('None of your revisions are waiting on review.'))74->setObjects($this->filterWaitingForReview($phids));7576$groups[] = $this->newGroup()77->setName(pht('Waiting on Authors'))78->setNoDataString(pht('No revisions are waiting on author action.'))79->setObjects($this->filterWaitingOnAuthors($phids));8081$groups[] = $this->newGroup()82->setName(pht('Waiting on Other Reviewers'))83->setNoDataString(pht('No revisions are waiting for other reviewers.'))84->setObjects($this->filterWaitingOnOtherReviewers($phids));8586// Because you can apply these buckets to queries which include revisions87// that have been closed, add an "Other" bucket if we still have stuff88// that didn't get filtered into any of the previous buckets.89if ($this->objects) {90$groups[] = $this->newGroup()91->setName(pht('Other Revisions'))92->setObjects($this->objects);93}9495return $groups;96}9798private function filterMustReview(array $phids) {99$blocking = array(100DifferentialReviewerStatus::STATUS_BLOCKING,101DifferentialReviewerStatus::STATUS_REJECTED,102DifferentialReviewerStatus::STATUS_REJECTED_OLDER,103);104$blocking = array_fuse($blocking);105106$objects = $this->getRevisionsUnderReview($this->objects, $phids);107108$results = array();109foreach ($objects as $key => $object) {110if (!$this->hasReviewersWithStatus($object, $phids, $blocking)) {111continue;112}113114$results[$key] = $object;115unset($this->objects[$key]);116}117118return $results;119}120121private function filterShouldReview(array $phids) {122$reviewing = array(123DifferentialReviewerStatus::STATUS_ADDED,124DifferentialReviewerStatus::STATUS_COMMENTED,125126// If an author has used "Request Review" to put an accepted revision127// back into the "Needs Review" state, include "Accepted" reviewers128// whose reviews have been voided in the "Should Review" bucket.129130// If we don't do this, they end up in "Waiting on Other Reviewers",131// even if there are no other reviewers.132DifferentialReviewerStatus::STATUS_ACCEPTED,133);134$reviewing = array_fuse($reviewing);135136$objects = $this->getRevisionsUnderReview($this->objects, $phids);137138$results = array();139foreach ($objects as $key => $object) {140if (!$this->hasReviewersWithStatus($object, $phids, $reviewing, true)) {141continue;142}143144$results[$key] = $object;145unset($this->objects[$key]);146}147148return $results;149}150151private function filterShouldLand(array $phids) {152$objects = $this->getRevisionsAuthored($this->objects, $phids);153154$results = array();155foreach ($objects as $key => $object) {156if (!$object->isAccepted()) {157continue;158}159160$results[$key] = $object;161unset($this->objects[$key]);162}163164return $results;165}166167private function filterShouldUpdate(array $phids) {168$statuses = array(169DifferentialRevisionStatus::NEEDS_REVISION,170DifferentialRevisionStatus::CHANGES_PLANNED,171);172$statuses = array_fuse($statuses);173174$objects = $this->getRevisionsAuthored($this->objects, $phids);175176$results = array();177foreach ($objects as $key => $object) {178if (empty($statuses[$object->getModernRevisionStatus()])) {179continue;180}181182$results[$key] = $object;183unset($this->objects[$key]);184}185186return $results;187}188189private function filterWaitingForReview(array $phids) {190$objects = $this->getRevisionsAuthored($this->objects, $phids);191192$results = array();193foreach ($objects as $key => $object) {194if (!$object->isNeedsReview()) {195continue;196}197198$results[$key] = $object;199unset($this->objects[$key]);200}201202return $results;203}204205private function filterWaitingOnAuthors(array $phids) {206$statuses = array(207DifferentialRevisionStatus::ACCEPTED,208DifferentialRevisionStatus::NEEDS_REVISION,209DifferentialRevisionStatus::CHANGES_PLANNED,210);211$statuses = array_fuse($statuses);212213$objects = $this->getRevisionsNotAuthored($this->objects, $phids);214215$results = array();216foreach ($objects as $key => $object) {217if (empty($statuses[$object->getModernRevisionStatus()])) {218continue;219}220221$results[$key] = $object;222unset($this->objects[$key]);223}224225return $results;226}227228private function filterWaitingOnOtherReviewers(array $phids) {229$objects = $this->getRevisionsNotAuthored($this->objects, $phids);230231$results = array();232foreach ($objects as $key => $object) {233if (!$object->isNeedsReview()) {234continue;235}236237$results[$key] = $object;238unset($this->objects[$key]);239}240241return $results;242}243244private function filterResigned(array $phids) {245$resigned = array(246DifferentialReviewerStatus::STATUS_RESIGNED,247);248$resigned = array_fuse($resigned);249250$objects = $this->getRevisionsNotAuthored($this->objects, $phids);251252$results = array();253foreach ($objects as $key => $object) {254if (!$this->hasReviewersWithStatus($object, $phids, $resigned)) {255continue;256}257258$results[$key] = $object;259unset($this->objects[$key]);260}261262return $results;263}264265private function filterOtherDrafts(array $phids) {266$objects = $this->getRevisionsNotAuthored($this->objects, $phids);267268$results = array();269foreach ($objects as $key => $object) {270if (!$object->isDraft()) {271continue;272}273274$results[$key] = $object;275unset($this->objects[$key]);276}277278return $results;279}280281private function filterDrafts(array $phids) {282$objects = $this->getRevisionsAuthored($this->objects, $phids);283284$results = array();285foreach ($objects as $key => $object) {286if (!$object->isDraft()) {287continue;288}289290$results[$key] = $object;291unset($this->objects[$key]);292}293294return $results;295}296297}298299300