[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phid/ -> PhabricatorObjectHandle.php (source)

   1  <?php
   2  
   3  final class PhabricatorObjectHandle
   4    implements PhabricatorPolicyInterface {
   5  
   6    private $uri;
   7    private $phid;
   8    private $type;
   9    private $name;
  10    private $fullName;
  11    private $title;
  12    private $imageURI;
  13    private $icon;
  14    private $tagColor;
  15    private $timestamp;
  16    private $status = PhabricatorObjectHandleStatus::STATUS_OPEN;
  17    private $complete;
  18    private $disabled;
  19    private $objectName;
  20    private $policyFiltered;
  21  
  22    public function setIcon($icon) {
  23      $this->icon = $icon;
  24      return $this;
  25    }
  26  
  27    public function getIcon() {
  28      if ($this->getPolicyFiltered()) {
  29        return 'fa-lock';
  30      }
  31  
  32      if ($this->icon) {
  33        return $this->icon;
  34      }
  35      return $this->getTypeIcon();
  36    }
  37  
  38    public function setTagColor($color) {
  39      static $colors;
  40      if (!$colors) {
  41        $colors = array_fuse(array_keys(PHUITagView::getShadeMap()));
  42      }
  43  
  44      if (isset($colors[$color])) {
  45        $this->tagColor = $color;
  46      }
  47  
  48      return $this;
  49    }
  50  
  51    public function getTagColor() {
  52      if ($this->getPolicyFiltered()) {
  53        return 'disabled';
  54      }
  55  
  56      if ($this->tagColor) {
  57        return $this->tagColor;
  58      }
  59      return 'blue';
  60    }
  61  
  62    public function getTypeIcon() {
  63      if ($this->getPHIDType()) {
  64        return $this->getPHIDType()->getTypeIcon();
  65      }
  66      return null;
  67    }
  68  
  69    public function setPolicyFiltered($policy_filered) {
  70      $this->policyFiltered = $policy_filered;
  71      return $this;
  72    }
  73  
  74    public function getPolicyFiltered() {
  75      return $this->policyFiltered;
  76    }
  77  
  78    public function setObjectName($object_name) {
  79      $this->objectName = $object_name;
  80      return $this;
  81    }
  82  
  83    public function getObjectName() {
  84      if (!$this->objectName) {
  85        return $this->getName();
  86      }
  87      return $this->objectName;
  88    }
  89  
  90    public function setURI($uri) {
  91      $this->uri = $uri;
  92      return $this;
  93    }
  94  
  95    public function getURI() {
  96      return $this->uri;
  97    }
  98  
  99    public function setPHID($phid) {
 100      $this->phid = $phid;
 101      return $this;
 102    }
 103  
 104    public function getPHID() {
 105      return $this->phid;
 106    }
 107  
 108    public function setName($name) {
 109      $this->name = $name;
 110      return $this;
 111    }
 112  
 113    public function getName() {
 114      if ($this->name === null) {
 115        if ($this->getPolicyFiltered()) {
 116          return pht('Restricted %s', $this->getTypeName());
 117        } else {
 118          return pht('Unknown Object (%s)', $this->getTypeName());
 119        }
 120      }
 121      return $this->name;
 122    }
 123  
 124    public function setStatus($status) {
 125      $this->status = $status;
 126      return $this;
 127    }
 128  
 129    public function getStatus() {
 130      return $this->status;
 131    }
 132  
 133    public function setFullName($full_name) {
 134      $this->fullName = $full_name;
 135      return $this;
 136    }
 137  
 138    public function getFullName() {
 139      if ($this->fullName !== null) {
 140        return $this->fullName;
 141      }
 142      return $this->getName();
 143    }
 144  
 145    public function setTitle($title) {
 146      $this->title = $title;
 147      return $this;
 148    }
 149  
 150    public function getTitle() {
 151      return $this->title;
 152    }
 153  
 154    public function setType($type) {
 155      $this->type = $type;
 156      return $this;
 157    }
 158  
 159    public function getType() {
 160      return $this->type;
 161    }
 162  
 163    public function setImageURI($uri) {
 164      $this->imageURI = $uri;
 165      return $this;
 166    }
 167  
 168    public function getImageURI() {
 169      return $this->imageURI;
 170    }
 171  
 172    public function setTimestamp($timestamp) {
 173      $this->timestamp = $timestamp;
 174      return $this;
 175    }
 176  
 177    public function getTimestamp() {
 178      return $this->timestamp;
 179    }
 180  
 181    public function getTypeName() {
 182      if ($this->getPHIDType()) {
 183        return $this->getPHIDType()->getTypeName();
 184      }
 185  
 186      return $this->getType();
 187    }
 188  
 189  
 190    /**
 191     * Set whether or not the underlying object is complete. See
 192     * @{method:isComplete} for an explanation of what it means to be complete.
 193     *
 194     * @param bool True if the handle represents a complete object.
 195     * @return this
 196     */
 197    public function setComplete($complete) {
 198      $this->complete = $complete;
 199      return $this;
 200    }
 201  
 202  
 203    /**
 204     * Determine if the handle represents an object which was completely loaded
 205     * (i.e., the underlying object exists) vs an object which could not be
 206     * completely loaded (e.g., the type or data for the PHID could not be
 207     * identified or located).
 208     *
 209     * Basically, @{class:PhabricatorHandleQuery} gives you back a handle for
 210     * any PHID you give it, but it gives you a complete handle only for valid
 211     * PHIDs.
 212     *
 213     * @return bool True if the handle represents a complete object.
 214     */
 215    public function isComplete() {
 216      return $this->complete;
 217    }
 218  
 219  
 220    /**
 221     * Set whether or not the underlying object is disabled. See
 222     * @{method:isDisabled} for an explanation of what it means to be disabled.
 223     *
 224     * @param bool True if the handle represents a disabled object.
 225     * @return this
 226     */
 227    public function setDisabled($disabled) {
 228      $this->disabled = $disabled;
 229      return $this;
 230    }
 231  
 232  
 233    /**
 234     * Determine if the handle represents an object which has been disabled --
 235     * for example, disabled users, archived projects, etc. These objects are
 236     * complete and exist, but should be excluded from some system interactions
 237     * (for instance, they usually should not appear in typeaheads, and should
 238     * not have mail/notifications delivered to or about them).
 239     *
 240     * @return bool True if the handle represents a disabled object.
 241     */
 242    public function isDisabled() {
 243      return $this->disabled;
 244    }
 245  
 246  
 247    public function renderLink($name = null) {
 248      if ($name === null) {
 249        $name = $this->getLinkName();
 250      }
 251      $classes = array();
 252      $classes[] = 'phui-handle';
 253      $title = $this->title;
 254  
 255      if ($this->status != PhabricatorObjectHandleStatus::STATUS_OPEN) {
 256        $classes[] = 'handle-status-'.$this->status;
 257        $title = $title ? $title : $this->status;
 258      }
 259  
 260      if ($this->disabled) {
 261        $classes[] = 'handle-disabled';
 262        $title = pht('Disabled'); // Overwrite status.
 263      }
 264  
 265      if ($this->getType() == PhabricatorPeopleUserPHIDType::TYPECONST) {
 266        $classes[] = 'phui-link-person';
 267      }
 268  
 269      $uri = $this->getURI();
 270  
 271      $icon = null;
 272      if ($this->getPolicyFiltered()) {
 273        $icon = id(new PHUIIconView())
 274          ->setIconFont('fa-lock lightgreytext');
 275      }
 276  
 277      return phutil_tag(
 278        $uri ? 'a' : 'span',
 279        array(
 280          'href'  => $uri,
 281          'class' => implode(' ', $classes),
 282          'title' => $title,
 283        ),
 284        array($icon, $name));
 285    }
 286  
 287    public function renderTag() {
 288      return id(new PHUITagView())
 289        ->setType(PHUITagView::TYPE_OBJECT)
 290        ->setShade($this->getTagColor())
 291        ->setIcon($this->getIcon())
 292        ->setHref($this->getURI())
 293        ->setName($this->getLinkName());
 294    }
 295  
 296    public function getLinkName() {
 297      switch ($this->getType()) {
 298        case PhabricatorPeopleUserPHIDType::TYPECONST:
 299          $name = $this->getName();
 300          break;
 301        default:
 302          $name = $this->getFullName();
 303          break;
 304      }
 305      return $name;
 306    }
 307  
 308    protected function getPHIDType() {
 309      $types = PhabricatorPHIDType::getAllTypes();
 310      return idx($types, $this->getType());
 311    }
 312  
 313  
 314  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
 315  
 316  
 317    public function getCapabilities() {
 318      return array(
 319        PhabricatorPolicyCapability::CAN_VIEW,
 320      );
 321    }
 322  
 323    public function getPolicy($capability) {
 324      return PhabricatorPolicies::POLICY_PUBLIC;
 325    }
 326  
 327    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
 328      // NOTE: Handles are always visible, they just don't get populated with
 329      // data if the user can't see the underlying object.
 330      return true;
 331    }
 332  
 333    public function describeAutomaticCapability($capability) {
 334      return null;
 335    }
 336  
 337  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1