コード例 #1
0
 public function updateAction($id = null)
 {
     if ($this->request->isPost()) {
         $id = $this->request->getPost('id');
         $userSession = $this->session->get("userSession");
         $jobs = Jobs::findFirst($id);
         $jobs->modified = date('Y-m-d H:i:s');
         $jobs->member_id = $userSession['id'];
         $jobs->position = $this->request->getPost('position');
         $jobs->job_category_id = $this->request->getPost('job_category_id');
         $jobs->job_description = $this->request->getPost('job_description');
         $jobs->requirements = $this->request->getPost('requirements');
         $jobs->benefits = $this->request->getPost('benefits');
         $jobs->salary_from = $this->request->getPost('salary_from');
         $jobs->salary_to = $this->request->getPost('salary_to');
         $jobs->company = $this->request->getPost('company');
         $jobs->website = $this->request->getPost('website');
         $jobs->telephone = $this->request->getPost('telephone');
         $jobs->email = $this->request->getPost('email');
         $jobs->street = $this->request->getPost('street');
         $jobs->city = $this->request->getPost('city');
         $jobs->country_id = $this->request->getPost('country_id');
         $jobs->how_to_apply = $this->request->getPost('how_to_apply');
         if ($jobs->update()) {
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>New job has been updated');
             if ($this->request->hasFiles() == true) {
                 set_time_limit(1200);
                 $uploads = $this->request->getUploadedFiles();
                 $isUploaded = false;
                 #do a loop to handle each file individually
                 foreach ($uploads as $upload) {
                     #define a “unique” name and a path to where our file must go
                     $fileName = $upload->getname();
                     $fileInfo = new SplFileInfo($fileName);
                     $fileExt = $fileInfo->getExtension();
                     $fileExt = strtolower($fileExt);
                     $newFileName = substr(md5(uniqid(rand(), true)), 0, 10) . date('ymdhis') . '.' . $fileExt;
                     //$fileExt = $upload->getExtension();
                     $fileImageExt = array('jpeg', 'jpg', 'png');
                     //error_log("File Extension :".$fileExt, 0);
                     $fileType = '';
                     $filePath = '';
                     $path = '';
                     //$path = ''.$newFileName;
                     if (in_array($fileExt, $fileImageExt)) {
                         $path = 'img/job/' . $newFileName;
                         $filePath = 'img/job/';
                         //$fileType = 'Image';
                     }
                     #move the file and simultaneously check if everything was ok
                     $upload->moveTo($path) ? $isUploaded = true : ($isUploaded = false);
                 }
                 #if any file couldn't be moved, then throw an message
                 if ($isUploaded) {
                     $jobLogo = JobLogos::findFirst('job_id="' . $id . '"');
                     if ($jobLogo) {
                         //delete previous logo first
                         unlink($jobLogo->file_path . $jobLogo->filename);
                         $jobLogo->created = date('Y-m-d H:i:s');
                         $jobLogo->modified = date('Y-m-d H:i:s');
                         $jobLogo->member_id = $userSession['id'];
                         $jobLogo->job_id = $id;
                         $jobLogo->file_path = $filePath;
                         $jobLogo->filename = $newFileName;
                         if ($jobLogo->update()) {
                         }
                         //before saving the new one
                     } else {
                         $jobLogo = new JobLogos();
                         $jobLogo->created = date('Y-m-d H:i:s');
                         $jobLogo->modified = date('Y-m-d H:i:s');
                         $jobLogo->member_id = $userSession['id'];
                         $jobLogo->job_id = $id;
                         $jobLogo->file_path = $filePath;
                         $jobLogo->filename = $newFileName;
                         if ($jobLogo->create()) {
                         }
                     }
                 }
             }
             return $this->response->redirect('job/view/' . $id);
         }
     }
     $this->view->setVar('job', Jobs::findFirst($id));
     $countries = Countries::find();
     $this->view->setVar('countries', $countries);
     $jobCategories = JobCategories::find();
     $this->view->setVar('jobCategories', $jobCategories);
     $jobLogo = JobLogos::findFirst('job_id="' . $id . '"');
     if ($jobLogo) {
         $jobLogo = $jobLogo->file_path . $jobLogo->filename;
     } else {
         $jobLogo = 'http://placehold.it/200x200';
     }
     $this->view->setVar('jobLogo', $jobLogo);
 }
コード例 #2
0
 public function updateAction($id = null)
 {
     if ($this->request->isPost()) {
         $id = $this->request->getPost('id');
         $userSession = $this->session->get("userSession");
         $jobs = Jobs::findFirst($id);
         $jobs->modified = date('Y-m-d H:i:s');
         $jobs->member_id = $userSession['id'];
         $jobs->position = $this->request->getPost('position');
         $jobs->job_category_id = $this->request->getPost('job_category_id');
         $jobs->job_description = $this->request->getPost('job_description');
         $jobs->requirements = $this->request->getPost('requirements');
         $jobs->benefits = $this->request->getPost('benefits');
         $jobs->salary_from = $this->request->getPost('salary_from');
         $jobs->salary_to = $this->request->getPost('salary_to');
         $jobs->company = $this->request->getPost('company');
         $jobs->website = $this->request->getPost('website');
         $jobs->telephone = $this->request->getPost('telephone');
         $jobs->email = $this->request->getPost('email');
         $jobs->street = $this->request->getPost('street');
         $jobs->city = $this->request->getPost('city');
         $jobs->country_id = $this->request->getPost('country_id');
         $jobs->how_to_apply = $this->request->getPost('how_to_apply');
         if ($jobs->update()) {
             $id = $jobs->id;
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>New job has been updated');
             return $this->response->redirect('job/view/' . $id);
         }
     }
     $this->view->setVar('job', Jobs::findFirst($id));
     $countries = Countries::find();
     $this->view->setVar('countries', $countries);
     $jobCategories = JobCategories::find();
     $this->view->setVar('jobCategories', $jobCategories);
 }