2014-03-04 09:07:18 +01:00
|
|
|
<?php
|
|
|
|
App::uses('AppModel', 'Model');
|
2014-04-13 13:28:39 +02:00
|
|
|
App::uses('CakeEmail', 'Network/Email');
|
2014-03-04 09:07:18 +01:00
|
|
|
/**
|
|
|
|
* MicDjJobsMsg Model
|
|
|
|
*
|
|
|
|
* @property Application $Application
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
2014-04-13 13:28:39 +02:00
|
|
|
public static function sendMail($mail,$id){
|
|
|
|
$Email = new CakeEmail('dreamjobMain');
|
|
|
|
$Email->to($mail);
|
|
|
|
$Email->subject('Welcome to our really cool thing');
|
|
|
|
$Email->template('job_application_msg');
|
2014-04-22 22:40:25 +02:00
|
|
|
$Email->viewVars(array('id'=>$id));
|
2014-04-13 13:28:39 +02:00
|
|
|
return $Email->send();
|
|
|
|
}
|
2014-04-11 19:43:26 +02:00
|
|
|
public function sendMessage(){
|
|
|
|
$dataSource = $this->getDataSource();
|
|
|
|
$dataSource->begin();
|
|
|
|
$result = $this->save();
|
|
|
|
if($result){
|
2014-04-29 21:21:36 +02:00
|
|
|
echo $result["DreamjobJobMsg"]["application_id"];
|
|
|
|
exit(1);
|
2014-04-29 21:20:38 +02:00
|
|
|
$app = $this->Application->find('first', array('conditions' => array('Application.id' => $result["DreamjobJobMsg"]["application_id"])));
|
2014-04-29 21:13:06 +02:00
|
|
|
|
2014-04-11 19:43:26 +02:00
|
|
|
if($this->fromcompany)
|
2014-04-13 13:28:39 +02:00
|
|
|
$result = self::sendMail($app['User']['mail'],$this->application_id);
|
2014-04-11 19:43:26 +02:00
|
|
|
else
|
2014-04-29 20:33:43 +02:00
|
|
|
$result = self::sendMail($app['WorkerUser']['mail'],$this->application_id);
|
2014-04-11 19:43:26 +02:00
|
|
|
}
|
|
|
|
if ($result) {
|
|
|
|
$dataSource->commit();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$dataSource->rollback();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 09:07:18 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
* belongsTo associations
|
|
|
|
*
|
|
|
|
* @var array
|
2014-04-11 19:43:26 +02:00
|
|
|
*//*
|
2014-03-04 09:07:18 +01:00
|
|
|
public $belongsTo = array(
|
|
|
|
'Application' => array(
|
2014-04-11 19:43:26 +02:00
|
|
|
'className' => 'DreamjobJobApplication',
|
2014-03-04 09:07:18 +01:00
|
|
|
'foreignKey' => 'application_id',
|
|
|
|
'conditions' => '',
|
|
|
|
'fields' => '',
|
|
|
|
'order' => ''
|
|
|
|
)
|
2014-04-11 19:43:26 +02:00
|
|
|
);*/
|
|
|
|
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
|
|
|
|
),
|
|
|
|
|
2014-03-04 09:07:18 +01:00
|
|
|
);
|
|
|
|
}
|