Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92698117
PonderAnswerSaveController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 21:33
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Nov 24, 21:33 (2 d)
Engine
blob
Format
Raw Data
Handle
22478969
Attached To
rPH Phabricator
PonderAnswerSaveController.php
View Options
<?php
final
class
PonderAnswerSaveController
extends
PonderController
{
public
function
processRequest
()
{
$request
=
$this
->
getRequest
();
$viewer
=
$request
->
getUser
();
if
(!
$request
->
isFormPost
())
{
return
new
Aphront400Response
();
}
$question_id
=
$request
->
getInt
(
'question_id'
);
$question
=
id
(
new
PonderQuestionQuery
())
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$question_id
))
->
needAnswers
(
true
)
->
executeOne
();
if
(!
$question
)
{
return
new
Aphront404Response
();
}
$answer
=
$request
->
getStr
(
'answer'
);
if
(!
strlen
(
trim
(
$answer
)))
{
$dialog
=
id
(
new
AphrontDialogView
())
->
setUser
(
$viewer
)
->
setTitle
(
pht
(
'Empty Answer'
))
->
appendChild
(
phutil_tag
(
'p'
,
array
(),
pht
(
'Your answer must not be empty.'
)))
->
addCancelButton
(
'/Q'
.
$question_id
);
return
id
(
new
AphrontDialogResponse
())->
setDialog
(
$dialog
);
}
$content_source
=
PhabricatorContentSource
::
newForSource
(
PhabricatorContentSource
::
SOURCE_WEB
,
array
(
'ip'
=>
$request
->
getRemoteAddr
(),
));
$res
=
id
(
new
PonderAnswer
())
->
setAuthorPHID
(
$viewer
->
getPHID
())
->
setQuestionID
(
$question
->
getID
())
->
setContent
(
$answer
)
->
setVoteCount
(
0
)
->
setContentSource
(
$content_source
);
$xactions
=
array
();
$xactions
[]
=
id
(
new
PonderQuestionTransaction
())
->
setTransactionType
(
PonderQuestionTransaction
::
TYPE_ANSWERS
)
->
setNewValue
(
array
(
'+'
=>
array
(
array
(
'answer'
=>
$res
),
),
));
$editor
=
id
(
new
PonderQuestionEditor
())
->
setActor
(
$viewer
)
->
setContentSourceFromRequest
(
$request
);
$editor
->
applyTransactions
(
$question
,
$xactions
);
return
id
(
new
AphrontRedirectResponse
())->
setURI
(
id
(
new
PhutilURI
(
'/Q'
.
$question
->
getID
())));
}
}
Event Timeline
Log In to Comment