| 1 |
<?php |
| 2 |
|
| 3 |
namespace ResponsiveMenu\ViewModels\Components\Admin; |
| 4 |
use ResponsiveMenu\Collections\OptionsCollection as OptionsCollection; |
| 5 |
use ResponsiveMenu\Form as Form; |
| 6 |
|
| 7 |
class Boxes { |
| 8 |
|
| 9 |
private $config; |
| 10 |
|
| 11 |
public function __construct(array $config, OptionsCollection $options) { |
| 12 |
$this->config = $config; |
| 13 |
$this->options = $options; |
| 14 |
} |
| 15 |
|
| 16 |
public function render() { |
| 17 |
|
| 18 |
foreach($this->config as $tab_name => $sub_menus): |
| 19 |
echo '<div class="tab_container" id="tab_container_' . $this->i($tab_name) . '">'; |
| 20 |
foreach($sub_menus as $sub_menu_name => $options): |
| 21 |
echo ' |
| 22 |
<div class="postbox" id="postbox_' . $this->i($sub_menu_name).'"> |
| 23 |
<div class="handlediv"> |
| 24 |
<button aria-expanded="true" class="button-link" type="button"> |
| 25 |
<span class="screen-reader-text">' . __('Toggle panel: Location', 'responsive-menu') . '</span> |
| 26 |
<span aria-hidden="true" class="toggle-indicator"></span> |
| 27 |
</button> |
| 28 |
</div> <!-- .handlediv --> |
| 29 |
<h2 class="ui-sortable-handle hndle">' . $tab_name . ' » ' . $sub_menu_name . '</h2> |
| 30 |
<div class="inside"> |
| 31 |
<table class="widefat">'; |
| 32 |
foreach($options as $option): |
| 33 |
$pro = isset($option['pro']) ? 'pro_option' : ''; |
| 34 |
$semi_pro = isset($option['semi_pro']) ? 'semi_pro_option' : ''; |
| 35 |
$type = isset($option['type']) ? $option['type'] : null; |
| 36 |
$unit = isset($option['unit']) ? '<span class="units">' . $option['unit'] . '</span>' : null; |
| 37 |
$select = isset($option['select']) ? $option['select'] : null; |
| 38 |
echo '<tr class="' . $pro . ' ' . $semi_pro . '" id="' . $option['option'] . '_container"> |
| 39 |
<td> |
| 40 |
<div class="label">' . $option['title'] . '</div> |
| 41 |
<span class="description">' . $option['label'] . '</span> |
| 42 |
</td> |
| 43 |
<td>'; |
| 44 |
$this->f($type, $option['option'], $select); |
| 45 |
echo $unit . '</td> |
| 46 |
</tr>'; |
| 47 |
endforeach; |
| 48 |
echo '</table> |
| 49 |
</div> <!-- .inside --> |
| 50 |
</div> <!-- .postbox -->'; |
| 51 |
endforeach; |
| 52 |
echo '</div> <!-- .tab_container -->'; |
| 53 |
endforeach; |
| 54 |
} |
| 55 |
|
| 56 |
public function i($data) { |
| 57 |
return strtolower(str_replace([' ', '/'], '_', $data)); |
| 58 |
} |
| 59 |
|
| 60 |
public function f($type, $option_name, $select) { |
| 61 |
switch($type): |
| 62 |
case 'checkbox' : $comp = new Form\Checkbox; |
| 63 |
$comp->render($this->options[$option_name]); |
| 64 |
break; |
| 65 |
case 'colour' : $comp = new Form\Colour; |
| 66 |
$comp->render($this->options[$option_name]); |
| 67 |
break; |
| 68 |
case 'textarea' : $comp = new Form\TextArea; |
| 69 |
$comp->render($this->options[$option_name]); |
| 70 |
break; |
| 71 |
case 'select' : $comp = new Form\Select; |
| 72 |
$comp->render($this->options[$option_name], $select); |
| 73 |
break; |
| 74 |
case 'image' : $comp = new Form\Image; |
| 75 |
$comp->render($this->options[$option_name]); |
| 76 |
break; |
| 77 |
case 'menu_ordering' : $comp = new Form\MenuOrdering; |
| 78 |
$comp->render($this->options[$option_name]); |
| 79 |
break; |
| 80 |
case 'header_ordering' : $comp = new Form\HeaderBarOrdering; |
| 81 |
$comp->render($this->options[$option_name]); |
| 82 |
break; |
| 83 |
case 'fonticons' : $comp = new Form\FontIconPageList; |
| 84 |
$comp->render($this->options[$option_name]); |
| 85 |
break; |
| 86 |
case 'import' : $comp = new Form\Import; |
| 87 |
$comp->render(); |
| 88 |
break; |
| 89 |
case 'export' : $comp = new Form\Export; |
| 90 |
$comp->render(); |
| 91 |
break; |
| 92 |
case 'reset' : $comp = new Form\Reset; |
| 93 |
$comp->render(); |
| 94 |
break; |
| 95 |
default : $comp = new Form\Text; |
| 96 |
$comp->render($this->options[$option_name]); |
| 97 |
break; |
| 98 |
endswitch; |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|