[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/phui/ -> PHUIHeaderView.php (source)

   1  <?php
   2  
   3  final class PHUIHeaderView extends AphrontView {
   4  
   5    const PROPERTY_STATUS = 1;
   6  
   7    private $objectName;
   8    private $header;
   9    private $tags = array();
  10    private $image;
  11    private $imageURL = null;
  12    private $subheader;
  13    private $headerColor;
  14    private $noBackground;
  15    private $bleedHeader;
  16    private $properties = array();
  17    private $actionLinks = array();
  18    private $buttonBar = null;
  19    private $policyObject;
  20  
  21    public function setHeader($header) {
  22      $this->header = $header;
  23      return $this;
  24    }
  25  
  26    public function setObjectName($object_name) {
  27      $this->objectName = $object_name;
  28      return $this;
  29    }
  30  
  31    public function setNoBackground($nada) {
  32      $this->noBackground = $nada;
  33      return $this;
  34    }
  35  
  36    public function addTag(PHUITagView $tag) {
  37      $this->tags[] = $tag;
  38      return $this;
  39    }
  40  
  41    public function setImage($uri) {
  42      $this->image = $uri;
  43      return $this;
  44    }
  45  
  46    public function setImageURL($url) {
  47      $this->imageURL = $url;
  48      return $this;
  49    }
  50  
  51    public function setSubheader($subheader) {
  52      $this->subheader = $subheader;
  53      return $this;
  54    }
  55  
  56    public function setBleedHeader($bleed) {
  57      $this->bleedHeader = $bleed;
  58      return $this;
  59    }
  60  
  61    public function setHeaderColor($color) {
  62      $this->headerColor = $color;
  63      return $this;
  64    }
  65  
  66    public function setPolicyObject(PhabricatorPolicyInterface $object) {
  67      $this->policyObject = $object;
  68      return $this;
  69    }
  70  
  71    public function addProperty($property, $value) {
  72      $this->properties[$property] = $value;
  73      return $this;
  74    }
  75  
  76    public function addActionLink(PHUIButtonView $button) {
  77      $this->actionLinks[] = $button;
  78      return $this;
  79    }
  80  
  81    public function setButtonBar(PHUIButtonBarView $bb) {
  82      $this->buttonBar = $bb;
  83      return $this;
  84    }
  85  
  86    public function setStatus($icon, $color, $name) {
  87      $header_class = 'phui-header-status';
  88  
  89      if ($color) {
  90        $icon = $icon.' '.$color;
  91        $header_class = $header_class.'-'.$color;
  92      }
  93  
  94      $img = id(new PHUIIconView())
  95        ->setIconFont($icon);
  96  
  97      $tag = phutil_tag(
  98        'span',
  99        array(
 100          'class' => "{$header_class} plr",
 101        ),
 102        array(
 103          $img,
 104          $name,
 105        ));
 106  
 107      return $this->addProperty(self::PROPERTY_STATUS, $tag);
 108    }
 109  
 110    public function render() {
 111      require_celerity_resource('phui-header-view-css');
 112  
 113      $classes = array();
 114      $classes[] = 'phui-header-shell';
 115  
 116      if ($this->noBackground) {
 117        $classes[] = 'phui-header-no-backgound';
 118      }
 119  
 120      if ($this->bleedHeader) {
 121        $classes[] = 'phui-bleed-header';
 122      }
 123  
 124      if ($this->headerColor) {
 125        $classes[] = 'sprite-gradient';
 126        $classes[] = 'gradient-'.$this->headerColor.'-header';
 127      }
 128  
 129      if ($this->properties || $this->policyObject || $this->subheader) {
 130        $classes[] = 'phui-header-tall';
 131      }
 132  
 133      $image = null;
 134      if ($this->image) {
 135        $image = phutil_tag(
 136          ($this->imageURL ? 'a' : 'span'),
 137          array(
 138            'href' => $this->imageURL,
 139            'class' => 'phui-header-image',
 140            'style' => 'background-image: url('.$this->image.')',
 141          ),
 142          ' ');
 143        $classes[] = 'phui-header-has-image';
 144      }
 145  
 146      $header = array();
 147      $header[] = $this->header;
 148  
 149      if ($this->objectName) {
 150        array_unshift(
 151          $header,
 152          phutil_tag(
 153            'a',
 154            array(
 155              'href' => '/'.$this->objectName,
 156            ),
 157            $this->objectName),
 158          ' ');
 159      }
 160  
 161      if ($this->tags) {
 162        $header[] = ' ';
 163        $header[] = phutil_tag(
 164          'span',
 165          array(
 166            'class' => 'phui-header-tags',
 167          ),
 168          array_interleave(' ', $this->tags));
 169      }
 170  
 171      if ($this->subheader) {
 172        $header[] = phutil_tag(
 173          'div',
 174          array(
 175            'class' => 'phui-header-subheader',
 176          ),
 177          $this->subheader);
 178      }
 179  
 180      if ($this->properties || $this->policyObject) {
 181        $property_list = array();
 182        foreach ($this->properties as $type => $property) {
 183          switch ($type) {
 184            case self::PROPERTY_STATUS:
 185              $property_list[] = $property;
 186            break;
 187            default:
 188              throw new Exception('Incorrect Property Passed');
 189            break;
 190          }
 191        }
 192  
 193        if ($this->policyObject) {
 194          $property_list[] = $this->renderPolicyProperty($this->policyObject);
 195        }
 196  
 197        $header[] = phutil_tag(
 198          'div',
 199          array(
 200            'class' => 'phui-header-subheader',
 201          ),
 202          $property_list);
 203      }
 204  
 205      if ($this->actionLinks) {
 206        $actions = array();
 207        foreach ($this->actionLinks as $button) {
 208          $button->setColor(PHUIButtonView::SIMPLE);
 209          $button->addClass(PHUI::MARGIN_SMALL_LEFT);
 210          $button->addClass('phui-header-action-link');
 211          $actions[] = $button;
 212        }
 213        $header[] = phutil_tag(
 214          'div',
 215          array(
 216            'class' => 'phui-header-action-links',
 217          ),
 218          $actions);
 219      }
 220  
 221      if ($this->buttonBar) {
 222        $header[] = phutil_tag(
 223          'div',
 224          array(
 225            'class' => 'phui-header-action-links',
 226          ),
 227          $this->buttonBar);
 228      }
 229  
 230      return phutil_tag(
 231        'div',
 232        array(
 233          'class' => implode(' ', $classes),
 234        ),
 235        array(
 236          $image,
 237          phutil_tag(
 238            'h1',
 239            array(
 240              'class' => 'phui-header-view',
 241            ),
 242            $header),
 243        ));
 244    }
 245  
 246    private function renderPolicyProperty(PhabricatorPolicyInterface $object) {
 247      $policies = PhabricatorPolicyQuery::loadPolicies(
 248        $this->getUser(),
 249        $object);
 250  
 251      $view_capability = PhabricatorPolicyCapability::CAN_VIEW;
 252      $policy = idx($policies, $view_capability);
 253      if (!$policy) {
 254        return null;
 255      }
 256  
 257      $phid = $object->getPHID();
 258  
 259      $icon = id(new PHUIIconView())
 260        ->setIconFont($policy->getIcon().' bluegrey');
 261  
 262      $link = javelin_tag(
 263        'a',
 264        array(
 265          'class' => 'policy-link',
 266          'href' => '/policy/explain/'.$phid.'/'.$view_capability.'/',
 267          'sigil' => 'workflow',
 268        ),
 269        $policy->getShortName());
 270  
 271      return array($icon, $link);
 272    }
 273  }


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