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

DAR-15: instant message subscriptions

This commit is contained in:
Alexander Yakovlev 2014-02-18 15:11:50 +07:00
parent f421dc7884
commit 09fc6bb843
7 changed files with 41 additions and 10 deletions

View file

@ -10,13 +10,13 @@ class Controller_Instant extends Controller_Layout {
protected $controls = array(
'subject' => 'input',
'text' => 'textarea',
'is_draft' => 'checkbox'
);
public function action_create()
{
$this->template = new View_Edit;
$id = $this->request->param('id');
if (!Model_Course::exists($id))
$subscription = ORM::factory('Subscription', $id);
if (!$subscription->loaded())
{
$this->redirect('error/500');
}
@ -54,4 +54,24 @@ class Controller_Instant extends Controller_Layout {
}
$this->_edit($model);
}
public function action_send()
{
$this->template = new View_Message;
$this->template->title = __('Send instant to all subscribers');
$id = $this->request->param('id');
$model = ORM::factory('Instant', $id);
if (!$model->loaded())
{
$this->redirect('error/404');
}
$subscription = ORM::factory('Subscription', $model->subscription_id)->with('clients');
$clients = $subscription->clients->find_all();
foreach ($clients as $client)
{
$model->send($client->email, $client->token);
}
$model->save();
$this->template->message = __('The instant has been sent.');
}
}

View file

@ -10,7 +10,6 @@ class Controller_Subscription extends Controller_Layout {
protected $controls = array(
'title' => 'input',
'description' => 'textarea',
'welcome' => 'textarea'
// 'price' => 'input'
);

View file

@ -24,9 +24,6 @@ class Model_Instant extends ORM {
array('not_empty'),
array('min_length', array(':value', 20)),
),
'is_draft' => array(
array('numeric')
)
);
}
@ -37,7 +34,7 @@ class Model_Instant extends ORM {
protected $_labels = array(
'text' => 'Message text',
'subject' => 'Message subject',
'is_draft' => 'Is a draft?'
'sent' => 'Is sent?'
);
/**
@ -47,6 +44,7 @@ class Model_Instant extends ORM {
**/
public function send($address, $token = '')
{
$this->sent = TRUE;
return self::_send($address, $this->text, $this->subject, $token);
}

View file

@ -7,7 +7,7 @@
**/
class Model_Subscription extends ORM {
protected $_has_many = array(
'client' => array(
'clients' => array(
'model' => 'Client',
'through' => 'clients_subscriptions'
),

View file

@ -22,8 +22,15 @@ class View_Instant_Index extends View_Index {
$output = array(
'description' => $item->text,
'view_link' => $item->subject,//HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'view','id' => $item->id)), $item->subject, array('class' => 'link_view')),
'edit_link' => HTML::anchor(Route::url('default', array('controller' => 'Instant', 'action' => 'edit','id' => $item->id)), __('Edit'), array('class' => 'link_edit')),
'is_sent' => __('Sent'),
'edit_link' => FALSE,
'send_button' => HTML::anchor(Route::url('default', array('controller' => 'Instant', 'action' => 'send','id' => $item->id)), Form::btn('send', 'Send to subscribers')),
);
if ($item->sent == 0)
{
$output['edit_link'] = HTML::anchor(Route::url('default', array('controller' => 'Instant', 'action' => 'edit','id' => $item->id)), __('Edit'), array('class' => 'link_edit'));
}
return $output;
}

View file

@ -58,5 +58,8 @@ return array(
'Page drafts' => 'Черновики страниц',
'Page index' => 'Список страниц',
'Delete page' => 'Удалить страницу',
'Welcome message' => 'Приветственное сообщение'
'Welcome message' => 'Приветственное сообщение',
'Sent' => 'Отправлено',
'Send instant to all subscribers' => 'Отослать мгновенное всем подписчикам',
'The instant has been sent.' => 'Мгновенное было выслано.'
);

View file

@ -12,6 +12,10 @@
{{#edit_link}}
<td>{{{edit_link}}}</td>
{{/edit_link}}
{{^edit_link}}
<td>{{is_sent}}</td>
{{/edit_link}}
<td>{{{send_button}}}</td>
</tr>
{{/get_items}}
</table>