本文整理汇总了PHP中Vote类的典型用法代码示例。如果您正苦于以下问题:PHP Vote类的具体用法?PHP Vote怎么用?PHP Vote使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vote类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
}
开发者ID:hrenos,项目名称:spreadit,代码行数:31,代码来源:VotesTableSeeder.php
示例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());
}
开发者ID:Toxantron,项目名称:scrumonline,代码行数:33,代码来源:poll-controller.php
示例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;
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:43,代码来源:VoteHooks.php
示例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]);
}
开发者ID:rakesh-mohanta,项目名称:scrumonline,代码行数:25,代码来源:poll-controller.php
示例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);
}
开发者ID:tilitala,项目名称:nForum,代码行数:56,代码来源:vote_controller.php
示例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();
}
开发者ID:shiftosnext,项目名称:Quotinator,代码行数:11,代码来源:VoteTableSeeder.php
示例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';
}
}
开发者ID:Rikuforever,项目名称:wiki,代码行数:14,代码来源:Vote_AjaxFunctions.php
示例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');
}
开发者ID:rmit-s3443163-quan-do,项目名称:its,代码行数:18,代码来源:SurveyCtrl.php
示例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);
}
开发者ID:hrenos,项目名称:spreadit,代码行数:15,代码来源:Comment.php
示例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');
}
}
开发者ID:shihab-92,项目名称:votting-system,代码行数:15,代码来源:vottingController.php
示例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;
}
开发者ID:huoybb,项目名称:movie,代码行数:7,代码来源:voteableTrait.php
示例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]);
}
开发者ID:CreativeMons,项目名称:creative-city,代码行数:28,代码来源:VoteTableSeeder.php
示例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;
}
开发者ID:Reval63,项目名称:projet_photo,代码行数:7,代码来源:VoteController.php
示例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);
}
开发者ID:loonix,项目名称:music-stream-vote,代码行数:10,代码来源:Db.php
示例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;
}
开发者ID:AxelPanda,项目名称:ibos,代码行数:25,代码来源:VoteUtil.php
示例16: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Vote::model()->findByPk((int) $id);
if ($model === null) {
throw new CHttpException(404, Yii::t('VoteModule.vote', 'Запрошенная страница не найдена!'));
}
return $model;
}
开发者ID:porem,项目名称:yupe-ext,代码行数:13,代码来源:DefaultController.php
示例17: handle
/**
* Handle the event.
*
* @param UserDeleted $event
* @return void
*/
public function handle(UserDeleted $event)
{
$user = $event->user;
$activeMotionVotes = Vote::onActiveMotion()->where('user_id', $user->id)->get();
foreach ($activeMotionVotes as $activeMotionVote) {
$activeMotionVote->delete();
}
}
开发者ID:dwoodard,项目名称:IserveU,代码行数:14,代码来源:DeleteActiveVotes.php
示例18: userHasVoted
public function userHasVoted()
{
$vote = Vote::where('user_id', '=', Auth::id())->where('meetup', '=', $this->id)->first();
if ($vote) {
return true;
}
return false;
}
开发者ID:betanotes,项目名称:betanotes.dev,代码行数:8,代码来源:Meetup.php
示例19: thumbsUp
public function thumbsUp($id, $slug)
{
$post = Post::where('id', $id)->where('slug', $slug)->with('user.profile')->firstOrFail();
if (!Vote::setVotePoints($post)) {
return Alert::flash(Lang::get('post.vote'), 'warning');
}
return Redirect::action('post', [$id, $slug]);
}
开发者ID:anthrotech,项目名称:laravel_sample,代码行数:8,代码来源:PostController.php
示例20: vote
public function vote($id)
{
$album = Album::find($id);
if ($album === null) {
$error = 'Can not vote. No such album found.';
return View::make('errors.error', array('errorMsg' => $error));
}
$input = Input::all();
if (1 > $input['vote'] || $input['vote'] > 10) {
$error = 'Invalid vote. Must be between 1 and 10.';
return View::make('errors.error', array('errorMsg' => $error));
}
$vote = new Vote(['value' => $input['vote'], 'album_id' => $album->id, 'voter_id' => Auth::user()->id]);
$album->rank = $album->rank + $vote->value;
$album->save();
$vote->save();
return Redirect::to('/albums/' . $album->id);
}
开发者ID:renankabal,项目名称:image-manager-system,代码行数:18,代码来源:VotesController.php
注:本文中的Vote类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论