Esempio n. 1
0
//XXX: make it read-only after you clicked it once
namespace cd;

switch ($this->view) {
    case 'handle':
        // handle user rating
        // 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
Esempio n. 2
0
?>
</textarea>
            </div>
            </form>
    <? } ?>

<h3><?php 
echo Text::getText("AllRatings");
?>
</h3>

<?php 
echo Text::getText("Average");
?>
: <?php 
echo Rating::getAverage($r);
?>
/5

<ul>
<?
$ratings = Rating::getForRecipe($r, 'value DESC');
foreach ($ratings as $rating) {
  $user_rating = $rating->getUser();
  ?>
  <li><a href="<?php 
echo $user_rating->href();
?>
"><?php 
echo $user_rating->getFullName();
?>