Пример #1
0
 public function testArrayInterleave()
 {
     $this->assertEquals([], array_interleave('x', []));
     $this->assertEquals(['y'], array_interleave('x', ['y']));
     $this->assertEquals(['y', 'x', 'z'], array_interleave('x', ['y', 'z']));
     $this->assertEquals(['y', 'x', 'z'], array_interleave('x', ['kangaroo' => 'y', 'marmoset' => 'z']));
     $obj1 = (object) [];
     $obj2 = (object) [];
     $this->assertEquals([$obj1, $obj2, $obj1, $obj2, $obj1], array_interleave($obj2, [$obj1, $obj1, $obj1]));
     $implode_tests = ['' => [1, 2, 3], 'x' => [1, 2, 3], 'y' => [], 'z' => [1]];
     foreach ($implode_tests as $x => $y) {
         $this->assertEquals(implode('', array_interleave($x, $y)), implode($x, $y));
     }
 }
Пример #2
0
 public function testArrayInterleave()
 {
     $this->assertEqual(array(), array_interleave('x', array()));
     $this->assertEqual(array('y'), array_interleave('x', array('y')));
     $this->assertEqual(array('y', 'x', 'z'), array_interleave('x', array('y', 'z')));
     $this->assertEqual(array('y', 'x', 'z'), array_interleave('x', array('kangaroo' => 'y', 'marmoset' => 'z')));
     $obj1 = (object) array();
     $obj2 = (object) array();
     $this->assertEqual(array($obj1, $obj2, $obj1, $obj2, $obj1), array_interleave($obj2, array($obj1, $obj1, $obj1)));
     $implode_tests = array('' => array(1, 2, 3), 'x' => array(1, 2, 3), 'y' => array(), 'z' => array(1));
     foreach ($implode_tests as $x => $y) {
         $this->assertEqual(implode('', array_interleave($x, $y)), implode($x, $y));
     }
 }
Пример #3
0
 protected function getTagContent()
 {
     $image = null;
     if ($this->image) {
         $image = phutil_tag($this->imageURL ? 'a' : 'span', array('href' => $this->imageURL, 'class' => 'phui-header-image', 'style' => 'background-image: url(' . $this->image . ')'), ' ');
     }
     $viewer = $this->getUser();
     $header = array();
     if ($viewer) {
         $header[] = id(new PHUISpacesNamespaceContextView())->setUser($viewer)->setObject($this->policyObject);
     }
     if ($this->objectName) {
         $header[] = array(phutil_tag('a', array('href' => '/' . $this->objectName), $this->objectName), ' ');
     }
     if ($this->actionLinks) {
         $actions = array();
         foreach ($this->actionLinks as $button) {
             $button->setColor(PHUIButtonView::SIMPLE);
             $button->addClass(PHUI::MARGIN_SMALL_LEFT);
             $button->addClass('phui-header-action-link');
             $actions[] = $button;
         }
         $header[] = phutil_tag('div', array('class' => 'phui-header-action-links'), $actions);
     }
     if ($this->buttonBar) {
         $header[] = phutil_tag('div', array('class' => 'phui-header-action-links'), $this->buttonBar);
     }
     $header[] = $this->header;
     if ($this->tags) {
         $header[] = ' ';
         $header[] = phutil_tag('span', array('class' => 'phui-header-tags'), array_interleave(' ', $this->tags));
     }
     if ($this->subheader) {
         $header[] = phutil_tag('div', array('class' => 'phui-header-subheader'), $this->subheader);
     }
     if ($this->properties || $this->policyObject) {
         $property_list = array();
         foreach ($this->properties as $type => $property) {
             switch ($type) {
                 case self::PROPERTY_STATUS:
                     $property_list[] = $property;
                     break;
                 default:
                     throw new Exception(pht('Incorrect Property Passed'));
                     break;
             }
         }
         if ($this->policyObject) {
             $property_list[] = $this->renderPolicyProperty($this->policyObject);
         }
         $header[] = phutil_tag('div', array('class' => 'phui-header-subheader'), $property_list);
     }
     return array($image, phutil_tag('h1', array('class' => 'phui-header-view grouped'), $header));
 }
