| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Layout |
| 3 |
{ |
| 4 |
public $ui, $uri, $request, $topmenu, $auth, $usersQuery, $usersPresenter; |
| 5 |
|
| 6 |
public function __construct( |
| 7 |
HC3_Hooks $hooks, |
| 8 |
HC3_Ui $ui, |
| 9 |
HC3_Request $request, |
| 10 |
HC3_Ui_Topmenu $topmenu, |
| 11 |
|
| 12 |
HC3_Uri $uri, |
| 13 |
HC3_Auth $auth, |
| 14 |
HC3_Users_Query $usersQuery, |
| 15 |
HC3_Users_Presenter $usersPresenter |
| 16 |
) |
| 17 |
{ |
| 18 |
$this->ui = $ui; |
| 19 |
$this->uri = $uri; |
| 20 |
$this->request = $request; |
| 21 |
$this->topmenu = $topmenu; |
| 22 |
|
| 23 |
$this->auth = $hooks->wrap( $auth ); |
| 24 |
$this->usersQuery = $hooks->wrap( $usersQuery ); |
| 25 |
$this->usersPresenter = $hooks->wrap( $usersPresenter ); |
| 26 |
} |
| 27 |
|
| 28 |
public function render( $content ) |
| 29 |
{ |
| 30 |
$options = $this->topmenu->getChildren(); |
| 31 |
$topmenu = array(); |
| 32 |
foreach( $options as $item ){ |
| 33 |
$link = $this->ui->makeAhref( $item[0], $item[1] ) |
| 34 |
->tag('tab-link') |
| 35 |
; |
| 36 |
|
| 37 |
if( $this->uri->isFullUrl($item[0]) ){ |
| 38 |
$link->newWindow(); |
| 39 |
} |
| 40 |
|
| 41 |
$topmenu[] = $link; |
| 42 |
} |
| 43 |
$topmenu = $this->ui->makeList( $topmenu ) |
| 44 |
->gutter(1) |
| 45 |
; |
| 46 |
|
| 47 |
$topmenuLabel = '__Menu__'; |
| 48 |
|
| 49 |
$currentUser = $this->auth->getCurrentUser(); |
| 50 |
$currentUserId = $currentUser->getId(); |
| 51 |
|
| 52 |
if( $currentUserId ){ |
| 53 |
$currentUser = $this->usersQuery->findById( $currentUserId ); |
| 54 |
$currentUserLabel = $this->usersPresenter->presentTitle( $currentUser ); |
| 55 |
// $topmenuLabel = $this->ui->makeListInline( array($topmenuLabel, $currentUserLabel) ); |
| 56 |
$topmenuLabel = $currentUserLabel; |
| 57 |
} |
| 58 |
|
| 59 |
$topmenu = $this->ui->makeCollapse( $topmenuLabel, $topmenu ) |
| 60 |
->border(FALSE) |
| 61 |
->arrow('☰') |
| 62 |
; |
| 63 |
|
| 64 |
$topmenu = $this->ui->makeBlock( $topmenu ) |
| 65 |
->tag('border', 'bottom') |
| 66 |
->tag('border-color', 'gray') |
| 67 |
->padding(2) |
| 68 |
; |
| 69 |
|
| 70 |
$out = $this->ui->makeList() |
| 71 |
->add( $topmenu ) |
| 72 |
->add( $content ) |
| 73 |
; |
| 74 |
|
| 75 |
return $out; |
| 76 |
} |
| 77 |
} |