webcron/src/Controller/JobController.php

47 lines
1.6 KiB
PHP
Raw Normal View History

2021-04-06 23:19:51 +02:00
<?php
namespace JeroenED\Webcron\Controller;
use JeroenED\Framework\Controller;
2021-04-08 12:54:49 +02:00
use JeroenED\Webcron\Repository\Job;
2021-04-06 23:19:51 +02:00
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
2021-04-08 14:54:30 +02:00
class JobController extends Controller
2021-04-06 23:19:51 +02:00
{
2021-04-08 14:54:30 +02:00
public function DefaultAction()
{
2021-04-06 23:19:51 +02:00
if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) {
return new RedirectResponse($this->generateRoute('login'));
}
2021-04-08 12:54:49 +02:00
$jobRepo = new Job($this->getDbCon());
$jobs = $jobRepo->getAllJobs();
return $this->render('job/index.html.twig', ['jobs' => $jobs]);
2021-04-06 23:19:51 +02:00
}
2021-04-08 14:54:30 +02:00
public function viewAction($id)
{
return new Response('Not implemented yet', Response::HTTP_TOO_EARLY);
}
2021-04-12 12:23:50 +02:00
public function addAction()
{
2021-04-13 14:07:11 +02:00
if($this->getRequest()->getMethod() == 'GET') {
return $this->render('job/add.html.twig');
} elseif ($this->getRequest()->getMethod() == 'POST') {
$allValues = $this->getRequest()->request->all();
$jobRepo = new Job($this->getDbCon());
$joboutput = $jobRepo->addJob($allValues);
if($joboutput['success']) {
$this->addFlash('success', $joboutput['message']);
return new RedirectResponse($this->generateRoute('job_index'));
} else {
$this->addFlash('danger', $joboutput['message']);
return new RedirectResponse($this->generateRoute('job_add'));
}
} else {
return new Response('Not implemented yet', Response::HTTP_TOO_EARLY);
}
2021-04-12 12:23:50 +02:00
}
2021-04-06 23:19:51 +02:00
}