dreamjob/app/Model/DreamjobJobMsg.php

165 lines
4.2 KiB
PHP
Raw Normal View History

<?php
App::uses('AppModel', 'Model');
2014-04-13 13:28:39 +02:00
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
*/
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 20:26:24 +02:00
$app = $this->Application->find('first', array('conditions' => array('DreamjobJobApplication.id' => $this->application_id)));
2014-04-29 20:49:20 +02:00
die($app);
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;
}
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
*//*
public $belongsTo = array(
'Application' => array(
2014-04-11 19:43:26 +02:00
'className' => 'DreamjobJobApplication',
'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
),
);
}