rating in portal announcement
duhol Offline
Junior Member
**
Posts: 34
Joined: Mar 2011
Post: #1
rating in portal announcement
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 Tongue
05-15-2011 05:12 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: rating in portal announcement
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).

My Blog
05-15-2011 10:35 AM
Find all posts by this user Quote this message in a reply
duhol Offline
Junior Member
**
Posts: 34
Joined: Mar 2011
Post: #3
RE: rating in portal announcement
i put into portal.php

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
	$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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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;">&nbsp;</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']}&amp;rating=1&amp;my_post_key={$mybb->post_code}">1</a></li>
				<li><a class="two_stars" title="{$lang->two_stars}" href="./ratethread.php?tid={$thread['tid']}&amp;rating=2&amp;my_post_key={$mybb->post_code}">2</a></li>
				<li><a class="three_stars" title="{$lang->three_stars}" href="./ratethread.php?tid={$thread['tid']}&amp;rating=3&amp;my_post_key={$mybb->post_code}">3</a></li>
				<li><a class="four_stars" title="{$lang->four_stars}" href="./ratethread.php?tid={$thread['tid']}&amp;rating=4&amp;my_post_key={$mybb->post_code}">4</a></li>
				<li><a class="five_stars" title="{$lang->five_stars}" href="./ratethread.php?tid={$thread['tid']}&amp;rating=5&amp;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?

(This post was last modified: 05-15-2011 03:43 PM by duhol.)
05-15-2011 03:39 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: rating in portal announcement
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:

PHP Code:
if(!$thread['rated'])

PHP Code:
$thread['tid'] = $tid;


My Blog
05-15-2011 07:14 PM
Find all posts by this user Quote this message in a reply
duhol Offline
Junior Member
**
Posts: 34
Joined: Mar 2011
Post: #5
RE: rating in portal announcement
i change code in portal.php:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
		$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.

05-15-2011 10:25 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #6
RE: rating in portal announcement
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).

05-16-2011 03:30 AM
Find all posts by this user Quote this message in a reply
duhol Offline
Junior Member
**
Posts: 34
Joined: Mar 2011
Post: #7
RE: rating in portal announcement
i think i have to put threadratings query inhere:

PHP Code:
1
2
3
4
5
6
7
8
9
$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 Ouch and i dont know how to make condition

PHP Code:
$rated = ???


i try, but didnt work Aww

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.

(This post was last modified: 05-16-2011 07:09 AM by duhol.)
05-16-2011 06:51 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #8
RE: rating in portal 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.

(This post was last modified: 05-16-2011 07:41 AM by RateU.)
05-16-2011 07:18 AM
Find all posts by this user Quote this message in a reply
duhol Offline
Junior Member
**
Posts: 34
Joined: Mar 2011
Post: #9
RE: rating in portal announcement
Well, i made it.

Add:

PHP Code:
r.uid AS rated

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 Smile

Hej, RateU, will you help me to write all of this as plugin? Is it possible to easy to make?

(This post was last modified: 05-16-2011 06:12 PM by duhol.)
05-16-2011 06:09 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #10
RE: rating in portal announcement
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.


Attached File(s)
.7z  portal_announcements_rating.7z (Size: 2.36 KB / Downloads: 340)

05-17-2011 05:59 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: