mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-05 05:02:44 +01:00
85798368be
Summary: Ref T2625. Also modernize some other things: - Fix double-"subscribers". - Use byline and more standard date. - Modernize some of the use of crumbs and navigation. - Delete some dead / uncalled code. Test Plan: {F50669} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3578, T2625 Differential Revision: https://secure.phabricator.com/D6486
112 lines
3 KiB
PHP
112 lines
3 KiB
PHP
<?php
|
|
|
|
final class PonderQuestionAskController extends PonderController {
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$question = id(new PonderQuestion())
|
|
->setAuthorPHID($user->getPHID())
|
|
->setVoteCount(0)
|
|
->setAnswerCount(0)
|
|
->setHeat(0.0);
|
|
|
|
$errors = array();
|
|
$e_title = true;
|
|
if ($request->isFormPost()) {
|
|
$question->setTitle($request->getStr('title'));
|
|
$question->setContent($request->getStr('content'));
|
|
|
|
$len = phutil_utf8_strlen($question->getTitle());
|
|
if ($len < 1) {
|
|
$errors[] = pht('Title must not be empty.');
|
|
$e_title = pht('Required');
|
|
} else if ($len > 255) {
|
|
$errors[] = pht('Title is too long.');
|
|
$e_title = pht('Too Long');
|
|
}
|
|
|
|
if (!$errors) {
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
array(
|
|
'ip' => $request->getRemoteAddr(),
|
|
));
|
|
$question->setContentSource($content_source);
|
|
|
|
id(new PonderQuestionEditor())
|
|
->setQuestion($question)
|
|
->setActor($user)
|
|
->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
->setURI('/Q'.$question->getID());
|
|
}
|
|
}
|
|
|
|
$error_view = null;
|
|
if ($errors) {
|
|
$error_view = id(new AphrontErrorView())
|
|
->setTitle(pht('Form Errors'))
|
|
->setErrors($errors);
|
|
}
|
|
|
|
$form = id(new AphrontFormView())
|
|
->setUser($user)
|
|
->setFlexible(true)
|
|
->appendChild(
|
|
id(new AphrontFormTextControl())
|
|
->setLabel(pht('Question'))
|
|
->setName('title')
|
|
->setValue($question->getTitle())
|
|
->setError($e_title))
|
|
->appendChild(
|
|
id(new PhabricatorRemarkupControl())
|
|
->setName('content')
|
|
->setID('content')
|
|
->setValue($question->getContent())
|
|
->setLabel(pht('Description'))
|
|
->setUser($user))
|
|
->appendChild(
|
|
id(new AphrontFormSubmitControl())
|
|
->addCancelButton($this->getApplicationURI())
|
|
->setValue(pht('Ask Away!')));
|
|
|
|
$preview = hsprintf(
|
|
'<div class="aphront-panel-flush">'.
|
|
'<div id="question-preview">'.
|
|
'<span class="aphront-panel-preview-loading-text">%s</span>'.
|
|
'</div>'.
|
|
'</div>',
|
|
pht('Loading question preview...'));
|
|
|
|
Javelin::initBehavior(
|
|
'ponder-feedback-preview',
|
|
array(
|
|
'uri' => '/ponder/question/preview/',
|
|
'content' => 'content',
|
|
'preview' => 'question-preview',
|
|
'question_id' => null
|
|
));
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
$crumbs->addCrumb(
|
|
id(new PhabricatorCrumbView())
|
|
->setName(pht('Ask Question')));
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$error_view,
|
|
$form,
|
|
$preview,
|
|
),
|
|
array(
|
|
'device' => true,
|
|
'dust' => true,
|
|
'title' => pht('Ask a Question'),
|
|
));
|
|
}
|
|
|
|
}
|