Added Tasks to KH

This commit is contained in:
Deon George
2011-08-16 12:27:19 +10:00
parent f272bc254d
commit 4c9b214ff7
53 changed files with 773 additions and 170 deletions

View File

@@ -39,12 +39,18 @@ class EmailTemplate {
public function __set($key,$value) {
switch ($key) {
case 'to':
if (! is_array($value) OR ! array_intersect(array('email','account'),array_keys($value)))
throw new Kohana_Exception('Values for to should be an array of either "mail" or "account", however :value was given',array(':value'=>serialize($value)));
$this->email_data[$key] = $value;
break;
case 'variables':
// Our variables should be an array
if (! is_array($value))
throw new Kohana_Exception('Values for variables should be an array, however :value was given',array(':value'=>$value));
case 'to':
$this->email_data[$key] = $value;
break;
@@ -53,12 +59,44 @@ class EmailTemplate {
}
}
public function __get($key) {
switch ($key) {
case 'to':
if (empty($this->email_data[$key]))
return array();
elseif (isset($this->email_data[$key]['email']))
return $this->email_data[$key]['email'];
elseif (isset($this->email_data[$key]['account'])) {
$list = array();
foreach ($this->email_data[$key]['account'] as $id) {
$ao = ORM::factory('account',$id);
if ($ao->loaded())
$list[$ao->email] = $ao->name();
}
return $list;
}
break;
case 'variables':
return $this->email_data[$key];
default:
throw new Kohana_Exception('Unknown variable :key (:value)',array(':key'=>$key,':value'=>is_string($value) ? $value : serialize($value)));
}
}
public static function instance($template) {
return new EmailTemplate($template);
}
public function variables() {
$return = array();
foreach ($this->components as $v)
foreach ($this->template_mail->variables($v) as $x=>$y)
if (! in_array($y,$return))
@@ -93,14 +131,46 @@ class EmailTemplate {
}
}
// @todo This should go to the admin defined in email_setup
if ($admin OR ($mail = Config::testmail($this->template->name)))
$sm->setTo($mail);
else
$sm->setTo($this->email_data['to']);
if ($admin OR ($admin = Config::testmail($this->template->name))) {
$sm->setTo($admin);
$sa = array(1);
} else {
$sm->setTo($this->to);
$sa = $this->to_accounts();
}
// @todo - Setup queue mode
$e->send($sm);
$result = $e->send($sm);
if ($result) {
// Store our email log.
$data = gzcompress(serialize($this->email_data['variables']));
$elo = ORM::factory('email_log');
foreach ($sa as $id) {
$elo->clear();
$elo->account_id = $id;
$elo->email_template_id = $this->template_mail->id;
$elo->data = $data;
$elo->save();
}
}
return $result;
}
private function to_accounts() {
// @todo Set the default account in a configuration file.
$default = array(1);
if (! isset($this->email_data['to']) OR ! is_array($this->email_data['to']) OR ! array_intersect(array('email','account'),array_keys($this->email_data['to'])))
return $default;
return isset($this->email_data['to']['account']) ? $this->email_data['to']['account'] : $default;
}
}
?>

View File

@@ -13,19 +13,21 @@ class Model_EmailTemplate extends ORMOSB {
protected $_table_name = 'email_template';
protected $_has_many = array(
'emailtemplate_translate'=>array('foreign_key'=>'email_template_id'),
'emailtemplate_translate'=>array('foreign_key'=>'email_template_id','far_key'=>'id'),
);
// This module doesnt keep track of column updates automatically
protected $_created_column = FALSE;
protected $_updated_column = FALSE;
protected $_formats = array(
'active'=>array('StaticList_YesNo::display'=>array()),
);
protected $_sorting = array(
'name'=>'ASC',
);
protected $_display_filters = array(
'status'=>array(
array('StaticList_YesNo::display',array(':value')),
),
);
}
?>