本文整理汇总了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();
}