diff --git a/app/Controller/JobController.php b/app/Controller/JobController.php index 3a99191..9cc4c9c 100644 --- a/app/Controller/JobController.php +++ b/app/Controller/JobController.php @@ -19,10 +19,9 @@ class JobController extends AppController { * @throws NotFoundException When the view file could not be found * or MissingViewException in debug mode. */ - private $OPENING_COUNT_GAP = 1; - - private function allowOpening($c,$diff=0){ - return ((count($c['DreamjobJobOpening'])+$diff) >= (($this->OPENING_COUNT_GAP < $c['Pro']['opening_count'])?$c['Pro']['opening_count']:$this->OPENING_COUNT_GAP)); + private static function monthAdd($date,$interval){ + $date = new DateTime($date); + return $date->add(new DateInterval('P'.$interval.'M'))->format("Y-m-d"); } public function openingList() { @@ -63,21 +62,24 @@ class JobController extends AppController { if ($this->request->is('post')) { $this->DreamjobJobOpening->create($this->request->data); $this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $c['AppUser']['id']; - if(!$this->allowOpening($c)){ - $this->DreamjobJobOpening->data['DreamjobJobOpening']['active'] = false; - } + $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate'] = JobController::monthAdd($this->DreamjobJobOpening->data['DreamjobJobOpening']['startdate'],3); + $this->request->data['DreamjobJobOpening']['enddate'] = $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate']; if ($this->DreamjobJobOpening->save()) { $this->MiconwareSession->setFlash(__('dreamjob.opening.save.success'), 'flash', array('alert' => 'success')); if($this->request->data['DreamjobJobOpening']['active'] and $this->request->data['DreamjobJobOpening']['startdate'] <= date("Y-m-d") and $this->request->data['DreamjobJobOpening']['enddate'] >= date("Y-m-d", strtotime("+1 day") ) ) return $this->redirect(array('action' => 'openingGet','id'=>$this->DreamjobJobOpening->id)); + $this->request->data=array(); + $this->request->data['DreamjobJobOpening']['active']=true; + $this->request->data['DreamjobJobOpening']['company_id']=$c['AppUser']['id']; } else { $this->MiconwareSession->setFlash(__('dreamjob.opening.save.error'), 'flash', array('alert' => 'danger')); } - }else{ - if(!$this->allowOpening($c,-1)) - $this->MiconwareSession->setFlash(__('dreamjob.opening.count'), 'flash', array('alert' => 'danger')); + }else{ + $this->MiconwareSession->setFlash(__('dreamjob.opening.cost'), 'flash', array('alert' => 'danger')); $this->request->data['DreamjobJobOpening']['active']=true; + $this->request->data['DreamjobJobOpening']['company_id']=$c['AppUser']['id']; } + $this->set('enddate_no',false); $this->set('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list')); $this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list')); $this->set('branches', $this->DreamjobListBranch->find('list')); @@ -108,25 +110,40 @@ class JobController extends AppController { $load = $this->DreamjobJobOpening->findById($this->request->params['id']); $cid = $a['AppUser']['id']; if (!empty($load) and $load['DreamjobJobOpening']['company_id'] == $cid and $load['DreamjobJobOpening']['delete']==false) { + $enddate_no = ($load['DreamjobJobOpening']['startdate']<=date("Y-m-d",strtotime("-1 day"))); + $this->set('enddate_no',$enddate_no); if ($this->request->is(array('post', 'put'))) { + $addToEnddate = !empty($this->request->data['DreamjobJobOpening']['addToEnddate']); $this->DreamjobJobOpening->create($this->request->data); $this->DreamjobJobOpening->data['DreamjobJobOpening']['id'] = $this->request->params['id']; $this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $cid; - if(!$this->allowOpening($a)){ - $this->DreamjobJobOpening->data['DreamjobJobOpening']['active'] = false; - } - if ($this->DreamjobJobOpening->save($this->DreamjobJobOpening->data)) { - if(!$this->allowOpening($a)) - $this->MiconwareSession->setFlash(__('dreamjob.opening.save.count'), 'flash', array('alert' => 'info')); + if($enddate_no){ + $this->DreamjobJobOpening->data['DreamjobJobOpening']['startdate'] = $load['DreamjobJobOpening']['startdate']; + if($addToEnddate) + $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate'] = JobController::monthAdd($load['DreamjobJobOpening']['enddate'],1); else - $this->MiconwareSession->setFlash(__('dreamjob.opening.save.success'), 'flash', array('alert' => 'success')); + $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate'] = $load['DreamjobJobOpening']['enddate']; + }else{ + $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate'] = JobController::monthAdd($this->DreamjobJobOpening->data['DreamjobJobOpening']['startdate'],3); + $this->request->data['DreamjobJobOpening']['startdate'] = $this->DreamjobJobOpening->data['DreamjobJobOpening']['startdate']; + } + if ($this->DreamjobJobOpening->save($this->DreamjobJobOpening->data)) { if($this->request->data['DreamjobJobOpening']['active'] and $this->request->data['DreamjobJobOpening']['startdate'] <= date("Y-m-d") and $this->request->data['DreamjobJobOpening']['enddate'] >= date("Y-m-d", strtotime("+1 day") )) return $this->redirect(array('action' => 'openingGet','id'=>$this->request->params['id'])); + $load = $this->DreamjobJobOpening->findById($this->request->params['id']); + $enddate_no = ($load['DreamjobJobOpening']['startdate']<=date("Y-m-d",strtotime("-1 day"))); + $this->set('enddate_no',$enddate_no); + $this->MiconwareSession->setFlash(__('dreamjob.opening.save.success'), 'flash', array('alert' => 'success')); } else $this->MiconwareSession->setFlash(__('dreamjob.opening.save.error'), 'flash', array('alert' => 'danger')); + }else{ + $this->MiconwareSession->setFlash(__('dreamjob.opening.cost'), 'flash', array('alert' => 'danger')); } } $this->request->data = $load; + $this->set('startdate',$load['DreamjobJobOpening']['startdate']); + $this->set('enddate',$load['DreamjobJobOpening']['enddate']); + $this->set('enddate_next',JobController::monthAdd($load['DreamjobJobOpening']['enddate'],3)); $this->set('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list')); $this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list')); $this->set('branches', $this->DreamjobListBranch->find('list')); diff --git a/app/View/Job/opening_edit.ctp b/app/View/Job/opening_edit.ctp index 3c7b087..d65f0fc 100644 --- a/app/View/Job/opening_edit.ctp +++ b/app/View/Job/opening_edit.ctp @@ -28,8 +28,19 @@ echo $this->Form->create('DreamjobJobOpening',$default_Form); ?> Form->input('DreamjobJobOpening.title',array('placeholder'=>__('dreamjob.opening.title.placeholder'),'label'=>array('text'=>__("dreamjob.title"),"class"=>$default_Form['inputDefaults']['label']['class']))); - echo $this->Form->input('DreamjobJobOpening.startdate',array('label'=>array('text'=>__("dreamjob.opening.startdate"),"class"=>$default_Form['inputDefaults']['label']['class']),"style"=>'width:20%;display:inline-block;','dateFormat' => 'DMY','minYear' => date('Y') - 10, 'maxYear' => date('Y')+10)); - echo $this->Form->input('DreamjobJobOpening.enddate',array('label'=>array('text'=>__("dreamjob.opening.enddate"),"class"=>$default_Form['inputDefaults']['label']['class']),"style"=>'width:20%;display:inline-block;','dateFormat' => 'DMY','minYear' => date('Y') - 10, 'maxYear' => date('Y')+10)); + if(empty($enddate_no)){ + echo $this->Form->input('DreamjobJobOpening.startdate',array('label'=>array('text'=>__("dreamjob.opening.startdate"),"class"=>$default_Form['inputDefaults']['label']['class']),"style"=>'width:20%;display:inline-block;','dateFormat' => 'DMY','minYear' => date('Y') - 10, 'maxYear' => date('Y')+10)); + }else + echo $startdate; + echo (empty($enddate))?__('dreamjob.opening.enddatum_description'):__('dreamjob.opening.enddatum_description (%s)',$enddate); + if(isset($enddate_next) && !empty($enddate_no)){ ?> +
+ +
+ Form->checkbox('DreamjobJobOpening.addToEnddate',array("class"=>'form-control',"label"=>__("dreamjob.opening.addToEnddate")))?> +
+
+ Form->input('DreamjobJobOpening.kindofjob_id',array('label'=>array('text'=>__("dreamjob.kindofjob"),"class"=>$default_Form['inputDefaults']['label']['class']))); echo $this->Form->input('DreamjobJobOpening.graducation_id',array('label'=>array('text'=>__("dreamjob.graducation"),"class"=>$default_Form['inputDefaults']['label']['class']))); echo $this->Form->input('DreamjobJobOpening.branch_id',array('label'=>array('text'=>__("dreamjob.branch"),"class"=>$default_Form['inputDefaults']['label']['class']))); ?>