/** * 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); } } }
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()); }
/** * 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; }
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]); }
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); }
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(); }
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'; } }
/** * @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'); }
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 = "******"; $v->data = "<p>user deleted this comment</p>"; $v->markdown = "user deleted this comment"; } return $v; }); return $vote->applySelection($comments, $vote->COMMENT_TYPE); }
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'); } }
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; }
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]); }
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; }
/** * Get printable message for this activity * * @return string */ public function getMessage() { if ($this->type == self::ACTIVITY_SERIES_ADD) { return 'New series "' . $this->object->getTitle() . '" added'; } else { if ($this->type == self::ACTIVITY_VOTE_UP) { return 'Line #' . $this->object->getLine()->getId() . ' voted up'; } else { if ($this->type == self::ACTIVITY_VOTE_DOWN) { return 'Line #' . $this->object->getLine()->getId() . ' voted down'; } else { if ($this->type == self::ACTIVITY_SUGGEST_SERIES) { return 'New series suggested'; } else { if ($this->type == self::ACTIVITY_SUGGEST_SCRIPT) { return 'New script submitted'; } else { if ($this->type == self::ACTIVITY_FLAG) { return 'Line #' . $this->object->getLine()->getId() . ' flagged as bad'; } } } } } } return 'Well, something happened'; }
/** * 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); }
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; }
/** * 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; }
/** * 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(); } }
public function userHasVoted() { $vote = Vote::where('user_id', '=', Auth::id())->where('meetup', '=', $this->id)->first(); if ($vote) { return true; } return false; }
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]); }
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); }
public function actionAddVote() { if (Yii::app()->request->isPostRequest && Yii::app()->request->isAjaxRequest) { $modelType = Yii::app()->request->getPost('modelType'); $model_id = (int) Yii::app()->request->getPost('model_id'); $value = (int) Yii::app()->request->getPost('value'); if (!$model_id || !$value || !$modelType) { Yii::app()->ajax->failure(Yii::t('VoteModule.vote', 'Произошла ошибка!')); } $model = new Vote(); $model->setAttributes(array('model' => $modelType, 'model_id' => $model_id, 'value' => $value)); if ($model->save()) { Yii::app()->ajax->success(); } Yii::app()->ajax->failure(Yii::t('VoteModule.vote', 'Произошла ошибка!')); } throw new CHttpException(404, Yii::t('VoteModule.vote', 'Страница не найдена!')); }
public function addVote($voteData, $voteItemList) { $vote = new Vote(); foreach ($vote->attributes as $field => $value) { if (isset($voteData[$field])) { $vote->{$field} = $voteData[$field]; } } $vote->save(); $voteid = Yii::app()->db->getLastInsertID(); for ($i = 0; $i < count($voteItemList); $i++) { $voteItem = new VoteItem(); $voteItem->voteid = $voteid; $voteItem->content = $voteItemList[$i]; $voteItem->number = 0; $voteItem->type = $voteData["voteItemType"]; $voteItem->save(); } }
public function executeVote(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post')); $user = $this->getUser(); $blog_id = $user->getAttribute('blog_id'); $vote_form = new VoteForm(); $bind_value = array('blog_id' => $blog_id, 'value' => $request->getParameter('vote')); $vote_form->bind($bind_value); if ($vote_form->isValid()) { $vote = new Vote(); $vote->setBlog_id($vote_form->getValue('blog_id')); $vote->setValue($vote_form->getValue('value')); $vote->save(); // Update vote_SUM Doctrine_Query::create()->update('Blog b')->set('b.vote_sum', 'b.vote_sum + ' . $vote_form->getValue('value'))->where('b.id = ?', $vote_form->getValue('blog_id'))->execute(); // Update vote_COUNT Doctrine_Query::create()->update('Blog b')->set('b.vote_count', 'b.vote_count + 1')->where('b.id = ?', $vote_form->getValue('blog_id'))->execute(); if (sfConfig::get('sf_exclusion_list')) { // Exclusion list! $session_list = $user->getAttribute('already_voted_list'); if (is_array($session_list) && count($session_list) > 0) { } else { //No data in the array $session_list = array(); } $session_list[] = $vote_form->getValue('blog_id'); $user->setAttribute('already_voted_list', $session_list); } // Check if the vote history is empty it it is initiate an empty list $vote_history = $user->getAttribute('vote_history'); if (is_array($vote_history) && count($vote_history) > 0) { } else { $vote_history = array(); } // Add the just rated blog to the vote_history $voted_blog = Doctrine::getTable('Blog')->find($vote_form->getValue('blog_id')); $vote_avg = $voted_blog->getVote_sum() / $voted_blog->getVote_count(); $vote_info = array('my_vote' => $vote_form->getValue('value'), 'vote_avg' => $vote_avg, 'vote_count' => $voted_blog->getVote_count(), 'vote_sum' => $voted_blog->getVote_sum(), 'blog_url' => $voted_blog->getUrl(), 'blog_thmbnail' => $voted_blog->getThumbnail_url()); array_unshift($vote_history, $vote_info); $user->setAttribute('vote_history', $vote_history); $this->redirect('blog/index'); } }
protected function _processVote($request) { if ($request->hasParameter("brat") && $request->hasParameter("post")) { $post = Doctrine::getTable('Post')->find($request->getParameter("post")); $vote = new Vote(); $vote->Post = $post; if (strtolower($request->getParameter("brat")) == "yes") { $vote->is_brat = true; } else { if (strtolower($request->getParameter("brat")) == "no") { $vote->is_brat = false; } } if ($vote->is_brat !== null) { $vote->save(); } } $this->redirect("vote/index"); }
function RenderVote($input) { global $wgUser, $wgTitle, $wgOut; $wgOut->addScript("<script type=\"text/javascript\" src=\"extensions/Vote-Mag/Vote.js\"></script>\n"); require_once 'VoteClass.php'; getValue($type, $input, "type"); switch ($type) { case 0: $Vote = new Vote($wgTitle->mArticleID); break; case 1: $Vote = new VoteStars($wgTitle->mArticleID); break; default: $Vote = new Vote($wgTitle->mArticleID); } $Vote->setUser($wgUser->mName, $wgUser->mId); $output = $Vote->display(); return $output; }
public function dislikePost() { $id = Input::get('id'); $dislikeVote = Vote::where('type', 'dislike')->where('user_id', Auth::id())->where('post_id', $id)->first(); if (!$dislikeVote) { $oppositeVote = Vote::where('type', 'like')->where('user_id', Auth::id())->where('post_id', $id)->first(); if (!empty($oppositeVote)) { $oppositeVote->delete(); } $vote = new Vote(); $vote->user_id = Auth::id(); $vote->post_id = $id; $vote->type = 'dislike'; $vote->save(); } $totalLikeVote = Vote::where('type', 'like')->where('post_id', $id)->count(); $totalDislikeVote = Vote::where('type', 'dislike')->where('post_id', $id)->count(); $result = array($totalLikeVote, $totalDislikeVote); return Response::json($result); }
function insert_vote($user = 0, $value = 10) { if (parent::insert_vote($user, $value)) { $vote = new Vote(); $vote->type = 'links'; $vote->link = $this->id; if (Voting_Method == 2) { $this->votes = $vote->rating("!=0"); $this->votecount = $vote->count("!=0"); $this->reports = $this->count_all_votes("<0"); } else { $this->reports = $this->count_all_votes("<0"); $this->votes = $vote->count() - $this->reports; } $this->store_basic(); $this->check_should_publish(); $vars = array('vote' => $this); check_actions('link_insert_vote_post', $vars); return true; } return false; }
public function voteCount($id, $type) { $voteCount = 0; $votes = Vote::findAll()->where('voteable_id', '=', $id)->where('votable_type', "=", $type); foreach ($votes as $vote) { if ($vote == 0) { $voteCount -= 1; } else { $voteCount += 1; } return $voteCount; } }
/** * 关注或取消赞成 * @param unknown_type $id */ public function run($id, $value) { $model = $this->controller->loadModel($id, $value); $model->toggleVote(Yii::app()->user->id, $value); $vote = Vote::model()->findByAttributes(array('voteableEntityId' => $model->entityId, 'userId' => Yii::app()->user->id)); if (isset($vote) && $vote) { if ($vote->userId != $model->userId) { $result = Notice::send($model->userId, $model->entity->type . "_vote_added", array('voteId' => $vote->id)); } } //feed // Feed::send("vote_added", array('voteid'=>$vote->id)); $this->controller->renderPartial('//vote/result', array('score' => $model->voteUpNum, 'voteUpers' => $model->getVoteUperDataProvider()->getData())); }