示例#1
0
switch ($this->owner) {
    case 'active':
        echo '<h1>Active polls</h1>';
        $list = PollItem::getActivePolls(SITE);
        //    d($list);
        foreach ($list as $p) {
            echo ahref('u/polls/show/' . $p->id, $p->text) . '<br/>';
        }
        break;
    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');
示例#2
0
        // owner = item type
        // child = item id
        $type = $this->owner;
        $id = $this->child;
        $header->includeJs('http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js');
        $header->includeCss($page->getRelativeCoreDevUrl() . 'js/ext/gallery-ratings/assets/gallery-ratings-core.css');
        $widget_id = 'rate_' . mt_rand();
        $max_stars = 5;
        $js = 'YUI({' . 'modules:{' . '"gallery-ratings":{' . 'fullpath:"' . relurl($page->getRelativeCoreDevUrl()) . 'js/ext/gallery-ratings/gallery-ratings-min.js",' . 'requires:["base","widget"]' . '}' . '},' . 'filter: "raw"' . '}).use("gallery-ratings", function(Y){' . 'var ratings = new Y.Ratings({' . 'max:' . $max_stars . ',' . 'srcNode: "#' . $widget_id . '"' . '});' . 'Y.log("rator created");' . 'Y.on("ratings:ratingChange",function(e){' . 'Y.log("ww2");' . 'YUI().use("io-base", function(Y){' . 'var uri = "u/rate/vote/' . $type . '/' . $id . '/" + e.newVal;' . 'Y.log(uri);' . '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);' . '});' . '});' . '});';
        $avg = Rating::getAverage($type, $id);
        echo js_embed($js) . '<span id="' . $widget_id . '">' . round($avg, 1) . '</span>';
        break;
    case 'vote':
        // owner = type
        // child = item id
        // child2 = option id
        echo 'WOWOWsls';
        if (!empty($_GET['rate_vote']) && !empty($_GET['opt'])) {
            if (!$session->id || !is_numeric($_GET['opt'])) {
                die('XXX');
            }
            $page->disableDesign();
            Rating::addVote($type, $_GET['rate_vote'], $_GET['opt']);
            ob_clean();
            // XXX hack.. removes previous output
            die('1');
        }
        break;
    default:
        echo 'no such view: ' . $this->view;
}