public function test_get_by_exclude_user_id() { $i1 = new MockVoteable(5); $i2 = new MockVoteable(6); $u1 = 8; $u2 = 9; $v1 = self::factory()->vote->create(array('item' => $i1, 'user_id' => $u1)); $v2 = self::factory()->vote->create(array('item' => $i2, 'user_id' => $u2)); $q = new \WeBWorK\Server\Vote\Query(array('user_id__not_in' => array($u1))); $found = $q->get(); $this->assertSame(1, count($found)); $first = reset($found); $this->assertEquals($v2, $first->id); }
/** * Get vote count. * * @param int $force_query Whether to skip the metadata cache. * @return int */ public function get_vote_count($force_query = false) { $item_id = $this->c->get_id(); $vote_count = get_post_meta($item_id, 'webwork_vote_count', true); if ($force_query || '' === $vote_count) { $vote_query = new \WeBWorK\Server\Vote\Query(array('item_id' => $item_id)); $vote_count = $vote_query->get('count'); update_post_meta($item_id, 'webwork_vote_count', $vote_count); } return intval($vote_count); }