-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPosts.php
103 lines (82 loc) · 2.95 KB
/
Posts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php namespace October\Test\Controllers;
use BackendMenu;
use Backend\Classes\Controller;
/**
* Posts [and Comments] Back-end Controller
*
* This is a mighty fine example of what October can do, here we have a single controller
* managing two Models (Posts and Comments). The ListController behavior handles two lists
* easily, by passing an array of definitions and config files. The FormController behavior
* natively handles the Posts, but for Comments we intercept the construction process and
* override the config to reference the comment form when a special flag is passed with the
* request (comment_mode). By itself this is enough to simply tack ?comment_mode=1 on to the
* URL, but to mix things up the Comments form is managed by AJAX popups.
*/
class Posts extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.Behaviors.RelationController',
];
public $formConfig = 'config_post_form.yaml';
public $listConfig = ['posts' => 'config_posts_list.yaml', 'comments' => 'config_comments_list.yaml'];
public $relationConfig = 'config_relation.yaml';
public function __construct()
{
if (post('comment_mode')) {
$this->formConfig = 'config_comment_form.yaml';
}
parent::__construct();
BackendMenu::setContext('October.Test', 'test', 'posts');
}
public function index()
{
$this->asExtension('ListController')->index();
$this->bodyClass = 'compact-container';
}
//
// Custom Delete workflow
//
public function onLoadDeleteReasonForm($recordId = null)
{
return $this->makePartial('delete_reason_form');
}
public function onDeleteWithReason($recordId = null)
{
$result = $this->asExtension('FormController')->update_onDelete($recordId);
$model = $this->formGetModel();
$reason = post('reason');
traceLog(sprintf('The post "%s" was deleted with reason "%s"', $model->name, $reason));
return $result;
}
//
// Comment form
//
public function onCreateForm()
{
$this->asExtension('FormController')->create();
return $this->makePartial('create_form');
}
public function onCreate()
{
$this->asExtension('FormController')->create_onSave();
return $this->listRefresh('comments');
}
public function onUpdateForm()
{
$this->asExtension('FormController')->update(post('record_id'));
$this->vars['recordId'] = post('record_id');
return $this->makePartial('update_form');
}
public function onUpdate()
{
$this->asExtension('FormController')->update_onSave(post('record_id'));
return $this->listRefresh('comments');
}
public function onDelete()
{
$this->asExtension('FormController')->update_onDelete(post('record_id'));
return $this->listRefresh('comments');
}
}