protected function renderResultList(array $countdowns, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($countdowns, 'PhabricatorCountdown'); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); $list->setUser($viewer); foreach ($countdowns as $countdown) { $id = $countdown->getID(); $ended = false; $epoch = $countdown->getEpoch(); if ($epoch <= PhabricatorTime::getNow()) { $ended = true; } $item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($countdown)->setObjectName("C{$id}")->setHeader($countdown->getTitle())->setHref($this->getApplicationURI("{$id}/"))->addByline(pht('Created by %s', $handles[$countdown->getAuthorPHID()]->renderLink())); if ($ended) { $item->addAttribute(pht('Launched on %s', phabricator_datetime($epoch, $viewer))); $item->setDisabled(true); } else { $time_left = $epoch - PhabricatorTime::getNow(); $num = round($time_left / (60 * 60 * 24)); $noun = pht('Days'); if ($num < 1) { $num = round($time_left / (60 * 60), 1); $noun = pht('Hours'); } $item->setCountdown($num, $noun); $item->addAttribute(phabricator_datetime($epoch, $viewer)); } $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No countdowns found.')); return $result; }
protected function renderResultList(array $usertimes, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($usertimes, 'PhrequentUserTime'); $viewer = $this->requireViewer(); $view = id(new PHUIObjectItemListView())->setUser($viewer); foreach ($usertimes as $usertime) { $item = new PHUIObjectItemView(); if ($usertime->getObjectPHID() === null) { $item->setHeader($usertime->getNote()); } else { $obj = $handles[$usertime->getObjectPHID()]; $item->setHeader($obj->getLinkName()); $item->setHref($obj->getURI()); } $item->setObject($usertime); $item->addByline(pht('Tracked: %s', $handles[$usertime->getUserPHID()]->renderLink())); $started_date = phabricator_date($usertime->getDateStarted(), $viewer); $item->addIcon('none', $started_date); $block = new PhrequentTimeBlock(array($usertime)); $time_spent = $block->getTimeSpentOnObject($usertime->getObjectPHID(), PhabricatorTime::getNow()); $time_spent = $time_spent == 0 ? 'none' : phutil_format_relative_time_detailed($time_spent); if ($usertime->getDateEnded() !== null) { $item->addAttribute(pht('Tracked %s', $time_spent)); $item->addAttribute(pht('Ended on %s', phabricator_datetime($usertime->getDateEnded(), $viewer))); } else { $item->addAttribute(pht('Tracked %s so far', $time_spent)); if ($usertime->getObjectPHID() !== null && $usertime->getUserPHID() === $viewer->getPHID()) { $item->addAction(id(new PHUIListItemView())->setIcon('fa-stop')->addSigil('phrequent-stop-tracking')->setWorkflow(true)->setRenderNameAsTooltip(true)->setName(pht('Stop'))->setHref('/phrequent/track/stop/' . $usertime->getObjectPHID() . '/')); } $item->setBarColor('green'); } $view->addItem($item); } return $view; }
/** * Set the caches which comprise this stack. * * @param list<PhutilKeyValueCache> Ordered list of key-value caches. * @return this * @task config */ public function setCaches(array $caches) { assert_instances_of($caches, 'PhutilKeyValueCache'); $this->cachesForward = $caches; $this->cachesBackward = array_reverse($caches); return $this; }
private function loadMessagesForTags(array $tags) { assert_instances_of($tags, 'DiffusionRepositoryTag'); $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); $futures = array(); foreach ($tags as $key => $tag) { $futures[$key] = $repository->getLocalCommandFuture('cat-file tag %s', $tag->getName()); } Futures($futures)->resolveAll(); foreach ($tags as $key => $tag) { $future = $futures[$key]; list($err, $stdout) = $future->resolve(); $message = null; if ($err) { // Not all tags are actually "tag" objects: a "tag" object is only // created if you provide a message or sign the tag. Tags created with // `git tag x [commit]` are "lightweight tags" and `git cat-file tag` // will fail on them. This is fine: they don't have messages. } else { $parts = explode("\n\n", $stdout, 2); if (count($parts) == 2) { $message = last($parts); } } $tag->attachMessage($message); } return $tags; }
protected function renderResultList(array $notifications, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($notifications, 'PhabricatorFeedStory'); $viewer = $this->requireViewer(); $image = id(new PHUIIconView())->setIconFont('fa-eye-slash'); $button = id(new PHUIButtonView())->setTag('a')->addSigil('workflow')->setColor(PHUIButtonView::SIMPLE)->setIcon($image)->setText(pht('Mark All Read')); switch ($query->getQueryKey()) { case 'unread': $header = pht('Unread Notifications'); $no_data = pht('You have no unread notifications.'); break; default: $header = pht('Notifications'); $no_data = pht('You have no notifications.'); break; } $clear_uri = id(new PhutilURI('/notification/clear/')); if ($notifications) { $builder = id(new PhabricatorNotificationBuilder($notifications))->setUser($viewer); $view = $builder->buildView(); $clear_uri->setQueryParam('chronoKey', head($notifications)->getChronologicalKey()); } else { $view = phutil_tag_div('phabricator-notification no-notifications', $no_data); $button->setDisabled(true); } $button->setHref((string) $clear_uri); $view = id(new PHUIBoxView())->addPadding(PHUI::PADDING_MEDIUM)->addClass('phabricator-notification-list')->appendChild($view); $result = new PhabricatorApplicationSearchResultView(); $result->addAction($button); $result->setContent($view); return $result; }
protected function renderResultList(array $polls, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($polls, 'PhabricatorSlowvotePoll'); $viewer = $this->requireViewer(); $list = id(new PHUIObjectItemListView())->setUser($viewer); $phids = mpull($polls, 'getAuthorPHID'); foreach ($polls as $poll) { $date_created = phabricator_datetime($poll->getDateCreated(), $viewer); if ($poll->getAuthorPHID()) { $author = $handles[$poll->getAuthorPHID()]->renderLink(); } else { $author = null; } $item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($poll)->setObjectName('V' . $poll->getID())->setHeader($poll->getQuestion())->setHref('/V' . $poll->getID())->addIcon('none', $date_created); if ($poll->getIsClosed()) { $item->setStatusIcon('fa-ban grey'); $item->setDisabled(true); } else { $item->setStatusIcon('fa-bar-chart'); } $description = $poll->getDescription(); if (strlen($description)) { $item->addAttribute(id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(120)->truncateString($poll->getDescription())); } if ($author) { $item->addByline(pht('Author: %s', $author)); } $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No polls found.')); return $result; }
protected function didFilterPage(array $books) { assert_instances_of($books, 'DivinerLiveBook'); if ($this->needRepositories) { $repositories = id(new PhabricatorRepositoryQuery())->setViewer($this->getViewer())->withPHIDs(mpull($books, 'getRepositoryPHID'))->execute(); $repositories = mpull($repositories, null, 'getPHID'); foreach ($books as $key => $book) { if ($book->getRepositoryPHID() === null) { $book->attachRepository(null); continue; } $repository = idx($repositories, $book->getRepositoryPHID()); if (!$repository) { $this->didRejectResult($book); unset($books[$key]); continue; } $book->attachRepository($repository); } } if ($this->needProjectPHIDs) { $edge_query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(mpull($books, 'getPHID'))->withEdgeTypes(array(PhabricatorProjectObjectHasProjectEdgeType::EDGECONST)); $edge_query->execute(); foreach ($books as $book) { $project_phids = $edge_query->getDestinationPHIDs(array($book->getPHID())); $book->attachProjectPHIDs($project_phids); } } return $books; }
public static function renderLastModifiedColumns(PhabricatorRepository $repository, array $handles, PhabricatorRepositoryCommit $commit = null, PhabricatorRepositoryCommitData $data = null) { assert_instances_of($handles, 'PhabricatorObjectHandle'); if ($commit) { $epoch = $commit->getEpoch(); $modified = DiffusionView::linkCommit($repository, $commit->getCommitIdentifier()); $date = date('M j, Y', $epoch); $time = date('g:i A', $epoch); } else { $modified = ''; $date = ''; $time = ''; } if ($data) { $author_phid = $data->getCommitDetail('authorPHID'); if ($author_phid && isset($handles[$author_phid])) { $author = $handles[$author_phid]->renderLink(); } else { $author = phutil_escape_html($data->getAuthorName()); } $details = AphrontTableView::renderSingleDisplayLine(phutil_escape_html($data->getSummary())); } else { $author = ''; $details = ''; } return array('commit' => $modified, 'date' => $date, 'time' => $time, 'author' => $author, 'details' => $details); }
private function updateBranchStates(PhabricatorRepository $repository, array $branches) { assert_instances_of($branches, 'DiffusionRepositoryRef'); $all_cursors = id(new PhabricatorRepositoryRefCursorQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withRepositoryPHIDs(array($repository->getPHID()))->execute(); $state_map = array(); $type_branch = PhabricatorRepositoryRefCursor::TYPE_BRANCH; foreach ($all_cursors as $cursor) { if ($cursor->getRefType() !== $type_branch) { continue; } $raw_name = $cursor->getRefNameRaw(); $hash = $cursor->getCommitIdentifier(); $state_map[$raw_name][$hash] = $cursor; } foreach ($branches as $branch) { $cursor = idx($state_map, $branch->getShortName(), array()); $cursor = idx($cursor, $branch->getCommitIdentifier()); if (!$cursor) { continue; } $fields = $branch->getRawFields(); $cursor_state = (bool) $cursor->getIsClosed(); $branch_state = (bool) idx($fields, 'closed'); if ($cursor_state != $branch_state) { $cursor->setIsClosed((int) $branch_state)->save(); } } }
protected function renderResultList(array $macros, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($macros, 'PhabricatorFileImageMacro'); $viewer = $this->requireViewer(); $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID')); $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); $pinboard = new PHUIPinboardView(); foreach ($macros as $macro) { $file = $macro->getFile(); $item = id(new PHUIPinboardItemView())->setUser($viewer)->setObject($macro); if ($file) { $item->setImageURI($file->getURIForTransform($xform)); list($x, $y) = $xform->getTransformedDimensions($file); $item->setImageSize($x, $y); } if ($macro->getDateCreated()) { $datetime = phabricator_date($macro->getDateCreated(), $viewer); $item->appendChild(phutil_tag('div', array(), pht('Created on %s', $datetime))); } else { // Very old macros don't have a creation date. Rendering something // keeps all the pins at the same height and avoids flow issues. $item->appendChild(phutil_tag('div', array(), pht('Created in ages long past'))); } if ($macro->getAuthorPHID()) { $author_handle = $handles[$macro->getAuthorPHID()]; $item->appendChild(pht('Created by %s', $author_handle->renderLink())); } $item->setURI($this->getApplicationURI('/view/' . $macro->getID() . '/')); $item->setDisabled($macro->getisDisabled()); $item->setHeader($macro->getName()); $pinboard->addItem($item); } return $pinboard; }
public function renderResultsList(array $requests, PhabricatorSavedQuery $query) { assert_instances_of($requests, 'ReleephRequest'); $viewer = $this->getRequest()->getUser(); // TODO: This is generally a bit sketchy, but we don't do this kind of // thing elsewhere at the moment. For the moment it shouldn't be hugely // costly, and we can batch things later. Generally, this commits fewer // sins than the old code did. $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer); $list = array(); foreach ($requests as $pull) { $field_list = PhabricatorCustomField::getObjectFields($pull, PhabricatorCustomField::ROLE_VIEW); $field_list->setViewer($viewer)->readFieldsFromStorage($pull); foreach ($field_list->getFields() as $field) { if ($field->shouldMarkup()) { $field->setMarkupEngine($engine); } } $list[] = id(new ReleephRequestView())->setUser($viewer)->setCustomFields($field_list)->setPullRequest($pull)->setIsListView(true); } // This is quite sketchy, but the list has not actually rendered yet, so // this still allows us to batch the markup rendering. $engine->process(); return $list; }
public static function sortAndGroupInlines(array $inlines, array $changesets) { assert_instances_of($inlines, 'DifferentialTransaction'); assert_instances_of($changesets, 'DifferentialChangeset'); $changesets = mpull($changesets, null, 'getID'); $changesets = msort($changesets, 'getFilename'); // Group the changesets by file and reorder them by display order. $inline_groups = array(); foreach ($inlines as $inline) { $changeset_id = $inline->getComment()->getChangesetID(); $inline_groups[$changeset_id][] = $inline; } $inline_groups = array_select_keys($inline_groups, array_keys($changesets)); foreach ($inline_groups as $changeset_id => $group) { // Sort the group of inlines by line number. $items = array(); foreach ($group as $inline) { $comment = $inline->getComment(); $num = $comment->getLineNumber(); $len = $comment->getLineLength(); $id = $comment->getID(); $items[] = array('inline' => $inline, 'sort' => sprintf('~%010d%010d%010d', $num, $len, $id)); } $items = isort($items, 'sort'); $items = ipull($items, 'inline'); $inline_groups[$changeset_id] = $items; } return $inline_groups; }
public function withUsers(array $users) { assert_instances_of($users, 'PhabricatorUser'); $this->users = mpull($users, null, 'getPHID'); $this->withUserPHIDs(array_keys($this->users)); return $this; }
public function __construct(DifferentialRevision $revision, PhabricatorObjectHandle $actor, array $changesets) { assert_instances_of($changesets, 'DifferentialChangeset'); $this->setRevision($revision); $this->setActorHandle($actor); $this->setChangesets($changesets); }
protected function renderResultList(array $logs, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($logs, 'PhabricatorCalendarImportLog'); $viewer = $this->requireViewer(); $view = id(new PhabricatorCalendarImportLogView())->setShowImportSources(true)->setViewer($viewer)->setLogs($logs); return id(new PhabricatorApplicationSearchResultView())->setTable($view->newTable()); }
public function applyHeraldEffects(array $effects) { assert_instances_of($effects, 'HeraldEffect'); $result = array(); foreach ($effects as $effect) { $action = $effect->getAction(); switch ($action) { case self::ACTION_NOTHING: $result[] = new HeraldApplyTranscript($effect, true, pht('Did nothing.')); break; case self::ACTION_EMAIL: foreach ($effect->getTarget() as $phid) { $this->emailPHIDs[$phid] = $phid; } $result[] = new HeraldApplyTranscript($effect, true, pht('Added mailable to mail targets.')); break; case self::ACTION_BLOCK: $result[] = new HeraldApplyTranscript($effect, true, pht('Blocked push.')); break; default: $custom_result = parent::handleCustomHeraldEffect($effect); if ($custom_result === null) { throw new Exception(pht("No rules to handle action '%s'.", $action)); } $result[] = $custom_result; break; } } return $result; }
public function apply(array $objects) { assert_instances_of($objects, 'PhabricatorPolicyInterface'); $viewer = $this->viewer; $capabilities = $this->capabilities; if (!$viewer || !$capabilities) { throw new Exception('Call setViewer() and requireCapabilities() before apply()!'); } $filtered = array(); foreach ($objects as $key => $object) { $object_capabilities = $object->getCapabilities(); foreach ($capabilities as $capability) { if (!in_array($capability, $object_capabilities)) { throw new Exception("Testing for capability '{$capability}' on an object which does " . "not have that capability!"); } if (!$this->checkCapability($object, $capability)) { // If we're missing any capability, move on to the next object. continue 2; } } // If we make it here, we have all of the required capabilities. $filtered[$key] = $object; } return $filtered; }
protected function renderResultList(array $questions, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($questions, 'PonderQuestion'); $viewer = $this->requireViewer(); $view = id(new PHUIObjectItemListView())->setUser($viewer); foreach ($questions as $question) { $color = PonderQuestionStatus::getQuestionStatusTagColor($question->getStatus()); $icon = PonderQuestionStatus::getQuestionStatusIcon($question->getStatus()); $full_status = PonderQuestionStatus::getQuestionStatusFullName($question->getStatus()); $item = new PHUIObjectItemView(); $item->setObjectName('Q' . $question->getID()); $item->setHeader($question->getTitle()); $item->setHref('/Q' . $question->getID()); $item->setObject($question); $item->setStatusIcon($icon . ' ' . $color, $full_status); $created_date = phabricator_date($question->getDateCreated(), $viewer); $item->addIcon('none', $created_date); $item->addByline(pht('Asked by %s', $handles[$question->getAuthorPHID()]->renderLink())); $item->addAttribute(pht('%d Answer(s)', $question->getAnswerCount())); $view->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($view); $result->setNoDataString(pht('No questions found.')); return $result; }
private function buildIssueList(array $issues, $group) { assert_instances_of($issues, 'PhabricatorSetupIssue'); $list = new PHUIObjectItemListView(); $list->setStackable(true); $ignored_items = array(); $items = 0; foreach ($issues as $issue) { if ($issue->getGroup() == $group) { $items++; $href = $this->getApplicationURI('/issue/' . $issue->getIssueKey() . '/'); $item = id(new PHUIObjectItemView())->setHeader($issue->getName())->setHref($href)->addAttribute($issue->getSummary()); if (!$issue->getIsIgnored()) { $item->setBarColor('yellow'); $list->addItem($item); } else { $item->addIcon('fa-eye-slash', pht('Ignored')); $item->setDisabled(true); $item->setBarColor('none'); $ignored_items[] = $item; } } } foreach ($ignored_items as $item) { $list->addItem($item); } if ($items == 0) { return null; } else { return $list; } }
public function setChangesets(array $changesets) { assert_instances_of($changesets, 'DifferentialChangeset'); // Ship these in sorted by getSortKey() and keyed by ID... or else! $this->changesets = $changesets; return $this; }
private function updateRawFacts(array $map) { foreach ($map as $phid => $facts) { assert_instances_of($facts, 'PhabricatorFactRaw'); } $phids = array_keys($map); if (!$phids) { return; } $table = new PhabricatorFactRaw(); $conn = $table->establishConnection('w'); $table_name = $table->getTableName(); $sql = array(); foreach ($map as $phid => $facts) { foreach ($facts as $fact) { $sql[] = qsprintf($conn, '(%s, %s, %s, %d, %d, %d)', $fact->getFactType(), $fact->getObjectPHID(), $fact->getObjectA(), $fact->getValueX(), $fact->getValueY(), $fact->getEpoch()); } } $table->openTransaction(); queryfx($conn, 'DELETE FROM %T WHERE objectPHID IN (%Ls)', $table_name, $phids); if ($sql) { foreach (array_chunk($sql, 256) as $chunk) { queryfx($conn, 'INSERT INTO %T (factType, objectPHID, objectA, valueX, valueY, epoch) VALUES %Q', $table_name, implode(', ', $chunk)); } } $table->saveTransaction(); }
protected function renderResultList(array $builds, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($builds, 'HarbormasterBuild'); $viewer = $this->requireViewer(); $buildables = mpull($builds, 'getBuildable'); $object_phids = mpull($buildables, 'getBuildablePHID'); $initiator_phids = mpull($builds, 'getInitiatorPHID'); $phids = array_mergev(array($initiator_phids, $object_phids)); $phids = array_unique(array_filter($phids)); $handles = $viewer->loadHandles($phids); $list = new PHUIObjectItemListView(); foreach ($builds as $build) { $id = $build->getID(); $initiator = $handles[$build->getInitiatorPHID()]; $buildable_object = $handles[$build->getBuildable()->getBuildablePHID()]; $item = id(new PHUIObjectItemView())->setViewer($viewer)->setObject($build)->setObjectName(pht('Build %d', $build->getID()))->setHeader($build->getName())->setHref($build->getURI())->setEpoch($build->getDateCreated())->addAttribute($buildable_object->getName()); if ($initiator) { $item->addHandleIcon($initiator, $initiator->getName()); } $status = $build->getBuildStatus(); $status_icon = HarbormasterBuildStatus::getBuildStatusIcon($status); $status_color = HarbormasterBuildStatus::getBuildStatusColor($status); $status_label = HarbormasterBuildStatus::getBuildStatusName($status); $item->setStatusIcon("{$status_icon} {$status_color}", $status_label); $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No builds found.')); return $result; }
protected function renderResultList(array $blogs, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($blogs, 'PhameBlog'); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); $list->setUser($viewer); foreach ($blogs as $blog) { $id = $blog->getID(); if ($blog->getDomain()) { $domain = $blog->getDomain(); } else { $domain = pht('Local Blog'); } $item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($blog)->setHeader($blog->getName())->setImageURI($blog->getProfileImageURI())->setDisabled($blog->isArchived())->setHref($this->getApplicationURI("/blog/view/{$id}/"))->addAttribute($domain); if (!$blog->isArchived()) { $button = id(new PHUIButtonView())->setTag('a')->setText('New Post')->setHref($this->getApplicationURI('/post/edit/?blog=' . $id)); $item->setLaunchButton($button); } $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No blogs found.')); return $result; }
protected function renderResultList(array $configs, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($configs, 'PhabricatorEditEngineConfiguration'); $viewer = $this->requireViewer(); $engine_key = $this->getEngineKey(); $list = id(new PHUIObjectItemListView())->setUser($viewer); foreach ($configs as $config) { $item = id(new PHUIObjectItemView())->setHeader($config->getDisplayName()); $id = $config->getID(); if ($id) { $item->setObjectName(pht('Form %d', $id)); $key = $id; } else { $item->setObjectName(pht('Builtin')); $key = $config->getBuiltinKey(); } $item->setHref("/transactions/editengine/{$engine_key}/view/{$key}/"); if ($config->getIsDefault()) { $item->addIcon('fa-plus', pht('Default')); } if ($config->getIsEdit()) { $item->addIcon('fa-pencil', pht('Edit Form')); } if ($config->getIsDisabled()) { $item->addIcon('fa-ban', pht('Disabled')); } $list->addItem($item); } return id(new PhabricatorApplicationSearchResultView())->setObjectList($list); }
protected function renderResultList(array $pastes, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($pastes, 'PhabricatorPaste'); $viewer = $this->requireViewer(); $lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices'); $list = new PHUIObjectItemListView(); $list->setUser($viewer); foreach ($pastes as $paste) { $created = phabricator_date($paste->getDateCreated(), $viewer); $author = $handles[$paste->getAuthorPHID()]->renderLink(); $snippet_type = $paste->getSnippet()->getType(); $lines = phutil_split_lines($paste->getSnippet()->getContent()); $preview = id(new PhabricatorSourceCodeView())->setLines($lines)->setTruncatedFirstBytes($snippet_type == PhabricatorPasteSnippet::FIRST_BYTES)->setTruncatedFirstLines($snippet_type == PhabricatorPasteSnippet::FIRST_LINES)->setURI(new PhutilURI($paste->getURI())); $source_code = phutil_tag('div', array('class' => 'phabricator-source-code-summary'), $preview); $created = phabricator_datetime($paste->getDateCreated(), $viewer); $line_count = count($lines); $line_count = pht('%s Line(s)', new PhutilNumber($line_count)); $title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)')); $item = id(new PHUIObjectItemView())->setObjectName('P' . $paste->getID())->setHeader($title)->setHref('/P' . $paste->getID())->setObject($paste)->addByline(pht('Author: %s', $author))->addIcon('none', $created)->addIcon('none', $line_count)->appendChild($source_code); if ($paste->isArchived()) { $item->setDisabled(true); } $lang_name = $paste->getLanguage(); if ($lang_name) { $lang_name = idx($lang_map, $lang_name, $lang_name); $item->addIcon('none', $lang_name); } $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No pastes found.')); return $result; }
protected function renderResultList(array $documents, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($documents, 'PhrictionDocument'); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); $list->setUser($viewer); foreach ($documents as $document) { $content = $document->getContent(); $slug = $document->getSlug(); $author_phid = $content->getAuthorPHID(); $slug_uri = PhrictionDocument::getSlugURI($slug); $byline = pht('Edited by %s', $handles[$author_phid]->renderLink()); $updated = phabricator_datetime($content->getDateCreated(), $viewer); $item = id(new PHUIObjectItemView())->setHeader($content->getTitle())->setHref($slug_uri)->addByline($byline)->addIcon('none', $updated); $item->addAttribute($slug_uri); switch ($document->getStatus()) { case PhrictionDocumentStatus::STATUS_DELETED: $item->setDisabled(true); $item->addIcon('delete', pht('Deleted')); break; case PhrictionDocumentStatus::STATUS_MOVED: $item->setDisabled(true); $item->addIcon('arrow-right', pht('Moved Away')); break; } $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No documents found.')); return $result; }
protected function renderResultList(array $posts, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($posts, 'PhamePost'); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); $list->setUser($viewer); foreach ($posts as $post) { $id = $post->getID(); $blog = $post->getBlog(); $blog_name = $viewer->renderHandle($post->getBlogPHID())->render(); $blog_name = pht('Blog: %s', $blog_name); $item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($post)->setObjectName($post->getMonogram())->setHeader($post->getTitle())->setStatusIcon('fa-star')->setHref($post->getViewURI())->addAttribute($blog_name); if ($post->isDraft()) { $item->setStatusIcon('fa-star-o grey'); $item->setDisabled(true); $item->addIcon('fa-star-o', pht('Draft Post')); } else { if ($post->isArchived()) { $item->setStatusIcon('fa-ban grey'); $item->setDisabled(true); $item->addIcon('fa-ban', pht('Archived Post')); } else { $date = $post->getDatePublished(); $item->setEpoch($date); } } $item->addAction(id(new PHUIListItemView())->setIcon('fa-pencil')->setHref($post->getEditURI())); $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No blogs posts found.')); return $result; }
protected function renderResultList(array $packages, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($packages, 'PhabricatorPackagesPackage'); $viewer = $this->requireViewer(); $list = id(new PhabricatorPackagesPackageListView())->setViewer($viewer)->setPackages($packages)->newListView(); return id(new PhabricatorApplicationSearchResultView())->setObjectList($list)->setNoDataString(pht('No packages found.')); }
private function buildIssueList(array $issues, $group, $fonticon) { assert_instances_of($issues, 'PhabricatorSetupIssue'); $list = new PHUIObjectItemListView(); $list->setBig(true); $ignored_items = array(); $items = 0; foreach ($issues as $issue) { if ($issue->getGroup() == $group) { $items++; $href = $this->getApplicationURI('/issue/' . $issue->getIssueKey() . '/'); $item = id(new PHUIObjectItemView())->setHeader($issue->getName())->setHref($href)->addAttribute($issue->getSummary()); if (!$issue->getIsIgnored()) { $icon = id(new PHUIIconView())->setIcon($fonticon)->setBackground('bg-sky'); $item->setImageIcon($icon); $list->addItem($item); } else { $icon = id(new PHUIIconView())->setIcon('fa-eye-slash')->setBackground('bg-grey'); $item->setDisabled(true); $item->setImageIcon($icon); $ignored_items[] = $item; } } } foreach ($ignored_items as $item) { $list->addItem($item); } if ($items == 0) { return null; } else { return $list; } }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $inlines = $this->loadInlineComments(); assert_instances_of($inlines, 'PhabricatorInlineCommentInterface'); $engine = new PhabricatorMarkupEngine(); $engine->setViewer($user); foreach ($inlines as $inline) { $engine->addObject($inline, PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); } $engine->process(); $phids = array($user->getPHID()); $handles = $this->loadViewerHandles($phids); $views = array(); foreach ($inlines as $inline) { $view = new DifferentialInlineCommentView(); $view->setInlineComment($inline); $view->setMarkupEngine($engine); $view->setHandles($handles); $view->setEditable(false); $view->setPreview(true); $views[] = $view->render(); } $views = phutil_implode_html("\n", $views); return id(new AphrontAjaxResponse())->setContent($views); }