Exemplo n.º 1
0
/**
 * stars_content_load_sql 
 * 
 * @param array $pObject 
 * @access public
 * @return SQL - using the following keys:
 *         stars_load         = content_id of the stars item belongs to
 *         stars_rating_count = number of ratings this content has recieved so far
 *         stars_rating       = the actual rating normalised to 100
 *         stars_pixels       = the number of pixels that should be displayed using the cool css method
 *         stars_user_rating  = the rating given by the user who rated is viewing the page
 *         stars_user_pixels  = the number of pixels that should be displayed using the cool css method
 *
 *         all the version related stars keys are the same as the above - but relating to the currently active version as opposed to the overall rating
 */
function stars_content_load_sql(&$pObject)
{
    global $gBitSystem, $gBitUser, $gBitSmarty;
    if (!method_exists($pObject, 'getContentType') || $gBitSystem->isFeatureActive('stars_rate_' . $pObject->getContentType())) {
        if ($gBitSystem->isFeatureActive('stars_use_ajax')) {
            $gBitSmarty->assign('loadAjax', TRUE);
        }
        $stars = $gBitSystem->getConfig('stars_used_in_display', 5);
        $pixels = $stars * $gBitSystem->getConfig('stars_icon_width', 22);
        stars_template_setup($stars);
        $ret['select_sql'] = ",\n\t\t\tlc.`content_id` AS `stars_load`,\n\t\t\tsts.`rating_count` AS stars_rating_count,\n\t\t\tsts.`rating` AS stars_rating,\n\t\t\t( sts.`rating` * {$pixels} / 100 ) AS stars_pixels,\n\t\t\t( sth.`rating` * {$stars} / 100 ) AS stars_user_rating,\n\t\t\t( sth.`rating` * {$pixels} / 100 ) AS stars_user_pixels ";
        $ret['join_sql'] = "\n\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "stars_version` sts ON\n\t\t\t\t( lc.`content_id`=sts.`content_id` AND sts.`version` = 0 )\n\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "stars_history` sth ON\n\t\t\t\t( lc.`content_id`=sth.`content_id` AND lc.`version`=sth.`version` AND sth.`user_id`='" . $gBitUser->mUserId . "' )";
        $ret['select_sql'] .= ",\n\t\t\tlc.`content_id` AS `stars_version_load`,\n\t\t\tv_sts.`rating_count` AS stars_version_rating_count,\n\t\t\tv_sts.`rating` AS stars_version_rating,\n\t\t\t( v_sts.`rating` * {$pixels} / 100 ) AS stars_version_pixels,\n\t\t\t( v_sth.`rating` * {$stars} / 100 ) AS stars_version_user_rating,\n\t\t\t( v_sth.`rating` * {$pixels} / 100 ) AS stars_version_user_pixels ";
        $ret['join_sql'] .= "\n\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "stars_version` v_sts ON\n\t\t\t\t( lc.`content_id`=v_sts.`content_id` AND lc.`version`=v_sts.`version` )\n\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "stars_history` v_sth ON\n\t\t\t\t( lc.`content_id`=v_sth.`content_id` AND lc.`version`=v_sth.`version` AND v_sth.`user_id`='" . $gBitUser->mUserId . "' )";
        if ($gBitSystem->isFeatureActive('stars_auto_hide_content')) {
            // need to take rating_count into the equation as well
            $ret['where_sql'] = " AND( sts.`rating`>? OR sts.`rating` IS NULL OR sts.`rating`=? )";
            $ret['bind_vars'][] = $gBitSystem->getConfig('stars_auto_hide_content');
            $ret['bind_vars'][] = 0;
        }
        return $ret;
    }
}
Exemplo n.º 2
0
<?php

global $gBitSystem, $gBitSmarty, $gBitThemes;
$registerHash = array('package_name' => 'stars', 'package_path' => dirname(__FILE__) . '/', 'service' => LIBERTY_SERVICE_RATING);
$gBitSystem->registerPackage($registerHash);
if ($gBitSystem->isPackageActive('stars')) {
    require_once STARS_PKG_PATH . 'LibertyStars.php';
    // if we are using a text browser theme, make sure not to use ajax
    if ($gBitThemes->getStyle() == 'lynx') {
        $gBitSystem->setConfig('recommends_use_ajax', FALSE);
    }
    // unfortunately we have situations where we can't load stars initiation
    // from the sql service functions due to the way the center modules work.
    stars_template_setup();
    $gLibertySystem->registerService(LIBERTY_SERVICE_RATING, STARS_PKG_NAME, array('content_load_sql_function' => 'stars_content_load_sql', 'content_list_sql_function' => 'stars_content_list_sql', 'content_expunge_function' => 'stars_content_expunge', 'content_body_tpl' => 'bitpackage:stars/stars_inline_service.tpl', 'content_comment_tpl' => 'bitpackage:stars/stars_inline_service.tpl', 'content_list_sort_tpl' => 'bitpackage:stars/stars_list_sort_service.tpl', 'content_list_actions_tpl' => 'bitpackage:stars/stars_list_actions_service.tpl', 'users_expunge_function' => 'contests_user_expunge'));
    // make sure all stars votes are removed
    function stars_user_expunge(&$pObject)
    {
        if (is_a($pObject, 'BitUser') && !empty($pObject->mUserId)) {
            $pObject->mDb->StartTrans();
            $pObject->mDb->query("DELETE FROM `" . BIT_DB_PREFIX . "stars_history` WHERE user_id=?", array($pObject->mUserId));
            $pObject->mDb->CompleteTrans();
        }
    }
}