Example #1
0
 /**
  * Inserts a job into a given package
  *
  * @param mixed $package
  */
 public function insertIntoPackage($package)
 {
     $job = new JobModel($this->em);
     $job->setPackage($package);
     $this->em->persist($job);
     return $job;
 }
Example #2
0
 /**
  * Creates a new job and adds it to the specified package.
  *
  * @param integer $packageID
  * @param array $data
  * @param array $files
  * @return bool|JobModel
  */
 public function createJob($packageID, $data, $files)
 {
     $package = $this->getPackageMapper()->findPackage($packageID);
     $job = new JobModel();
     $job->setPackage($package);
     return $this->saveJobData($job, $data, $files);
 }
Example #3
0
 /**
  * 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;
 }