Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • sakattack Friend
    #168376

    Hello

    I’ve been trying to show the rating of K2 items in the result page after searching through the K2 Filter module.
    I’ve managed to load the rating by hacking default_results.php (template overrided) and jak2_filter.php (plugins/search). However, my sql query must be wrong because now it only displays items that have rating (if an item has not been rated it won’t show up in the results). Also, I can’t get it to load the vote percentage from the beginning, I have to first click on a rating star for it to show me what the current rating is.

    Here’s what I’ve coded so far (I’ve applied some more hacks, like the hack proposed in here about displaying item images in search results) :

    default_results.php

    This php is right after the foreach (It’s what was suggested in here in order to display images, with a few additions by me -> the bold text was added for the rating issue)

    <?php
    $image =””;

    if(isset($result->extra_fields_search))
    {
    $query = “
    SELECT i.id,i.title,r.itemID,
    r.rating_count,
    (r.rating_sum/r.rating_count) as rating,

    i.metadesc,
    i.featured,
    i.featured_ordering,
    i.metakey,
    c.name as section,
    i.image_caption,
    i.image_credits,
    i.video_caption,
    i.video_credits,
    i.extra_fields_search,
    i.created,
    i.introtext as text,
    CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(‘:’, i.id, i.alias) ELSE i.id END as slug,
    CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(‘:’, c.id, c.alias) ELSE c.id END as catslug
    FROM #__k2_items AS i
    INNER JOIN #__k2_categories AS c ON c.id=i.catid
    INNER JOIN #__k2_rating AS r ON r.itemID=i.id
    WHERE i.id = “. $result->id;
    $db->setQuery($query);
    $item = $db->loadObject();
    if(!empty($item))
    {
    $arr_k2image = getK2Images($item);
    $image = isset($arr_k2image[“imageGeneric”])?$arr_k2image[“imageGeneric”]:””;

    }
    }

    ?>

    and this DIV was added in the fieldset in order to display the rating

    <!– Item Rating –>
    <div class=”catItemRatingBlock”>
    <span><?php echo JText::_(‘Rate this item’); ?></span>
    <div class=”itemRatingForm”>
    <ul class=”itemRatingList”>
    <li class=”itemCurrentRating” id=”itemCurrentRating<?php echo $result->id; ?>” style=”width:<?php echo $result->rating; ?>%;”></li>
    <li><a href=”#” rel=”<?php echo $result->id; ?>” title=”<?php echo JText::_(‘1 star out of 5’); ?>” class=”one-star”>1</a></li>
    <li><a href=”#” rel=”<?php echo $result->id; ?>” title=”<?php echo JText::_(‘2 stars out of 5’); ?>” class=”two-stars”>2</a></li>
    <li><a href=”#” rel=”<?php echo $result->id; ?>” title=”<?php echo JText::_(‘3 stars out of 5’); ?>” class=”three-stars”>3</a></li>
    <li><a href=”#” rel=”<?php echo $result->id; ?>” title=”<?php echo JText::_(‘4 stars out of 5’); ?>” class=”four-stars”>4</a></li>
    <li><a href=”#” rel=”<?php echo $result->id; ?>” title=”<?php echo JText::_(‘5 stars out of 5’); ?>” class=”five-stars”>5</a></li>
    </ul>
    <div id=”itemRatingLog<?php echo $result->id; ?>” class=”itemRatingLog”><?php echo $result->rating_count; ?></div>
    <div class=”clr”></div>
    </div>
    <div class=”clr”></div>
    </div>

    jak2_filter.php line:226

    I’ve bolded what I added for the rating issue

    $query = “
    SELECT i.id, i.title, r.itemID,
    r.rating_count,
    (r.rating_sum/r.rating_count) as rating,

    i.metadesc,
    i.featured,
    i.featured_ordering,
    i.metakey,
    c.name as section,
    i.image_caption,
    i.image_credits,
    i.video_caption,
    i.video_credits,
    i.extra_fields_search,
    i.created,
    i.introtext as text,
    CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(‘:’, i.id, i.alias) ELSE i.id END as slug,
    CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(‘:’, c.id, c.alias) ELSE c.id END as catslug
    FROM #__k2_items AS i
    INNER JOIN #__k2_rating AS r ON r.itemID=i.id
    INNER JOIN #__k2_categories AS c ON c.id=i.catid AND c.access <= {$access} “;
    $sql[] =” i.published = 1 “;

    Can any1 help me correct the code?

    This code has the problems I discussed at the beginning. I need it to display items that have no rating as well, and to display the voting percentage right from the start.

    I’d really appreciate any suggestion.

    Blaine Friend
    #411255

    HI!
    Here is what JA says about the module:
    <blockquote> It comprises of one module and two plugins. One of the plugin (JA k2 search – reindexing Plguin) re-indexes the extra-field data for the module to function, it needs to be done one time so as to cover the already present K2 articles. The second plugin (JA K2 Extrafield plguin) has the configuration for the module, we have made it so easy that even a newbie would not have any trouble making it work. Features * First and the only module to provide such advanced search feature. * Multi (combo) parameters filtering. * Configurable filter parameters (option to select specific parameter to display in the search). * Multi display options for each filter parameter. Eg: you can choose to display a pricing range as min-max value or as a preset dropdown or even multiselct or radio select. </blockquote>
    Is it not configurable this way for you?
    Have you looked at the User Guide?

    sakattack Friend
    #411285

    The module uses joomla’s search component, and since it’s not made to show ratings, module doesn’t show them as well. They both need hard coding in order to show ratings, and that’s what I’ve been trying to do and failed so far.

    Blaine Friend
    #411544

    Hi sakattack,
    This really is custom work involving the K2 and we only provide the module for integrating the K2 search not K2 itself.
    I want to try to help you so try this in K2:
    If you want to retrieve only count of votes, you have to add the following PHP code:

    $query = 'SELECT rating_count FROM #__k2_rating WHERE itemID = ' . $item->id;
    $db->setQuery($query);
    $item->votes=$db->loadResult();

    Insert this code into modules/mod_k2_content/helper.php, straight after foreach ($items as $item) (statement, somewhere at line 220). Then all you have to do in your template file of k2_content is:

    <?php echo $item->votes; ?>

    This may also be of help in the code you are lacking in your hack.
    Please advise when we may close this thread and your issue is resolved.
    Thanks!

    sakattack Friend
    #411771

    Thank you for taking the time to answer. I actually managed to make my code work by adding a *20 at this line :
    (<li class=”itemCurrentRating” id=”itemCurrentRating<?php echo $result->id; ?>” style=”width:<?php echo $result->rating; ?>%;”>)

    which became

    <li class=”itemCurrentRating” id=”itemCurrentRating<?php echo $result->id; ?>” style=”width:<?php echo $result->rating*20; ?>%;”>

    With that change rating shows just fine in search results (I’ve ofcourse added the appropriate classes in the template.css). However it still doesn’t retrieve items that haven’t been rated yet, and I believe it’st he sql statement, I need to break it down and apply the 2 queries to different foreach statements. I’ll update as soon as I fix it. Meanwhile, if any1 has and Ideas, please do tell, I’d appreciate it.

    Blaine Friend
    #411798

    Hi sakattack,
    I am so glad the issue is resolved for you!
    I also want to thank you for taking the time to post your solution here. It will benefit so many other users!
    You’re great!

Viewing 6 posts - 1 through 6 (of 6 total)

This topic contains 6 replies, has 2 voices, and was last updated by  Blaine 13 years, 2 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum