167 lines
4.2 KiB
PHP
167 lines
4.2 KiB
PHP
<?php
|
|
App::uses('AppModel', 'Model');
|
|
App::uses('CakeEmail', 'Network/Email');
|
|
/**
|
|
* 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
|
|
*/
|
|
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');
|
|
$Email->viewVars(array('id'=>$id));
|
|
return $Email->send();
|
|
}
|
|
public function sendMessage(){
|
|
$dataSource = $this->getDataSource();
|
|
$dataSource->begin();
|
|
$result = $this->save();
|
|
if($result){
|
|
echo "Lola";
|
|
exit(0);
|
|
$app = $this->Application->find('first', array('conditions' => array('Application.id' => $this->application_id)));
|
|
|
|
if($this->fromcompany)
|
|
$result = self::sendMail($app['User']['mail'],$this->application_id);
|
|
else
|
|
$result = self::sendMail($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(
|
|
'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
|
|
*//*
|
|
public $belongsTo = array(
|
|
'Application' => array(
|
|
'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
|
|
),
|
|
|
|
);
|
|
}
|