From 05faa0c78b0a8585f17d70011a8f4470ff56abbb Mon Sep 17 00:00:00 2001
From: Stefan Galinski <stefan@sgalinski.de>
Date: Fri, 8 Dec 2017 17:33:35 +0100
Subject: [PATCH] [TASK] Another ton of smaller fixes and more feedback
 reported already

---
 Classes/Controller/JoblistController.php      | 24 ++++++-------------
 Classes/Domain/Model/JobApplication.php       |  8 +++----
 .../Private/Templates/Joblist/ApplyForm.html  |  2 +-
 3 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/Classes/Controller/JoblistController.php b/Classes/Controller/JoblistController.php
index 050eba0b..33520620 100644
--- a/Classes/Controller/JoblistController.php
+++ b/Classes/Controller/JoblistController.php
@@ -28,7 +28,6 @@ namespace SGalinski\SgJobs\Controller;
 
 use SGalinski\SgJobs\Domain\Model\JobApplication;
 use SGalinski\SgMail\Service\MailTemplateService;
-use TYPO3\CMS\Core\Exception;
 use TYPO3\CMS\Core\Resource\DuplicationBehavior;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
@@ -74,8 +73,10 @@ class JoblistController extends ActionController {
 
 	/**
 	 * Renders the application form with an optional job
+	 *
+	 * @param JobApplication $applyData
 	 */
-	public function applyFormAction() {
+	public function applyFormAction(JobApplication $applyData = NULL) {
 		if ($this->request->getOriginalRequest()) {
 			$uploadedFiles = $this->request->getOriginalRequest()->getArguments()['uploadedFiles'];
 			$this->view->assign('uploadedFiles', $uploadedFiles);
@@ -89,29 +90,18 @@ class JoblistController extends ActionController {
 
 		$allowedMimeTypes = $this->settings['allowedMimeTypes'];
 		$this->view->assign('allowedMimeTypes', $allowedMimeTypes);
+		$this->view->assign('jobApplication', $applyData);
 	}
 
 	/**
 	 * Saves the application send by the applyFormAction
 	 *
 	 * @param JobApplication $applyData
-	 * @return void
-	 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
-	 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException
-	 * @throws \TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
-	 * @throws \TYPO3\CMS\Core\Exception
-	 * @throws \RuntimeException
-	 * @throws \BadFunctionCallException
-	 * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException
-	 * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
-	 * @throws \TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException
-	 * @throws \Exception
-	 * @throws \InvalidArgumentException
 	 */
 	public function applyAction(JobApplication $applyData) {
-		$this->submitApplicationFiles($GLOBALS['TSFE']->fe_user->id, $applyData);
-
 		try {
+			$this->submitApplicationFiles($GLOBALS['TSFE']->fe_user->id, $applyData);
+
 			/** @noinspection PhpMethodParametersCountMismatchInspection */
 			$mailService = $this->objectManager->get(
 				MailTemplateService::class, 'application_mail', 'sg_jobs',
@@ -121,7 +111,7 @@ class JoblistController extends ActionController {
 			$mailService->setToAddresses($this->settings['applicationEmail']);
 
 			$mailService->sendEmail();
-		} catch (Exception $exception) {
+		} catch (\Exception $exception) {
 			// possible errors, because of wrong mails (maybe log that somewhere? Does this makes sense?)
 		}
 	}
diff --git a/Classes/Domain/Model/JobApplication.php b/Classes/Domain/Model/JobApplication.php
index 3436fbe7..bb58f047 100644
--- a/Classes/Domain/Model/JobApplication.php
+++ b/Classes/Domain/Model/JobApplication.php
@@ -40,7 +40,7 @@ class JobApplication extends AbstractEntity {
 	protected $jobTitle = '';
 
 	/**
-	 * @var string $jobTitle
+	 * @var \SGalinski\SgJobs\Domain\Model\Job
 	 */
 	protected $jobId = '';
 
@@ -160,16 +160,16 @@ class JobApplication extends AbstractEntity {
 	}
 
 	/**
-	 * @return string
+	 * @return \SGalinski\SgJobs\Domain\Model\Job
 	 */
 	public function getJobId() {
 		return $this->jobId;
 	}
 
 	/**
-	 * @param string $jobId
+	 * @param \SGalinski\SgJobs\Domain\Model\Job $jobId
 	 */
-	public function setJobId(string $jobId) {
+	public function setJobId(Job $jobId) {
 		$this->jobId = $jobId;
 	}
 
diff --git a/Resources/Private/Templates/Joblist/ApplyForm.html b/Resources/Private/Templates/Joblist/ApplyForm.html
index 8ab23e8e..8300a5bd 100644
--- a/Resources/Private/Templates/Joblist/ApplyForm.html
+++ b/Resources/Private/Templates/Joblist/ApplyForm.html
@@ -2,7 +2,7 @@
 
 <f:section name="main">
 	<f:form action="apply" controller="Joblist" method="post" objectName="applyData" object="{applyData}" enctype="multipart/form-data">
-		<f:form.hidden value="{job}" property="uid" />
+		<f:form.hidden value="{job.uid}" property="jobId" />
 
 		<label for="apply-gender"><f:translate key="frontend.apply.gender" /></label>
 		<f:form.select property="gender" id="apply-gender" class="" options="{None: '', Male: 'Male', Female: 'Female'}" />
-- 
GitLab