forked from projects/fipamo
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use App\Interfaces\PageRepositoryInterface;
|
||
|
use App\Services\Assets\AssetService;
|
||
|
use App\Services\Assets\RenderService;
|
||
|
use App\Interfaces\MemberRepositoryInterface;
|
||
|
use App\Services\Data\SettingsService;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class RoutePutController extends Controller
|
||
|
{
|
||
|
protected $page;
|
||
|
protected $assets;
|
||
|
protected $render;
|
||
|
protected $settings;
|
||
|
protected $member;
|
||
|
|
||
|
public function __construct(
|
||
|
PageRepositoryInterface $pageRepo,
|
||
|
AssetService $assetService,
|
||
|
RenderService $renderService,
|
||
|
SettingsService $settingsService,
|
||
|
MemberRepositoryInterface $memberRepo,
|
||
|
) {
|
||
|
$this->page = $pageRepo;
|
||
|
$this->assets = $assetService;
|
||
|
$this->render = $renderService;
|
||
|
$this->settings = $settingsService;
|
||
|
$this->member = $memberRepo;
|
||
|
}
|
||
|
|
||
|
public function handleRequest(Request $request)
|
||
|
{
|
||
|
$path = explode('/', $request->path());
|
||
|
switch ($path[0]) {
|
||
|
case 'page':
|
||
|
$body = json_decode($request->getContent());
|
||
|
$result = $this->page->update($body);
|
||
|
return response()->json($result)->header('Content-Type', 'application/json');
|
||
|
break;
|
||
|
case 'settings':
|
||
|
return $this->settingsTasks($request, $path[1]);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private function settingsTasks($request, $task)
|
||
|
{
|
||
|
$result = [];
|
||
|
switch ($task) {
|
||
|
case 'publish':
|
||
|
$this->assets->moveToTheme(true);
|
||
|
$result = $this->render->publishAll();
|
||
|
break;
|
||
|
case 'sync':
|
||
|
$body = json_decode($request->getContent());
|
||
|
//update member if needed
|
||
|
$this->member->update($body->member);
|
||
|
//sync settings
|
||
|
$result = $this->settings->sync($body);
|
||
|
break;
|
||
|
case 'nav-sync':
|
||
|
$body = json_decode($request->getContent());
|
||
|
$result = $this->settings->navSync($body);
|
||
|
break;
|
||
|
}
|
||
|
return response()->json($result)->header('Content-Type', 'application/json');
|
||
|
}
|
||
|
}
|