mail message user/company switch
This commit is contained in:
parent
f453285de1
commit
6eadfb2c25
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
App::uses('AppModel', 'Model');
|
App::uses('AppModel', 'Model');
|
||||||
App::uses('CakeEmail', 'Network/Email');
|
App::uses('CakeEmail', 'Network/Email');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MicDjJobsMsg Model
|
* MicDjJobsMsg Model
|
||||||
*
|
*
|
||||||
|
@ -8,163 +10,165 @@ App::uses('CakeEmail', 'Network/Email');
|
||||||
*/
|
*/
|
||||||
class DreamjobJobMsg extends AppModel {
|
class DreamjobJobMsg extends AppModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use database config
|
* Use database config
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $useDbConfig = 'dreamjobMain';
|
public $useDbConfig = 'dreamjobMain';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use table
|
* Use table
|
||||||
*
|
*
|
||||||
* @var mixed False or table name
|
* @var mixed False or table name
|
||||||
*/
|
*/
|
||||||
public $useTable = 'mic_dj_jobs_msg';
|
public $useTable = 'mic_dj_jobs_msg';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display field
|
* Display field
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $displayField = 'id';
|
public $displayField = 'id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation rules
|
* Validation rules
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static function sendMail($mail,$id,$data,$fromcompany=false){
|
public static function sendMail($mail, $id, $data, $fromcompany = false) {
|
||||||
$Email = new CakeEmail('dreamjobMain');
|
$Email = new CakeEmail('dreamjobMain');
|
||||||
$Email->to($mail);
|
$Email->to($mail);
|
||||||
if($fromcompany){
|
if ($fromcompany) {
|
||||||
$Email->subject('Du hast eine neue Nachricht bei dreamJOB');
|
$Email->subject('Du hast eine neue Nachricht bei dreamJOB');
|
||||||
$Email->template('job_application_msg_worker');
|
$Email->template('job_application_msg_worker');
|
||||||
}else{
|
} else {
|
||||||
$Email->subject('Sie haben eine neue Nachricht auf dreamJOB');
|
$Email->subject('Sie haben eine neue Nachricht auf dreamJOB');
|
||||||
$Email->template('job_application_msg_company');
|
$Email->template('job_application_msg_company');
|
||||||
}
|
}
|
||||||
$Email->attachments(array('dak.jpg' => WWW_ROOT.DS.'mail'.DS.'dak.jpg'));
|
$Email->attachments(array('dak.jpg' => WWW_ROOT . DS . 'mail' . DS . 'dak.jpg'));
|
||||||
$Email->viewVars(array('id'=>$id,'data'=>$data));
|
$Email->viewVars(array('id' => $id, 'data' => $data));
|
||||||
return $Email->send();
|
return $Email->send();
|
||||||
}
|
}
|
||||||
public function sendMessage(){
|
|
||||||
$dataSource = $this->getDataSource();
|
|
||||||
$dataSource->begin();
|
|
||||||
$result = $this->save();
|
|
||||||
if($result){
|
|
||||||
$app = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.id' => $result["DreamjobJobMsg"]["application_id"])) );
|
|
||||||
|
|
||||||
if($this->fromcompany)
|
|
||||||
$result = self::sendMail($app['User']['mail'],$this->application_id,array('DreamjobCompany'=>$app['DreamjobCompany']),true);
|
|
||||||
else
|
|
||||||
$result = self::sendMail($app['WorkerUser']['mail'],$this->application_id,array('User'=>$app['WorkerUser'],'AppUser'=>$app['AppUserWorker']));
|
|
||||||
}
|
|
||||||
if ($result) {
|
|
||||||
$dataSource->commit();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
$dataSource->rollback();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public $validate = array(
|
|
||||||
'application_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
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'fromcompany' => 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
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'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
|
public function sendMessage() {
|
||||||
|
$dataSource = $this->getDataSource();
|
||||||
|
$dataSource->begin();
|
||||||
|
$result = $this->save();
|
||||||
|
if ($result) {
|
||||||
|
$app = $this->DreamjobJobApplication->find('first', array('conditions' => array('DreamjobJobApplication.id' => $result["DreamjobJobMsg"]["application_id"])));
|
||||||
|
|
||||||
/**
|
if ($this->fromcompany)
|
||||||
* belongsTo associations
|
$result = self::sendMail($app['WorkerUser']['mail'], $this->application_id, array('User' => $app['WorkerUser'], 'AppUser' => $app['AppUserWorker']));
|
||||||
*
|
else
|
||||||
* @var array
|
$result = self::sendMail($app['User']['mail'], $this->application_id, array('DreamjobCompany' => $app['DreamjobCompany']), true);
|
||||||
*//*
|
}
|
||||||
public $belongsTo = array(
|
if ($result) {
|
||||||
'Application' => array(
|
$dataSource->commit();
|
||||||
'className' => 'DreamjobJobApplication',
|
return true;
|
||||||
'foreignKey' => 'application_id',
|
} else {
|
||||||
'conditions' => '',
|
$dataSource->rollback();
|
||||||
'fields' => '',
|
}
|
||||||
'order' => ''
|
return false;
|
||||||
)
|
}
|
||||||
);*/
|
|
||||||
public $hasOne = array(
|
public $validate = array(
|
||||||
'DreamjobJobApplication' => array(
|
'application_id' => array(
|
||||||
'className' => 'DreamjobJobApplication',
|
'numeric' => array(
|
||||||
'foreignKey' => false,
|
'rule' => array('numeric'),
|
||||||
'conditions' => array('DreamjobJobApplication.id = DreamjobJobMsg.application_id'),
|
//'message' => 'Your custom message here',
|
||||||
'fields' => '',
|
//'allowEmpty' => false,
|
||||||
'order' => ''
|
//'required' => false,
|
||||||
),
|
//'last' => false, // Stop validation after this rule
|
||||||
'Opening' => array(
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
||||||
'className' => 'DreamjobJobOpening',
|
),
|
||||||
'foreignKey' => false,
|
),
|
||||||
'conditions' => array('Opening.id = DreamjobJobApplication.opening_id'),
|
'fromcompany' => array(
|
||||||
'limit' => 1
|
'boolean' => array(
|
||||||
),
|
'rule' => array('boolean'),
|
||||||
'AppUserWorker' => array(
|
//'message' => 'Your custom message here',
|
||||||
'className' => 'AppUser',
|
//'allowEmpty' => false,
|
||||||
'foreignKey' => false,
|
//'required' => false,
|
||||||
'conditions' => array('DreamjobJobApplication.worker_id = AppUserWorker.id'),
|
//'last' => false, // Stop validation after this rule
|
||||||
'limit' => 1
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
||||||
),
|
),
|
||||||
'Worker' => array(
|
),
|
||||||
'className' => 'User',
|
'saw' => array(
|
||||||
'foreignKey' => false,
|
'boolean' => array(
|
||||||
'conditions' => array('DreamjobJobApplication.worker_id = AppUserWorker.id and Worker.id = AppUserWorker.user_id'),
|
'rule' => array('boolean'),
|
||||||
'limit' => 1
|
//'message' => 'Your custom message here',
|
||||||
),
|
//'allowEmpty' => false,
|
||||||
'AppUserCompany' => array(
|
//'required' => false,
|
||||||
'className' => 'AppUser',
|
//'last' => false, // Stop validation after this rule
|
||||||
'foreignKey' => false,
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
||||||
'conditions' => array('Opening.company_id = AppUserCompany.id'),
|
),
|
||||||
'limit' => 1
|
),
|
||||||
),
|
'text' => array(
|
||||||
'Company' => array(
|
'notEmpty' => array(
|
||||||
'className' => 'User',
|
'rule' => array('notEmpty'),
|
||||||
'foreignKey' => false,
|
//'message' => 'Your custom message here',
|
||||||
'conditions' => array('Opening.company_id = AppUserCompany.id and Company.id = AppUserWorker.user_id'),
|
//'allowEmpty' => false,
|
||||||
'limit' => 1
|
//'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(
|
||||||
|
'Application' => array(
|
||||||
|
'className' => 'DreamjobJobApplication',
|
||||||
|
'foreignKey' => 'application_id',
|
||||||
|
'conditions' => '',
|
||||||
|
'fields' => '',
|
||||||
|
'order' => ''
|
||||||
|
)
|
||||||
|
); */
|
||||||
|
public $hasOne = array(
|
||||||
|
'DreamjobJobApplication' => array(
|
||||||
|
'className' => 'DreamjobJobApplication',
|
||||||
|
'foreignKey' => false,
|
||||||
|
'conditions' => array('DreamjobJobApplication.id = DreamjobJobMsg.application_id'),
|
||||||
|
'fields' => '',
|
||||||
|
'order' => ''
|
||||||
|
),
|
||||||
|
'Opening' => array(
|
||||||
|
'className' => 'DreamjobJobOpening',
|
||||||
|
'foreignKey' => false,
|
||||||
|
'conditions' => array('Opening.id = DreamjobJobApplication.opening_id'),
|
||||||
|
'limit' => 1
|
||||||
|
),
|
||||||
|
'AppUserWorker' => array(
|
||||||
|
'className' => 'AppUser',
|
||||||
|
'foreignKey' => false,
|
||||||
|
'conditions' => array('DreamjobJobApplication.worker_id = AppUserWorker.id'),
|
||||||
|
'limit' => 1
|
||||||
|
),
|
||||||
|
'Worker' => array(
|
||||||
|
'className' => 'User',
|
||||||
|
'foreignKey' => false,
|
||||||
|
'conditions' => array('DreamjobJobApplication.worker_id = AppUserWorker.id and Worker.id = AppUserWorker.user_id'),
|
||||||
|
'limit' => 1
|
||||||
|
),
|
||||||
|
'AppUserCompany' => array(
|
||||||
|
'className' => 'AppUser',
|
||||||
|
'foreignKey' => false,
|
||||||
|
'conditions' => array('Opening.company_id = AppUserCompany.id'),
|
||||||
|
'limit' => 1
|
||||||
|
),
|
||||||
|
'Company' => array(
|
||||||
|
'className' => 'User',
|
||||||
|
'foreignKey' => false,
|
||||||
|
'conditions' => array('Opening.company_id = AppUserCompany.id and Company.id = AppUserWorker.user_id'),
|
||||||
|
'limit' => 1
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue