2014-01-17 13:39:34 +02:00
|
|
|
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
2014-01-18 08:03:47 +02:00
|
|
|
/**
|
|
|
|
* Electronic letter model.
|
|
|
|
* Stores HTML to be placed in e-mail template.
|
|
|
|
* @package Models
|
|
|
|
* @author Oreolek
|
|
|
|
**/
|
2014-01-17 13:39:34 +02:00
|
|
|
class Model_Letter extends ORM {
|
2014-01-18 08:03:47 +02:00
|
|
|
protected $belongs_to = array(
|
|
|
|
'subscription'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array validation rules
|
|
|
|
**/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return array(
|
2014-01-29 12:41:25 +02:00
|
|
|
'subject' => array(
|
|
|
|
array('not_empty'),
|
|
|
|
array('max_length', array(':value', 128)),
|
|
|
|
),
|
2014-01-18 08:03:47 +02:00
|
|
|
'text' => array(
|
|
|
|
array('not_empty'),
|
|
|
|
array('min_length', array(':value', 20)),
|
|
|
|
),
|
|
|
|
'order' => array(
|
|
|
|
array('numeric')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of field labels.
|
|
|
|
* Used in forms.
|
|
|
|
**/
|
|
|
|
protected $_labels = array(
|
|
|
|
'text' => 'Message text',
|
2014-01-29 12:41:25 +02:00
|
|
|
'subject' => 'Message subject',
|
2014-01-18 08:03:47 +02:00
|
|
|
'order' => 'Message order'
|
|
|
|
);
|
|
|
|
|
2014-01-29 10:52:33 +02:00
|
|
|
public function customize()
|
|
|
|
{
|
|
|
|
if(empty($this->order))
|
|
|
|
{
|
|
|
|
$this->order = Model_Subscription::count_letters($this->subscription_id) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-29 12:41:25 +02:00
|
|
|
/**
|
|
|
|
* Function to send a email to a specified address.
|
|
|
|
* Not suitable for a large-scale use.
|
|
|
|
* @param email $address email address
|
|
|
|
* TODO: render text in HTML template
|
|
|
|
**/
|
|
|
|
public function send($address)
|
|
|
|
{
|
|
|
|
$sender = Kohana::$config->load('email')->get('sender');
|
|
|
|
$email = Email::factory($this->subject, $this->text)->to($address)->from($sender);
|
|
|
|
return $email->send();
|
|
|
|
}
|
|
|
|
|
2014-01-17 13:39:34 +02:00
|
|
|
}
|