示例#1
0
/**
 * Returns the HTML and JS code for the ratings widget for $bnum
 *
 * @param object $user Drupal user object
 * @param int $bnum Bib number
 * @param float $rating Rating value override
 * @param boolean $show_label Displays the vote count
 * @param boolean $post_redirect Redirect the page back on itself after form submit.  Useful for lists.
 * @return string HTML/JS widget
 */
function theme_sopac_get_rating_stars($bnum, $rating = NULL, $show_label = TRUE, $post_redirect = FALSE, $id = 'default')
{
    global $user;
    // Load Required JS libraries
    drupal_add_js(drupal_get_path('module', 'sopac') . '/js/jquery.rating.js');
    $insurge = sopac_get_insurge();
    $rate_options = array('0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0');
    if ($_POST[$id . '_rating_submit_' . $bnum] && $user->uid) {
        $insurge = sopac_get_insurge();
        $insurge->submit_rating($user->uid, $bnum, $_POST[$id . '_bib_rating_' . $bnum]);
        // Summer Game
        if (module_exists('summergame')) {
            if (variable_get('summergame_points_enabled', 0)) {
                if ($player = summergame_player_load(array('uid' => $user->uid))) {
                    // Check that player has not already rated this item
                    $res = db_query("SELECT lid FROM sg_ledger WHERE pid = %d AND type = 'Rated an Item' " . "AND metadata LIKE '%%bnum:%d' LIMIT 1", $player['pid'], $bnum);
                    $rate_count = db_fetch_object($res);
                    if (!$rate_count->lid) {
                        $points = 10;
                        // Check if the item is in their checkout history
                        $ch_list = db_fetch_object(db_query("SELECT * FROM sopac_lists WHERE uid = %d and title = 'Checkout History'", $user->uid));
                        if ($ch_list->list_id) {
                            $ch_items = $insurge->get_list_items($ch_list->list_id);
                            foreach ($ch_items as $ch_item) {
                                if ($ch_item['bnum'] == $bnum) {
                                    $points = 50;
                                    $extra_message = ' from your ' . l('Checkout History', 'user/lists/' . $ch_list->list_id);
                                    break;
                                }
                            }
                        }
                        $points = summergame_player_points($player['pid'], $points, 'Rated an Item', 'Added a Rating to the Catalog', 'bnum:' . $bnum);
                        $points_link = l($points . ' Summer Game points', 'summergame/player');
                        drupal_set_message("Earned {$points_link} for rating an item in the catalog" . $extra_message);
                    }
                }
            }
        }
        if ($post_redirect) {
            header('Location: ' . request_uri());
        }
    }
    if (!$user->uid) {
        $disable_flag = ' disabled="disabled" ';
        $login_string = ' - ' . l(t('Login'), 'user/login', array('query' => drupal_get_destination())) . t(' to add yours');
    }
    $ratings_info_arr = $insurge->get_rating($bnum);
    if ($rating) {
        $ratings_info_arr['value'] = $rating;
    }
    $star_code = '
  <script>
  $(function(){
    $(\'.hover-star\').rating({
      callback: function(value, link) {
        this.form.submit();
      },
      required: true,
      half: true
    });
  });
  </script>
  <form method="post" name="form_' . $bnum . '">
  <table><tr><td width="90px">';
    foreach ($rate_options as $val) {
        $checked_flag = '';
        if ((double) $val == (double) $ratings_info_arr['value']) {
            $checked_flag = ' checked="checked"';
        }
        $star_code .= '<input class="hover-star {split:2}" type="radio" name="' . $id . '_bib_rating_' . $bnum . '" value="' . $val . '"' . $disable_flag . $checked_flag . "/>\n";
    }
    $star_code .= '<input type="hidden" name="' . $id . '_rating_submit_' . $bnum . '" value="1"></form></td><td>';
    if ($show_label) {
        if (!$ratings_info_arr['count']) {
            $count_msg = t('No ratings yet');
        } elseif ($ratings_info_arr['count'] == 1) {
            $count_msg = '1 rating';
        } else {
            $count_msg = $ratings_info_arr['count'] . t(' ratings');
        }
        $count_msg .= $login_string;
        $star_code .= '<span id="star_vote_count">(' . $count_msg . ')</span>';
    }
    $star_code .= '</td></tr></table>';
    return $star_code;
}
示例#2
0
文件: sopac_user.php 项目: aadl/sopac
function sopac_update_history($list)
{
    $account = user_load($list['uid']);
    $locum = sopac_get_locum();
    $insurge = sopac_get_insurge();
    $userinfo = $locum->get_patron_info($account->profile_pref_cardnum);
    $total = 0;
    db_set_active('iiipfile');
    $res = db_query("SELECT * FROM circhistory WHERE patronNum = %d ORDER BY checkout DESC", $userinfo['pnum']);
    db_set_active('default');
    // Summer Game
    if (module_exists('summergame')) {
        if (variable_get('summergame_points_enabled', 0)) {
            $player = summergame_player_load(array('uid' => $list['uid']));
        }
    }
    while ($checkout = db_fetch_array($res)) {
        $checkoutTimestamp = strtotime($checkout['checkOut']);
        if ($insurge->add_list_item($account->uid, $list['list_id'], $checkout['bibNum'], $checkoutTimestamp)) {
            $total++;
            // Summer Game
            $checkoutLimit = strtotime('2013-06-13 23:59:59');
            if ($player && $checkoutTimestamp > $checkoutLimit) {
                // after June 14, 2013 12:00:00 AM
                $metadata = array('bnum' => $checkout['bibNum']);
                $points = summergame_player_points($player['pid'], 50, 'Checkout History', 'Item added from Checkout History', $metadata);
                $points_link = l($points . ' Summer Game points', 'summergame/player');
                drupal_set_message("Earned {$points_link} for a new checkout");
            }
        }
    }
    if ($total) {
        // remove rows from the iiipfile table
        db_set_active('iiipfile');
        db_query("DELETE FROM circhistory WHERE patronNum = %d", $userinfo['pnum']);
        db_set_active('default');
        drupal_set_message("Updated Checkout History with {$total} new checkouts");
    }
}