当前位置: 首页>>代码示例>>PHP>>正文


PHP Vote::save方法代码示例

本文整理汇总了PHP中Vote::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Vote::save方法的具体用法?PHP Vote::save怎么用?PHP Vote::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vote的用法示例。


在下文中一共展示了Vote::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: toggleVote

 /**
  * 投票
  *  1、如果vote不存在,则创建之
  * 2、如果vote存在,且value相同,则删除之
  * 3、如果vote存在,且value不同,则改变value
  * @param unknown_type $userId
  */
 public function toggleVote($userId, $value)
 {
     $value = $value > 0 ? 1 : 0;
     $owner = $this->getOwner();
     $vote = Vote::model()->findByAttributes(array('voteableEntityId' => $owner->entityId, 'userId' => $userId));
     //判断是否重复点击
     if ($vote && $vote->value == $value) {
         $result = $vote->delete();
         $this->refreshVoteNum();
         return $result;
     }
     //以前还没有点击过?
     if (!$vote) {
         $vote = new Vote();
         $isNew = true;
         $vote->value = $value;
         $vote->addTime = time();
         $vote->voteableEntityId = $owner->entityId;
         $vote->userId = $userId;
     }
     if ($vote->save()) {
         if ($isNew) {
             //触发响应函数
             $this->handleOnAdded(new CEvent($this, array('vote' => $vote)));
         }
         return true;
     }
 }
开发者ID:stan5621,项目名称:jp_edu_online,代码行数:35,代码来源:VoteableBehavior.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $data = Input::all();
     $vote = new Vote();
     $vote->school_no = Session::get('school_no');
     $vote->school_name = Session::get('school_name');
     $vote->vote_title = $data['vote_title'];
     $vote->vote_amount = $data['vote_amount'];
     $vote->start_at = $data['start_at'];
     $vote->end_at = $data['end_at'];
     $vote->vote_goal = $data['vote_goal'];
     $vote->can_select = $data['can_select'];
     $vote->builder_name = Session::get('builder_name');
     $vote->save();
     $arr = ['vote' => $vote, 'flash' => ['type' => 'success', 'msg' => '新增成功!']];
     $vote_new = DB::table('votes')->orderBy('id', 'desc')->get();
     $vote_id = $vote_new[0]->id;
     $vote_data = [$vote_id, $vote->vote_amount];
     Session::put('vote_data', $vote_data);
     Session::put('redo', 1);
     $this->account_create();
     //$this->passsec($vote_id);
     //Session::put('vote_id_insert', $vote_id);
     //return Redirect::route('vote.insert-second');
     return Redirect::route('vote.insert-second', array('vote_id' => $vote_id));
     //Redirect::action('VoteController@passsec', ['id' => $vote_id]);
 }
开发者ID:sandy7772266,项目名称:vote_test6,代码行数:33,代码来源:VoteController.php

示例3: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Vote();
     if (isset($_POST['Vote'])) {
         $model->attributes = $_POST['Vote'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:RSol,项目名称:yupe,代码行数:15,代码来源:DefaultController.php

示例4: 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

示例5: addVoteBy

 /**
  * @param $vote : 这个参数应该是yes或者no,以便能够统一统计
  * @param Users $user
  */
 public function addVoteBy($YesOrNo, Users $user)
 {
     if (!$this->isVotedBy($user)) {
         $vote = new Vote();
         $vote->voteable_type = get_class($this);
         $vote->voteable_id = $this->id;
         $vote->user_id = $user->id;
         $vote->vote = $YesOrNo;
         $vote->save();
     }
     return $this;
 }
开发者ID:huoybb,项目名称:movie,代码行数:16,代码来源:voteableTrait.php

示例6: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Vote();
     $model->imageId = 1;
     $model->fbid = $_SESSION["fbid"];
     $model->created = time();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Vote'])) {
         $model->attributes = $_POST['Vote'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:rjuppa,项目名称:viral_startup,代码行数:20,代码来源:VoteController.php

示例7: actionAddVote

 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', 'Страница не найдена!'));
 }
开发者ID:porem,项目名称:yupe-ext,代码行数:18,代码来源:VoteController.php

示例8: 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

示例9: addVote

 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();
     }
 }
开发者ID:AxelPanda,项目名称:ibos,代码行数:19,代码来源:ICArticleVote.php

示例10: _processVote

 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");
 }
开发者ID:rmcgrew,项目名称:brat_or_not,代码行数:19,代码来源:actions.class.php

示例11: executeVote

 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');
     }
 }
