3 final class ConpherenceRoomPictureController
4 extends ConpherenceController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $conpherence = id(new ConpherenceThreadQuery())
13 ->needProfileImage(true)
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
24 $monogram = $conpherence->getMonogram();
26 $supported_formats = PhabricatorFile
::getTransformableImageFormats();
30 if ($request->isFormPost()) {
31 $phid = $request->getStr('phid');
33 if ($phid == PhabricatorPHIDConstants
::PHID_VOID
) {
37 $file = id(new PhabricatorFileQuery())
39 ->withPHIDs(array($phid))
42 if ($request->getFileExists('picture')) {
43 $file = PhabricatorFile
::newFromPHPUpload(
46 'authorPHID' => $viewer->getPHID(),
50 $e_file = pht('Required');
52 'You must choose a file when uploading a new room picture.');
56 if (!$errors && !$is_default) {
57 if (!$file->isTransformableImage()) {
58 $e_file = pht('Not Supported');
60 'This server only supports these image formats: %s.',
61 implode(', ', $supported_formats));
63 $xform = PhabricatorFileTransform
::getTransformByKey(
64 PhabricatorFileThumbnailTransform
::TRANSFORM_PROFILE
);
65 $xformed = $xform->executeTransform($file);
73 $xformed->attachToObject($conpherence->getPHID());
74 $new_value = $xformed->getPHID();
78 $xactions[] = id(new ConpherenceTransaction())
80 ConpherenceThreadPictureTransaction
::TRANSACTIONTYPE
)
81 ->setNewValue($new_value);
83 $editor = id(new ConpherenceEditor())
85 ->setContentSourceFromRequest($request)
86 ->setContinueOnMissingFields(true)
87 ->setContinueOnNoEffect(true);
89 $editor->applyTransactions($conpherence, $xactions);
91 return id(new AphrontRedirectResponse())->setURI('/'.$monogram);
95 $title = pht('Edit Room Picture');
97 $form = id(new PHUIFormLayoutView())
100 $default_image = PhabricatorFile
::loadBuiltin($viewer, 'conpherence.png');
104 $current = $conpherence->getProfileImagePHID();
105 $has_current = false;
107 $file = id(new PhabricatorFileQuery())
109 ->withPHIDs(array($current))
112 if ($file->isTransformableImage()) {
114 $images[$current] = array(
115 'uri' => $file->getBestURI(),
116 'tip' => pht('Current Picture'),
122 $images[PhabricatorPHIDConstants
::PHID_VOID
] = array(
123 'uri' => $default_image->getBestURI(),
124 'tip' => pht('Default Picture'),
127 require_celerity_resource('people-profile-css');
128 Javelin
::initBehavior('phabricator-tooltips', array());
131 foreach ($images as $phid => $spec) {
132 $button = javelin_tag(
135 'class' => 'button-grey profile-image-button',
136 'sigil' => 'has-tooltip',
138 'tip' => $spec['tip'],
147 'src' => $spec['uri'],
161 $button = phabricator_form(
164 'class' => 'profile-image-form',
169 $buttons[] = $button;
174 id(new AphrontFormMarkupControl())
175 ->setLabel(pht('Current Picture'))
176 ->setValue(array_shift($buttons)));
180 id(new AphrontFormMarkupControl())
181 ->setLabel(pht('Use Picture'))
182 ->setValue($buttons));
184 $form_box = id(new PHUIObjectBoxView())
185 ->setHeaderText($title)
186 ->setFormErrors($errors)
187 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
190 $upload_form = id(new AphrontFormView())
192 ->setEncType('multipart/form-data')
194 id(new AphrontFormFileControl())
196 ->setLabel(pht('Upload Picture'))
199 pht('Supported formats: %s', implode(', ', $supported_formats))))
201 id(new AphrontFormSubmitControl())
202 ->addCancelButton('/'.$monogram)
203 ->setValue(pht('Upload Picture')));
205 $upload_box = id(new PHUIObjectBoxView())
206 ->setHeaderText(pht('Upload New Picture'))
207 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
208 ->setForm($upload_form);
210 $crumbs = $this->buildApplicationCrumbs();
211 $crumbs->addTextCrumb($conpherence->getTitle(), '/'.$monogram);
212 $crumbs->addTextCrumb(pht('Room Picture'));
213 $crumbs->setBorder(true);
215 $header = id(new PHUIHeaderView())
216 ->setHeader(pht('Edit Room Picture'))
217 ->setHeaderIcon('fa-camera');
219 $view = id(new PHUITwoColumnView())
226 return $this->newPage()