Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F107361790
PonderVoteEditor.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
Mon, Apr 7, 11:26
Size
1 KB
Mime Type
text/x-php
Expires
Wed, Apr 9, 11:26 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25378052
Attached To
rPH Phabricator
PonderVoteEditor.php
View Options
<?php
final
class
PonderVoteEditor
extends
PhabricatorEditor
{
private
$answer
;
private
$votable
;
private
$anwer
;
private
$vote
;
public
function
setAnswer
(
$answer
)
{
$this
->
answer
=
$answer
;
return
$this
;
}
public
function
setVotable
(
$votable
)
{
$this
->
votable
=
$votable
;
return
$this
;
}
public
function
setVote
(
$vote
)
{
$this
->
vote
=
$vote
;
return
$this
;
}
public
function
saveVote
()
{
$actor
=
$this
->
requireActor
();
if
(!
$this
->
votable
)
{
throw
new
PhutilInvalidStateException
(
'setVotable'
);
}
$votable
=
$this
->
votable
;
$newvote
=
$this
->
vote
;
// prepare vote add, or update if this user is amending an
// earlier vote
$editor
=
id
(
new
PhabricatorEdgeEditor
())
->
addEdge
(
$actor
->
getPHID
(),
$votable
->
getUserVoteEdgeType
(),
$votable
->
getVotablePHID
(),
array
(
'data'
=>
$newvote
))
->
removeEdge
(
$actor
->
getPHID
(),
$votable
->
getUserVoteEdgeType
(),
$votable
->
getVotablePHID
());
$conn
=
$votable
->
establishConnection
(
'w'
);
$trans
=
$conn
->
openTransaction
();
$trans
->
beginReadLocking
();
$votable
->
reload
();
$curvote
=
(
int
)
PhabricatorEdgeQuery
::
loadSingleEdgeData
(
$actor
->
getPHID
(),
$votable
->
getUserVoteEdgeType
(),
$votable
->
getVotablePHID
());
if
(!
$curvote
)
{
$curvote
=
PonderVote
::
VOTE_NONE
;
}
// Adjust votable's score by this much.
$delta
=
$newvote
-
$curvote
;
queryfx
(
$conn
,
'UPDATE %T as t
SET t.voteCount = t.voteCount + %d
WHERE t.PHID = %s'
,
$votable
->
getTableName
(),
$delta
,
$votable
->
getVotablePHID
());
$editor
->
save
();
$trans
->
endReadLocking
();
$trans
->
saveTransaction
();
}
}
Event Timeline
Log In to Comment