本文整理匯總了PHP中PhabricatorEdgeQuery::loadSingleEdgeData方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhabricatorEdgeQuery::loadSingleEdgeData方法的具體用法?PHP PhabricatorEdgeQuery::loadSingleEdgeData怎麽用?PHP PhabricatorEdgeQuery::loadSingleEdgeData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PhabricatorEdgeQuery
的用法示例。
在下文中一共展示了PhabricatorEdgeQuery::loadSingleEdgeData方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: saveVote
public function saveVote()
{
if (!$this->votable) {
throw new Exception("Must set votable before saving vote");
}
if (!$this->user) {
throw new Exception("Must set user before saving vote");
}
$user = $this->user;
$votable = $this->votable;
$newvote = $this->vote;
// prepare vote add, or update if this user is amending an
// earlier vote
$editor = id(new PhabricatorEdgeEditor())->setUser($user)->addEdge($user->getPHID(), $votable->getUserVoteEdgeType(), $votable->getVotablePHID(), array('data' => $newvote))->removeEdge($user->getPHID(), $votable->getUserVoteEdgeType(), $votable->getVotablePHID());
$conn = $votable->establishConnection('w');
$trans = $conn->openTransaction();
$trans->beginReadLocking();
$votable->reload();
$curvote = (int) PhabricatorEdgeQuery::loadSingleEdgeData($user->getPHID(), $votable->getUserVoteEdgeType(), $votable->getVotablePHID());
if (!$curvote) {
$curvote = PonderConstants::NONE_VOTE;
}
// 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();
}
示例2: saveVote
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();
}