예제 #1
0
파일: sopac_social.php 프로젝트: aadl/sopac
/**
 * 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_admin.php 프로젝트: aadl/sopac
function sopac_admin_moderate_delete_confirm_submit($form, &$form_state)
{
    $insurge = sopac_get_insurge();
    if ($reviews = $form_state['values']['reviews']) {
        foreach ($reviews as $review) {
            if (module_exists('summergame')) {
                if ($player = summergame_player_load(array('uid' => $review['uid']))) {
                    // Delete the points from the player record if found
                    db_query("DELETE FROM sg_ledger WHERE pid = %d AND type = 'Wrote Review' " . "AND metadata LIKE '%%bnum:%d%%'", $player['pid'], $review['bnum']);
                    if (db_affected_rows()) {
                        $player_link = l($points . ' Summer Game score card', 'summergame/player/' . $player['pid']);
                        drupal_set_message("Removed points for this review from player's {$player_link}");
                    }
                }
            }
            $insurge->delete_review($review['uid'], $review['rev_id']);
        }
        drupal_goto('admin/settings/sopac/moderate/reviews');
    } else {
        if ($tags = $form_state['values']['tags']) {
            if (module_exists('summergame')) {
                foreach ($tags as $tag) {
                    if ($player = summergame_player_load(array('uid' => $tag['uid']))) {
                        // Delete the points from the player record if found
                        db_query("DELETE FROM sg_ledger WHERE pid = %d AND type = 'Tagged an Item' " . "AND metadata LIKE '%%bnum:%d%%'", $player['pid'], $tag['bnum']);
                        if (db_affected_rows()) {
                            $player_link = l($points . ' Summer Game score card', 'summergame/player/' . $player['pid']);
                            drupal_set_message("Removed points for this tag from player's {$player_link}");
                        }
                    }
                    $insurge->delete_user_tag($tag['uid'], $tag['tag'], $tag['bnum']);
                }
            }
            drupal_goto('admin/settings/sopac/moderate/tags');
        }
    }
}
예제 #3
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");
    }
}
예제 #4
0
        } else {
            print sopac_put_request_link($item['_id'], 1, 0, $locum_config['formats'][$item['mat_code']]);
            if (user_access('staff request') && $item['bnum']) {
                print sopac_put_staff_request_link($item['bnum']);
            }
        }
    }
}
if ($user->uid && $item['bnum']) {
    include_once 'sopac_user.php';
    print sopac_put_list_links($item['bnum']);
}
// Summer Game links
if (module_exists('summergame')) {
    if (variable_get('summergame_points_enabled', 0)) {
        if ($player = summergame_player_load(array('uid' => $user->uid))) {
            print '<li class="button">' . l('I Finished This', 'http://play.aadl.org/summergame/player/consume/' . $player['pid'] . '/' . $item['bnum']) . '</li>';
        }
    }
}
?>
    </ul>

    <!-- Item Title -->
    <h1>
      <?php 
print title_case($item['title']);
if ($item['title_medium']) {
    print ' ' . title_case($item[title_medium]);
}
?>