Conversie codeigniter 4
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class CustomersController 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 getAllCustomers(string $archive = 'F'): ResponseInterface
|
||||
{
|
||||
$customers = \Customer::getAllCustomers($archive);
|
||||
|
||||
return $this->json($customers);
|
||||
}
|
||||
|
||||
public function saveCustomer(): ResponseInterface
|
||||
{
|
||||
$customerValidation = new \CustomerValidation();
|
||||
|
||||
if (!$customerValidation->getValidationResult()) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'messages' => $customerValidation->getErrorMessages()
|
||||
]);
|
||||
}
|
||||
|
||||
$customer = $this->request->getPost();
|
||||
|
||||
$customerID = $customer['id'];
|
||||
unset($customer['id']);
|
||||
|
||||
$customerID = \Customer::saveCustomer($customerID, $customer);
|
||||
|
||||
return $this->json(['success' => true, 'customerID' => $customerID]);
|
||||
}
|
||||
|
||||
public function archiveCustomer(int $customerID, string $status): ResponseInterface
|
||||
{
|
||||
\Customer::whereId($customerID)->update(['archive' => $status]);
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function removeCustomer(int $customerID): ResponseInterface
|
||||
{
|
||||
$removeCustomer = new \RemoveCustomer($customerID);
|
||||
|
||||
if ($removeCustomer->getAllowDelete() === false) {
|
||||
return $this->json(['result' => false]);
|
||||
}
|
||||
|
||||
\Customer::removeCustomer($customerID);
|
||||
|
||||
return $this->json(['result' => true]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user