public function getItem() { if (array_key_exists('PollItem', $this->reference)) { return $this->reference['PollItem']; } require_once "PollItem.php"; $item = new PollItem($this->plugin); $this->reference[$item->getClassName()] = $item; return $item; }
case 'vote': // child = vote id // child2 = option id if (!$session->id || !is_numeric($this->child) || !is_numeric($this->child2)) { throw new \Exception('XXX'); } Rating::addVote(POLL, $this->child, $this->child2); $page->disableDesign(); echo '1'; break; case 'show': //child = poll id if (!$this->child) { throw new \Exception('no id set'); } $poll = PollItem::get($this->child); if (!$poll) { die('meh'); } $header = XhtmlHeader::getInstance(); $header->embedCss('.poll_item{' . 'background-color:#eee;' . 'padding:5px;' . 'cursor:pointer;' . '}'); $header->includeJs('http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js'); $header->embedJs('function submit_poll(id,opt)' . '{' . 'YUI().use("io-base", function(Y) {' . 'var uri = "' . relurl('') . 'u/polls/vote/" + id + "/" + opt;' . 'Y.on("io:complete", function(id,o){' . 'var id = id;' . 'var data = o.responseText;' . 'if (data==1) return;' . 'alert("Voting error " + data);' . '});' . 'var request = Y.io(uri);' . '});' . 'hide_el("poll"+id);' . 'show_el("poll_voted"+id);' . '}'); $active = false; if (time() >= ts($poll->time_start) && time() <= ts($poll->time_end)) { $active = true; } if (!$poll->time_start) { $active = true; } echo '<div class="item">';
function addPoll($p) { if (empty($p['poll_q'])) { return; } if (!empty($p['poll_start_man'])) { $pollId = PollItem::addPollExactPeriod(SITE, 0, $p['poll_q'], $p['poll_start_man'], $p['poll_end_man']); } else { $pollId = PollItem::add(SITE, 0, $p['poll_q'], $p['poll_dur'], $p['poll_start']); } for ($i = 1; $i <= 8; $i++) { if (empty($p['poll_a' . $i])) { continue; } $item = new CategoryItem(POLL); $item->owner = $pollId; $item->title = $p['poll_a' . $i]; $item->store(); } js_redirect('a/polls/list'); }