[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PonderVoteEditor extends PhabricatorEditor { 4 5 private $answer; 6 private $votable; 7 private $anwer; 8 private $vote; 9 10 public function setAnswer($answer) { 11 $this->answer = $answer; 12 return $this; 13 } 14 15 public function setVotable($votable) { 16 $this->votable = $votable; 17 return $this; 18 } 19 20 public function setVote($vote) { 21 $this->vote = $vote; 22 return $this; 23 } 24 25 public function saveVote() { 26 $actor = $this->requireActor(); 27 if (!$this->votable) { 28 throw new Exception('Must set votable before saving vote'); 29 } 30 31 $votable = $this->votable; 32 $newvote = $this->vote; 33 34 // prepare vote add, or update if this user is amending an 35 // earlier vote 36 $editor = id(new PhabricatorEdgeEditor()) 37 ->addEdge( 38 $actor->getPHID(), 39 $votable->getUserVoteEdgeType(), 40 $votable->getVotablePHID(), 41 array('data' => $newvote)) 42 ->removeEdge( 43 $actor->getPHID(), 44 $votable->getUserVoteEdgeType(), 45 $votable->getVotablePHID()); 46 47 $conn = $votable->establishConnection('w'); 48 $trans = $conn->openTransaction(); 49 $trans->beginReadLocking(); 50 51 $votable->reload(); 52 $curvote = (int)PhabricatorEdgeQuery::loadSingleEdgeData( 53 $actor->getPHID(), 54 $votable->getUserVoteEdgeType(), 55 $votable->getVotablePHID()); 56 57 if (!$curvote) { 58 $curvote = PonderVote::VOTE_NONE; 59 } 60 61 // adjust votable's score by this much 62 $delta = $newvote - $curvote; 63 64 queryfx($conn, 65 'UPDATE %T as t 66 SET t.`voteCount` = t.`voteCount` + %d 67 WHERE t.`PHID` = %s', 68 $votable->getTableName(), 69 $delta, 70 $votable->getVotablePHID()); 71 72 $editor->save(); 73 74 $trans->endReadLocking(); 75 $trans->saveTransaction(); 76 } 77 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |