/** * Checks if the data is valid, and if it is, saves the Job * * @param JobModel $job * @param array $data * @param array $files * * @return JobModel|bool */ public function saveJobData($job, $data, $files) { $jobForm = $this->getJobForm(); $mergedData = array_merge_recursive($data->toArray(), $files->toArray()); $jobForm->setCompanySlug($job->getCompany()->getSlugName()); $jobForm->bind($job); $jobForm->setData($mergedData); if (!$jobForm->isValid()) { return false; } $file = $files['attachment_file']; if ($file['error'] !== UPLOAD_ERR_NO_FILE) { $oldPath = $job->getAttachment(); try { $newPath = $this->getFileStorageService()->storeUploadedFile($file); } catch (\Exception $e) { return false; } if (!is_null($oldPath) && $oldPath != $newPath) { $this->getFileStorageService()->removeFile($oldPath); } $job->setAttachment($newPath); } $job->setTimeStamp(new \DateTime()); $this->getJobMapper()->persist($job); return $job; }