dreamjob/app/Model/DreamjobJobApplication.php

298 lines
9.1 KiB
PHP
Raw Normal View History

2014-03-02 11:35:22 +01:00
<?php
App::uses('AppModel', 'Model');
2014-04-13 13:28:39 +02:00
App::uses('CakeEmail', 'Network/Email');
2014-03-02 11:35:22 +01:00
/**
* MicDjJobsApplication Model
*
* @property Worker $Worker
* @property Opening $Opening
*/
class DreamjobJobApplication extends AppModel {
/**
* Use database config
*
* @var string
*/
public $useDbConfig = 'dreamjobMain';
/**
* Use table
*
* @var mixed False or table name
*/
public $useTable = 'mic_dj_jobs_application';
/**
* Display field
*
* @var string
*/
public $displayField = 'id';
/**
* Validation rules
*
* @var array
*/
public static function sendMail($mail,$data,$id){
2014-04-13 13:28:39 +02:00
$Email = new CakeEmail('dreamjobMain');
$Email->to($mail);
$Email->subject('Sie haben eine neue Bewerbung auf dreamJOB erhalten');
2014-04-13 13:28:39 +02:00
$Email->template('job_application');
$Email->viewVars(array('id'=>$id,'data'=>$data));
2014-04-13 13:28:39 +02:00
return $Email->send();
}
2014-04-11 19:43:26 +02:00
public function sendApplication($data){
$dataSource = $this->getDataSource();
$dataSource->begin();
$result=$this->saveAssociated($data);
if($result){
$open = $this->DreamjobJobOpening->find('first', array('conditions' => array('DreamjobJobOpening.id' => $data['DreamjobJobApplication']['opening_id'])));
$result = self::sendMail($open['User']['mail'],array('DreamjobCompany'=>$open['DreamjobCompany']),$this->id);
2014-04-11 19:43:26 +02:00
}
if ($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
2014-03-02 11:35:22 +01:00
public $validate = array(
'id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
2014-03-10 23:53:06 +01:00
)
2014-03-02 11:35:22 +01:00
),
'stars' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'closed' => array(
'boolean' => array(
'rule' => array('boolean'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'offered' => array(
'boolean' => array(
'rule' => array('boolean'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'saw' => array(
'boolean' => array(
'rule' => array('boolean'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'worker_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'opening_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'text' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'DreamjobWorker' => array(
'className' => 'DreamjobWorker',
'foreignKey' => 'worker_id'
),
2014-03-02 11:44:06 +01:00
'DreamjobUserWorker' => array(
2014-03-02 11:35:22 +01:00
'className' => 'DreamjobUser',
'foreignKey' => 'worker_id'
),
2014-03-02 11:44:06 +01:00
'AppUserWorker' => array(
2014-03-02 11:35:22 +01:00
'className' => 'AppUser',
'foreignKey' => 'worker_id'
),
'DreamjobJobOpening' => array(
'className' => 'DreamjobJobOpening',
'foreignKey' => 'opening_id'
)
);
public $hasOne = array(
2014-04-22 22:17:01 +02:00
'Mannerofaddress' => array(
'className' => 'Mannerofaddress',
'foreignKey' => false,
'conditions' => array('AppUserWorker.mannerofaddress_id = Mannerofaddress.id'),
'limit' => 1
),
'WorkerGraducation' => array(
'className' => 'DreamjobListGraducation',
'foreignKey' => false,
'conditions' => array('DreamjobWorker.graducation_id = WorkerGraducation.id'),
'limit' => 1
),
'WorkerUser' => array(
'className' => 'User',
'foreignKey' => false,
'conditions' => array('DreamjobJobApplication.worker_id = AppUserWorker.id and WorkerUser.id = AppUserWorker.user_id'),
'limit' => 1
),
2014-04-22 22:17:01 +02:00
'DreamjobWorkerListCity' => array(
'className' => 'DreamjobListCity',
'foreignKey' => false,
'conditions' => array('DreamjobUserWorker.city_id = DreamjobWorkerListCity.id'),
'limit' => 1
),
//achtung
2014-03-02 11:35:22 +01:00
'DreamjobCompany' => array(
'className' => 'DreamjobCompany',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.company_id = DreamjobCompany.djaccount_ptr_id'),
'limit' => 1
2014-03-02 11:44:06 +01:00
),
'DreamjobUser' => array(
'className' => 'DreamjobUser',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.company_id = DreamjobUser.micapplication_ptr_id'),
'limit' => 1
),
'AppUser' => array(
'className' => 'AppUser',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.company_id = AppUser.id'),
'limit' => 1
),
'User' => array(
'className' => 'User',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.company_id = AppUser.id and User.id = AppUser.user_id'),
'limit' => 1
2014-03-02 11:35:22 +01:00
),
'DreamjobListKindofjob' => array(
'className' => 'DreamjobListKindofjob',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.kindofjob_id = DreamjobListKindofjob.id'),
'limit' => 1
),
2014-04-22 22:17:01 +02:00
'DreamjobCompanyListCity' => array(
'className' => 'DreamjobListCity',
'foreignKey' => false,
'conditions' => array('DreamjobUser.city_id = DreamjobCompanyListCity.id'),
'limit' => 1
),
2014-03-02 11:35:22 +01:00
'DreamjobListGraducation' => array(
'className' => 'DreamjobListGraducation',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.graducation_id = DreamjobListGraducation.id'),
'limit' => 1
),
2014-04-22 20:50:09 +02:00
'DreamjobListCity' => array(
'className' => 'DreamjobListCity',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.city_id = DreamjobListCity.id'),
'limit' => 1
),
'DreamjobListBranch' => array(
'className' => 'DreamjobListBranch',
'foreignKey' => false,
'conditions' => array('DreamjobJobOpening.branch_id = DreamjobListBranch.id'),
'limit' => 1
)
2014-03-02 11:35:22 +01:00
);
public $hasAndBelongsToMany = array(
'PageText' =>
array(
'className' => 'DreamjobPageText',
'with' => 'DreamjobJobApplicationPage',
'foreignKey' => 'application_id',
'associationForeignKey' => 'page_id'
),
'PageImage' =>
array(
'className' => 'DreamjobPageImage',
'with' => 'DreamjobJobApplicationPage',
'foreignKey' => 'application_id',
'associationForeignKey' => 'page_id'
),
'Page' =>
array(
'className' => 'DreamjobPageInh',
'with' => 'DreamjobJobApplicationPage',
'foreignKey' => 'application_id',
'associationForeignKey' => 'page_id'
)
);
public $hasMany = array(
'DreamjobJobMsg' => array(
'className' => 'DreamjobJobMsg',
'foreignKey' => 'application_id'
),
2014-03-10 23:53:06 +01:00
'DreamjobJobApplicationPage' => array(
'className' => 'DreamjobJobApplicationPage',
'foreignKey' => 'application_id'
),
);
2014-03-02 11:35:22 +01:00
}