2012-08-10 19:44:04 +02:00
|
|
|
<?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)
|
2012-10-01 05:09:18 +02:00
|
|
|
->setHeat(0.0);
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2012-10-01 05:09:18 +02:00
|
|
|
$errors = array();
|
|
|
|
$e_title = true;
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$question->setTitle($request->getStr('title'));
|
|
|
|
$question->setContent($request->getStr('content'));
|
2013-07-28 03:37:17 +02:00
|
|
|
$question->setStatus(PonderQuestionStatus::STATUS_OPEN);
|
2012-10-01 05:09:18 +02:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
2012-10-07 23:35:01 +02:00
|
|
|
id(new PonderQuestionEditor())
|
|
|
|
->setQuestion($question)
|
2012-10-10 19:18:23 +02:00
|
|
|
->setActor($user)
|
2012-10-07 23:35:01 +02:00
|
|
|
->save();
|
2012-10-01 05:09:18 +02:00
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/Q'.$question->getID());
|
|
|
|
}
|
|
|
|
}
|
2012-08-10 19:44:04 +02:00
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = id(new AphrontErrorView())
|
2013-05-20 16:55:23 +02:00
|
|
|
->setTitle(pht('Form Errors'))
|
2012-08-10 19:44:04 +02:00
|
|
|
->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
2012-10-01 05:09:18 +02:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->setFlexible(true)
|
2012-08-10 19:44:04 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2012-10-01 05:09:18 +02:00
|
|
|
->setLabel(pht('Question'))
|
2012-08-10 19:44:04 +02:00
|
|
|
->setName('title')
|
2012-10-01 05:09:18 +02:00
|
|
|
->setValue($question->getTitle())
|
|
|
|
->setError($e_title))
|
2012-08-10 19:44:04 +02:00
|
|
|
->appendChild(
|
2012-09-19 21:27:28 +02:00
|
|
|
id(new PhabricatorRemarkupControl())
|
2012-08-10 19:44:04 +02:00
|
|
|
->setName('content')
|
|
|
|
->setID('content')
|
2012-10-01 05:09:18 +02:00
|
|
|
->setValue($question->getContent())
|
2012-11-27 23:06:31 +01:00
|
|
|
->setLabel(pht('Description'))
|
|
|
|
->setUser($user))
|
2012-08-10 19:44:04 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-07-18 21:40:51 +02:00
|
|
|
->addCancelButton($this->getApplicationURI())
|
|
|
|
->setValue(pht('Ask Away!')));
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$preview = hsprintf(
|
2012-08-10 19:44:04 +02:00
|
|
|
'<div class="aphront-panel-flush">'.
|
|
|
|
'<div id="question-preview">'.
|
2013-02-13 23:50:15 +01:00
|
|
|
'<span class="aphront-panel-preview-loading-text">%s</span>'.
|
2012-08-10 19:44:04 +02:00
|
|
|
'</div>'.
|
2013-02-13 23:50:15 +01:00
|
|
|
'</div>',
|
|
|
|
pht('Loading question preview...'));
|
2012-08-10 19:44:04 +02:00
|
|
|
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'ponder-feedback-preview',
|
|
|
|
array(
|
|
|
|
'uri' => '/ponder/question/preview/',
|
|
|
|
'content' => 'content',
|
|
|
|
'preview' => 'question-preview',
|
|
|
|
'question_id' => null
|
|
|
|
));
|
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName(pht('Ask Question')));
|
2012-10-01 05:09:18 +02:00
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
return $this->buildApplicationPage(
|
2012-10-01 05:09:18 +02:00
|
|
|
array(
|
2013-07-18 21:40:51 +02:00
|
|
|
$crumbs,
|
2012-10-01 05:09:18 +02:00
|
|
|
$error_view,
|
|
|
|
$form,
|
|
|
|
$preview,
|
2013-07-18 21:40:51 +02:00
|
|
|
),
|
2012-10-01 05:09:18 +02:00
|
|
|
array(
|
|
|
|
'device' => true,
|
2013-05-20 16:55:23 +02:00
|
|
|
'dust' => true,
|
|
|
|
'title' => pht('Ask a Question'),
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2012-08-10 19:44:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|