1
0
Fork 0
mirror of https://github.com/Oreolek/kangana.git synced 2024-06-26 03:40:56 +03:00

ready for the task implementation

This commit is contained in:
Alexander Yakovlev 2014-01-29 19:13:04 +07:00
parent 3036d23d56
commit 0c091b4dcf
3 changed files with 33 additions and 2 deletions

View file

@ -112,7 +112,15 @@ class Controller_Subscription extends Controller_Layout {
{
$model->save();
$model->add('subscription', $subscription);
// TODO: send welcome letter
$task = ORM::factory('Task');
$letter = $subscription->next_letter();
$task->letter_id = $letter->id;
$task->client_id = $model->id;
// now we break the abstraction to speed things up
$task->status = Model_Task::STATUS_SENT;
$task->date = date('Y-m-d');
$task->create();
$letter->send($model->email);
}
else
{

View file

@ -70,4 +70,18 @@ class Model_Subscription extends ORM {
$count = DB::select(array(DB::expr('COUNT(*)'), 'cnt'))->from('subscriptions')->where('id', '=', $id)->execute()->get('cnt');
return ($count == 1);
}
/**
* Get next letter in subscription
* @param int $offset search offset (typically number of already sent letters)
**/
public function next_letter($offset = 0)
{
return ORM::factory('Letter')
->where('subscription_id', '=', $this->id)
->order_by('order', 'ASC')
->limit(1)
->offset($offset)
->find();
}
}

View file

@ -11,7 +11,7 @@ class Model_Task extends ORM {
const STATUS_SENDING = 2;
const STATUS_SENT = 3;
protected $has_many = array(
protected $_has_many = array(
'letter',
'client'
);
@ -40,4 +40,13 @@ class Model_Task extends ORM {
'date' => 'Mailing date',
'status' => 'Status'
);
public function execute()
{
$letter = ORM::factory('Letter', $this->letter_id);
$client = ORM::factory('Client', $this->client_id);
$letter->send($client->email);
$this->status = STATUS_SENT;
$this->save();
}
}