[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhamePostNewController extends PhameController { 4 5 private $id; 6 7 public function willProcessRequest(array $data) { 8 $this->id = idx($data, 'id'); 9 } 10 11 public function processRequest() { 12 $request = $this->getRequest(); 13 $user = $request->getUser(); 14 15 $post = null; 16 $view_uri = null; 17 if ($this->id) { 18 $post = id(new PhamePostQuery()) 19 ->setViewer($user) 20 ->withIDs(array($this->id)) 21 ->requireCapabilities( 22 array( 23 PhabricatorPolicyCapability::CAN_EDIT, 24 )) 25 ->executeOne(); 26 if (!$post) { 27 return new Aphront404Response(); 28 } 29 30 $view_uri = '/post/view/'.$post->getID().'/'; 31 $view_uri = $this->getApplicationURI($view_uri); 32 33 if ($request->isFormPost()) { 34 $blog = id(new PhameBlogQuery()) 35 ->setViewer($user) 36 ->withIDs(array($request->getInt('blog'))) 37 ->requireCapabilities( 38 array( 39 PhabricatorPolicyCapability::CAN_JOIN, 40 )) 41 ->executeOne(); 42 43 if ($blog) { 44 $post->setBlogPHID($blog->getPHID()); 45 $post->save(); 46 47 return id(new AphrontRedirectResponse())->setURI($view_uri); 48 } 49 } 50 51 $title = pht('Move Post'); 52 } else { 53 $title = pht('Create Post'); 54 $view_uri = $this->getApplicationURI('/post/new'); 55 } 56 57 $blogs = id(new PhameBlogQuery()) 58 ->setViewer($user) 59 ->requireCapabilities( 60 array( 61 PhabricatorPolicyCapability::CAN_JOIN, 62 )) 63 ->execute(); 64 65 $nav = $this->renderSideNavFilterView(); 66 $nav->selectFilter('post/new'); 67 68 $crumbs = $this->buildApplicationCrumbs(); 69 $crumbs->addTextCrumb($title, $view_uri); 70 $nav->appendChild($crumbs); 71 72 if (!$blogs) { 73 $notification = id(new AphrontErrorView()) 74 ->setSeverity(AphrontErrorView::SEVERITY_NODATA) 75 ->appendChild( 76 pht('You do not have permission to join any blogs. Create a blog '. 77 'first, then you can post to it.')); 78 79 $nav->appendChild($notification); 80 } else { 81 $options = mpull($blogs, 'getName', 'getID'); 82 asort($options); 83 84 $selected_value = null; 85 if ($post && $post->getBlog()) { 86 $selected_value = $post->getBlog()->getID(); 87 } 88 89 $form = id(new AphrontFormView()) 90 ->setUser($user) 91 ->appendChild( 92 id(new AphrontFormSelectControl()) 93 ->setLabel(pht('Blog')) 94 ->setName('blog') 95 ->setOptions($options) 96 ->setValue($selected_value)); 97 98 if ($post) { 99 $form 100 ->appendChild( 101 id(new AphrontFormSubmitControl()) 102 ->setValue(pht('Move Post')) 103 ->addCancelButton($view_uri)); 104 } else { 105 $form 106 ->setAction($this->getApplicationURI('post/edit/')) 107 ->setMethod('GET') 108 ->appendChild( 109 id(new AphrontFormSubmitControl()) 110 ->setValue(pht('Continue'))); 111 } 112 113 114 $form_box = id(new PHUIObjectBoxView()) 115 ->setHeaderText($title) 116 ->setForm($form); 117 118 $nav->appendChild($form_box); 119 } 120 121 return $this->buildApplicationPage( 122 $nav, 123 array( 124 'title' => $title, 125 )); 126 } 127 128 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |