| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Calendars_Html_Admin_View_New |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Ui $ui, |
| 7 |
HC3_Ui_Layout1 $layout, |
| 8 |
|
| 9 |
SH4_Calendars_Query $calendarsQuery, |
| 10 |
SH4_Shifts_Availability $availability, |
| 11 |
|
| 12 |
HC3_Hooks $hooks |
| 13 |
) |
| 14 |
{ |
| 15 |
$this->self = $hooks->wrap( $this ); |
| 16 |
$this->ui = $ui; |
| 17 |
$this->layout = $layout; |
| 18 |
|
| 19 |
$this->calendarsQuery = $hooks->wrap( $calendarsQuery ); |
| 20 |
$this->availability = $hooks->wrap( $availability ); |
| 21 |
} |
| 22 |
|
| 23 |
public function render() |
| 24 |
{ |
| 25 |
$form = $this->ui->makeForm( |
| 26 |
'admin/calendars/new', |
| 27 |
$this->self->form() |
| 28 |
); |
| 29 |
|
| 30 |
$this->layout |
| 31 |
->setContent( $form ) |
| 32 |
->setBreadcrumb( $this->self->breadcrumb() ) |
| 33 |
->setHeader( $this->self->header() ) |
| 34 |
; |
| 35 |
|
| 36 |
$out = $this->layout->render(); |
| 37 |
return $out; |
| 38 |
} |
| 39 |
|
| 40 |
public function header() |
| 41 |
{ |
| 42 |
$out = '__Add New Calendar__'; |
| 43 |
return $out; |
| 44 |
} |
| 45 |
|
| 46 |
public function breadcrumb() |
| 47 |
{ |
| 48 |
$return = array(); |
| 49 |
$return['admin'] = array( 'admin', '__Administration__' ); |
| 50 |
$return['calendars'] = array( 'admin/calendars', '__Calendars__' ); |
| 51 |
return $return; |
| 52 |
} |
| 53 |
|
| 54 |
public function form() |
| 55 |
{ |
| 56 |
$inputs = array(); |
| 57 |
$inputs[] = $this->ui->makeInputText( 'title', '__Title__' )->bold(); |
| 58 |
$inputs[] = $this->ui->makeInputRichTextarea( 'description', '__Description__' )->setRows(6); |
| 59 |
|
| 60 |
$typeOptions = array( |
| 61 |
SH4_Calendars_Model::TYPE_SHIFT => '__Shift__', |
| 62 |
SH4_Calendars_Model::TYPE_TIMEOFF => '__Time Off__', |
| 63 |
// SH4_Calendars_Model::TYPE_AVAILABILITY => '__Availability__', |
| 64 |
); |
| 65 |
|
| 66 |
// if( ! $this->availability->hasAvailability() ){ |
| 67 |
// $typeOptions[SH4_Calendars_Model::TYPE_AVAILABILITY] = '__Availability__'; |
| 68 |
// } |
| 69 |
|
| 70 |
$typeInput = $this->ui->makeInputRadioSet( 'calendar_type', '__Type__', $typeOptions, SH4_Calendars_Model::TYPE_SHIFT ); |
| 71 |
$inputs[] = $typeInput; |
| 72 |
|
| 73 |
$inputs[] = $this->ui->makeInputColorpicker( 'color', '__Color__' ); |
| 74 |
|
| 75 |
// existing other calendars |
| 76 |
$calendars = $this->calendarsQuery->findAll(); |
| 77 |
if( count($calendars) ){ |
| 78 |
$option = []; |
| 79 |
$option[ 0 ] = '- ' . '__No__' . ' -'; |
| 80 |
foreach( $calendars as $e ){ |
| 81 |
$option[ $e->getId() ] = $e->getTitle(); |
| 82 |
} |
| 83 |
$copyInput = $this->ui->makeInputSelect( 'copy', '__Copy Other Settings From Existing Calendar__', $option, null ); |
| 84 |
$inputs[] = $copyInput; |
| 85 |
} |
| 86 |
|
| 87 |
$inputs = $this->ui->makeList( $inputs ); |
| 88 |
|
| 89 |
$buttons = $this->ui->makeInputSubmit( '__Add New Calendar__') |
| 90 |
->tag('primary') |
| 91 |
; |
| 92 |
|
| 93 |
$out = $this->ui->makeList( array($inputs, $buttons) ); |
| 94 |
|
| 95 |
return $out; |
| 96 |
} |
| 97 |
} |