Path: blob/master/src/applications/people/view/PhabricatorUserCardView.php
12256 views
<?php12final class PhabricatorUserCardView extends AphrontTagView {34private $profile;5private $viewer;6private $tag;7private $isExiled;89public function setProfile(PhabricatorUser $profile) {10$this->profile = $profile;11return $this;12}1314public function setViewer(PhabricatorUser $viewer) {15$this->viewer = $viewer;16return $this;17}1819public function setTag($tag) {20$this->tag = $tag;21return $this;22}2324protected function getTagName() {25if ($this->tag) {26return $this->tag;27}28return 'div';29}3031protected function getTagAttributes() {32$classes = array();33$classes[] = 'project-card-view';34$classes[] = 'people-card-view';3536if ($this->profile->getIsDisabled()) {37$classes[] = 'project-card-disabled';38}3940return array(41'class' => implode(' ', $classes),42);43}4445public function setIsExiled($is_exiled) {46$this->isExiled = $is_exiled;47return $this;48}4950public function getIsExiled() {51return $this->isExiled;52}5354protected function getTagContent() {5556$user = $this->profile;57$profile = $user->loadUserProfile();58$picture = $user->getProfileImageURI();59$viewer = $this->viewer;6061require_celerity_resource('project-card-view-css');6263// We don't have a ton of room on the hovercard, so we're trying to show64// the most important tag. Users can click through to the profile to get65// more details.6667$classes = array();68if ($user->getIsDisabled()) {69$tag_icon = 'fa-ban';70$tag_title = pht('Disabled');71$tag_shade = PHUITagView::COLOR_RED;72$classes[] = 'phui-image-disabled';73} else if (!$user->getIsApproved()) {74$tag_icon = 'fa-ban';75$tag_title = pht('Unapproved Account');76$tag_shade = PHUITagView::COLOR_RED;77} else if (!$user->getIsEmailVerified()) {78$tag_icon = 'fa-envelope';79$tag_title = pht('Email Not Verified');80$tag_shade = PHUITagView::COLOR_VIOLET;81} else if ($user->getIsAdmin()) {82$tag_icon = 'fa-star';83$tag_title = pht('Administrator');84$tag_shade = PHUITagView::COLOR_INDIGO;85} else {86$tag_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon());87$tag_title = $profile->getDisplayTitle();88$tag_shade = null;89}9091$tag = id(new PHUITagView())92->setIcon($tag_icon)93->setName($tag_title)94->setType(PHUITagView::TYPE_SHADE);9596if ($tag_shade !== null) {97$tag->setColor($tag_shade);98}99100$body = array();101102/* TODO: Replace with Conpherence Availability if we ship it */103$body[] = $this->addItem(104'fa-user-plus',105phabricator_date($user->getDateCreated(), $viewer));106107$has_calendar = PhabricatorApplication::isClassInstalledForViewer(108'PhabricatorCalendarApplication',109$viewer);110if ($has_calendar) {111if (!$user->getIsDisabled()) {112$body[] = $this->addItem(113'fa-calendar-o',114id(new PHUIUserAvailabilityView())115->setViewer($viewer)116->setAvailableUser($user));117}118}119120if ($this->getIsExiled()) {121$body[] = $this->addItem(122'fa-eye-slash red',123pht('This user can not see this object.'),124array(125'project-card-item-exiled',126));127}128129$classes[] = 'project-card-image';130$image = phutil_tag(131'img',132array(133'src' => $picture,134'class' => implode(' ', $classes),135));136137$href = urisprintf(138'/p/%s/',139$user->getUsername());140141$image = phutil_tag(142'a',143array(144'href' => $href,145'class' => 'project-card-image-href',146),147$image);148149$name = phutil_tag_div('project-card-name',150$user->getRealname());151$username = phutil_tag_div('project-card-username',152'@'.$user->getUsername());153$tag = phutil_tag_div('phui-header-subheader',154$tag);155156$header = phutil_tag(157'div',158array(159'class' => 'project-card-header',160),161array(162$name,163$username,164$tag,165$body,166));167168$card = phutil_tag(169'div',170array(171'class' => 'project-card-inner',172),173array(174$header,175$image,176));177178return $card;179}180181private function addItem($icon, $value, $classes = array()) {182$classes[] = 'project-card-item';183184$icon = id(new PHUIIconView())185->addClass('project-card-item-icon')186->setIcon($icon);187188$text = phutil_tag(189'span',190array(191'class' => 'project-card-item-text',192),193$value);194195return phutil_tag(196'div',197array(198'class' => implode(' ', $classes),199),200array($icon, $text));201}202203}204205206