mirror of
https://github.com/Oreolek/kangana.git
synced 2024-06-26 03:40:56 +03:00
DAR-24: unsubscription
This commit is contained in:
parent
01c60ac3c3
commit
cd7f62a9d7
|
@ -78,4 +78,30 @@ class Controller_Letter extends Controller_Layout {
|
|||
$this->template->subject = $model->subject;
|
||||
$this->template->id = $model->id;
|
||||
}
|
||||
|
||||
public function action_unsubscribe()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$letter = ORM::factory('Letter', $id);
|
||||
$token = $this->request->query('token');
|
||||
$email = $this->request->query('email');
|
||||
if (!$letter->loaded() || empty($token) || empty($email))
|
||||
{
|
||||
$this->redirect('error/500');
|
||||
}
|
||||
$client = ORM::factory('Client')->where('email', '=', $email)->and_where('token', '=', $token)->find();
|
||||
$course = ORM::factory('Course', $letter->course_id);
|
||||
if (!$client->loaded() || !$course->loaded())
|
||||
{
|
||||
Session::instance()->set_once('flash_error', __('Client not found. Possible subscription token problem.'));
|
||||
$this->redirect('error/403');
|
||||
}
|
||||
// token is valid, client is found, letter is found - we can unsubscribe him now
|
||||
$course->remove('clients', $client);
|
||||
Log::instance()->add(Log::NOTICE, 'Client '.$client->name.' has been unsubscribed from course '.$course->title);
|
||||
Model_Task::cancel($client->id, $course->id);
|
||||
$this->template = new View_Message;
|
||||
$this->template->message = __('You have been successfully unsubscribed from course %s', array('%s' => $course->title));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
**/
|
||||
class Model_Course extends ORM {
|
||||
protected $_has_many = array(
|
||||
'client' => array(
|
||||
'clients' => array(
|
||||
'model' => 'Client',
|
||||
'through' => 'clients_courses'
|
||||
),
|
||||
|
|
|
@ -74,6 +74,7 @@ class Model_Letter extends ORM {
|
|||
$template->id = $id;
|
||||
$template->subject = $subject;
|
||||
$template->token = $token;
|
||||
$template->address = $address;
|
||||
$renderer = Kostache_Layout::factory($template->_layout);
|
||||
$html = $renderer->render($template, $template->_view);
|
||||
$email = Email::factory($subject, $html, 'text/html')->from($sender[0], $sender[1]);
|
||||
|
|
|
@ -10,6 +10,7 @@ class Model_Task extends ORM {
|
|||
const STATUS_PENDING = 1;
|
||||
const STATUS_SENDING = 2;
|
||||
const STATUS_SENT = 3;
|
||||
const STATUS_CANCELED = 4;
|
||||
|
||||
protected $_has_many = array(
|
||||
'letter' => array(
|
||||
|
@ -161,4 +162,17 @@ class Model_Task extends ORM {
|
|||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel tasks for specified client. If a course ID parameter is present, cancel only tasks for this course.
|
||||
**/
|
||||
public static function cancel($client_id, $course_id = 0)
|
||||
{
|
||||
$query = DB::update('tasks')->set(array('status' => self::STATUS_CANCELED))->where('client_id', '=', $client_id);
|
||||
if ($course_id > 0)
|
||||
{
|
||||
$query->and_where('letter_id', 'IN', Model_Course::get_letter_ids($course_id));
|
||||
}
|
||||
return $query->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,22 @@
|
|||
class View_Letter_View extends View {
|
||||
public $_view = NULL;
|
||||
public $_layout = 'email';
|
||||
|
||||
/**
|
||||
* Unsubscription token
|
||||
**/
|
||||
public $token = '';
|
||||
/**
|
||||
* Email receiver address
|
||||
**/
|
||||
public $address = '';
|
||||
/**
|
||||
* Email subject
|
||||
**/
|
||||
public $subject = '';
|
||||
/**
|
||||
* Letter ID
|
||||
**/
|
||||
public $id = NULL;
|
||||
public $scripts = array();
|
||||
|
||||
|
@ -20,4 +34,20 @@ class View_Letter_View extends View {
|
|||
{
|
||||
return Kostache::factory()->render($this->content);
|
||||
}
|
||||
|
||||
public function unsubscribe()
|
||||
{
|
||||
return self::unsubscribe_link($this->id, $this->address, $this->token);
|
||||
}
|
||||
|
||||
public static function unsubscribe_link($id, $address, $token)
|
||||
{
|
||||
return HTML::anchor(
|
||||
Route::url('default', array('controller' => 'Letter', 'action' => 'unsubscribe', 'id' => $id), TRUE).'?'.http_build_query(array(
|
||||
'email' => $address,
|
||||
'token' => $token
|
||||
)),
|
||||
__('Tired of receiving these emails? Click this link to unsubscribe.')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,5 +70,8 @@ return array(
|
|||
'From now on you will receive letters from this subscription.' => 'Теперь вы будете получать письма из этой рассылки.',
|
||||
'Problems viewing this email? Click here.' => 'Проблемы с отображением письма? Нажмите сюда.',
|
||||
'What is your name?' => 'Как вас зовут?',
|
||||
'Your e-mail' => 'Ваш адрес электронной почты'
|
||||
'Your e-mail' => 'Ваш адрес электронной почты',
|
||||
'Tired of receiving these emails? Click this link to unsubscribe.' => 'Устали получать эти письма? Нажмите на эту ссылку для отписки.',
|
||||
'Client not found. Possible subscription token problem.' => 'Клиент не найден. Возможна проблема с токеном подписки.',
|
||||
'You have been successfully unsubscribed from course %s' => 'Вы были успешно отписаны от курса %s'
|
||||
);
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
<div class="row">
|
||||
{{>content}}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div style="font-size: 10px; margin-bottom: 10px">{{{unsubscribe}}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue