This commit is contained in:
Martin Müller 2014-11-25 19:50:10 +01:00
parent 32c041b795
commit 11b6254dbe
2 changed files with 47 additions and 19 deletions

View File

@ -19,10 +19,9 @@ class JobController extends AppController {
* @throws NotFoundException When the view file could not be found * @throws NotFoundException When the view file could not be found
* or MissingViewException in debug mode. * or MissingViewException in debug mode.
*/ */
private $OPENING_COUNT_GAP = 1; private static function monthAdd($date,$interval){
$date = new DateTime($date);
private function allowOpening($c,$diff=0){ return $date->add(new DateInterval('P'.$interval.'M'))->format("Y-m-d");
return ((count($c['DreamjobJobOpening'])+$diff) >= (($this->OPENING_COUNT_GAP < $c['Pro']['opening_count'])?$c['Pro']['opening_count']:$this->OPENING_COUNT_GAP));
} }
public function openingList() { public function openingList() {
@ -63,21 +62,24 @@ class JobController extends AppController {
if ($this->request->is('post')) { if ($this->request->is('post')) {
$this->DreamjobJobOpening->create($this->request->data); $this->DreamjobJobOpening->create($this->request->data);
$this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $c['AppUser']['id']; $this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $c['AppUser']['id'];
if(!$this->allowOpening($c)){ $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate'] = JobController::monthAdd($this->DreamjobJobOpening->data['DreamjobJobOpening']['startdate'],3);
$this->DreamjobJobOpening->data['DreamjobJobOpening']['active'] = false; $this->request->data['DreamjobJobOpening']['enddate'] = $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate'];
}
if ($this->DreamjobJobOpening->save()) { if ($this->DreamjobJobOpening->save()) {
$this->MiconwareSession->setFlash(__('dreamjob.opening.save.success'), 'flash', array('alert' => 'success')); $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") ) ) 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)); 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 { } else {
$this->MiconwareSession->setFlash(__('dreamjob.opening.save.error'), 'flash', array('alert' => 'danger')); $this->MiconwareSession->setFlash(__('dreamjob.opening.save.error'), 'flash', array('alert' => 'danger'));
} }
}else{ }else{
if(!$this->allowOpening($c,-1)) $this->MiconwareSession->setFlash(__('dreamjob.opening.cost'), 'flash', array('alert' => 'danger'));
$this->MiconwareSession->setFlash(__('dreamjob.opening.count'), 'flash', array('alert' => 'danger'));
$this->request->data['DreamjobJobOpening']['active']=true; $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('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list'));
$this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list')); $this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list'));
$this->set('branches', $this->DreamjobListBranch->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']); $load = $this->DreamjobJobOpening->findById($this->request->params['id']);
$cid = $a['AppUser']['id']; $cid = $a['AppUser']['id'];
if (!empty($load) and $load['DreamjobJobOpening']['company_id'] == $cid and $load['DreamjobJobOpening']['delete']==false) { 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'))) { if ($this->request->is(array('post', 'put'))) {
$addToEnddate = !empty($this->request->data['DreamjobJobOpening']['addToEnddate']);
$this->DreamjobJobOpening->create($this->request->data); $this->DreamjobJobOpening->create($this->request->data);
$this->DreamjobJobOpening->data['DreamjobJobOpening']['id'] = $this->request->params['id']; $this->DreamjobJobOpening->data['DreamjobJobOpening']['id'] = $this->request->params['id'];
$this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $cid; $this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $cid;
if(!$this->allowOpening($a)){ if($enddate_no){
$this->DreamjobJobOpening->data['DreamjobJobOpening']['active'] = false; $this->DreamjobJobOpening->data['DreamjobJobOpening']['startdate'] = $load['DreamjobJobOpening']['startdate'];
} if($addToEnddate)
if ($this->DreamjobJobOpening->save($this->DreamjobJobOpening->data)) { $this->DreamjobJobOpening->data['DreamjobJobOpening']['enddate'] = JobController::monthAdd($load['DreamjobJobOpening']['enddate'],1);
if(!$this->allowOpening($a))
$this->MiconwareSession->setFlash(__('dreamjob.opening.save.count'), 'flash', array('alert' => 'info'));
else 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") )) 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'])); 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 } else
$this->MiconwareSession->setFlash(__('dreamjob.opening.save.error'), 'flash', array('alert' => 'danger')); $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->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('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list'));
$this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list')); $this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list'));
$this->set('branches', $this->DreamjobListBranch->find('list')); $this->set('branches', $this->DreamjobListBranch->find('list'));

View File

@ -28,8 +28,19 @@ echo $this->Form->create('DreamjobJobOpening',$default_Form);
?> ?>
</legend> </legend>
<?php echo $this->Form->input('DreamjobJobOpening.title',array('placeholder'=>__('dreamjob.opening.title.placeholder'),'label'=>array('text'=>__("dreamjob.title"),"class"=>$default_Form['inputDefaults']['label']['class']))); <?php echo $this->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)); if(empty($enddate_no)){
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)); 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)){ ?>
<div class="form-group">
<label class="col-sm-3 control-label"><?=__("dreamjob.opening.addToEnddate");?></label>
<div class="col-sm-9" style="text-align:left;">
<?=$this->Form->checkbox('DreamjobJobOpening.addToEnddate',array("class"=>'form-control',"label"=>__("dreamjob.opening.addToEnddate")))?>
</div>
</div>
<?php }
echo $this->Form->input('DreamjobJobOpening.kindofjob_id',array('label'=>array('text'=>__("dreamjob.kindofjob"),"class"=>$default_Form['inputDefaults']['label']['class']))); echo $this->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.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']))); ?> echo $this->Form->input('DreamjobJobOpening.branch_id',array('label'=>array('text'=>__("dreamjob.branch"),"class"=>$default_Form['inputDefaults']['label']['class']))); ?>