| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface HC3_Ui_Layout1_ |
| 3 |
{ |
| 4 |
public function setMenu( $set ); |
| 5 |
public function setSidebar( $set ); |
| 6 |
public function setBreadcrumb( $set ); |
| 7 |
public function setHeader( $set ); |
| 8 |
public function setContent( $set ); |
| 9 |
public function render(); |
| 10 |
} |
| 11 |
|
| 12 |
class HC3_Ui_Layout1 implements HC3_Ui_Layout1_ |
| 13 |
{ |
| 14 |
public function __construct( HC3_Ui $ui ) |
| 15 |
{ |
| 16 |
$this->ui = $ui; |
| 17 |
|
| 18 |
$this->partialBreadcrumb = array(); |
| 19 |
$this->partialBreadcrumbMultiline = FALSE; |
| 20 |
|
| 21 |
$this->partialHeader = NULL; |
| 22 |
$this->partialContent = NULL; |
| 23 |
$this->partialMenu = array(); |
| 24 |
$this->partialSidebar = array(); |
| 25 |
} |
| 26 |
|
| 27 |
public function setSidebar( $set ) |
| 28 |
{ |
| 29 |
$this->partialSidebar = $set; |
| 30 |
return $this; |
| 31 |
} |
| 32 |
|
| 33 |
public function setMenu( $set ) |
| 34 |
{ |
| 35 |
$this->partialMenu = $set; |
| 36 |
return $this; |
| 37 |
} |
| 38 |
|
| 39 |
public function setBreadcrumb( $set, $multiline = FALSE ) |
| 40 |
{ |
| 41 |
$this->partialBreadcrumb = $set; |
| 42 |
$this->partialBreadcrumbMultiline = $multiline; |
| 43 |
return $this; |
| 44 |
} |
| 45 |
|
| 46 |
public function setHeader( $set ) |
| 47 |
{ |
| 48 |
$this->partialHeader = $set; |
| 49 |
return $this; |
| 50 |
} |
| 51 |
|
| 52 |
public function setContent( $set ) |
| 53 |
{ |
| 54 |
$this->partialContent = $set; |
| 55 |
return $this; |
| 56 |
} |
| 57 |
|
| 58 |
public function render() |
| 59 |
{ |
| 60 |
$out = array(); |
| 61 |
|
| 62 |
$header = array(); |
| 63 |
|
| 64 |
if( $this->partialBreadcrumb ){ |
| 65 |
$breadcrumb = array(); |
| 66 |
|
| 67 |
$breadcrumbParts = array(); |
| 68 |
if( $this->partialBreadcrumbMultiline ){ |
| 69 |
$breadcrumbParts = $this->partialBreadcrumb; |
| 70 |
} |
| 71 |
else { |
| 72 |
$breadcrumbParts = array( $this->partialBreadcrumb ); |
| 73 |
} |
| 74 |
|
| 75 |
foreach( $breadcrumbParts as $thisBreadcrumbParts ){ |
| 76 |
$thisBreadcrumb = array(); |
| 77 |
foreach( $thisBreadcrumbParts as $item ){ |
| 78 |
if( is_array($item) ){ |
| 79 |
list( $href, $hrefLabel ) = $item; |
| 80 |
$thisBreadcrumb[] = $this->ui->makeAhref( $href, $hrefLabel ); |
| 81 |
} |
| 82 |
else { |
| 83 |
$thisBreadcrumb[] = $this->ui->makeSpan( $item ) |
| 84 |
// ->tag('font-size', 4) |
| 85 |
// ->tag('font-style', 'bold') |
| 86 |
; |
| 87 |
} |
| 88 |
} |
| 89 |
$thisBreadcrumb = $this->ui->makeListInline( $thisBreadcrumb ) |
| 90 |
->tag('breadcrumb'); |
| 91 |
; |
| 92 |
$breadcrumb[] = $thisBreadcrumb; |
| 93 |
} |
| 94 |
|
| 95 |
if( $this->partialBreadcrumbMultiline ){ |
| 96 |
$breadcrumb = $this->ui->makeList( $breadcrumb ) |
| 97 |
->gutter(1) |
| 98 |
; |
| 99 |
} |
| 100 |
else { |
| 101 |
$breadcrumb = array_shift( $breadcrumb ); |
| 102 |
} |
| 103 |
|
| 104 |
$header[] = $breadcrumb; |
| 105 |
} |
| 106 |
|
| 107 |
if( strlen($this->partialHeader) ){ |
| 108 |
$label = $this->ui->makeBlock( $this->partialHeader ) |
| 109 |
->tag('page-header') |
| 110 |
; |
| 111 |
|
| 112 |
$links = array(); |
| 113 |
if( $this->partialMenu ){ |
| 114 |
foreach( $this->partialMenu as $item ){ |
| 115 |
if( is_array($item) ){ |
| 116 |
list( $href, $hrefLabel ) = $item; |
| 117 |
$item = $this->ui->makeAhref( $href, $hrefLabel ) |
| 118 |
->tag('secondary') |
| 119 |
; |
| 120 |
} |
| 121 |
$links[] = $item; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
if( $links ){ |
| 126 |
$links = $this->ui->makeListInline( $links ); |
| 127 |
$label = $this->ui->makeListInline( array($label, $links) ); |
| 128 |
} |
| 129 |
|
| 130 |
$header[] = $label; |
| 131 |
} |
| 132 |
|
| 133 |
$content = $this->partialContent; |
| 134 |
|
| 135 |
if( $this->partialSidebar ){ |
| 136 |
$sidebar = $this->ui->makeList( $this->partialSidebar ); |
| 137 |
$content = $this->ui->makeGrid() |
| 138 |
->add( $content, 9 ) |
| 139 |
->add( $sidebar, 3 ) |
| 140 |
->gutter(3) |
| 141 |
; |
| 142 |
} |
| 143 |
|
| 144 |
$out[] = $content; |
| 145 |
|
| 146 |
$out = $this->ui->makeList( $out ); |
| 147 |
|
| 148 |
if( $header ){ |
| 149 |
$header = $this->ui->makeList( $header )->gutter(0); |
| 150 |
$out = $this->ui->makeList( array($header,$out) )->gutter(1); |
| 151 |
} |
| 152 |
|
| 153 |
return $out; |
| 154 |
} |
| 155 |
} |