- Posts: 11
COMMUNITY FORUM
How to add k2 rating to search results?
- Panagiotis Sakellariou
- Topic Author
- Offline
- New Member
Less
More
13 years 2 months ago #99745
by Panagiotis Sakellariou
How to add k2 rating to search results? was created by Panagiotis Sakellariou
Hello all
I've been trying to customise my search results page and while I managed to load the rating system for any k2 items that appear in a search, it loads as if noone has voted, and when you click to vote, it then loads the correct amount of votes.
Below is my default_results.php (of joomla's com_search, template override).
<?php defined('_JEXEC') or die('Restricted access'); ?><?php function getK2Images( $item) { jimport('joomla.filesystem.file'); //Image $arr_return = array(); if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg'; return $arr_return; }?><?php ?><table class="contentpaneopen<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>"> <tr> <td> <?php $db = JFactory::getDBO(); foreach( $this->results as $result ) : ?> <?php $image =""; if(isset($result->extra_fields_search)) { $query = " SELECT i.id,i.title, 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 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"]:""; } } ?> <fieldset> <div class="sea1"> <span class="small<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>"> <?php echo $this->pagination->limitstart + $result->count.'. ';?> </span> <?php if ( $result->href ) : if ($result->browsernav == 1 ) : ?> <a class="modal" rel="{handler:'iframe',size:{x:800,y:600}}" href="<?php echo JRoute::_($result->href); ?>?tmpl=component" target="_blank"> <?php else : ?> <a class="modal" rel="{handler:'iframe',size:{x:800,y:600}}" href="<?php echo JRoute::_($result->href); ?>?tmpl=component"> <?php endif; echo $this->escape($result->title); if ( $result->href ) : ?> </a> <?php endif; if ( $result->section ) : ?> <br /> <span class="small<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>"> (<?php echo $this->escape($result->section); ?>) </span> <?php endif; ?> <?php endif; ?> </div> <!-- 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->votingPercentage; ?>%;"></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->numOfvotes; ?></div> <div class="clr"></div> </div> <div class="clr"></div> </div> <?php if ( $result->featured == 1) : ?> <span class="feat"> <sup> <?php echo '<img class="sear" src="/images/stories/featuredItem.png" title="Designer" alt="Designer" />'; ?> </sup> </span> <?php endif; ?> <div> <div class="result_image"> <?php if(!empty($image)) { ?><a class="modal" rel="{handler:'iframe',size:{x:800,y:600}}" href="<?php echo JRoute::_($result->href); ?>?tmpl=component" title="<?php echo $result->title;?>"> <img class="search_image" src="<?php echo $image; ?>" alt="<?php echo $result->title; ?>" width="200px" height="auto"/></a> <?php } ?> </div> <div class="catItemIntroText"> <?php echo JHTML::_('content.prepare', $result->text); ?> </div> </div> </fieldset> <?php endforeach; ?> </td> </tr> <tr> <td colspan="3"> <div align="center"> <?php echo $this->pagination->getPagesLinks( ); ?> </div> </td> </tr></table>
I believe the problem is at line 116 and 123, and more specifically the votingPercentage @ line 116 and the numOfvotes @ line 123. (I have bolded the 2 lines of code).
How can I fix that? Any help will be greatly appreciated.
p.s. The code above contains hacks to show the item's image with a link, open title link and image link as popup, show the featured notice-graphic(if there is one), load content plugins that are being invoked with tags in introtext, show only introtext with full HTML and some more that I can't remember,
feel free to copy at will.
I've been trying to customise my search results page and while I managed to load the rating system for any k2 items that appear in a search, it loads as if noone has voted, and when you click to vote, it then loads the correct amount of votes.
Below is my default_results.php (of joomla's com_search, template override).
<?php defined('_JEXEC') or die('Restricted access'); ?><?php function getK2Images( $item) { jimport('joomla.filesystem.file'); //Image $arr_return = array(); if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg'; if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg')) $arr_return = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg'; return $arr_return; }?><?php ?><table class="contentpaneopen<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>"> <tr> <td> <?php $db = JFactory::getDBO(); foreach( $this->results as $result ) : ?> <?php $image =""; if(isset($result->extra_fields_search)) { $query = " SELECT i.id,i.title, 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 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"]:""; } } ?> <fieldset> <div class="sea1"> <span class="small<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>"> <?php echo $this->pagination->limitstart + $result->count.'. ';?> </span> <?php if ( $result->href ) : if ($result->browsernav == 1 ) : ?> <a class="modal" rel="{handler:'iframe',size:{x:800,y:600}}" href="<?php echo JRoute::_($result->href); ?>?tmpl=component" target="_blank"> <?php else : ?> <a class="modal" rel="{handler:'iframe',size:{x:800,y:600}}" href="<?php echo JRoute::_($result->href); ?>?tmpl=component"> <?php endif; echo $this->escape($result->title); if ( $result->href ) : ?> </a> <?php endif; if ( $result->section ) : ?> <br /> <span class="small<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>"> (<?php echo $this->escape($result->section); ?>) </span> <?php endif; ?> <?php endif; ?> </div> <!-- 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->votingPercentage; ?>%;"></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->numOfvotes; ?></div> <div class="clr"></div> </div> <div class="clr"></div> </div> <?php if ( $result->featured == 1) : ?> <span class="feat"> <sup> <?php echo '<img class="sear" src="/images/stories/featuredItem.png" title="Designer" alt="Designer" />'; ?> </sup> </span> <?php endif; ?> <div> <div class="result_image"> <?php if(!empty($image)) { ?><a class="modal" rel="{handler:'iframe',size:{x:800,y:600}}" href="<?php echo JRoute::_($result->href); ?>?tmpl=component" title="<?php echo $result->title;?>"> <img class="search_image" src="<?php echo $image; ?>" alt="<?php echo $result->title; ?>" width="200px" height="auto"/></a> <?php } ?> </div> <div class="catItemIntroText"> <?php echo JHTML::_('content.prepare', $result->text); ?> </div> </div> </fieldset> <?php endforeach; ?> </td> </tr> <tr> <td colspan="3"> <div align="center"> <?php echo $this->pagination->getPagesLinks( ); ?> </div> </td> </tr></table>
I believe the problem is at line 116 and 123, and more specifically the votingPercentage @ line 116 and the numOfvotes @ line 123. (I have bolded the 2 lines of code).
How can I fix that? Any help will be greatly appreciated.
p.s. The code above contains hacks to show the item's image with a link, open title link and image link as popup, show the featured notice-graphic(if there is one), load content plugins that are being invoked with tags in introtext, show only introtext with full HTML and some more that I can't remember,
feel free to copy at will.
Please Log in or Create an account to join the conversation.