Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98563903
PhabricatorSlowvoteVoteController.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
Tue, Jan 14, 09:30
Size
1 KB
Mime Type
text/x-php
Expires
Thu, Jan 16, 09:30 (1 d, 14 h)
Engine
blob
Format
Raw Data
Handle
23604740
Attached To
rPH Phabricator
PhabricatorSlowvoteVoteController.php
View Options
<?php
final
class
PhabricatorSlowvoteVoteController
extends
PhabricatorSlowvoteController
{
public
function
handleRequest
(
AphrontRequest
$request
)
{
$viewer
=
$request
->
getViewer
();
$id
=
$request
->
getURIData
(
'id'
);
if
(!
$request
->
isFormPost
())
{
return
id
(
new
Aphront404Response
());
}
$poll
=
id
(
new
PhabricatorSlowvoteQuery
())
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$id
))
->
needOptions
(
true
)
->
needViewerChoices
(
true
)
->
executeOne
();
if
(!
$poll
)
{
return
new
Aphront404Response
();
}
if
(
$poll
->
getIsClosed
())
{
return
new
Aphront400Response
();
}
$options
=
$poll
->
getOptions
();
$options
=
mpull
(
$options
,
null
,
'getID'
);
$old_votes
=
$poll
->
getViewerChoices
(
$viewer
);
$old_votes
=
mpull
(
$old_votes
,
null
,
'getOptionID'
);
$votes
=
$request
->
getArr
(
'vote'
);
$votes
=
array_fuse
(
$votes
);
$method
=
$poll
->
getMethod
();
$is_plurality
=
(
$method
==
PhabricatorSlowvotePoll
::
METHOD_PLURALITY
);
if
(
$is_plurality
&&
count
(
$votes
)
>
1
)
{
throw
new
Exception
(
pht
(
'In this poll, you may only vote for one option.'
));
}
foreach
(
$votes
as
$vote
)
{
if
(!
isset
(
$options
[
$vote
]))
{
throw
new
Exception
(
pht
(
'Option ("%s") is not a valid poll option. You may only '
.
'vote for valid options.'
,
$vote
));
}
}
foreach
(
$old_votes
as
$old_vote
)
{
if
(!
idx
(
$votes
,
$old_vote
->
getOptionID
(),
false
))
{
$old_vote
->
delete
();
}
}
foreach
(
$votes
as
$vote
)
{
if
(
idx
(
$old_votes
,
$vote
,
false
))
{
continue
;
}
id
(
new
PhabricatorSlowvoteChoice
())
->
setAuthorPHID
(
$viewer
->
getPHID
())
->
setPollID
(
$poll
->
getID
())
->
setOptionID
(
$vote
)
->
save
();
}
return
id
(
new
AphrontRedirectResponse
())
->
setURI
(
$poll
->
getURI
());
}
}
Event Timeline
Log In to Comment