| 1 |
<?php |
| 2 |
|
| 3 |
namespace ResponsiveMenu\Controllers; |
| 4 |
use ResponsiveMenu\View\View as View; |
| 5 |
use ResponsiveMenu\Services\OptionService as OptionService; |
| 6 |
|
| 7 |
class Admin { |
| 8 |
|
| 9 |
public function __construct(OptionService $service, View $view) { |
| 10 |
$this->service = $service; |
| 11 |
$this->view = $view; |
| 12 |
} |
| 13 |
|
| 14 |
public function update($default_options, $new_options) { |
| 15 |
$this->view->render('main', [ |
| 16 |
'options' => $this->service->updateOptions(array_merge($default_options, array_filter($new_options))), |
| 17 |
'flash' => ['success' => __('Responsive Menu Options Updated Successfully', 'responsive-menu')] |
| 18 |
]); |
| 19 |
} |
| 20 |
|
| 21 |
public function reset($default_options) { |
| 22 |
$this->view->render('main', [ |
| 23 |
'options' => $this->service->updateOptions($default_options), |
| 24 |
'flash' => ['success' => __('Responsive Menu Options Reset Successfully', 'responsive-menu')] |
| 25 |
]); |
| 26 |
} |
| 27 |
|
| 28 |
public function index() { |
| 29 |
$this->view->render('main', ['options' => $this->service->all()]); |
| 30 |
} |
| 31 |
|
| 32 |
public function import($default_options, $file) { |
| 33 |
if(!empty($file['tmp_name'])): |
| 34 |
$file = file_get_contents($file['tmp_name']); |
| 35 |
$decoded = json_decode($file); |
| 36 |
$options = $this->service->updateOptions(array_merge($default_options, array_filter($decoded))); |
| 37 |
$flash['success'] = __('Responsive Menu Options Reset Successfully', 'responsive-menu'); |
| 38 |
else: |
| 39 |
$flash['errors'][] = __('No file selected', 'responsive-menu'); |
| 40 |
$options = $this->service->all(); |
| 41 |
endif; |
| 42 |
|
| 43 |
$this->view->render('main', ['options' => $options, 'flash' => $flash]); |
| 44 |
} |
| 45 |
|
| 46 |
public function export() { |
| 47 |
nocache_headers(); |
| 48 |
header( 'Content-Type: application/json; charset=utf-8' ); |
| 49 |
header( 'Content-Disposition: attachment; filename=export.json' ); |
| 50 |
header( "Expires: 0" ); |
| 51 |
$final = []; |
| 52 |
foreach($this->service->all()->all() as $option) |
| 53 |
$final[$option->getName()] = $option->getValue(); |
| 54 |
echo json_encode($final); |
| 55 |
exit(); |
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
|