mail message user/company switch

This commit is contained in:
Martin Müller 2014-05-14 00:06:09 +02:00
parent f453285de1
commit 6eadfb2c25
1 changed files with 157 additions and 153 deletions

View File

@ -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) public function sendMessage() {
$result = self::sendMail($app['User']['mail'],$this->application_id,array('DreamjobCompany'=>$app['DreamjobCompany']),true); $dataSource = $this->getDataSource();
else $dataSource->begin();
$result = self::sendMail($app['WorkerUser']['mail'],$this->application_id,array('User'=>$app['WorkerUser'],'AppUser'=>$app['AppUserWorker'])); $result = $this->save();
} if ($result) {
if ($result) { $app = $this->DreamjobJobApplication->find('first', array('conditions' => array('DreamjobJobApplication.id' => $result["DreamjobJobMsg"]["application_id"])));
$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 if ($this->fromcompany)
$result = self::sendMail($app['WorkerUser']['mail'], $this->application_id, array('User' => $app['WorkerUser'], 'AppUser' => $app['AppUserWorker']));
else
$result = self::sendMail($app['User']['mail'], $this->application_id, array('DreamjobCompany' => $app['DreamjobCompany']), true);
}
if ($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
/** public $validate = array(
* belongsTo associations 'application_id' => array(
* 'numeric' => array(
* @var array 'rule' => array('numeric'),
*//* //'message' => 'Your custom message here',
public $belongsTo = array( //'allowEmpty' => false,
'Application' => array( //'required' => false,
'className' => 'DreamjobJobApplication', //'last' => false, // Stop validation after this rule
'foreignKey' => 'application_id', //'on' => 'create', // Limit validation to 'create' or 'update' operations
'conditions' => '', ),
'fields' => '', ),
'order' => '' 'fromcompany' => array(
) 'boolean' => array(
);*/ 'rule' => array('boolean'),
public $hasOne = array( //'message' => 'Your custom message here',
'DreamjobJobApplication' => array( //'allowEmpty' => false,
'className' => 'DreamjobJobApplication', //'required' => false,
'foreignKey' => false, //'last' => false, // Stop validation after this rule
'conditions' => array('DreamjobJobApplication.id = DreamjobJobMsg.application_id'), //'on' => 'create', // Limit validation to 'create' or 'update' operations
'fields' => '', ),
'order' => '' ),
), 'saw' => array(
'Opening' => array( 'boolean' => array(
'className' => 'DreamjobJobOpening', 'rule' => array('boolean'),
'foreignKey' => false, //'message' => 'Your custom message here',
'conditions' => array('Opening.id = DreamjobJobApplication.opening_id'), //'allowEmpty' => false,
'limit' => 1 //'required' => false,
), //'last' => false, // Stop validation after this rule
'AppUserWorker' => array( //'on' => 'create', // Limit validation to 'create' or 'update' operations
'className' => 'AppUser', ),
'foreignKey' => false, ),
'conditions' => array('DreamjobJobApplication.worker_id = AppUserWorker.id'), 'text' => array(
'limit' => 1 'notEmpty' => array(
), 'rule' => array('notEmpty'),
'Worker' => array( //'message' => 'Your custom message here',
'className' => 'User', //'allowEmpty' => false,
'foreignKey' => false, //'required' => false,
'conditions' => array('DreamjobJobApplication.worker_id = AppUserWorker.id and Worker.id = AppUserWorker.user_id'), //'last' => false, // Stop validation after this rule
'limit' => 1 //'on' => 'create', // Limit validation to 'create' or 'update' operations
), ),
'AppUserCompany' => array( ),
'className' => 'AppUser', );
'foreignKey' => false,
'conditions' => array('Opening.company_id = AppUserCompany.id'), //The Associations below have been created with all possible keys, those that are not needed can be removed
'limit' => 1
), /**
'Company' => array( * belongsTo associations
'className' => 'User', *
'foreignKey' => false, * @var array
'conditions' => array('Opening.company_id = AppUserCompany.id and Company.id = AppUserWorker.user_id'), *//*
'limit' => 1 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
),
);
);
} }