PDA

Zobacz pełną wersję : VOTE / RATE / jak wydobyć z bazy danych ocene danego przedmiotu ??



stickoman
19-07-2008, 00:18
witam

mam zainstalowana Joomle 1.0.8 oraz system oceniania ajaxvote, mam rowniez modul mod_highestrated, ktory wyswietla na frontpage 5 najlepiej ocenionych przedmiotow z mojego serwisu.


moje pytanie brzmi : skoro ten modul potrafi wyciagnac ocene kazdej rzeczy (ajaxvote bazuje na mosvote tzn ocena zapisuje sie w tym samym miejscu w bazie danych mozna zamiennie stosowac sprawdzalem)

to jak napisac skypt ktory wyciagnie mi ta ocene. Nie znam sie na php, prosze ludzi madrzejszych ;) zaby napisali mi jakis prosty kod dzieki ktoremu wyciagne te informacje z bazy danych.


tutaj zamieszczam kod modulu mod_highestrated moze ktos to zrozumie i z tego wyciagnie co trzeba. mnie sie nie udalo.




<?php
/**
* @version $Id: mod_highestrated v1.0
* @Coded by pe7er / db8.nl, 6 March 2007
* @This module shows the highest rated content of your site.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

global $mosConfig_offset, $mosConfig_live_site;

$type = intval( $params->get( 'type', 0 ) );
$count = intval( $params->get( 'count', 5 ) );
$catid = trim( $params->get( 'catid' ) );
$secid = trim( $params->get( 'secid' ) );
//$show_front = $params->get( 'show_front', 1 );

$now = _CURRENT_SERVER_TIME;
$access = !$mainframe->getCfg( 'shownoauth' );
$nullDate = $database->getNullDate();
// select between Content Items, Static Content or both
//Content Items only
$query = "SELECT a.id, a.title, a.sectionid, a.catid,"
. "\n #__content_rating.rating_sum AS sum, #__content_rating.rating_count AS count,"
. "\n (#__content_rating.rating_sum / #__content_rating.rating_count) AS rating"
. "\n FROM #__content AS a"
. "\n LEFT JOIN #__content_rating ON #__content_rating.content_id = a.id"
. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
. "\n INNER JOIN #__sections AS s ON s.id = a.sectionid"
. "\n WHERE ( a.state = 1 AND a.sectionid > 0 )"
. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid AND s.access <= $my->gid" : '' )
. ( $catid ? "\n AND ( a.catid IN ( $catid ) )" : '' )
. ( $secid ? "\n AND ( a.sectionid IN ( $secid ) )" : '' )
. "\n AND s.published = 1"
. "\n AND cc.published = 1"
. "\n AND #__content_rating.rating_count > 0"
. "\n ORDER BY rating DESC"
;
$database->setQuery( $query, 0, $count );
$rows = $database->loadObjectList();

// needed to reduce queries used by getItemid for Content Items
if ( ( $type == 1 ) || ( $type == 3 ) ) {
$bs = $mainframe->getBlogSectionCount();
$bc = $mainframe->getBlogCategoryCount();
$gbs = $mainframe->getGlobalBlogSectionCount();
}

// Output
?>
<ul class="highestrated<?php echo $moduleclass_sfx; ?>">
<?php
foreach ($rows as $row) {
// get Itemid
$Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );

// Blank itemid checker for SEF
if ($Itemid == NULL) {
$Itemid = '';
} else {
$Itemid = '&amp;Itemid='.$Itemid;
}

$link = sefRelToAbs( 'index.php?option=com_content&amp;task=view&amp;id='. $row->id . $Itemid );
?>
<li class="higestrated<?php echo $moduleclass_sfx; ?>">
<a href="<?php echo $link; ?>" class="higestrated<?php echo $moduleclass_sfx; ?>">
<?php echo $row->title; ?></a>
<?php
if ($type=="1"){echo " (".$row->count.")";}
if ($type=="2"){echo " (".round($row->rating,1).")";}
?>
</li>
<?php
}
?>
</ul>