forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhamePostNewController.php
131 lines (109 loc) · 3.28 KB
/
PhamePostNewController.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @group phame
*/
final class PhamePostNewController extends PhameController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$post = null;
$view_uri = null;
if ($this->id) {
$post = id(new PhamePostQuery())
->setViewer($user)
->withIDs(array($this->id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$post) {
return new Aphront404Response();
}
$view_uri = '/post/view/'.$post->getID().'/';
$view_uri = $this->getApplicationURI($view_uri);
if ($request->isFormPost()) {
$blog = id(new PhameBlogQuery())
->setViewer($user)
->withIDs(array($request->getInt('blog')))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_JOIN,
))
->executeOne();
if ($blog) {
$post->setBlogPHID($blog->getPHID());
$post->save();
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
}
$title = pht('Move Post');
} else {
$title = pht('Create Post');
$view_uri = $this->getApplicationURI('/post/new');
}
$blogs = id(new PhameBlogQuery())
->setViewer($user)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_JOIN,
))
->execute();
$nav = $this->renderSideNavFilterView();
$nav->selectFilter('post/new');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, $view_uri);
$nav->appendChild($crumbs);
if (!$blogs) {
$notification = id(new AphrontErrorView())
->setSeverity(AphrontErrorView::SEVERITY_NODATA)
->appendChild(
pht('You do not have permission to join any blogs. Create a blog '.
'first, then you can post to it.'));
$nav->appendChild($notification);
} else {
$options = mpull($blogs, 'getName', 'getID');
asort($options);
$selected_value = null;
if ($post && $post->getBlog()) {
$selected_value = $post->getBlog()->getID();
}
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Blog'))
->setName('blog')
->setOptions($options)
->setValue($selected_value));
if ($post) {
$form
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Move Post'))
->addCancelButton($view_uri));
} else {
$form
->setAction($this->getApplicationURI('post/edit/'))
->setMethod('GET')
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Continue')));
}
$form_box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setForm($form);
$nav->appendChild($form_box);
}
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
}
}