Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F113311402
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
Sat, May 17, 02:59
Size
1 KB
Mime Type
text/x-php
Expires
Mon, May 19, 02:59 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
26234256
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
Exception
(
'Must set votable before saving vote'
);
}
$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