本文整理匯總了PHP中Vote::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP Vote::add方法的具體用法?PHP Vote::add怎麽用?PHP Vote::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Vote
的用法示例。
在下文中一共展示了Vote::add方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ajax_add
public function ajax_add()
{
if (!$this->RequestHandler->isPost()) {
$this->error(ECode::$SYS_REQUESTERROR);
}
$this->requestLogin();
$db = DB::getInstance();
$u = User::getInstance();
if (!$u->isAdmin()) {
$sql = "select count(*) as num from pl_vote where status=1 and start>=? and uid=?";
$res = $db->one($sql, array(strtotime(date("Y-m-d", time())), $u->userid));
if ($res !== false && $res['num'] >= 2) {
$this->error("每天你最多開啟兩次投票");
}
}
$subject = @trim($this->params['form']['subject']);
$desc = @trim($this->params['form']['desc']);
$end = @trim($this->params['form']['end']);
$type = @trim($this->params['form']['type']);
$limit = @trim($this->params['form']['limit']);
$result_voted = isset($this->params['form']['result_voted']) ? 1 : 0;
if (empty($subject) || empty($end)) {
$this->error();
}
if ($type != "0" && $type != "1") {
$type = 0;
}
if (empty($limit) || intval($limit) < 2 || intval($limit) > 19) {
$limit = 0;
}
if (strtotime($end) === false || !preg_match("/\\d{4}(-\\d{2}){2}/", $end)) {
$this->error("截止日期錯誤");
}
$items = array();
foreach ($this->params['form'] as $k => $v) {
if (preg_match('/^i\\d+$/', $k) && trim($v) != "") {
$items[] = nforum_iconv('UTF-8', $this->encoding, trim($v));
}
}
$realNum = count($items);
if ($realNum < 2 || $realNum > 20) {
$this->error("選項數量錯誤,發起投票失敗");
}
if ($limit > $realNum) {
$limit = $realNum;
}
$subject = nforum_iconv('UTF-8', $this->encoding, $subject);
$desc = nforum_iconv('UTF-8', $this->encoding, $desc);
$vid = Vote::add($u->userid, $subject, $desc, strtotime($end), $type, $limit, $items, $result_voted);
$site = Configure::read("site");
$a_title = $subject;
$a_content = "主題:{$subject}\n描述:{$desc}\n發起人:{$u->userid}\n類型:" . ($type == 0 ? '單選' : '多選') . "\n截止日期:{$end}\n鏈接:[url={$site['domain']}{$site['prefix']}/vote/view/{$vid}]{$site['domain']}{$site['prefix']}/vote/view/{$vid}[/url]\n[vote={$vid}][/vote]";
App::import("vendor", "model/article");
$aid = Article::autoPost($this->_board, $a_title, $a_content);
$db->update("pl_vote", array("aid" => $aid), "where vid=?", array($vid));
if (isset($this->params['form']['b'])) {
App::import("vendor", "model/board");
try {
$board = Board::getInstance(trim($this->params['form']['b']));
if ($board->hasPostPerm($u)) {
Article::autoPost($board->NAME, '[投票]' . $a_title, $a_content);
}
} catch (Exception $e) {
}
}
$ret['ajax_code'] = "發起投票成功";
$ret['default'] = "/vote?c=list&u=" . $u->userid;
$ret['list'][] = array("text" => '我的投票', "url" => "/vote?c=list&u=" . $u->userid);
$ret['list'][] = array("text" => '熱門投票', "url" => "/vote?c=hot");
$this->set('no_html_data', $ret);
}