Keyword

[SOLVED] Item rating on Generic page

  • jozsefke
  • jozsefke's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 3 months ago - 9 years 3 months ago #144980 by jozsefke
Item rating on Generic page was created by jozsefke
I have tried to implement the rating function on Generic pages also, however, it is not working for some reason. The block displays fine, but the current rating is not shown either by the stars or the numericRating variable I created (which works in other views). The number of votes doesn't display either. The code I added is the following. What am I doing wrong?
<?php if($item->params->get('catItemRating')): ?>

  <li class="itemRatingBlock"> <span><?php echo JText::_('K2_RATE_THIS_ITEM'); ?></span>

    <div class="itemRatingForm">

      <ul class="itemRatingList">

        <li class="itemCurrentRating" id="itemCurrentRating<?php echo $item->id; ?>" style="width:<?php echo $item->votingPercentage; ?>%;"></li>

        <li><a href="#" rel="<?php echo $item->id; ?>" title="<?php echo JText::_('K2_1_STAR_OUT_OF_5'); ?>" class="one-star">1</a></li>

        <li><a href="#" rel="<?php echo $item->id; ?>" title="<?php echo JText::_('K2_2_STARS_OUT_OF_5'); ?>" class="two-stars">2</a></li>

        <li><a href="#" rel="<?php echo $item->id; ?>" title="<?php echo JText::_('K2_3_STARS_OUT_OF_5'); ?>" class="three-stars">3</a></li>

        <li><a href="#" rel="<?php echo $item->id; ?>" title="<?php echo JText::_('K2_4_STARS_OUT_OF_5'); ?>" class="four-stars">4</a></li>

        <li><a href="#" rel="<?php echo $item->id; ?>" title="<?php echo JText::_('K2_5_STARS_OUT_OF_5'); ?>" class="five-stars">5</a></li>

      </ul>

      <span><?php $numericRating = round(($item->votingPercentage / 2), 0); $numericRating = round(($numericRating / 10), 1); echo $numericRating; ?></span>

      <div id="itemRatingLog<?php echo $item->id; ?>" class="itemRatingLog"><?php echo $item->numOfvotes; ?></div>

    </div>

  </li>

<?php endif; ?>
Last edit: 9 years 3 months ago by jozsefke.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 3 months ago #144985 by Krikor Boghossian
Replied by Krikor Boghossian on topic Item rating on Generic page
Hello,

This will produce non valid HTML.
You need to replace the li tags with a div one.

Then send me a link so I can take a look, since this a visual issue.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • jozsefke
  • jozsefke's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 3 months ago - 9 years 3 months ago #144988 by jozsefke
Replied by jozsefke on topic Item rating on Generic page
Well, yes, I have copied it from category view, where it's inside an unordered list tag, and that's why it is a list item. It's not valid this way indeed. But changing it to div still doesn't make it work unfortunately. Here you can take a look at the page: 'szellms.hu/kereses?searchword=teszt'. I think the problem is something with the PHP, I'm not an expert in that.
Last edit: 9 years 3 months ago by jozsefke.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 3 months ago #144992 by Krikor Boghossian
Replied by Krikor Boghossian on topic Item rating on Generic page
It seems to work fine now on my end.
It was probably a CSS thing, right?

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • jozsefke
  • jozsefke's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 3 months ago #144995 by jozsefke
Replied by jozsefke on topic Item rating on Generic page
It is working fine on category pages, but not on generic pages like search or date listings. You can see that the items you rated don't have any ratings on the search page, and the number of votes doesn't show either. There's something wrong with my PHP code, it can't get these two variables this way.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 3 months ago #145012 by Krikor Boghossian
Replied by Krikor Boghossian on topic Item rating on Generic page
The rating is not included in the generic view.
You can 'hack' a core file in order to include it but this is not recommended.

Backup before editing the /components/com_k2/models/item.php

Line 194 locate
if (($view == 'item' && $item->params->get('itemRating')) || ($view == 'itemlist' && ($task == '' || $task == 'category' ) && $item->params->get('catItemRating')))

and add || $task == 'search'
if (($view == 'item' && $item->params->get('itemRating')) ||  $task == 'search' || ($view == 'itemlist' && ($task == '' || $task == 'category' ) && $item->params->get('catItemRating')))

Finally you should also remove
<?php if($item->params->get('catItemRating')): ?>
and the appropriate <?php endif; ?>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • jozsefke
  • jozsefke's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 3 months ago #145017 by jozsefke
Replied by jozsefke on topic Item rating on Generic page
Thank you very much again, Krikor! It is working like a charm. Could you please explain why it is not recommended?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 3 months ago #145030 by Krikor Boghossian
Replied by Krikor Boghossian on topic Item rating on Generic page
Because you will lose your edits when you update and you will have to reapply them.
In general editing core files is not recommended since they might lead into unexpected results. This is a minor edit however.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • jozsefke
  • jozsefke's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 3 months ago - 9 years 3 months ago #145111 by jozsefke
Replied by jozsefke on topic Item rating on Generic page
Well yes, I'm aware of this. I have also heavily modified the template files, but I keep a changelog of every single edit I make, so it will be no problem when K2 will be updated.
Last edit: 9 years 3 months ago by jozsefke.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 3 months ago #145120 by Krikor Boghossian
Replied by Krikor Boghossian on topic Item rating on Generic page
The template files can be overriden so you can freely change every aspect of them.

Just in case if you don't use overrides this is a good starting point: getk2.org/documentation/tutorials/174

Kudos on the changelog :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum