71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Beheer;
|
|
|
|
use App\Controllers\BaseController;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
class ExternalsController extends BaseController
|
|
{
|
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
|
|
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
|
die('NO ACCESS');
|
|
}
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
// Default action
|
|
}
|
|
|
|
public function getAllExternals(string $archive = 'F'): ResponseInterface
|
|
{
|
|
$externals = \External::getAllExternals($archive);
|
|
|
|
return $this->json($externals);
|
|
}
|
|
|
|
public function saveExternal(): ResponseInterface
|
|
{
|
|
$externalValidation = new \ExternalValidation();
|
|
|
|
if (!$externalValidation->getValidationResult()) {
|
|
return $this->json([
|
|
'success' => false,
|
|
'messages' => $externalValidation->getErrorMessages()
|
|
]);
|
|
}
|
|
|
|
$external = $this->request->getPost();
|
|
|
|
$externalID = $external['id'];
|
|
unset($external['id']);
|
|
|
|
$externalID = \External::saveExternal($externalID, $external);
|
|
|
|
return $this->json(['success' => true, 'externalID' => $externalID]);
|
|
}
|
|
|
|
public function archiveExternal(int $externalID, string $status): ResponseInterface
|
|
{
|
|
\External::whereId($externalID)->update(['archive' => $status]);
|
|
return $this->json(['success' => true]);
|
|
}
|
|
|
|
public function removeExternal(int $externalID): ResponseInterface
|
|
{
|
|
$removeExternal = new \RemoveExternal($externalID);
|
|
|
|
if ($removeExternal->getAllowDelete() === false) {
|
|
return $this->json(['result' => false]);
|
|
}
|
|
|
|
\External::removeExternal($externalID);
|
|
|
|
return $this->json(['result' => true]);
|
|
}
|
|
}
|