mirror of
https://github.com/Oreolek/kangana.git
synced 2024-05-05 02:28:17 +03:00
Auto group assigning on subscription, issue #3
This commit is contained in:
parent
2b5c90408f
commit
3850092b20
|
@ -72,7 +72,7 @@ class Controller_Course extends Controller_Layout {
|
|||
$course->type = Model_Course::TYPE_SCHEDULED;
|
||||
$letter = ORM::factory('Letter');
|
||||
if ($this->request->method() === Request::POST) {
|
||||
$course->values($this->request->post(), array('title', 'description'));
|
||||
$course->values($this->request->post(), array('title', 'description', 'group_id'));
|
||||
$letter->values($this->request->post(), array('subject', 'text'));
|
||||
$course->price = 0;
|
||||
$course->period = 1;
|
||||
|
@ -84,7 +84,6 @@ class Controller_Course extends Controller_Layout {
|
|||
if ($validation_course->check() AND $validation_letter->check())
|
||||
{
|
||||
$course->create();
|
||||
$course->add('group', (int) $this->request->post('group'));
|
||||
$letter->course_id = $course->id;
|
||||
$letter->create();
|
||||
}
|
||||
|
@ -111,7 +110,7 @@ class Controller_Course extends Controller_Layout {
|
|||
|
||||
public function action_edit()
|
||||
{
|
||||
$this->template = new View_Edit;
|
||||
$this->template = new View_Course_Edit;
|
||||
$this->template->title = I18n::translate('Edit course');
|
||||
$id = $this->request->param('id');
|
||||
$model = ORM::factory('Course', $id);
|
||||
|
@ -199,7 +198,11 @@ class Controller_Course extends Controller_Layout {
|
|||
{
|
||||
$model->add('course', $course);
|
||||
}
|
||||
if ($course->type = Course::TYPE_SCHEDULED)
|
||||
if ($course->group)
|
||||
{
|
||||
$model->add('group', $course->group);
|
||||
}
|
||||
if ($course->type = Model_Course::TYPE_SCHEDULED)
|
||||
{
|
||||
$task = ORM::factory('Task');
|
||||
$letter = $course->next_letter();
|
||||
|
@ -215,7 +218,7 @@ class Controller_Course extends Controller_Layout {
|
|||
$instant->course_id = $id;
|
||||
$instant->subject = I18n::translate('You were subscribed to ').$course->title;
|
||||
$instant->text = I18n::translate('From now on you will receive letters from this subscription.');
|
||||
$instant->send($course->email, $course->token);
|
||||
$instant->send($model->email, $model->token);
|
||||
// instant is not saved because it's just a welcome email
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ class Controller_Layout extends Controller {
|
|||
if ($validation->check())
|
||||
{
|
||||
$model->save();
|
||||
$this->afterSave($model);
|
||||
$this->after_save($model);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ class Controller_User extends Controller_Layout {
|
|||
{
|
||||
if (Auth::instance()->logged_in())
|
||||
{
|
||||
$this->redirect('post/index');
|
||||
$this->redirect('course/index');
|
||||
}
|
||||
$this->template = new View_Edit;
|
||||
$this->template->title = I18n::translate('User login');
|
||||
|
|
|
@ -25,9 +25,11 @@ class Model_Course extends ORM {
|
|||
'letters' => array(
|
||||
'model' => 'Letter'
|
||||
),
|
||||
);
|
||||
|
||||
protected $_belongs_to = array(
|
||||
'group' => array(
|
||||
'model' => 'Group',
|
||||
'through' => 'courses_groups'
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -148,16 +150,19 @@ class Model_Course extends ORM {
|
|||
public function delete()
|
||||
{
|
||||
$letter_ids = $this->get_letter_ids($this->id);
|
||||
$query = DB::delete('tasks');
|
||||
if (is_array($letter_ids))
|
||||
if (!empty($letter_ids))
|
||||
{
|
||||
$query->where('letter_id', 'IN', $letter_ids);
|
||||
$query = DB::delete('tasks');
|
||||
if (is_array($letter_ids))
|
||||
{
|
||||
$query->where('letter_id', 'IN', $letter_ids);
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where('letter_id', '=', $letter_ids);
|
||||
}
|
||||
$query->execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where('letter_id', '=', $letter_ids);
|
||||
}
|
||||
$query->execute();
|
||||
DB::delete('letters')
|
||||
->where('course_id', '=', $this->id)
|
||||
->execute();
|
||||
|
|
13
application/classes/View/Course/Edit.php
Normal file
13
application/classes/View/Course/Edit.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Course details editing view controller
|
||||
**/
|
||||
class View_Course_Edit extends View_Edit {
|
||||
public function group_select()
|
||||
{
|
||||
return Form::select('group_id', ORM::factory('Group')->find_all()->as_array('id', 'name'), NULL, [
|
||||
'label' => I18n::translate('Group')
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ class View_Course_Simple extends View_Edit {
|
|||
public $model_letter;
|
||||
public function controls_course()
|
||||
{
|
||||
$select = Form::select('group', ORM::factory('Group')->find_all()->as_array('id', 'name'), NULL, [
|
||||
$select = Form::select('group_id', ORM::factory('Group')->find_all()->as_array('id', 'name'), NULL, [
|
||||
'label' => I18n::translate('Group')
|
||||
]);
|
||||
return array(
|
||||
|
|
|
@ -85,4 +85,5 @@ return array(
|
|||
"Each new subscriber gets the first message in this series." => 'Каждый новый подписчик получает первое сообщение в этой серии.',
|
||||
"You can customize the delay (1 day by default) between the messages." => 'Вы можете настроить задержку (по умолчанию - один день) между сообщениями.',
|
||||
'Group' => 'Группа',
|
||||
'New group' => 'Новая группа',
|
||||
);
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* single group for courses
|
||||
*/
|
||||
class Migration_Kangana_20161023123945 extends Minion_Migration_Base {
|
||||
|
||||
/**
|
||||
* Run queries needed to apply this migration
|
||||
*
|
||||
* @param Kohana_Database $db Database connection
|
||||
*/
|
||||
public function up(Kohana_Database $db)
|
||||
{
|
||||
$db->query(NULL, 'DROP TABLE courses_groups');
|
||||
$db->query(NULL, 'ALTER TABLE courses ADD COLUMN group_id INT(11) NULL');
|
||||
$db->query(NULL, "ALTER TABLE `courses`
|
||||
ADD CONSTRAINT `fk_courses_groups` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Run queries needed to remove this migration
|
||||
*
|
||||
* @param Kohana_Database $db Database connection
|
||||
*/
|
||||
public function down(Kohana_Database $db)
|
||||
{
|
||||
$db->query(NULL, 'ALTER TABLE courses DROP COLUMN group_id');
|
||||
$db->query(NULL, "
|
||||
CREATE TABLE IF NOT EXISTS `courses_groups` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`course_id` int(11) NOT NULL,
|
||||
`group_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_courses_groups_course_index` (`course_id`),
|
||||
KEY `fk_courses_groups_group_index` (`group_id`)
|
||||
) ENGINE=InnoDB;");
|
||||
|
||||
$db->query(NULL, "
|
||||
ALTER TABLE `courses_groups`
|
||||
ADD CONSTRAINT `fk_courses_groups_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
ADD CONSTRAINT `fk_courses_groups_group` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
");
|
||||
}
|
||||
|
||||
}
|
23
application/templates/course/edit.mustache
Normal file
23
application/templates/course/edit.mustache
Normal file
|
@ -0,0 +1,23 @@
|
|||
<form method="POST">
|
||||
{{#has_errors}}
|
||||
<p class="message">При проверке формы были найдены ошибки:</p>
|
||||
<ul class="errors">
|
||||
{{#get_errors}}
|
||||
<li>{{.}}</li>
|
||||
{{/get_errors}}
|
||||
</ul>
|
||||
{{/has_errors}}
|
||||
{{{group_select}}}
|
||||
{{{get_controls}}}
|
||||
</form>
|
||||
{{#preview}}
|
||||
<h2>Предпросмотр</h2>
|
||||
<hr>
|
||||
<div class="hyphenate" id="preview">
|
||||
{{{preview}}}
|
||||
</div>
|
||||
<hr>
|
||||
{{/preview}}
|
||||
{{^preview}}
|
||||
<div class="hyphenate" id="preview"></div>
|
||||
{{/preview}}
|
Loading…
Reference in a new issue