Conversie codeigniter 4
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Beheer;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class EmployeeTargetController 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 getEmployeeTargets(int $employeeID): ResponseInterface
|
||||
{
|
||||
$employeeTargets = \Employeetarget::whereUserId($employeeID)
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
return $this->json($employeeTargets);
|
||||
}
|
||||
|
||||
public function saveEmployeeTarget(): ResponseInterface
|
||||
{
|
||||
$employeeTargetValidation = new \EmployeeTargetValidation();
|
||||
|
||||
if (!$employeeTargetValidation->getValidationResult()) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'messages' => $employeeTargetValidation->getErrorMessages()
|
||||
]);
|
||||
}
|
||||
|
||||
$target = $this->request->getPost();
|
||||
|
||||
$targetID = $target['id'];
|
||||
unset($target['id']);
|
||||
|
||||
$target['endmonth'] = $target['endmonth'] ? $target['endmonth'] : null;
|
||||
$target['endyear'] = $target['endyear'] ? $target['endyear'] : null;
|
||||
|
||||
$targetID = \Employeetarget::saveTarget($targetID, $target);
|
||||
|
||||
return $this->json(['success' => true, 'targetID' => $targetID]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user