本文整理汇总了PHP中Vote类的典型用法代码示例。如果您正苦于以下问题:PHP Vote类的具体用法?PHP Vote怎么用?PHP Vote使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vote类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker\Factory::create();
$voter = new Vote();
Auth::login(User::find(1));
for ($i = 1; $i < 9; $i++) {
$user = User::find($i);
for ($j = 0; $j < 30; $j++) {
$type = rand(0, 2);
$type_id = 0;
switch ($type) {
case 0:
$type_id = rand(1, 9);
break;
case 1:
$type_id = rand(1, 9);
break;
case 2:
$type_id = rand(1, 9);
break;
}
$updown = rand(0, 1) ? Constant::VOTE_UP : Constant::VOTE_DOWN;
$voter->applyVote($user, $type, $type_id, $updown);
}
}
}
示例2: placeVote
private function placeVote($sessionId, $memberId, $voteValue)
{
// Fetch entities
$session = $this->getSession($sessionId);
$currentPoll = $session->getCurrentPoll();
$member = $this->getMember($memberId);
// Reject votes if poll is completed
if ($currentPoll != null && $currentPoll->getResult() > 0) {
throw new Exception("Can not vote on completed polls!");
}
// Find or create vote
foreach ($currentPoll->getVotes() as $vote) {
if ($vote->getMember() == $member) {
$match = $vote;
}
}
// Create vote if not found
if (!isset($match)) {
$match = new Vote();
$match->setPoll($currentPoll);
$match->setMember($member);
}
// Set value
$match->setValue($voteValue);
// Evaluate the poll
$this->evaluatePoll($session, $currentPoll);
if ($currentPoll->getResult() > 0) {
$this->highlightVotes($currentPoll);
}
// Save all to db
$this->saveAll([$match, $currentPoll]);
$this->saveAll($currentPoll->getVotes()->toArray());
}
示例3: renderVote
/**
* Callback function for registerParserHook.
*
* @param $input String: user-supplied input, unused
* @param $args Array: user-supplied arguments, unused
* @param $parser Parser: instance of Parser, unused
* @return String: HTML
*/
public static function renderVote($input, $args, $parser)
{
global $wgOut;
wfProfileIn(__METHOD__);
// Disable parser cache (sadly we have to do this, because the caching is
// messing stuff up; we want to show an up-to-date rating instead of old
// or totally wrong rating, i.e. another page's rating...)
$parser->disableCache();
// Add CSS & JS
// In order for us to do this *here* instead of having to do this in
// registerParserHook(), we must've disabled parser cache
$wgOut->addModules('ext.voteNY');
// Define variable - 0 means that we'll get that green voting box by default
$type = 0;
// Determine what kind of a voting gadget the user wants: a box or pretty stars?
if (preg_match("/^\\s*type\\s*=\\s*(.*)/mi", $input, $matches)) {
$type = htmlspecialchars($matches[1]);
} elseif (!empty($args['type'])) {
$type = intval($args['type']);
}
$articleID = $wgOut->getTitle()->getArticleID();
switch ($type) {
case 0:
$vote = new Vote($articleID);
break;
case 1:
$vote = new VoteStars($articleID);
break;
default:
$vote = new Vote($articleID);
}
$output = $vote->display();
wfProfileOut(__METHOD__);
return $output;
}
示例4: placeVote
private function placeVote($sessionId, $memberId, $voteValue)
{
// Fetch entities
$session = $this->getSession($sessionId);
$currentPoll = $session->getCurrentPoll();
$member = $this->getMember($memberId);
// Find or create vote
foreach ($currentPoll->getVotes() as $vote) {
if ($vote->getMember() == $member) {
$match = $vote;
}
}
// Create vote if not found
if (!isset($match)) {
$match = new Vote();
$match->setPoll($currentPoll);
$match->setMember($member);
}
// Set value
$match->setValue($voteValue);
// Evaluate current poll
$this->evaluatePoll($session, $currentPoll);
// Save all to db
$this->saveAll([$match, $currentPoll]);
}
示例5: index
public function index()
{
$id = intval($this->params['id']);
try {
$vote = new Vote($id);
} catch (VoteNullException $e) {
$this->error("未知的投票");
}
$u = User::getInstance();
if ($this->RequestHandler->isPost()) {
$this->requestLogin();
if ($vote->isDeleted()) {
$this->error("此投票已删除");
}
if ($vote->isEnd()) {
$this->error("此投票已截止");
}
if ($vote->getResult($u->userid) !== false) {
$this->error("你已经投过票了");
}
if (!isset($this->params['form']['vote'])) {
$this->error("未知的参数");
}
if ($vote->type == "0") {
$viid = intval($this->params['form']['vote']);
if (!$vote->hasItem($viid)) {
$this->error("未知的选项,投票失败");
}
$vote->vote($u->userid, $viid);
} else {
if ($vote->type == "1") {
$items = array_values((array) $this->params['form']['vote']);
if (count($items) == 0) {
$this->error("请至少选择一个选项");
}
if (count($items) > $vote->limit && $vote->limit != 0) {
$this->error("投票个数超过限制,投票失败");
}
foreach ($items as $v) {
if (!$vote->hasItem(intval($v))) {
$this->error("未知的选项,投票失败");
}
}
$vote->vote($u->userid, $items);
} else {
$this->error("错误的投票");
}
}
}
if ($vote->isDeleted() && !$u->isAdmin()) {
$this->error("此投票已删除");
}
$wrapper = Wrapper::getInstance();
$data['vote'] = $wrapper->vote($vote, array('items' => true));
$this->set('data', $data);
}
示例6: run
public function run()
{
DB::table('votes')->delete();
$vote = new Vote();
$vote->vote = 1;
$quote = Quote::where('title', '=', 'Test Quote')->first();
$user = User::where('username', '=', 'tjbenator')->first();
$vote->user()->associate($user);
$vote->quote()->associate($quote);
$vote->save();
}
示例7: wfVoteDelete
function wfVoteDelete($pageId)
{
global $wgUser;
if (!$wgUser->isAllowed('voteny')) {
return '';
}
if (is_numeric($pageId)) {
$vote = new Vote($pageId);
$vote->delete();
return $vote->count(1);
} else {
return 'error';
}
}
示例8: vote
/**
* @param Vote $v
*/
public static function vote($v)
{
$db = DB::getConn();
$s = $v->getSurvey();
$u = $v->getUid();
$r = $v->getRate();
$c = $v->getComment();
$stm = $db->prepare('insert into Vote (survey, uid, rate, comment) values (:survey, :uid, :rate, :comment)');
$stm->bindParam(':survey', $s);
$stm->bindParam(':uid', $u);
$stm->bindParam(':rate', $r);
$stm->bindParam(':comment', $c);
$stm->execute();
// return DB::getLastID('Vote');
}
示例9: getByPostId
public function getByPostId($post_id, Vote $vote)
{
$comments = Cache::remember(Constant::COMMENT_CACHE_NEWLIST_NAME . $post_id, Constant::COMMENT_CACHE_NEWLIST_MINS, function () use($post_id) {
return DB::table('comments')->join('users', 'comments.user_id', '=', 'users.id')->select('comments.id', 'comments.post_id', 'comments.user_id', 'comments.created_at', 'comments.updated_at', 'comments.deleted_at', 'comments.upvotes', 'comments.downvotes', 'comments.parent_id', 'comments.data', 'comments.markdown', 'users.username', 'users.points', 'users.id AS users_user_id', 'users.votes', 'users.anonymous')->where('post_id', '=', $post_id)->orderBy('id', 'asc')->get();
});
F::each($comments, function ($v) {
if ($v->deleted_at != 0) {
$v->username = "deleted";
$v->data = "<p>user deleted this comment</p>";
$v->markdown = "user deleted this comment";
}
return $v;
});
return $vote->applySelection($comments, $vote->COMMENT_TYPE);
}
示例10: vote_store
public function vote_store($id)
{
$same = Vote::where('user_id', '=', $id)->where('login_id', '=', Auth::User()->id)->get();
//var_dump($same);die;
if (count($same) != 0 and $same) {
return Redirect::back();
} else {
$votes = new Vote();
$data = Input::all();
$data['login_id'] = Auth::User()->id;
$data['user_id'] = $id;
$votes->create($data);
return Redirect::intended('home');
}
}
示例11: isVotedBy
public function isVotedBy(Users $user = null)
{
if (null == $user) {
$user = \Phalcon\Di::getDefault()->get('auth');
}
return Vote::query()->where('voteable_type = :type:', ['type' => get_class($this)])->andWhere('voteable_id = :id:', ['id' => $this->id])->andWhere('user_id = :user:', ['user' => $user->id])->execute()->count() > 0;
}
示例12: run
public function run()
{
DB::table('votes')->delete();
Vote::create(['user_id' => 1, 'entry_id' => 1, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 1, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 1, 'up' => true]);
Vote::create(['user_id' => 1, 'entry_id' => 2, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 2, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 2, 'up' => true]);
Vote::create(['user_id' => 1, 'entry_id' => 3, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 3, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 3, 'up' => true]);
Vote::create(['user_id' => 1, 'entry_id' => 4, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 4, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 4, 'up' => true]);
Vote::create(['user_id' => 1, 'entry_id' => 5, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 5, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 5, 'up' => true]);
Vote::create(['user_id' => 1, 'entry_id' => 6, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 6, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 6, 'up' => true]);
Vote::create(['user_id' => 1, 'entry_id' => 7, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 7, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 7, 'up' => true]);
Vote::create(['user_id' => 1, 'entry_id' => 8, 'up' => true]);
Vote::create(['user_id' => 2, 'entry_id' => 8, 'up' => true]);
Vote::create(['user_id' => 3, 'entry_id' => 8, 'up' => true]);
}
示例13: getNote
public function getNote()
{
$user = Request::get('user_id');
$post = Request::get('post_id');
$vote = Vote::where('user_id', $user)->where('post_id', $post)->first();
return $vote->note;
}
示例14: update_schema
/**
* Create/update schema in database.
*/
public static function update_schema()
{
global $wpdb;
$sql = "\n\n CREATE TABLE " . Track::table_name() . " (\n id int(11) NOT NULL AUTO_INCREMENT,\n stream_title varchar(200) NOT NULL,\n track_key varchar(200) NOT NULL,\n artist varchar(100) NOT NULL,\n title varchar(100) NOT NULL,\n play_count int(11) NOT NULL,\n vote_count int(11) NOT NULL,\n vote_total int(11) DEFAULT NULL,\n vote_average double DEFAULT NULL,\n PRIMARY KEY (id),\n UNIQUE KEY (track_key),\n KEY (vote_average),\n KEY (play_count),\n KEY (vote_count),\n KEY (vote_total)\n ) CHARACTER SET utf8;\n\n CREATE TABLE " . Play::table_name() . " (\n id int(11) NOT NULL AUTO_INCREMENT,\n time_utc datetime NOT NULL,\n track_id int(11) NOT NULL,\n stream_title varchar(200) NOT NULL,\n PRIMARY KEY (id),\n KEY (track_id),\n KEY (time_utc),\n CONSTRAINT " . Play::table_name() . "_ibfk_1 FOREIGN KEY (track_id) REFERENCES " . Track::table_name() . " (id)\n ) CHARACTER SET utf8;\n\n CREATE TABLE " . Vote::table_name() . " (\n id int(11) NOT NULL AUTO_INCREMENT,\n time_utc datetime NOT NULL,\n track_id int(11) NOT NULL,\n stream_title varchar(200) NOT NULL,\n value tinyint(4) NOT NULL,\n nick varchar(30) NOT NULL,\n user_id varchar(150) NOT NULL,\n is_authed bit(1) NOT NULL,\n deleted tinyint(4) NOT NULL DEFAULT '0',\n comment varchar(200) NULL,\n PRIMARY KEY (id),\n KEY (track_id),\n KEY (time_utc),\n KEY (nick),\n CONSTRAINT " . Vote::table_name() . "_ibfk_1 FOREIGN KEY (track_id) REFERENCES " . Track::table_name() . " (id)\n ) CHARACTER SET utf8;\n\n ";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql);
}
示例15: checkVote
public static function checkVote($relatedModule, $relatedId, $uid = 0)
{
$result = false;
$uid = empty($uid) ? Ibos::app()->user->uid : $uid;
$condition = "relatedmodule=:relatedmodule AND relatedid=:relatedid";
$params = array(":relatedmodule" => $relatedModule, ":relatedid" => $relatedId);
$vote = Vote::model()->fetch($condition, $params);
if (!empty($vote)) {
$voteid = $vote["voteid"];
$voteItemList = VoteItem::model()->fetchAll("voteid=:voteid", array(":voteid" => $voteid));
foreach ($voteItemList as $voteItem) {
$itemid = $voteItem["itemid"];
$itemCountList = VoteItemCount::model()->fetchAll("itemid=:itemid", array(":itemid" => $itemid));
if (!empty($itemCountList) && 0 < count($itemCountList)) {
foreach ($itemCountList as $itemCount) {
if ($itemCount["uid"] == $uid) {
$result = true;
break;
}
}
}
}
}
return $result;
}