本文整理汇总了PHP中Vote::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Vote::create方法的具体用法?PHP Vote::create怎么用?PHP Vote::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vote
的用法示例。
在下文中一共展示了Vote::create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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]);
}
示例2: 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');
}
}
示例3: action_vote
public static function action_vote($id = null)
{
if (!$id) {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
return Response::error(404);
} else {
$id = (int) Param::post('id');
$answers = Param::post('answers');
$poll = Poll::get($id);
$poll->various_answers = '0' != $poll->various_answers;
$cookiename = 'p_' . $poll->id . '_v';
// Si no hay respuestas o hay más de una respuesta
if (count($answers) === 0 || !$poll->various_answers && count($answers) > 1) {
Redirect::to(Url::get('vote', $id, 'vote_error=true'));
}
if (Vote::where('voter_ip', '=', CURRENT_USER_IP)->and_where('poll_id', '=', $id)->first() || Cookie::get($cookiename)) {
Cookie::set($cookiename, !$poll->various_answers ? (string) $answers[0] : 'true', 360);
Redirect::to(Url::get('view', $poll->slug, 'poll_already_voted=true'));
}
Cookie::set($cookiename, !$poll->various_answers ? (string) $answers[0] : 'true', 360);
Vote::create(array('voter_ip' => CURRENT_USER_IP, 'poll_id' => $id, 'answer_id' => !$poll->various_answers ? $answers[0] : 0));
foreach ($answers as $answer_id) {
Answer::find($answer_id)->set(array('nofilter:votes' => '`votes` + 1'));
}
Poll::find($id)->set(array('nofilter:total_votes' => '`total_votes` + 1'));
Redirect::to(Url::get('view', $poll->slug, 'voted=true'));
}
} elseif (!is_numeric($id)) {
return Response::error(404);
}
$id = intval($id, 10);
if (!($poll = Poll::get($id))) {
return Response::error(404);
}
$answers = Answer::where('poll_id', '=', $poll->id)->get();
return View::make('vote')->add_var('poll', $poll)->add_var('answers', $answers);
}
示例4: vote_down
private function vote_down($id, $obj)
{
if (Auth::check()) {
$user_id = Auth::user()->id;
$vote = Vote::where('user_id', $user_id)->where('obj_id', $id)->where('obj', $obj)->first();
if ($vote) {
if ($vote->vote == -1) {
return;
}
$vote->vote = -1;
$vote->save();
} else {
Vote::create(['vote' => -1, 'obj_id' => $id, 'user_id' => $user_id, 'obj' => $obj]);
}
$obj = $obj::find($id);
$obj->vote_down -= 1;
$obj->save();
$arr = [];
$arr['vote_up'] = $obj->vote_up;
$arr['vote_down'] = $obj->vote_down;
return $arr;
}
}
示例5: elseif
$votePoints = (int) $_GET['points'];
if (empty($videoID)) {
die;
}
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$ip = md5($ip);
$dbh = new Database();
$sth = $dbh->prepare("SELECT * FROM " . DB_PREFIX . "votes WHERE video = ? AND ip = ?");
$sth->execute(array($videoID, $ip));
$result = $sth->fetchObject();
$vote = new Vote();
$vote->ip = $ip;
$vote->video = $videoID;
$vote->vote = $votePoints;
if (empty($result)) {
if ($votePoints == 1 || $votePoints == -1) {
$vote->create();
}
} else {
if ($votePoints == 1 || $votePoints == -1) {
$vote->save();
} elseif ($votePoints == 0) {
$vote->delete();
}
}
示例6: post
/**
* Vote to a survey
*
* Request body must be an object with properties :
* * survey_id : identifier of the survey the vote is to be added to
* * answers : array of objects with properties
* * key : choice key
* * value : answer value for choice
*
* @return array
*
* @throws RestBadParameterException
* @throws RestMissingParameterException
* @throws NotFoundException
* @throws RestNotAllowedException
*/
public static function post()
{
// Get creation data
$data = RestServer::getRequest()->input;
if (!is_object($data)) {
throw new RestBadParameterException('vote');
}
// Get related survey
if (!property_exists($data, 'survey_id')) {
throw new RestMissingParameterException('vote.survey_id');
}
$survey = Survey::fromId($data->survey_id);
// Check permissions
if (!$survey->can->vote) {
throw new RestNotAllowedException('add vote to survey ' . $survey->id);
}
// Check if vote did not exists already
foreach ($survey->votes as $vote) {
if ($vote->author->is(Auth::user())) {
throw new RestVoteAlreadyExistsException($survey);
}
}
// Check if there is answers
if (!property_exists($data, 'answers')) {
throw new RestMissingParameterException('vote.answers');
}
if (!is_array($data->answers)) {
throw new RestBadParameterException('vote.answers');
}
// Create the vote and add answers
$vote = Vote::create($survey);
foreach ($data->answers as $answer) {
if (!is_object($answer)) {
throw new RestBadParameterException('vote.answers[]');
}
if (!property_exists($answer, 'key')) {
throw new RestMissingParameterException('vote.answers[].key');
}
if (!property_exists($answer, 'value')) {
throw new RestMissingParameterException('vote.answers[].value');
}
$vote->addAnswer($answer->key, $answer->value);
// throws if anything wrong
}
$vote->save();
return array('path' => '/vote/' . $vote->id, 'data' => self::cast($vote));
}