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
App::uses('AppModel', 'Model');
App::uses('CakeEmail', 'Network/Email');
/**
* MicDjJobsMsg Model
*
@ -8,57 +10,58 @@ App::uses('CakeEmail', 'Network/Email');
*/
class DreamjobJobMsg extends AppModel {
/**
/**
* Use database config
*
* @var string
*/
public $useDbConfig = 'dreamjobMain';
/**
/**
* Use table
*
* @var mixed False or table name
*/
public $useTable = 'mic_dj_jobs_msg';
/**
/**
* Display field
*
* @var string
*/
public $displayField = 'id';
/**
/**
* Validation rules
*
* @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->to($mail);
if($fromcompany){
if ($fromcompany) {
$Email->subject('Du hast eine neue Nachricht bei dreamJOB');
$Email->template('job_application_msg_worker');
}else{
} else {
$Email->subject('Sie haben eine neue Nachricht auf dreamJOB');
$Email->template('job_application_msg_company');
}
$Email->attachments(array('dak.jpg' => WWW_ROOT.DS.'mail'.DS.'dak.jpg'));
$Email->viewVars(array('id'=>$id,'data'=>$data));
$Email->attachments(array('dak.jpg' => WWW_ROOT . DS . 'mail' . DS . 'dak.jpg'));
$Email->viewVars(array('id' => $id, 'data' => $data));
return $Email->send();
}
public function sendMessage(){
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 ($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);
if ($this->fromcompany)
$result = self::sendMail($app['WorkerUser']['mail'], $this->application_id, array('User' => $app['WorkerUser'], 'AppUser' => $app['AppUserWorker']));
else
$result = self::sendMail($app['WorkerUser']['mail'],$this->application_id,array('User'=>$app['WorkerUser'],'AppUser'=>$app['AppUserWorker']));
$result = self::sendMail($app['User']['mail'], $this->application_id, array('DreamjobCompany' => $app['DreamjobCompany']), true);
}
if ($result) {
$dataSource->commit();
@ -68,6 +71,7 @@ class DreamjobJobMsg extends AppModel {
}
return false;
}
public $validate = array(
'application_id' => array(
'numeric' => array(
@ -113,7 +117,7 @@ class DreamjobJobMsg extends AppModel {
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
/**
* belongsTo associations
*
* @var array
@ -126,7 +130,7 @@ class DreamjobJobMsg extends AppModel {
'fields' => '',
'order' => ''
)
);*/
); */
public $hasOne = array(
'DreamjobJobApplication' => array(
'className' => 'DreamjobJobApplication',
@ -165,6 +169,6 @@ class DreamjobJobMsg extends AppModel {
'conditions' => array('Opening.company_id = AppUserCompany.id and Company.id = AppUserWorker.user_id'),
'limit' => 1
),
);
}