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


PHP Vote::add方法代码示例

本文整理汇总了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);
 }
开发者ID:rainsun,项目名称:nForum,代码行数:71,代码来源:index_controller.php


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