dreamjob/app/Controller/JobController.php

181 lines
6.7 KiB
PHP
Raw Normal View History

2014-02-19 00:03:29 +01:00
<?php
App::uses('AppController', 'Controller');
class JobController extends AppController {
/**
* This controller use User Model
*
* @var array
*/
2014-03-02 11:56:22 +01:00
public $components = array('Security','MiconwareSession');
2014-03-02 11:35:22 +01:00
public $uses = array('DreamjobJobOpening','DreamjobJobFavority','DreamjobJobApplication');
2014-02-19 00:03:29 +01:00
/**
* Displays a view
*
* @param mixed What page to display
* @return void
* @throws NotFoundException When the view file could not be found
* or MissingViewException in debug mode.
*/
public function openingList() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$self = $this->MiconwareSession->getCompany();
2014-02-23 09:39:07 +01:00
if(!empty($this->request->query['del'])){
2014-03-01 11:17:23 +01:00
$this->DreamjobJobFavority->delete($this->request->query['del'],false);
2014-02-23 09:39:07 +01:00
$this->MiconwareSession->setFlash('dreamjob.opening.delete','flash',array('alert'=>'success'));
}
2014-02-19 00:03:29 +01:00
if(!is_array($self) and count($self) <= 0){
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
$openings = $this->DreamjobJobOpening->find('all',array('conditions' => array('DreamjobJobOpening.company_id' => $self['AppUser']['id'])));
$this->set('openings',$openings);
$this->render('/Job/opening_list');
}
}
public function openingAdd() {
2014-03-01 11:17:23 +01:00
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$this->set('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list'));
$this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list'));
if(empty($this->MiconwareSession->getCompany())){
$this->set('error', 'dreamjob.error.noCompany');
$this->render('/Home/error');
}else{
if ($this->request->is('post')) {
$this->DreamjobJobOpening->create($this->request->data);
$this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $this->MiconwareSession->getCompany()['AppUser']['id'];
if ($this->DreamjobJobOpening->save()) {
$this->MiconwareSession->setFlash('dreamjob.opening.save.add','flash',array('alert'=>'success'));
}else{
$this->MiconwareSession->setFlash('dreamjob.opening.save.error','flash',array('alert'=>'danger'));
}
}
$this->render('/Job/opening_edit');
}
2014-02-19 00:03:29 +01:00
}
2014-02-23 09:39:07 +01:00
public function openingEdit() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
2014-03-01 11:17:23 +01:00
$a = $this->MiconwareSession->getCompany();
if(empty($a)){
$this->set('error', 'dreamjob.error.noCompany');
$this->render('/Home/error');
return null;
}
2014-02-23 09:39:07 +01:00
if(!empty($this->request->params['id'])){
2014-03-01 11:17:23 +01:00
$load = $this->DreamjobJobOpening->findById($this->request->params['id']);
$cid = $a['AppUser']['id'];
if (!empty($load) and $load['DreamjobJobOpening']['company_id'] == $cid) {
if ($this->request->is(array('post', 'put'))) {
$this->DreamjobJobOpening->create($this->request->data);
$this->DreamjobJobOpening->data['DreamjobJobOpening']['id'] = $this->request->params['id'];
$this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $cid;
echo var_dump($this->DreamjobJobOpening);
if ($this->DreamjobJobOpening->save($this->DreamjobJobOpening->data)) {
$this->MiconwareSession->setFlash('dreamjob.opening.save','flash',array('alert'=>'success'));
}else
$this->MiconwareSession->setFlash('dreamjob.opening.save.error','flash',array('alert'=>'danger'));
}
}
$this->request->data=$load;
$this->set('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list'));
$this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list'));
2014-02-23 09:39:07 +01:00
}
2014-03-01 11:17:23 +01:00
if(empty($this->request->data['DreamjobJobOpening'])){
2014-02-23 09:39:07 +01:00
$this->set('error', 'dreamjob.error.opening.notFound');
$this->render('/Home/error');
2014-03-01 11:17:23 +01:00
}elseif( $this->request->data['DreamjobJobOpening']['company_id'] != $a['AppUser']['id']){
$this->set('error', 'dreamjob.error.noPermission');
$this->render('/Home/error');
2014-02-23 09:39:07 +01:00
}else{
$this->render('/Job/opening_edit');
}
}
2014-02-19 00:03:29 +01:00
public function openingGet() {
$this->MiconwareSession->init($this);
$opening = false;
if(!empty($this->request->params['id'])){
if(!empty($this->request->params['favorite']) and count($this->request->params['favorite'])>0){
$WORKER = $this->MiconwareSession->getWorker();
$fav=false;
foreach($WORKER['Favority'] as $val){
if($val['id'] == $this->request->params['id'])
$fav=true;
}
2014-02-19 00:18:48 +01:00
$data = array('DreamjobJobFavority' => array('opening_id' => $this->request->params['id'], 'worker_id' => $WORKER['AppUser']['id']),'modified' => false);
2014-02-19 00:03:29 +01:00
$data2 = array('DreamjobJobFavority.opening_id' => $this->request->params['id'], 'DreamjobJobFavority.worker_id' => $WORKER['AppUser']['id']);
if($fav){
$this->MiconwareSession->setFlash('dreamjob.opening.fav.delete','flash',array('alert'=>'success'));
$this->DreamjobJobFavority->deleteAll($data2,false);
}else{
$this->DreamjobJobFavority->create();
$this->DreamjobJobFavority->save($data);
$this->MiconwareSession->setFlash('dreamjob.opening.fav.add','flash',array('alert'=>'success'));
}
}
$opening = $this->DreamjobJobOpening->find('first',array('conditions' => array('DreamjobJobOpening.id' => $this->request->params['id'])));
}
$this->MiconwareSession->refreshCache();
$this->MiconwareSession->initWeb($this);
if(!is_array($opening) and count($opening) <= 0 ){
$this->set('error', 'dreamjob.error.opening.notFound');
$this->render('/Home/error');
}else{
$this->set('opening',$opening);
$this->render('/Job/opening');
}
}
public function favorite() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$self = $this->MiconwareSession->getWorker();
if(!is_array($self) and count($self) <= 0){
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
$fav_id = array();
foreach($self['Favority'] as $fav)
$fav_id[]=$fav['id'];
$openings = $this->DreamjobJobOpening->find('all',array('conditions' => array('DreamjobJobOpening.id' =>$fav_id)));
$this->set('openings',$openings);
$this->render('/Job/favorite');
}
}
2014-03-02 10:38:47 +01:00
public function applicationList() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$self = $this->MiconwareSession->getWorker();
if(!is_array($self) and count($self) <= 0){
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
2014-03-02 11:35:22 +01:00
$applications = $this->DreamjobJobApplication->find('all',array('conditions' => array('DreamjobJobApplication.worker_id' => $self['AppUser']['id'])));
$this->set('applications',$applications);
$this->render('/Job/applicationWorker_list');
2014-03-02 10:38:47 +01:00
}
}
2014-02-19 00:03:29 +01:00
}
?>