diff --git a/app/Controller/JobController.php b/app/Controller/JobController.php index 57a5177..4ea1b66 100644 --- a/app/Controller/JobController.php +++ b/app/Controller/JobController.php @@ -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{ diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index 7afb6cf..3d941cd 100755 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -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'); } } diff --git a/app/Model/DreamjobCompany.php b/app/Model/DreamjobCompany.php index 77d688e..9721ec9 100755 --- a/app/Model/DreamjobCompany.php +++ b/app/Model/DreamjobCompany.php @@ -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; diff --git a/app/Model/DreamjobJobApplication.php b/app/Model/DreamjobJobApplication.php index a50264d..09cc17d 100644 --- a/app/Model/DreamjobJobApplication.php +++ b/app/Model/DreamjobJobApplication.php @@ -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( diff --git a/app/Model/DreamjobJobMsg.php b/app/Model/DreamjobJobMsg.php index cff130a..20f60cf 100644 --- a/app/Model/DreamjobJobMsg.php +++ b/app/Model/DreamjobJobMsg.php @@ -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 + ), + ); } diff --git a/app/View/Emails/html/job_application.ctp b/app/View/Emails/html/job_application.ctp new file mode 100644 index 0000000..e519b6b --- /dev/null +++ b/app/View/Emails/html/job_application.ctp @@ -0,0 +1,3 @@ +Html->link(__('dreamjob.message.send'),array('controller'=>'job','action'=>'applicationGet','id'=>$id,'full_base' => true)); +?> diff --git a/app/View/Emails/html/job_application_msg.ctp b/app/View/Emails/html/job_application_msg.ctp new file mode 100644 index 0000000..1e46afe --- /dev/null +++ b/app/View/Emails/html/job_application_msg.ctp @@ -0,0 +1,3 @@ +Html->link(__('dreamjob.message.send'),array('controller'=>'job','action'=>'applicationGet','id'=>$id,'ages'=>'ages','full_base' => true)); +?> diff --git a/app/View/Emails/text/job_application.ctp b/app/View/Emails/text/job_application.ctp new file mode 100644 index 0000000..ea3a82c --- /dev/null +++ b/app/View/Emails/text/job_application.ctp @@ -0,0 +1,3 @@ +Html->url(array('controller'=>'job','action'=>'applicationGet','id'=>$id), true); +?> diff --git a/app/View/Emails/text/job_application_msg.ctp b/app/View/Emails/text/job_application_msg.ctp new file mode 100644 index 0000000..2cc1df1 --- /dev/null +++ b/app/View/Emails/text/job_application_msg.ctp @@ -0,0 +1,3 @@ +Html->url(array('controller'=>'job','action'=>'applicationGet','id'=>$id,'ages'=>'ages'),true); +?>