2011-02-21 03:41:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
class PhabricatorProjectProfileEditController
|
2011-02-21 03:41:23 +01:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-26 17:37:47 +02:00
|
|
|
$this->id = $data['id'];
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
$project = id(new PhabricatorProject())->load($this->id);
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
2011-06-26 17:37:47 +02:00
|
|
|
$profile = $project->loadProfile();
|
2011-02-21 03:41:23 +01:00
|
|
|
|
|
|
|
if (empty($profile)) {
|
|
|
|
$profile = new PhabricatorProjectProfile();
|
|
|
|
}
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
$options = PhabricatorProjectStatus::getStatusMap();
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$project->setName($request->getStr('name'));
|
2011-06-18 10:13:56 +02:00
|
|
|
$project->setStatus($request->getStr('status'));
|
2011-02-21 03:41:23 +01:00
|
|
|
$profile->setBlurb($request->getStr('blurb'));
|
|
|
|
|
|
|
|
if (!strlen($project->getName())) {
|
|
|
|
$e_name = 'Required';
|
|
|
|
$errors[] = 'Project name is required.';
|
|
|
|
} else {
|
|
|
|
$e_name = null;
|
|
|
|
}
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
if (!empty($_FILES['image'])) {
|
|
|
|
$err = idx($_FILES['image'], 'error');
|
|
|
|
if ($err != UPLOAD_ERR_NO_FILE) {
|
|
|
|
$file = PhabricatorFile::newFromPHPUpload($_FILES['image']);
|
|
|
|
$okay = $file->isTransformableImage();
|
|
|
|
if ($okay) {
|
2011-06-26 17:37:47 +02:00
|
|
|
$xformer = new PhabricatorImageTransformer();
|
|
|
|
$xformed = $xformer->executeProfileTransform(
|
|
|
|
$file,
|
|
|
|
$width = 280,
|
|
|
|
$min_height = 140,
|
|
|
|
$max_height = 420);
|
|
|
|
$profile->setProfileImagePHID($xformed->getPHID());
|
2011-06-18 10:13:56 +02:00
|
|
|
} else {
|
|
|
|
$errors[] =
|
|
|
|
'Only valid image files (jpg, jpeg, png or gif) '.
|
|
|
|
'will be accepted.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
if (!$errors) {
|
|
|
|
$project->save();
|
|
|
|
$profile->setProjectPHID($project->getPHID());
|
|
|
|
$profile->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/project/view/'.$project->getID().'/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = new AphrontErrorView();
|
|
|
|
$error_view->setTitle('Form Errors');
|
|
|
|
$error_view->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
$header_name = 'Edit Project';
|
|
|
|
$title = 'Edit Project';
|
|
|
|
$action = '/project/edit/'.$project->getID().'/';
|
2011-02-21 03:41:23 +01:00
|
|
|
|
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form
|
|
|
|
->setUser($user)
|
|
|
|
->setAction($action)
|
2011-06-18 10:13:56 +02:00
|
|
|
->setEncType('multipart/form-data')
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Name')
|
|
|
|
->setName('name')
|
|
|
|
->setValue($project->getName())
|
|
|
|
->setError($e_name))
|
2011-06-18 10:13:56 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel('Project Status')
|
|
|
|
->setName('status')
|
|
|
|
->setOptions($options)
|
|
|
|
->setValue($project->getStatus()))
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel('Blurb')
|
|
|
|
->setName('blurb')
|
|
|
|
->setValue($profile->getBlurb()))
|
2011-06-18 10:13:56 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormFileControl())
|
|
|
|
->setLabel('Change Image')
|
2011-06-26 17:37:47 +02:00
|
|
|
->setName('image'))
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2011-06-18 10:13:56 +02:00
|
|
|
->addCancelButton('/project/view/'.$project->getID().'/')
|
2011-02-21 03:41:23 +01:00
|
|
|
->setValue('Save'));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader($header_name);
|
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
|
|
|
$panel->appendChild($form);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array(
|
|
|
|
$error_view,
|
|
|
|
$panel,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|