开发者ID:nazab,项目名称:Blog-or-Not,代码行数:43,代码来源:actions.class.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $data = Input::all();
     $vote = new Vote();
     $vote->school_no = Session::get('school_no');
     $vote->school_name = Session::get('school_name');
     $vote->vote_title = $data['vote_title'];
     $vote->vote_amount = $data['vote_amount'];
     $date_now = $this->getDatetimeNow();
     $date_n = new DateTime("now");
     $date_s = new DateTime($data['start_at']);
     $date_e = new DateTime($data['end_at']);
     if ($date_s < $date_n or $date_s > $date_e) {
         //dd($date_now,$data['start_at'] ,$data['end_at'] ) ;
         echo '<script type="text/javascript">';
         echo 'alert("起始時間不可大於結束時間或小於現在時間")';
         echo '</script>';
         return View::make('tasks.vote-insert-first', compact('votes', 'date_now'));
     }
     $temp_date = date("Y-m-d H:i:s", strtotime($data['start_at']));
     $vote->start_at = $temp_date;
     $temp_date = date("Y-m-d H:i:s", strtotime($data['end_at']));
     $vote->end_at = $temp_date;
     //判斷起始時間是否小於結束時間,並且比現在時間大。
     $vote->vote_goal = $data['vote_goal'];
     $vote->can_select = $data['can_select'];
     $vote->public_or_private = $data['public_or_private'];
     $vote->builder_name = Session::get('builder_name');
     $vote->save();
     $vote_new = DB::table('votes')->orderBy('id', 'desc')->get();
     $vote_id = $vote_new[0]->id;
     $vote_data = [$vote_id, $vote->vote_amount];
     Session::put('vote_data', $vote_data);
     Session::put('redo', 1);
     $this->account_create();
     //$this->passsec($vote_id);
     //Session::put('vote_id_insert', $vote_id);
     //return Redirect::route('vote.insert-second');
     return Redirect::route('vote.insert-second', array('vote_id' => $vote_id));
     //Redirect::action('VoteController@passsec', ['id' => $vote_id]);
 }
开发者ID:sandy7772266,项目名称:vote_1031,代码行数:47,代码来源:VoteController.php

示例13: dislikePost

 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);
 }
开发者ID:ChavezRuston,项目名称:fansemo,代码行数:20,代码来源:VoteController.php

示例14: executeVote

 public function executeVote(sfWebRequest $request)
 {
     $liste_id = $request->getParameter('id');
     if ($liste_id != 0) {
         $liste = $this->getRoute()->getObject();
     } else {
         $liste = 0;
     }
     if ($liste_id != 0 && !$liste) {
         $this->getUser()->setFlash('error', 'Cette liste n\'existe pas.');
     } else {
         if ($liste_id != 0 && $liste->getSemestreId() != sfConfig::get('app_portail_current_semestre')) {
             $this->getUser()->setFlash('error', 'Vous ne pouvez pas voter pour cette liste.');
         } else {
             if (!$this->isCotisant()) {
                 $this->getUser()->setFlash('error', 'Vous n\'êtes pas cotisant. Vous ne pouvez pas participer aux élections du BDE.');
             } else {
                 if (VoteTable::getInstance()->getVoteForUserAndSemestre($this->getUser()->getGuardUser()->getPrimaryKey(), sfConfig::get('app_portail_current_semestre'))->fetchOne()) {
                     $this->getUser()->setFlash('error', 'Vous avez déjà voté.');
                 } else {
                     $vote = new Vote();
                     $vote->setIp($_SERVER['REMOTE_ADDR']);
                     $vote->setSemestreId(sfConfig::get('app_portail_current_semestre'));
                     $vote->setUserId($this->getUser()->getGuardUser()->getId());
                     $vote->setLogin($this->getUser()->getGuardUser()->getUsername());
                     $vote->save();
                     if ($liste_id != 0) {
                         $pdo = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
                         $stmt = $pdo->prepare('UPDATE `vote_liste` SET `count`=(`count`+1) WHERE `id` = :id');
                         $stmt->bindParam(':id', $liste->getPrimaryKey(), PDO::PARAM_INT);
                         $stmt->execute();
                     }
                     $this->getUser()->setFlash('success', 'Votre vote a été pris en compte.');
                 }
             }
         }
     }
     $this->redirect('homepage');
 }
开发者ID:TheoJD,项目名称:portail,代码行数:39,代码来源:actions.class.php

示例15: actionRestcreate

 public function actionRestcreate()
 {
     $this->checkRestAuth();
     if (!isset($_GET['dreamId']) || !isset($_POST['subOpenId'])) {
         return $this->sendResponse(400, 'missed required properties');
     }
     $dream = Dream::model()->findByPk($_GET['dreamId']);
     if ($dream == null || $dream->nickname == null) {
         $this->sendResponse(404, 'not found');
     }
     if ($dream->sub_open_id == $_POST['subOpenId']) {
         $this->sendResponse(400, 'forbidden to vote');
     }
     $criteria = new CDbCriteria();
     $criteria->addCondition('dream_id=:dreamId', 'and');
     $criteria->addCondition('sub_open_id=:sub_open_id');
     $criteria->params = array(':sub_open_id' => $_POST['subOpenId'], ':dreamId' => $_GET['dreamId']);
     $results = Vote::model()->findAll($criteria);
     if (count($results) > 0) {
         $this->sendResponse(400, 'voted');
     }
     // create vote
     $vote = new Vote();
     $vote->dream_id = $_GET['dreamId'];
     $vote->sub_open_id = $_POST['subOpenId'];
     $vote->nickname = $_POST['nickname'];
     $vote->headimgurl = $_POST['headimgurl'];
     $vote->bonus = (int) rand(100, 500);
     // 3 - 5元之间随机
     if (!$vote->save()) {
         return $this->sendResponse(500, 'faild to save vote');
     }
     $dream->bonus += $vote->bonus;
     if (!$dream->save()) {
         return $this->sendResponse(500, 'faild to save dream');
     }
     $this->sendResponse(201, $vote->id);
 }
开发者ID:aer123456,项目名称:yougou,代码行数:38,代码来源:VoteController.php


注:本文中的Vote::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。