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,57 +10,58 @@ 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(){
public function sendMessage() {
$dataSource = $this->getDataSource(); $dataSource = $this->getDataSource();
$dataSource->begin(); $dataSource->begin();
$result = $this->save(); $result = $this->save();
if($result){ if ($result) {
$app = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.id' => $result["DreamjobJobMsg"]["application_id"])) ); $app = $this->DreamjobJobApplication->find('first', array('conditions' => array('DreamjobJobApplication.id' => $result["DreamjobJobMsg"]["application_id"])));
if($this->fromcompany) if ($this->fromcompany)
$result = self::sendMail($app['User']['mail'],$this->application_id,array('DreamjobCompany'=>$app['DreamjobCompany']),true); $result = self::sendMail($app['WorkerUser']['mail'], $this->application_id, array('User' => $app['WorkerUser'], 'AppUser' => $app['AppUserWorker']));
else 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) { if ($result) {
$dataSource->commit(); $dataSource->commit();
@ -68,6 +71,7 @@ class DreamjobJobMsg extends AppModel {
} }
return false; return false;
} }
public $validate = array( public $validate = array(
'application_id' => array( 'application_id' => array(
'numeric' => 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 //The Associations below have been created with all possible keys, those that are not needed can be removed
/** /**
* belongsTo associations * belongsTo associations
* *
* @var array * @var array
@ -126,7 +130,7 @@ class DreamjobJobMsg extends AppModel {
'fields' => '', 'fields' => '',
'order' => '' 'order' => ''
) )
);*/ ); */
public $hasOne = array( public $hasOne = array(
'DreamjobJobApplication' => array( 'DreamjobJobApplication' => array(
'className' => 'DreamjobJobApplication', 'className' => 'DreamjobJobApplication',
@ -165,6 +169,6 @@ class DreamjobJobMsg extends AppModel {
'conditions' => array('Opening.company_id = AppUserCompany.id and Company.id = AppUserWorker.user_id'), 'conditions' => array('Opening.company_id = AppUserCompany.id and Company.id = AppUserWorker.user_id'),
'limit' => 1 'limit' => 1
), ),
); );
} }