當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Vote::vote方法代碼示例

本文整理匯總了PHP中Vote::vote方法的典型用法代碼示例。如果您正苦於以下問題:PHP Vote::vote方法的具體用法?PHP Vote::vote怎麽用?PHP Vote::vote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Vote的用法示例。


在下文中一共展示了Vote::vote方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

示例2: Vote

}
</style>
</head>
<body>
<?php 
include 'vote.php';
$vote = new Vote();
$action = '';
//get action
if (isset($_REQUEST['action'])) {
    $action = $_REQUEST['action'];
}
//vote and show results
if ('vote' == $action) {
    //vote
    $vote->vote($_REQUEST['id']);
    //show results
    $total = $vote->getTotal();
    echo '<ul>';
    foreach ($vote->showResults() as $vote) {
        $percent = 0;
        if (isset($vote['number']) && !empty($vote['number'])) {
            $percent = $vote['number'] / $total * 100;
        }
        echo '<li class="result">';
        echo '<span class="bar" style="width:' . $percent . '%;">&nbsp;</span>';
        echo '<span class="label">' . $vote['name'] . '&nbsp;(<strong>' . $percent . '%</strong>)</span>';
        echo '</li>';
    }
    echo '</ul>';
    //show options
開發者ID:neevan1e,項目名稱:Done,代碼行數:31,代碼來源:index.php

示例3: ajax_vote

 public function ajax_vote()
 {
     if (!$this->RequestHandler->isPost()) {
         $this->error(ECode::$SYS_REQUESTERROR);
     }
     $this->requestLogin();
     if (!isset($this->params['vid'])) {
         $this->error("未知的投票");
     }
     $vid = intval($this->params['vid']);
     try {
         $vote = new Vote($vid);
     } catch (VoteNullException $e) {
         $this->error("未知的投票");
     }
     $u = User::getInstance();
     if ($vote->isDeleted() && !$u->isAdmin()) {
         $this->error("此投票已刪除");
     }
     $myres = $vote->getResult($u->userid);
     if ($myres !== false) {
         $this->error("你已經投過票了");
     }
     if ($vote->isDeleted()) {
         $this->error("此投票已刪除");
     }
     if ($vote->isEnd()) {
         $this->error("此投票已截止");
     }
     if ($vote->type == "0") {
         @($viid = $this->params['form']['v' . $vote->vid]);
         if (!$vote->hasItem($viid)) {
             $this->error("未知的選項,投票失敗");
         }
         $vote->vote($u->userid, $viid);
     } else {
         if ($vote->type == "1") {
             $items = array_keys($this->params['form']);
             if (count($items) > $vote->limit && $vote->limit != 0) {
                 $this->error("投票個數超過限製,投票失敗");
             }
             $items = preg_replace("/v{$vote->vid}_/", "", $items);
             foreach ($items as $v) {
                 if (!$vote->hasItem($v)) {
                     $this->error("未知的選項,投票失敗");
                 }
             }
             $vote->vote($u->userid, $items);
         } else {
             $this->error("錯誤的投票");
         }
     }
 }
開發者ID:rainsun,項目名稱:nForum,代碼行數:53,代碼來源:index_controller.php

示例4: Exception

require_once '../class/nl-auth-class.php';
require_once '../class/nl-vote-class.php';
require_once 'api_headers.php';
try {
    if (is_get()) {
        if (0 >= ($newsID = _get("newsID", 0))) {
            throw new Exception("could not find news by ID", -1);
        }
        $voteObj = new Vote($newsID);
        echo $voteObj->getJson();
    } else {
        if (is_post()) {
            if (0 >= ($newsID = _get("newsID", 0))) {
                throw new Exception("could not find news by ID", -1);
            }
            $voteType = _post("voteType", null);
            if ($voteType != "agree" && $voteType != "disagree") {
                throw new Exception("unknown vote type " . $voteType, -1);
            }
            $auth = Auth::getInstance();
            if (!$auth->canVote()) {
                throw new Exception("current user cannot vote", -1);
            }
            $voteObj = new Vote($newsID);
            echo $voteObj->vote($voteType, $auth->getUserID())->getJson();
        }
    }
} catch (Exception $e) {
    $result = array("errCode" => $e->getCode(), "errMessage" => $e->getMessage());
    echo json_encode($result);
}
開發者ID:cntjmj,項目名稱:newslogue,代碼行數:31,代碼來源:vote.php


注:本文中的Vote::vote方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。