Hey
I need some plugin that let to user to rate an announcement. I try to do it by myself, but i stuck. I can only rate, but it doesn't show that was made. I will start again, but maybe someone have ready plugin.
Sorry for my english grama
Unless you really need the ability to have it in multiple forums, I'd recommend sticky threads personally. Announcements and threads are handled differently in MyBB, so it would take some work to get ratings on announcements.
Ultimately, it might even be easier to have a thread appear in more than one forum than a rating system for announcements, although the former has a number of issues (the thread will still only belong to one forum, though shown in multiple).
i put into portal.php
PHP Code:
$thread['tid'] = $tid;
$rating = '';
if($foruminfo['allowtratings'] != 1)
{
if($moved[0] == "moved")
{
$rating = "<td class=\"{$bgcolor}\" style=\"text-align: center;\">-</td>";
}
else
{
$thread['averagerating'] = floatval(round($thread['averagerating'], 2));
$thread['width'] = intval(round($thread['averagerating']))*20;
$thread['numratings'] = intval($thread['numratings']);
$not_rated = '';
if(!$thread['rated'])
{
$not_rated = ' star_rating_notrated';
}
$ratingvotesav = $lang->sprintf($lang->rating_votes_average, $thread['numratings'], $thread['averagerating']);
eval("\$rating = \"".$templates->get("portal_announcement_rating")."\";");
}
}
|
before:
PHP Code:
$lastpostdate = my_date($mybb->settings['dateformat'], $announcement['lastpost']);
|
i put everything from "star_ratings.css" into "global.css"
i make global tamplate "portal_announcement_rating" and i put in there:
PHP Code:
<div style="margin-top: 6px; padding-right: 10px;" class="float_right">
<script type="text/javascript" src="jscripts/rating.js?ver=1400"></script>
<div id="success_rating_{$thread['tid']}" style="float: left; padding-top: 2px; padding-right: 10px;"> </div>
<strong style="float: left; padding-right: 10px;">{$lang->thread_rating}</strong>
<div class="inline_rating">
<ul class="star_rating{$not_rated}" id="rating_thread_{$thread['tid']}">
<li style="width: {$thread['width']}%" class="current_rating" id="current_rating_{$thread['tid']}">{$ratingvotesav}</li>
<li><a class="one_star" title="{$lang->one_star}" href="./ratethread.php?tid={$thread['tid']}&rating=1&my_post_key={$mybb->post_code}">1</a></li>
<li><a class="two_stars" title="{$lang->two_stars}" href="./ratethread.php?tid={$thread['tid']}&rating=2&my_post_key={$mybb->post_code}">2</a></li>
<li><a class="three_stars" title="{$lang->three_stars}" href="./ratethread.php?tid={$thread['tid']}&rating=3&my_post_key={$mybb->post_code}">3</a></li>
<li><a class="four_stars" title="{$lang->four_stars}" href="./ratethread.php?tid={$thread['tid']}&rating=4&my_post_key={$mybb->post_code}">4</a></li>
<li><a class="five_stars" title="{$lang->five_stars}" href="./ratethread.php?tid={$thread['tid']}&rating=5&my_post_key={$mybb->post_code}">5</a></li>
</ul>
</div>
</div>
|
and i put "{$rating}" into "portal_announcement" tamplate
It works. Rating for thread works, but after refresh site it doesnt show that rate was done.
Do you know how to fix it?
If you want you can look for yourself. I make test account: login test_user, password: test_user. Forum url: http://www.filmtoks.pl
Can you help with this?
Oh, so you're referring to rating
threads from the portal (as opposed to forum announcements)?
I'm not going to fix your code for you, but I'll tell you this:
- the variables $foruminfo and $moved don't exist on the portal - you probably want $forum[$thread['fid']] for the former instead
- stuff like this makes no sense:
i change code in portal.php:
PHP Code:
$lang->load("ratethread");
if($announcement['numratings'] <= 0)
{
$announcement['width'] = 0;
$announcement['averagerating'] = 0;
$announcement['numratings'] = 0;
}
else
{
$announcement['averagerating'] = floatval(round($announcement['totalratings']/$announcement['numratings'], 2));
$announcement['width'] = intval(round($announcement['averagerating']))*20;
$announcement['numratings'] = intval($announcement['numratings']);
}
$rated = '';
$not_rated = '';
if(!$rated)
{
$not_rated = ' star_rating_notrated';
}
$ratingvotesav = $lang->sprintf($lang->rating_votes_average, $announcement['numratings'], $announcement['averagerating']);
eval("\$rating = \"".$templates->get("portal_announcement_rating")."\";");
|
but what to put here: "$rated = '?';" ? Because when i put:
PHP Code:
$query = $db->simple_select("threadratings", "uid", "tid='{$tid}' AND uid='{$mybb->user['uid']}'");
$rated = $db->fetch_field($query, 'uid');
|
only first announcement is visible.
I think you need to join the query (the threadratings query) into the main query, if you want to check whether the thread already rated by the user. Then specify the user id in the condition (probably that's what you mean by the $rated variable).
i think i have to put
threadratings query inhere:
PHP Code:
$announcements = '';
$query = $db->query("
SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
WHERE t.fid IN (".$announcementsfids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
ORDER BY t.dateline DESC
LIMIT 0, {$numannouncements}"
);
|
but i dont know how and i dont know how to make condition
i try, but didnt work
BUT if i rate announcement once i cant do it again, cause there is an info that i already rate announcement. so, i cant rate two times on the same announcement.
Yeah. You can join the query there. You can use LEFT_JOIN.
About the $rated condition, you can create the condition after you put the query there.
Basically (I think), your threadratings query is used to check whether an announcement already rated by a user or not. And the value of the user's uid is stored in the $rated variable. So, you need to specify the value first before you use the $rated variable in your code (depends on how you build the query).
For your portal_announcement_rating template, I think you need to use $announcement array.
Well, i made it.
Add:
and
PHP Code:
LEFT JOIN ".TABLE_PREFIX."threadratings r ON(r.tid=t.tid AND r.uid='{$mybb->user['uid']}')
|
then i put:
PHP Code:
$not_rated = '';
if(!$announcement['rated'])
{
$not_rated = ' star_rating_notrated';
}
|
instead of:
PHP Code:
$not_rated = '';
if(!$rated)
{
$not_rated = ' star_rating_notrated';
}
|
and no need to make $rated condition
Hej, RateU, will you help me to write all of this as plugin? Is it possible to easy to make?
You can try this plugin (attached):
This plugin depends on
XThreads. So, you need to install
XThreads before using this plugin.
Reposition the
{$portal_announcements_rating_rating} variable in your
portal_announcement template as you like. If you can't find the variable there, you need to add it manually.
If you want to change the style, edit the
cache/portal_announcements_rating.css file. Basically, the contents of this file is the same as the default
star_rating.css stylsheet.