Пример #4
0
 protected function getTagContent()
 {
     $image = null;
     if ($this->image) {
         $image_href = null;
         if ($this->imageURL) {
             $image_href = $this->imageURL;
         } else {
             if ($this->imageEditURL) {
                 $image_href = $this->imageEditURL;
             }
         }
         $image = phutil_tag('span', array('class' => 'phui-header-image', 'style' => 'background-image: url(' . $this->image . ')'));
         if ($image_href) {
             $edit_view = null;
             if ($this->imageEditURL) {
                 $edit_view = phutil_tag('span', array('class' => 'phui-header-image-edit'), pht('Edit'));
             }
             $image = phutil_tag('a', array('href' => $image_href, 'class' => 'phui-header-image-href'), array($image, $edit_view));
         }
     }
     $viewer = $this->getUser();
     $left = array();
     $right = array();
     if ($viewer) {
         $left[] = id(new PHUISpacesNamespaceContextView())->setUser($viewer)->setObject($this->policyObject);
     }
     if ($this->actionLinks) {
         $actions = array();
         foreach ($this->actionLinks as $button) {
             $button->setColor(PHUIButtonView::GREY);
             $button->addClass(PHUI::MARGIN_SMALL_LEFT);
             $button->addClass('phui-header-action-link');
             $actions[] = $button;
         }
         $right[] = phutil_tag('div', array('class' => 'phui-header-action-links'), $actions);
     }
     if ($this->buttonBar) {
         $right[] = phutil_tag('div', array('class' => 'phui-header-action-links'), $this->buttonBar);
     }
     if ($this->actionIcons || $this->tags) {
         $action_list = array();
         if ($this->actionIcons) {
             foreach ($this->actionIcons as $icon) {
                 $action_list[] = phutil_tag('li', array('class' => 'phui-header-action-icon'), $icon);
             }
         }
         if ($this->tags) {
             $action_list[] = phutil_tag('li', array('class' => 'phui-header-action-tag'), array_interleave(' ', $this->tags));
         }
         $right[] = phutil_tag('ul', array('class' => 'phui-header-action-list'), $action_list);
     }
     if ($this->headerIcon) {
         $icon = id(new PHUIIconView())->setIcon($this->headerIcon);
         $left[] = $icon;
     }
     $header_content = $this->header;
     $href = $this->getHref();
     if ($href !== null) {
         $header_content = phutil_tag('a', array('href' => $href), $header_content);
     }
     $left[] = phutil_tag('span', array('class' => 'phui-header-header'), $header_content);
     if ($this->subheader || $this->badges) {
         $badges = null;
         if ($this->badges) {
             $badges = new PHUIBadgeBoxView();
             $badges->addItems($this->badges);
             $badges->setCollapsed(true);
         }
         $left[] = phutil_tag('div', array('class' => 'phui-header-subheader'), array($badges, $this->subheader));
     }
     if ($this->properties || $this->policyObject) {
         $property_list = array();
         foreach ($this->properties as $type => $property) {
             switch ($type) {
                 case self::PROPERTY_STATUS:
                     $property_list[] = $property;
                     break;
                 default:
                     throw new Exception(pht('Incorrect Property Passed'));
                     break;
             }
         }
         if ($this->policyObject) {
             $property_list[] = $this->renderPolicyProperty($this->policyObject);
         }
         $left[] = phutil_tag('div', array('class' => 'phui-header-subheader'), $property_list);
     }
     // We here at @phabricator
     $header_image = null;
     if ($image) {
         $header_image = phutil_tag('div', array('class' => 'phui-header-col1'), $image);
     }
     // All really love
     $header_left = phutil_tag('div', array('class' => 'phui-header-col2'), $left);
     // Tables and Pokemon.
     $header_right = phutil_tag('div', array('class' => 'phui-header-col3'), $right);
     $header_row = phutil_tag('div', array('class' => 'phui-header-row'), array($header_image, $header_left, $header_right));
     return phutil_tag('h1', array('class' => 'phui-header-view'), $header_row);
 }
Пример #5
0
 public function render()
 {
     require_celerity_resource('phui-header-view-css');
     $classes = array();
     $classes[] = 'phui-header-shell';
     if ($this->noBackground) {
         $classes[] = 'phui-header-no-backgound';
     }
     if ($this->bleedHeader) {
         $classes[] = 'phui-bleed-header';
     }
     if ($this->headerColor) {
         $classes[] = 'sprite-gradient';
         $classes[] = 'gradient-' . $this->headerColor . '-header';
     }
     if ($this->properties || $this->policyObject || $this->subheader) {
         $classes[] = 'phui-header-tall';
     }
     $image = null;
     if ($this->image) {
         $image = phutil_tag($this->imageURL ? 'a' : 'span', array('href' => $this->imageURL, 'class' => 'phui-header-image', 'style' => 'background-image: url(' . $this->image . ')'), ' ');
         $classes[] = 'phui-header-has-image';
     }
     $header = array();
     $header[] = $this->header;
     if ($this->objectName) {
         array_unshift($header, phutil_tag('a', array('href' => '/' . $this->objectName), $this->objectName), ' ');
     }
     if ($this->tags) {
         $header[] = ' ';
         $header[] = phutil_tag('span', array('class' => 'phui-header-tags'), array_interleave(' ', $this->tags));
     }
     if ($this->subheader) {
         $header[] = phutil_tag('div', array('class' => 'phui-header-subheader'), $this->subheader);
     }
     if ($this->properties || $this->policyObject) {
         $property_list = array();
         foreach ($this->properties as $type => $property) {
             switch ($type) {
                 case self::PROPERTY_STATUS:
                     $property_list[] = $property;
                     break;
                 default:
                     throw new Exception('Incorrect Property Passed');
                     break;
             }
         }
         if ($this->policyObject) {
             $property_list[] = $this->renderPolicyProperty($this->policyObject);
         }
         $header[] = phutil_tag('div', array('class' => 'phui-header-subheader'), $property_list);
     }
     if ($this->actionLinks) {
         $actions = array();
         foreach ($this->actionLinks as $button) {
             $button->setColor(PHUIButtonView::SIMPLE);
             $button->addClass(PHUI::MARGIN_SMALL_LEFT);
             $button->addClass('phui-header-action-link');
             $actions[] = $button;
         }
         $header[] = phutil_tag('div', array('class' => 'phui-header-action-links'), $actions);
     }
     if ($this->buttonBar) {
         $header[] = phutil_tag('div', array('class' => 'phui-header-action-links'), $this->buttonBar);
     }
     return phutil_tag('div', array('class' => implode(' ', $classes)), array($image, phutil_tag('h1', array('class' => 'phui-header-view'), $header)));
 }