<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Nodevote extends vB_Api { protected $assertor; protected $library; protected function __construct() { parent::__construct(); $this->assertor = vB::getDbAssertor(); $this->library = vB_Library::instance('nodevote'); } private function canUnvoteNode($nodeid, $votetypeid) { [$currentUserid, $votetype, $votegroup, $node] = $this->library->digestVoteUnvoteRequest($nodeid, $votetypeid); $can = true; vB::getHooks()->invoke('hookCanUnvoteNode', [ 'currentUserid' => $currentUserid, 'votetype' => $votetype, 'votegroup' => $votegroup, 'node' => $node, 'can' => &$can, ]); return $can; } private function canVoteNode($nodeid, $votetypeid) { [$currentUserid, $votetype, $votegroup, $node] = $this->library->digestVoteUnvoteRequest($nodeid, $votetypeid); $can = true; vB::getHooks()->invoke('hookCanVoteNode', [ 'currentUserid' => $currentUserid, 'votetype' => $votetype, 'votegroup' => $votegroup, 'node' => $node, 'can' => &$can, ]); return $can; } public function unvoteNode($nodeid, $votetypeid) { if (!$this->canUnvoteNode($nodeid, $votetypeid)) { throw new vB_Exception_Api('no_permission'); } $this->library->unvoteNode($nodeid, $votetypeid); $nodevotes = $this->library->getNodevoteCounts($nodeid); return [ 'success' => true, 'nodevotes' => $nodevotes[$nodeid] ?? [], ]; } public function voteNode($nodeid, $votetypeid) { if (!$this->canVoteNode($nodeid, $votetypeid)) { throw new vB_Exception_Api('no_permission'); } $voteid = $this->library->voteNode($nodeid, $votetypeid); $nodevotes = $this->library->getNodevoteCounts($nodeid); return [ 'success' => true, 'voteid' => $voteid, 'nodevotes' => $nodevotes[$nodeid] ?? [], ]; } } 