2013-04-02 20:23:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AphrontMultiColumnView extends AphrontView {
|
|
|
|
|
|
|
|
const GUTTER_SMALL = 'msr';
|
|
|
|
const GUTTER_MEDIUM = 'mmr';
|
|
|
|
const GUTTER_LARGE = 'mlr';
|
|
|
|
|
|
|
|
private $column = array();
|
|
|
|
private $fluidLayout = false;
|
|
|
|
private $gutter;
|
2013-05-22 00:28:43 +02:00
|
|
|
private $shadow;
|
2013-04-02 20:23:24 +02:00
|
|
|
|
|
|
|
public function addColumn($column) {
|
|
|
|
$this->columns[] = $column;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFluidlayout($layout) {
|
|
|
|
$this->fluidLayout = $layout;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setGutter($gutter) {
|
|
|
|
$this->gutter = $gutter;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-22 00:28:43 +02:00
|
|
|
public function setShadow($shadow) {
|
|
|
|
$this->shadow = $shadow;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-02 20:23:24 +02:00
|
|
|
public function render() {
|
|
|
|
require_celerity_resource('aphront-multi-column-view-css');
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'aphront-multi-column-inner';
|
|
|
|
$classes[] = 'grouped';
|
|
|
|
|
2013-04-06 16:23:59 +02:00
|
|
|
if (count($this->columns) > 7) {
|
|
|
|
throw new Exception("No more than 7 columns per view.");
|
2013-04-02 20:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$classes[] = 'aphront-multi-column-'.count($this->columns).'-up';
|
|
|
|
|
|
|
|
$columns = array();
|
|
|
|
$column_class = array();
|
|
|
|
$column_class[] = 'aphront-multi-column-column';
|
2013-05-22 00:28:43 +02:00
|
|
|
$outer_class = array();
|
|
|
|
$outer_class[] = 'aphront-multi-column-column-outer';
|
2013-04-02 20:23:24 +02:00
|
|
|
if ($this->gutter) {
|
|
|
|
$column_class[] = $this->gutter;
|
|
|
|
}
|
|
|
|
$i = 0;
|
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
if (++$i === count($this->columns)) {
|
|
|
|
$column_class[] = 'aphront-multi-column-column-last';
|
2013-05-22 00:28:43 +02:00
|
|
|
$outer_class[] = 'aphront-multi-colum-column-outer-last';
|
2013-04-02 20:23:24 +02:00
|
|
|
}
|
|
|
|
$column_inner = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $column_class)
|
|
|
|
),
|
|
|
|
$column);
|
|
|
|
$columns[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2013-05-22 00:28:43 +02:00
|
|
|
'class' => implode(' ', $outer_class)
|
2013-04-02 20:23:24 +02:00
|
|
|
),
|
|
|
|
$column_inner);
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $classes),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$columns,
|
|
|
|
));
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'aphront-multi-column-outer';
|
|
|
|
if ($this->fluidLayout) {
|
|
|
|
$classes[] = 'aphront-multi-column-fluid';
|
|
|
|
} else {
|
|
|
|
$classes[] = 'aphront-multi-column-fixed';
|
|
|
|
}
|
|
|
|
|
|
|
|
$board = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $classes)
|
|
|
|
),
|
|
|
|
$view);
|
|
|
|
|
2013-05-22 00:28:43 +02:00
|
|
|
if ($this->shadow) {
|
|
|
|
$board = id(new PHUIBoxView())
|
|
|
|
->setShadow(true)
|
|
|
|
->appendChild($board)
|
|
|
|
->addPadding(PHUI::PADDING_MEDIUM_TOP)
|
|
|
|
->addPadding(PHUI::PADDING_MEDIUM_BOTTOM);
|
|
|
|
}
|
|
|
|
|
2013-04-02 20:23:24 +02:00
|
|
|
return phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-multi-column-view'
|
|
|
|
),
|
|
|
|
$board);
|
|
|
|
}
|
|
|
|
}
|