mail in job und msg

This commit is contained in:
Martin Müller 2014-04-11 19:43:26 +02:00
parent 5be6f451d7
commit ca42efc55f
9 changed files with 116 additions and 10 deletions

View File

@ -20,6 +20,25 @@ class JobController extends AppController {
* @throws NotFoundException When the view file could not be found
* or MissingViewException in debug mode.
*/
public static function sendApplicationMail($mail,$id){
$Email = new CakeEmail('dreamjobMain');
$Email->to($mail);
$Email->subject('Welcome to our really cool thing');
$Email->template('job_application');
$Email->viewVars(array('app_id'=>$id));
return $Email->send();
}
public static function sendMsgMail($mail,$id){
$Email = new CakeEmail('dreamjobMain');
$Email->to($mail);
$Email->subject('Welcome to our really cool thing');
$Email->template('job_application_msg');
$Email->viewVars(array('app_id'=>$id));
return $Email->send();
}
public function openingList() {
$this->MiconwareSession->init($this);
@ -224,7 +243,7 @@ class JobController extends AppController {
$this->DreamjobJobMsg->data['DreamjobJobMsg']['saw'] = false;
$this->DreamjobJobMsg->data['DreamjobJobMsg']['application_id'] = $application['DreamjobJobApplication']['id'];
$this->DreamjobJobMsg->data['DreamjobJobMsg']['fromcompany'] = is_array($COMPANY) and count($COMPANY) > 0;
if($this->DreamjobJobMsg->save()) {
if($this->DreamjobJobMsg->sendMessage()) {
$application = $this->DreamjobJobApplication->find('first',array('conditions' => array('DreamjobJobApplication.id'=> $this->request->params['id'] )));
$this->MiconwareSession->setFlash('dreamjob.application.msg.add','flash',array('alert'=>'success'));
}else{
@ -334,7 +353,7 @@ class JobController extends AppController {
unset($this->request->data['DreamjobJobApplicationPage']['page_id']);
foreach($pages as $id)
$this->request->data['DreamjobJobApplicationPage'][]=array('page_id'=> $id);
$result = $this->DreamjobJobApplication->saveAssociated($this->request->data);
$result = $this->DreamjobJobApplication->sendApplication($this->request->data);
if ($result) {
$this->MiconwareSession->setFlash('dreamjob.opening.save.add','flash',array('alert'=>'success'));
}else{

View File

@ -467,7 +467,7 @@ class UserController extends AppController {
$this->MiconwareSession->initWeb($this);
// $this->set('data', $this->DreamjobCompany->find('all'));
$this->set('data', $this->MiconwareSession->getApplication('DreamjobWorker'));
$this->set('data', $this->DreamjobJobMsg->find('first'));
$this->render('/User/test');
}
}

View File

@ -38,7 +38,7 @@ class DreamjobCompany extends AppModel {
public $displayField = 'djaccount_ptr_id';
public function registration($data){
public function registration($data){
$dataSource = $this->getDataSource();
$dataSource->begin();
@ -72,7 +72,8 @@ class DreamjobCompany extends AppModel {
$this->create(array('DreamjobCompany'=>$data['DreamjobCompany']));
$result=$this->save();
}
if($result)
$result = RegistrationController::registrationMail($data);
if ($result) {
$dataSource->commit();
return true;
@ -140,9 +141,6 @@ class DreamjobCompany extends AppModel {
$result = $this->User->saveField('mannerofaddress_id',$data['AppUser']['mannerofaddress_id']);
}
if($result)
$result = RegistrationController::registrationMail($data);
if ($result) {
$dataSource->commit();
return true;

View File

@ -34,6 +34,24 @@ class DreamjobJobApplication extends AppModel {
*
* @var array
*/
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 = JobController::sendApplicationMail($open['User']['mail']l,$this->id);
}
if ($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
public $validate = array(
'id' => array(
'numeric' => array(

View File

@ -33,6 +33,25 @@ class DreamjobJobMsg extends AppModel {
*
* @var array
*/
public function sendMessage(){
$dataSource = $this->getDataSource();
$dataSource->begin();
$result = $this->save();
if($result){
$app = $this->DreamjobJobApplication->find('first', array('conditions' => array('DreamjobJobApplication.id' => $this->application_id)));
if($this->fromcompany)
$result = JobController::sendMsgMail($app['User']['mail'],$this->application_id);
else
$result = JobController::sendMsgMail($app['WorkerUser']['mail'],$this->application_id);
}
if ($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
public $validate = array(
'application_id' => array(
'numeric' => array(
@ -82,14 +101,54 @@ class DreamjobJobMsg extends AppModel {
* belongsTo associations
*
* @var array
*/
*//*
public $belongsTo = array(
'Application' => array(
'className' => 'Application',
'className' => 'DreamjobJobApplication',
'foreignKey' => 'application_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);*/
public $hasOne = array(
'Application' => array(
'className' => 'DreamjobJobApplication',
'foreignKey' => false,
'conditions' => array('Application.id = DreamjobJobMsg.application_id'),
'fields' => '',
'order' => ''
),
'Opening' => array(
'className' => 'DreamjobJobOpening',
'foreignKey' => false,
'conditions' => array('Opening.id = Application.opening_id'),
'limit' => 1
),
'AppUserWorker' => array(
'className' => 'AppUser',
'foreignKey' => false,
'conditions' => array('Application.worker_id = AppUserWorker.id'),
'limit' => 1
),
'Worker' => array(
'className' => 'User',
'foreignKey' => false,
'conditions' => array('Application.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
),
);
}

View File

@ -0,0 +1,3 @@
<?php
echo $this->Html->link(__('dreamjob.message.send'),array('controller'=>'job','action'=>'applicationGet','id'=>$id,'full_base' => true));
?>

View File

@ -0,0 +1,3 @@
<?php
echo $this->Html->link(__('dreamjob.message.send'),array('controller'=>'job','action'=>'applicationGet','id'=>$id,'ages'=>'ages','full_base' => true));
?>

View File

@ -0,0 +1,3 @@
<?php
echo $this->Html->url(array('controller'=>'job','action'=>'applicationGet','id'=>$id), true);
?>

View File

@ -0,0 +1,3 @@
<?php
echo $this->Html->url(array('controller'=>'job','action'=>'applicationGet','id'=>$id,'ages'=>'ages'),true);
?>