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){ $app = $this->DreamjobJobApplication->find('first', array('conditions' => array('DreamjobJobApplication.id' => $this->application_id))); if($this->fromcompany) $result = self::sendMail($app['User']['mail'],$this->application_id); else $result = sel::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 ), ); }