本文整理汇总了PHP中Vote::hasItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Vote::hasItem方法的具体用法?PHP Vote::hasItem怎么用?PHP Vote::hasItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vote
的用法示例。
在下文中一共展示了Vote::hasItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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("错误的投票");
}
}
}