JeBy VIP
Total posts: 10
10 Янв 2015 18:18

Hi everyone!

Since I started working with Cobalt 8 I've noticed that I could not rate any of the records I created. It didn't even show the mouseover effect! I thought it was a bug with one of the javascripts but then when I created a test user I noticed that that user (that didn't create all of the records) could rate all of the records!

This made me check out how this is decided and didn't see anything in administration on either Content Type Edit or Section Edit. I managed to track it down to the file "rating.php" in "joomla/components/com_cobalt/library/php/helpers" where I found the function "canRate".

public static function canRate($type, $user_id, $id, $accessLevel = 1, $index = 0)
    {
        $user = JFactory::getUser();
        if($accessLevel == -1)
        {

            if(!$user->get('id') || !$user_id)
            {
                return FALSE;
            }

            if($user_id != $user->get('id'))
            {
                return FALSE;
            }
        }
        else
        {
            if(!in_array($accessLevel, $user->getAuthorisedViewLevels()))
            {
                return FALSE;
            }

            if($user_id == $user->get('id') && $user->get('id'))
            {
                return FALSE;
            }

            if($user->get('id') && JFactory::getApplication()->input->cookie->get("{$type}_rate_{$id}_{$index}", 0, 'INT'))
            {
                return FALSE;
            }

            $ses = JFactory::getSession();
            if($ses->get("{$type}_rate_{$id}_{$index}"))
            {
                return FALSE;
            }
        }

        return TRUE;
    }

To my surprise I found that there's a rule that user can not vote for their own content and it's not even conditional with a parameter yes/no:

if($user_id == $user->get('id') && $user->get('id'))
            {
                return FALSE;
            }

Now, I decided to comment out this code, and now as the user that created those records I can see the mouseover effect but when I click the rating it does not record. Is there anything I'm missing here? Is there another check somewhere that I'm not finding? Or am I being stupid and can this be changed in the administration section anyway??

Thanks ahead!

JB

Последние изменения: 13 Янв 2015


pepperstreet VIP
Total posts: 3,837
11 Янв 2015 03:25

JeBy Is there another check somewhere that I'm not finding? Or am I being stupid and can this be changed in the administration section anyway??

As far as I can tell, it works pretty well. And you have a complete set of parameter values.
See your Type -> General Parameters tab -> Rating -> Who can rate
You can set a certain J! ACL or None or even author only:

Bildschirmfoto 2015-01-11 um 04.16.22


JeBy VIP
Total posts: 10
11 Янв 2015 13:36

Thanks for your reply pepperstreet. I have that setting on "Registered", from which I expect it to allow any registered users (including the author) to rate the record. I have now tested it with any other setting and the only setting allowing the author to rate their own content is "Only article author" (obviously). The other settings are all making the stars inactive and thus not being able to rate.

Is this only happening to me?


pepperstreet VIP
Total posts: 3,837
11 Янв 2015 22:25

JeBy the only setting allowing the author to rate their own content is "Only article author" (obviously). The other settings are all making the stars inactive and thus not being able to rate.

Is this only happening to me?

AFAIK, that's the way it should be.

1.) Primarily it is for ratings made by other users/visiters. If the author could rate his records, it would be "fake" or "abuse". This is the case for most applications.

2.) The only use case to allow the author to rate his own record is to utilize ratings/multi-ratings to display "skills", "features" or "abilities" etc. So, nobody else should have access to change that.

What is your use case/workflow?


Sergey
Total posts: 13,748
12 Янв 2015 03:45

pepperstreet 2.) The only use case to allow the author to rate his own record is to utilize ratings/multi-ratings to display "skills", "features" or "abilities" etc. So, nobody else should have access to change that.

Another use of this (what is actulay was created for) if reviews. When you write a review you attach a rating to it. So it is your review and your opinion and no one have to be able to change it.


JeBy VIP
Total posts: 10
12 Янв 2015 10:54

Thanks for your replies guys!

My case is a movie database where users can add movies but as movies are a public "thing" and not their own article or anything personal, the user should be able to rate the movie too. Sergey, could you tell me which other files handle the author checking? I can't seem to find the 2nd check the system makes other than the one I posted in my first post. If I find all checks, I can just hide the code and thus letting both registered users and the author to rate :)


pepperstreet VIP
Total posts: 3,837
13 Янв 2015 06:37

@Sergey

I would suggest to extend the current parameter and restrictions. If possible...
Maybe a checkbox to "in/exclude" the author to the selected ACL?

Better than hacking core functions, isn't it?!


Sergey
Total posts: 13,748
13 Янв 2015 12:10

pepperstreet Better than hacking core functions, isn't it?!

Sure

JeBy Sergey, could you tell me which other files handle the author checking?

I'll try to add thisparameter to next release. But for cases like yours I would suggest reviews. Then rating of the movie in the other record and only author of that record can rate. Also vithout review, just the starts is not very helpfull. People like to read people's impression of the movie. Sometimes theer are 3 starts, bet movie is still worth to watch.


Sergey
Total posts: 13,748
13 Янв 2015 12:12

BTW the only one place where access to rating is checked in /components/com_cobalt/library/php/helpers/rating.php line 28-67 function canRate()


pepperstreet VIP
Total posts: 3,837
13 Янв 2015 16:21

JeBy movie database where users can add movies but as movies are a public "thing" and not their own article or anything personal, the user should be able to rate the movie too.

Sorry, first I was thinking of a direct rating INSIDE the same record/movie. Sergey is totally right. Multiple Reviews/Ratings are attached to another type called "movie". Comparable to IMDB.com

Example setup:

  • Type1 is your movie record.
    (this might even include a special rating design and review for author only!)
  • Type2 is your rating record for everyone.
    (this could be done by "Cobalt Type as Comments", or "Relation field". Both solutions allow author AND other users to submit a rating)
Работает на Cobalt