klox7 VIP
Total posts: 914
22 Sep 2014 12:35

I have troubles displaying multi rating results:

When I display total rating of all ratings I display it like this: $rating['total'].

When I display ratings list (record list with individual rating) I used to have it like this:$item-votes_result. But it seems this is wrong because when I edited one review and changed rating the results in output didn't change. Do I have to use something with $rating...?

Last Modified: 03 Oct 2014


Sergey
Total posts: 13,748
23 Sep 2014 02:47

What is your rating acces in cobalt type as comment? It should be only author.


klox7 VIP
Total posts: 914
23 Sep 2014 07:57

"Who can rate" is set to "only article author". So $item->votes_result is ok for displaying record rating?

So if I as admin change rating it won't change because of rating access?


Sergey
Total posts: 13,748
24 Sep 2014 10:21

klox7 So if I as admin change rating it won't change because of rating access?

Perhaps. It checks record author. But in the code everything looks ok. I cannot reproduce. rating stores values.


klox7 VIP
Total posts: 914
25 Sep 2014 13:09

Why is $rating['total'] calculated even if record has not yet been approved? Is there any other code that will show total rating only when record (which has rating) has been approved?


Sergey
Total posts: 13,748
26 Sep 2014 03:05

Yes, there is code. the same code in a new release I am going to make later today. I added a fix.


Sergey
Total posts: 13,748
26 Sep 2014 03:06

Or you always may add to condition 'r.published = 1'


jimie VIP
Total posts: 531
26 Sep 2014 06:52

Can you write here an example Sergey ?

Rgds


klox7 VIP
Total posts: 914
26 Sep 2014 07:37

I think it's like this:

<?php $rating = CobaltApi::renderRating($type_id, $section_id, 'r.published = 1'); ?>
<?php echo $rating['total'];?>

Docs here.


klox7 VIP
Total posts: 914
30 Sep 2014 11:56

I'm using one template list for displaying reviews everywhere.

My setup is:
* Type 1 (Section 1) with cobalt types as comments.
* Type 2 (Section 2) with cobalt types as comments.
* Section 3 (Type 3)is for storing reviews but it has subcategories.
* Type 1 and Type 2 have "force to category" set up when submiting review. Section is Section 3.

Now this is my code for displaying rating:

<?php 
if($params->get('tmpl_core.item_rating')):
$rating = CobaltApi::renderRating(13, 8, 'r.published = 1'); 
?>
    <div class="pull-right">Total rating: 
            <?php if($rating['total']/10 <= 5):?>
            <div class="content_rating btn btn-danger btn-small" rel="tooltip" data-original-title="Rating">
                <?php echo round($rating['total']/10, 1);?>
            </div>
            <?php elseif($rating['total']/10 < 8):?>
            <div class="content_rating btn btn-warning btn-small" rel="tooltip" data-original-title="Rating">
                <?php echo round($rating['total']/10, 1);?>
            </div>
            <?php else:?>
            <div class="content_rating btn btn-success btn-small" rel="tooltip" data-original-title="Rating">
                <?php echo round($rating['total']/10, 1);?>
            </div>
            <?php endif;?>
            out of <?php echo $rating['num']; ?> votes!
    </div>
<?php endif;?>

Problem: It doesn't matter if I submit rating to Type1 record or Type2 record, $rating['total'] and $rating['num'] always takes into account ratings from both Types. Why? Is this because ratings are stored in subcategories of same section? How can I separate ratings?


Sergey
Total posts: 13,748
01 Oct 2014 02:03
$rating = CobaltApi::renderRating(13, 8, 'r.published = 1 AND r.parent_id = '.$item->id); 

You need to add condition so that only ratings of current article are calculated.


klox7 VIP
Total posts: 914
01 Oct 2014 15:50

Sergey $rating = CobaltApi::renderRating(13, 8, 'r.published = 1 AND r.parent_id = '.$item->id);

You can use this in record.

If you output total rating and total number of votes in comments list template you must replace $item->idwith $item->parent_id


Sergey
Total posts: 13,748
02 Oct 2014 01:42

klox7 If you output total rating and total number of votes in comments list template you must replace $item-&gt;idwith $item-&gt;parent_id

You want total ratings for all records in section but only made for one type?


klox7 VIP
Total posts: 914
02 Oct 2014 07:26

Sergey You want total ratings for all records in section but only made for one type?

Ratings are already in one type. That's why this is $rating = CobaltApi::renderRating(13, 8, 'r.published = 1');

Or maybe I don't understand your question?

What I wanted to say is that if you want do display total rating somwhere in "main record" you use $item->id as you said. You can use this also in "main records list". But if you want do display total rating in comments list in record then you use $item->parent_id. This works for me.


Sergey
Total posts: 13,748
03 Oct 2014 01:46

klox7 But if you want do display total rating in comments list in record then you use $item-&gt;parent_id. This works for me.

Got you! Yes. Correct.

Powered by Cobalt