dreamjob/app/Controller/JobController.php

366 lines
16 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 12:14:02 +01:00
2014-04-29 20:26:24 +02:00
public $uses = array('DreamjobJobOpening','DreamjobJobFavority','DreamjobJobApplication','DreamjobPageText','DreamjobPageImage','DreamjobJobMsg','DreamjobCvEntry','DreamjobListCvCategory','DreamjobListBranch','DreamjobListCity');
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.
2014-03-02 12:25:36 +01:00
*/
2014-04-11 19:43:26 +02:00
2014-04-13 13:28:39 +02:00
2014-02-19 00:03:29 +01:00
public function openingList() {
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$self = $this->MiconwareSession->getCompany();
if(!is_array($self) or count($self) <= 0){
2014-02-19 00:03:29 +01:00
$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);
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.delete'),'flash',array('alert'=>'success'));
}else{
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.delete.error'),'flash',array('alert'=>'danger'));
}
}
2014-02-19 00:03:29 +01:00
$openings = $this->DreamjobJobOpening->find('all',array('conditions' => array('DreamjobJobOpening.company_id' => $self['AppUser']['id'])));
$this->set('openings',$openings);
$this->render('/Job/opening_list');
}
}
2014-03-02 12:26:38 +01:00
2014-02-19 00:03:29 +01:00
public function openingAdd() {
2014-03-01 11:17:23 +01:00
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
2014-03-02 12:29:41 +01:00
$c = $this->MiconwareSession->getCompany();
if(!empty($c)){
2014-03-01 11:17:23 +01:00
if ($this->request->is('post')) {
$this->DreamjobJobOpening->create($this->request->data);
2014-03-02 12:29:41 +01:00
$this->DreamjobJobOpening->data['DreamjobJobOpening']['company_id'] = $c['AppUser']['id'];
2014-03-01 11:17:23 +01:00
if ($this->DreamjobJobOpening->save()) {
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.save.add'),'flash',array('alert'=>'success'));
2014-03-01 11:17:23 +01:00
}else{
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.save.error'),'flash',array('alert'=>'danger'));
2014-03-01 11:17:23 +01:00
}
}
2014-03-02 12:29:41 +01:00
$this->set('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list'));
$this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list'));
2014-03-28 16:22:19 +01:00
$this->set('branches',$this->DreamjobListBranch->find('list'));
2014-04-22 16:01:00 +02:00
$this->set('cities',$this->DreamjobListCity->find('list'));
2014-03-01 11:17:23 +01:00
$this->render('/Job/opening_edit');
2014-03-02 12:29:41 +01:00
}else{
$this->set('error', 'dreamjob.error.noCompany');
$this->render('/Home/error');
2014-03-01 11:17:23 +01:00
}
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;
if ($this->DreamjobJobOpening->save($this->DreamjobJobOpening->data)) {
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.save'),'flash',array('alert'=>'success'));
2014-03-01 11:17:23 +01:00
}else
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.save.error'),'flash',array('alert'=>'danger'));
2014-03-01 11:17:23 +01:00
}
}
$this->request->data=$load;
$this->set('kindofjobs', $this->DreamjobJobOpening->DreamjobListKindofjob->find('list'));
$this->set('graducations', $this->DreamjobJobOpening->DreamjobListGraducation->find('list'));
2014-03-28 16:22:19 +01:00
$this->set('branches',$this->DreamjobListBranch->find('list'));
2014-04-22 16:01:00 +02:00
$this->set('cities',$this->DreamjobListCity->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']){
2014-04-29 21:40:03 +02:00
$this->set('error', 'dreamjob.error.noPermision');
2014-03-01 11:17:23 +01:00
$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'])){
2014-03-05 22:01:30 +01:00
if(!empty($this->request->params['favorite']) and count($this->request->params['favorite'])>0){
2014-02-19 00:03:29 +01:00
$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){
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.fav.delete'),'flash',array('alert'=>'success'));
2014-02-19 00:03:29 +01:00
$this->DreamjobJobFavority->deleteAll($data2,false);
}else{
$this->DreamjobJobFavority->create();
$this->DreamjobJobFavority->save($data);
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.opening.fav.add'),'flash',array('alert'=>'success'));
2014-02-19 00:03:29 +01:00
}
}
2014-03-28 16:22:19 +01:00
$con = $this->MiconwareSession->getOpeningCondition();
2014-03-26 19:49:36 +01:00
$con['DreamjobJobOpening.id'] = $this->request->params['id'];
$opening = $this->DreamjobJobOpening->find('first',array('conditions' => $con));
2014-02-19 00:03:29 +01:00
}
$this->MiconwareSession->refreshCache();
$this->MiconwareSession->initWeb($this);
if(!is_array($opening) or count($opening) <= 0 ){
2014-02-19 00:03:29 +01:00
$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){
2014-02-19 00:03:29 +01:00
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
$fav_id = array();
foreach($self['Favority'] as $fav)
$fav_id[]=$fav['id'];
2014-03-28 16:22:19 +01:00
$con = $this->MiconwareSession->getOpeningCondition();
2014-03-26 19:49:36 +01:00
$con['DreamjobJobOpening.id'] =$fav_id;
$openings = $this->DreamjobJobOpening->find('all',array('conditions' => $con));
2014-02-19 00:03:29 +01:00
$this->set('openings',$openings);
$this->set('opening_MINI',true);
2014-02-19 00:03:29 +01:00
$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) or count($self) <= 0){
2014-03-02 10:38:47 +01:00
$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->set('opening_MINI',true);
2014-03-02 11:35:22 +01:00
$this->render('/Job/applicationWorker_list');
2014-03-02 10:38:47 +01:00
}
}
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);
2014-04-22 22:59:02 +02:00
$this->set("edit",false);
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'] )));
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.application.archiv'),'flash',array('alert'=>'success'));
}else{
2014-04-29 20:49:20 +02:00
$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;
2014-04-11 19:43:26 +02:00
if($this->DreamjobJobMsg->sendMessage()) {
$application = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.id'=> $this->request->params['id'] )));
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.application.msg.add'),'flash',array('alert'=>'success'));
}else{
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.application.msg.error'),'flash',array('alert'=>'danger'));
}
}
2014-03-05 00:01:58 +01:00
if(is_array($WORKER) and count($WORKER) > 0)
$this->DreamjobJobMsg->updateAll(array("saw"=>true),array("DreamjobJobMsg.fromcompany"=>true,"DreamjobJobMsg.application_id"=>$this->request->params['id']));
if(is_array($COMPANY) and count($COMPANY) > 0)
$this->DreamjobJobMsg->updateAll(array("saw"=>true),array("DreamjobJobMsg.fromcompany"=>false,"DreamjobJobMsg.application_id"=>$this->request->params['id']));
}else{
$this->set('msg',false);
2014-03-15 01:52:07 +01:00
// CV
if(!empty($this->request->params['vitea'])){
2014-04-22 22:17:01 +02:00
$cv = $this->DreamjobCvEntry->find('all',array('conditions' => array('worker_id'=> $application['DreamjobJobApplication']['worker_id'])));
2014-03-15 01:52:07 +01:00
$this->set("cv",$cv);
2014-04-22 22:59:02 +02:00
$cvp0 = $this->DreamjobListCvCategory->find('first',array('conditions' => array('DreamjobListCvCategory.position' => 0)));
$this->set('cvp0', $cvp0);
2014-03-15 01:52:07 +01:00
}else{
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'] )));
2014-03-05 00:01:58 +01:00
if(!empty($this->request->query['archiv']) and count($opening)>0){
$application = $this->DreamjobJobApplication->find('first',array('conditions' =>array('DreamjobJobApplication.id'=>$this->request->query['archiv'], 'DreamjobJobApplication.opening_id'=> $this->request->params['id'])));
$this->DreamjobJobApplication->id = $this->request->query['archiv'];
if ($this->DreamjobJobApplication->saveField('closed',!$application['DreamjobJobApplication']['closed'])) {
$application = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.id'=> $this->request->params['id'] )));
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.application.archiv'),'flash',array('alert'=>'success'));
2014-03-05 00:01:58 +01:00
}else{
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.application.archiv.error'),'flash',array('alert'=>'danger'));
2014-03-05 00:01:58 +01:00
}
}
$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() {
2014-03-05 22:01:30 +01:00
$this->MiconwareSession->init($this);
$this->MiconwareSession->initWeb($this);
$w = $this->MiconwareSession->getWorker();
if(!empty($w)){
$opening = null;
if(!empty($this->request->params['id'])){
2014-03-28 16:22:19 +01:00
$con = $this->MiconwareSession->getOpeningCondition();
2014-03-26 19:49:36 +01:00
$con['DreamjobJobOpening.id'] = $this->request->params['id'];
$opening = $this->DreamjobJobOpening->find('first',array('conditions' => $con));
2014-03-05 22:01:30 +01:00
}
if(!is_array($opening) or count($opening) <= 0 ){
$this->set('error', 'dreamjob.error.opening.notFound');
$this->render('/Home/error');
}else{
2014-03-10 23:53:06 +01:00
if ($this->request->is('post')){
if($this->request->data['DreamjobJobApplication']['agb']) {
unset($this->request->data['DreamjobJobApplication']['agb']);
$this->request->data['DreamjobJobApplication']['worker_id'] = $w['AppUser']['id'];
$this->request->data['DreamjobJobApplication']['opening_id'] = $this->request->params['id'];
$pages = $this->request->data['DreamjobJobApplicationPage']['page_id'];
unset($this->request->data['DreamjobJobApplicationPage']['page_id']);
foreach($pages as $id)
$this->request->data['DreamjobJobApplicationPage'][]=array('page_id'=> $id);
2014-04-11 19:43:26 +02:00
$result = $this->DreamjobJobApplication->sendApplication($this->request->data);
2014-03-10 23:53:06 +01:00
if ($result) {
2014-05-07 10:31:25 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.application.send.success'),'flash',array('alert'=>'success'));
2014-03-05 22:01:30 +01:00
}else{
2014-05-06 18:12:23 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.application.send.error'),'flash',array('alert'=>'danger'));
2014-03-05 22:01:30 +01:00
}
2014-03-10 23:53:06 +01:00
}else{
2014-04-29 20:49:20 +02:00
$this->MiconwareSession->setFlash(__('dreamjob.agb.error.notAccept'),'flash',array('alert'=>'danger'));
2014-03-05 22:01:30 +01:00
}
}
$this->set('pages', $w['DreamjobPageInh']);
$this->set('opening', $opening);
$this->render('/Job/application_send');
}
}else{
$this->set('error', 'dreamjob.error.noWorker');
2014-03-05 22:01:30 +01:00
$this->render('/Home/error');
}
}
2014-02-19 00:03:29 +01:00
}
?>