dreamjob/app/Controller/JobController.php

289 lines
12 KiB
PHP

<?php
App::uses('AppController', 'Controller');
class JobController extends AppController {
/**
* This controller use User Model
*
* @var array
*/
public $uses = array('DreamjobJobOpening','DreamjobJobFavority','DreamjobJobApplication','DreamjobPageText','DreamjobPageImage','DreamjobJobMsg');
/**
* 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();
if(!is_array($self) or count($self) <= 0){
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
if(!empty($this->request->query['del'])){
$o =$this->DreamjobJobOpening->findById($this->request->query['del']);
if($o['AppUser']['id']== $self['AppUser']['id']){
$this->DreamjobJobOpening->delete($this->request->query['del'],false);
$this->MiconwareSession->setFlash('dreamjob.opening.delete','flash',array('alert'=>'success'));
}else{
$this->MiconwareSession->setFlash('dreamjob.opening.delete.error','flash',array('alert'=>'danger'));
}
}
$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() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$c = $this->MiconwareSession->getCompany();
if(!empty($c)){
if ($this->request->is('post')) {
$this->DreamjobJobOpening->create($this->request->data);
$this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $c['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->set('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list'));
$this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list'));
$this->render('/Job/opening_edit');
}else{
$this->set('error', 'dreamjob.error.noCompany');
$this->render('/Home/error');
}
}
public function openingEdit() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$a = $this->MiconwareSession->getCompany();
if(empty($a)){
$this->set('error', 'dreamjob.error.noCompany');
$this->render('/Home/error');
return null;
}
if(!empty($this->request->params['id'])){
$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'));
}
if(empty($this->request->data['DreamjobJobOpening'])){
$this->set('error', 'dreamjob.error.opening.notFound');
$this->render('/Home/error');
}elseif( $this->request->data['DreamjobJobOpening']['company_id'] != $a['AppUser']['id']){
$this->set('error', 'dreamjob.error.noPermission');
$this->render('/Home/error');
}else{
$this->render('/Job/opening_edit');
}
}
public function openingGet() {
$this->MiconwareSession->init($this);
$opening = false;
if(!empty($this->request->params['id'])){
if(!empty($this->request->params['favorite']) or 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;
}
$data = array('DreamjobJobFavority' => array('opening_id' => $this->request->params['id'], 'worker_id' => $WORKER['AppUser']['id']),'modified' => false);
$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) or 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) or 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->set('opening_MINI',true);
$this->render('/Job/favorite');
}
}
public function applicationList() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$self = $this->MiconwareSession->getWorker();
if(!is_array($self) or count($self) <= 0){
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
$applications = $this->DreamjobJobApplication->find('all',array('conditions' => array('DreamjobJobApplication.worker_id' => $self['AppUser']['id'])));
$this->set('applications',$applications);
$this->set('opening_MINI',true);
$this->render('/Job/applicationWorker_list');
}
}
public function applicationGet() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$WORKER = $this->MiconwareSession->getWorker();
$COMPANY = $self = $this->MiconwareSession->getCompany();
$application = null;
if(isset($this->request->params['id'])){
if(is_array($WORKER) and count($WORKER) > 0)
$application = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.worker_id' => $WORKER['AppUser']['id'],'DreamjobJobApplication.id'=> $this->request->params['id'] )));
if(is_array($COMPANY) and count($COMPANY) > 0)
$application = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobOpening.company_id' => $COMPANY['AppUser']['id'],'DreamjobJobApplication.id'=> $this->request->params['id'] )));
}
if(!is_array($application) or count($application) <= 0){
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
$this->set('page',null);
if(!empty($this->request->params['hiv'])){
$this->DreamjobJobApplication->id = $application['DreamjobJobApplication']['id'];
if ($this->DreamjobJobApplication->saveField('closed',!$application['DreamjobJobApplication']['closed'])) {
$application = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.id'=> $this->request->params['id'] )));
$this->MiconwareSession->setFlash('dreamjob.application.archiv','flash',array('alert'=>'success'));
}else{
$this->MiconwareSession->setFlash('dreamjob.application.archiv.error','flash',array('alert'=>'danger'));
}
}
if(!empty($this->request->params['ages'])){
$this->set('msg',true);
if ($this->request->is('post')) {
$this->DreamjobJobMsg->create($this->request->data);
$this->DreamjobJobMsg->data['DreamjobJobMsg']['saw'] = false;
$this->DreamjobJobMsg->data['DreamjobJobMsg']['application_id'] = $application['DreamjobJobApplication']['id'];
$this->DreamjobJobMsg->data['DreamjobJobMsg']['fromcompany'] = is_array($COMPANY) and count($COMPANY) > 0;
if ($this->DreamjobJobMsg->save()) {
$application = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.id'=> $this->request->params['id'] )));
$this->MiconwareSession->setFlash('dreamjob.application.msg.add','flash',array('alert'=>'success'));
}else{
$this->MiconwareSession->setFlash('dreamjob.application.msg.error','flash',array('alert'=>'danger'));
}
}
}else{
$this->set('msg',false);
if(!empty($this->request->params['page'])){
$this->set('pageInh',$this->DreamjobJobApplication->Page->find('first',
array('conditions' => array("Page.id" => $this->request->params['page']))
));
$page = $this->DreamjobJobApplication->PageText->find('first',
array('conditions' => array("PageText.page_ptr_id" => $this->request->params['page']))
);
if(!is_array($page) or count($page)<= 0)
$page = $this->DreamjobJobApplication->PageImage->find('first',
array('conditions' => array("PageImage.page_ptr_id" => $this->request->params['page']))
);
$this->set('page',$page);
}
}
$this->set('application',$application);
$this->render('/Job/application');
}
}
public function applicationByOpening(){
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$COMPANY = $self = $this->MiconwareSession->getCompany();
$applications = null;
$opening = null;
if(isset($this->request->params['id'])){
if(is_array($COMPANY) and count($COMPANY) > 0)
$opening = $this->DreamjobJobOpening->find('first',array('conditions' => array('DreamjobJobOpening.company_id' => $COMPANY['AppUser']['id'],'DreamjobJobOpening.id'=> $this->request->params['id'] )));
$filter_current = false;
$filter_archiv = false;
$condition = array('DreamjobJobOpening.company_id' => $COMPANY['AppUser']['id'],'DreamjobJobApplication.opening_id'=> $this->request->params['id']);
if(isset($this->request->query['filter']) and $this->request->query['filter'] =='all'){
}elseif(isset($this->request->query['filter']) and $this->request->query['filter'] =='archiv'){
$condition['closed'] = true;
$filter_archiv = true;
}else{
$condition['closed'] = false;
$filter_current = true;
}
$applications = $this->DreamjobJobApplication->find('all',array('conditions' =>$condition));
$this->set("filter_archiv",$filter_archiv);
$this->set("filter_current",$filter_current);
}
if(!is_array($opening) or count($opening) <= 0){
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
$this->set('opening',$opening);
$this->set('applications',$applications);
$this->render('/Job/applicationCompany_list');
}
}
public function applicationSend() {
}
}
?>