mirror of
https://github.com/Oreolek/kangana.git
synced 2024-05-04 01:59:22 +03:00
Irregular letter sending
This commit is contained in:
parent
4353228c86
commit
ffe0cbee8a
|
@ -1,77 +0,0 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Instant controller.
|
||||
**/
|
||||
class Controller_Instant extends Controller_Layout {
|
||||
protected $secure_actions = array(
|
||||
'index','create', 'edit', 'delete'
|
||||
);
|
||||
protected $controls = array(
|
||||
'subject' => 'input',
|
||||
'text' => 'textarea',
|
||||
);
|
||||
public function action_create()
|
||||
{
|
||||
$this->template = new View_Edit;
|
||||
$id = $this->request->param('id');
|
||||
$subscription = ORM::factory('Subscription', $id);
|
||||
if ( ! $subscription->loaded())
|
||||
{
|
||||
$this->redirect('error/500');
|
||||
}
|
||||
$this->template->model = ORM::factory('Instant');
|
||||
$this->template->model->subscription_id = $id;
|
||||
$this->template->title = I18n::translate('New letter');
|
||||
$this->_edit($this->template->model);
|
||||
}
|
||||
public function action_index()
|
||||
{
|
||||
$this->template = new View_Instant_Index;
|
||||
$id = $this->request->param('id');
|
||||
$model = ORM::factory('Subscription', $id)->with('instants');
|
||||
if ( ! $model->loaded())
|
||||
{
|
||||
$this->redirect('error/404');
|
||||
}
|
||||
$this->template->title = I18n::translate('Subscription').' '.$model->title;
|
||||
$this->template->subscription_id = $id;
|
||||
$this->template->items = $model->instants
|
||||
->filter_by_page($this->request->param('page'))
|
||||
->order_by('timestamp')
|
||||
->find_all();
|
||||
}
|
||||
|
||||
public function action_edit()
|
||||
{
|
||||
$this->template = new View_Edit;
|
||||
$this->template->title = I18n::translate('Instant editing');
|
||||
$id = $this->request->param('id');
|
||||
$model = ORM::factory('Instant', $id);
|
||||
if ( ! $model->loaded())
|
||||
{
|
||||
$this->redirect('error/404');
|
||||
}
|
||||
$this->_edit($model);
|
||||
}
|
||||
|
||||
public function action_send()
|
||||
{
|
||||
$this->template = new View_Message;
|
||||
$this->template->title = I18n::translate('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 = I18n::translate('The instant has been sent.');
|
||||
}
|
||||
}
|
|
@ -103,5 +103,30 @@ class Controller_Letter extends Controller_Layout {
|
|||
$this->template = new View_Message;
|
||||
$this->template->message = I18n::translate('You have been successfully unsubscribed from course %s', array('%s' => $course->title));
|
||||
}
|
||||
|
||||
public function action_send()
|
||||
{
|
||||
$this->template = new View_Message;
|
||||
$this->template->title = I18n::translate('Send instant to all subscribers');
|
||||
$id = $this->request->param('id');
|
||||
$model = ORM::factory('Letter', $id);
|
||||
if ( ! $model->loaded())
|
||||
{
|
||||
$this->redirect('error/404');
|
||||
}
|
||||
$subscription = ORM::factory('Course', $model->course_id)->with('clients');
|
||||
$clients = $subscription->get_clients();
|
||||
if (empty($clients))
|
||||
{
|
||||
$this->template->message = I18n::translate('No clients to send to!');
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($clients as $client)
|
||||
{
|
||||
$model->send($client->email, $client->token);
|
||||
}
|
||||
$model->save();
|
||||
$this->template->message = I18n::translate('The instant has been sent.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ class Model_Course extends ORM {
|
|||
/**
|
||||
* Get ID of all courses which have subscribers
|
||||
**/
|
||||
public static function get_ids()
|
||||
public static function get_ids($type = self::TYPE_SCHEDULED)
|
||||
{
|
||||
$use_groups = Kohana::$config->load('common.groupmode');
|
||||
if( ! $use_groups)
|
||||
|
@ -117,8 +117,11 @@ class Model_Course extends ORM {
|
|||
return DB::select('course_id')
|
||||
->distinct(TRUE)
|
||||
->from('clients_courses')
|
||||
->join('courses')
|
||||
->on('courses.id', '=', 'clients_courses.course_id')
|
||||
->where('courses.type', '=', $type)
|
||||
->execute()
|
||||
->get('course_id');
|
||||
->as_array(NULL, 'course_id');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -126,8 +129,9 @@ class Model_Course extends ORM {
|
|||
$ids = DB::select('id')
|
||||
->from('courses')
|
||||
->where('group_id', 'IN', $groups)
|
||||
->and_where('type', '=', $type)
|
||||
->execute()
|
||||
->get('id');
|
||||
->as_array(NULL, 'id');
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
|
@ -175,6 +179,19 @@ class Model_Course extends ORM {
|
|||
}
|
||||
}
|
||||
|
||||
public function get_clients()
|
||||
{
|
||||
$use_groups = Kohana::$config->load('common.groupmode');
|
||||
if( ! $use_groups)
|
||||
{
|
||||
return $this->clients->find_all();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->group->clients->find_all();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next letter in course
|
||||
* @param int $offset search offset (typically number of already sent letters)
|
||||
|
|
|
@ -71,7 +71,7 @@ class Task_Prepare extends Minion_Task
|
|||
try
|
||||
{
|
||||
// get courses which have subscribers
|
||||
$courses = Model_Course::get_ids();
|
||||
$courses = Model_Course::get_ids(Model_Course::TYPE_SCHEDULED);
|
||||
if ( ! is_array($courses))
|
||||
{
|
||||
$this->prepare_course($courses);
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Instant index view controller.
|
||||
* @package Views
|
||||
* @author Oreolek
|
||||
**/
|
||||
class View_Instant_Index extends View_Index {
|
||||
protected $is_admin = TRUE; // admin only view
|
||||
public $show_date = FALSE;
|
||||
public $subscription_id;
|
||||
/**
|
||||
* An internal function to prepare item data.
|
||||
**/
|
||||
protected function show_item($item)
|
||||
{
|
||||
if ( ! $item instanceof ORM)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$output = array(
|
||||
'description' => $item->text,
|
||||
'view_link' => $item->subject,
|
||||
'is_sent' => I18n::translate('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)), I18n::translate('Edit'), array('class' => 'link_edit'));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function link_new()
|
||||
{
|
||||
return HTML::anchor(Route::url('default', array('controller' => 'Instant', 'action' => 'create', 'id' => $this->subscription_id)), I18n::translate('Add'), array('class' => 'link_new'));
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ class View_Letter_Index extends View_Index {
|
|||
$output = array(
|
||||
'description' => $item->text,
|
||||
'view_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'view','id' => $item->id)), $item->subject, array('class' => 'link_view')),
|
||||
'send_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'send','id' => $item->id)), I18n::translate('Send'), array('class' => 'link_send btn btn-warning')),
|
||||
'edit_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'edit','id' => $item->id)), I18n::translate('Edit'), array('class' => 'link_edit')),
|
||||
'delete_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'delete','id' => $item->id)), I18n::translate('Delete'), array('class' => 'link_delete')),
|
||||
);
|
||||
|
|
|
@ -97,4 +97,5 @@ return array(
|
|||
'Groups' => 'Группы',
|
||||
'Courses' => 'Курсы',
|
||||
'Add letter' => 'Добавить сообщение',
|
||||
'No clients to send to!' => 'Нет клиентов, кому отправлять!',
|
||||
);
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
{{#show_create}}
|
||||
{{{link_new}}}
|
||||
{{/show_create}}
|
||||
<div class="hyphenate">
|
||||
{{{content}}}
|
||||
</div>
|
||||
<table class="table">
|
||||
{{#get_items}}
|
||||
<tr>
|
||||
<td>{{{view_link}}}</td>
|
||||
<td class="hyphenate">{{{description}}}</td>
|
||||
{{#edit_link}}
|
||||
<td>{{{edit_link}}}</td>
|
||||
{{/edit_link}}
|
||||
{{^edit_link}}
|
||||
<td>{{is_sent}}</td>
|
||||
{{/edit_link}}
|
||||
<td>{{{send_button}}}</td>
|
||||
</tr>
|
||||
{{/get_items}}
|
||||
</table>
|
|
@ -12,6 +12,7 @@
|
|||
<tr>
|
||||
<td>{{{view_link}}}</td>
|
||||
<td class="hyphenate">{{{description}}}</td>
|
||||
<td>{{{send_link}}}</td>
|
||||
{{#edit_link}}
|
||||
<td>{{{edit_link}}}</td>
|
||||
<td>{{{delete_link}}}</td>
|
||||
|
|
Loading…
Reference in a new issue