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


PHP Vote::setValue方法代码示例

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


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

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

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

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

示例4: survey_submit

function survey_submit()
{
    // get global user object
    global $user;
    // protect from unauthorized access
    if (!isset($user) || !isset($_POST['formSurveySubmit'])) {
        logout();
        die;
    }
    // create empty array for $_POST container
    $post = array();
    // escape mysql injections array
    foreach ($_POST as $key => $value) {
        $post[$key] = stripslashes($value);
    }
    $post_keys = array_keys($_POST);
    $substring = 'Answer';
    $pattern = '/' . $substring . '/';
    $survey_keys = preg_grep($pattern, $post_keys);
    foreach ($survey_keys as $key) {
        // get question
        preg_match_all('!\\d+!', $key, $matches);
        $question_id = $matches[0][0];
        $question = new Question();
        $question->get_from_db($question_id);
        //get answer value
        $answer_value = $_POST[$key];
        //get answer id
        $answer_id = $answer_value;
        if (isset($matches[0][1])) {
            $answer_id = $matches[0][1];
        }
        // get current time
        $time_now = date("Y-m-d H:i:s");
        // create vote object
        $vote = new Vote();
        $vote->setIsActive(1);
        $vote->setCreatedOn($time_now);
        $vote->setLastEditedOn($time_now);
        $vote->setUser($user->getId());
        $vote->setSurvey($question->getSurvey());
        $vote->setQuestion($question_id);
        $vote->setAnswer($answer_id);
        $vote->setValue($answer_value);
        $vote->store_in_db();
    }
    // set message cookie
    $cookie_key = 'msg';
    $cookie_value = 'Благодарим Ви за отговорения въпрос!';
    setcookie($cookie_key, $cookie_value, time() + 1);
    header('location:' . ROOT_DIR . '?page=survey');
}
开发者ID:tttodorov13,项目名称:suSurvey,代码行数:52,代码来源:functions.php

示例5: testSetZeroVoteValue

 /**
  * @expectedException InvalidArgumentException
  */
 public function testSetZeroVoteValue()
 {
     $vote = new Vote();
     $vote->setValue(0);
 }
开发者ID:helmer,项目名称:FOSCommentBundle,代码行数:8,代码来源:VoteTest.php


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