Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/app/addons/discussion/func.php b/app/addons/discussion/func.php
- index a6256ef..948e0c9 100644
- --- a/app/addons/discussion/func.php
- +++ b/app/addons/discussion/func.php
- @@ -267,7 +267,7 @@ function fn_get_discussion($object_id, $object_type, $get_posts = false, $params
- list($cache[$_cache_key]['posts'], $cache[$_cache_key]['search']) = fn_get_discussion_posts($params, Registry::get('addons.discussion.' . $discussion_object_types[$cache[$_cache_key]['object_type']] . '_posts_per_page'));
- - $cache[$_cache_key]['average_rating'] = fn_get_average_rating($cache[$_cache_key]);
- + $cache[$_cache_key]['average_rating'] = fn_discussion_get_average_object_rating($object_id, $object_type);
- }
- $saved_post_data = fn_restore_post_data('post_data');
- @@ -847,6 +847,46 @@ function fn_get_discussion_rating($rating_value)
- return $cache[$rating_value];
- }
- +/**
- + * Returns average rating of an object taking into account:
- + * - whether the object is shared or not
- + * - reviews setting: Communication and Rating or just Rating
- + * - discussion posts status - active
- + *
- + * @param $object_id
- + * @param $object_type
- + *
- + * @return mixed
- + */
- +function fn_discussion_get_average_object_rating($object_id, $object_type)
- +{
- + if ($object_type === DISCUSSION_OBJECT_TYPE_PRODUCT) {
- + $share_status = Registry::get('addons.discussion.product_share_discussion');
- + } elseif ($object_type === DISCUSSION_OBJECT_TYPE_PAGE) {
- + $share_status = Registry::get('addons.discussion.page_share_discussion');
- + } else {
- + $share_status = null;
- + }
- +
- + $rating = db_get_field(
- + 'SELECT AVG (dr.rating_value) FROM ?:discussion_rating AS dr'
- + . ' LEFT JOIN ?:discussion_posts AS dp ON dp.post_id = dr.post_id'
- + . ' LEFT JOIN ?:discussion AS d ON d.thread_id = dp.thread_id'
- + . ' WHERE d.object_id = ?i AND d.object_type = ?s AND type IN ( ?a ) ?p'
- + . ' AND dp.status = ?s AND dr.rating_value > ?i',
- + $object_id,
- + $object_type,
- + array(DISCUSSION_REVIEW_COMMUNICATION_AND_RATING, DISCUSSION_REVIEW_RATING),
- + $share_status === 'Y' ? '' : fn_get_discussion_company_condition('d.company_id'),
- + DISCUSSION_POST_STATUS_ACTIVE,
- + 0
- + );
- +
- + $rating = number_format($rating, 2);
- +
- + return intval($rating) == $rating ? intval($rating) : $rating;
- +}
- +
- //
- // Get thread average rating
- //
Add Comment
Please, Sign In to add comment