Forum Moderators: coopster

Message Too Old, No Replies

Help in selecting featured items through custom field

         

itoo73

11:46 am on May 25, 2010 (gmt 0)

10+ Year Member



Hello, i have joomla site with sobi catalog installed. What i want is to scroll some items in the frontpage not by random selection but by selecting those items that have a "featured" field checked. I found some addons for this work but they dont do what i want or they are problematic unfortunately. I am trying to modify the one that is most close to what i want. This one scrolls items by taking the newest, the most popular or some random. I need some help to modify the query in the database so that it calls only the items that have a field_featured=1.
The sobi database has items that are stored in table jos_sobi2_item as i can see in my phpmyadmin interface. The fields for each item are stored in jos_sobi2_fields and the field_featured has a fieldid =21. The data are stored in table jos_sobi2_fields_data.
Below its the php code from the addon. I think it wont be too difficult to modify the query so that it will return only the checked items. The rest is done bye the script carousel as i can infer... Please anyone can help?! :)

<?php


class modSobiAdsliderHelper
{
/**
* Retrieves the hello message
*
* @param array $params An object containing the module parameters
* @access public
*/


function PrepareCustomHeader( $params, $cId, $cl )
{

if (!defined("_JQUERY")){
JHTML::script('jquery-1.3.2.min.js','modules/mod_sobi2adslider/jcarousel/lib/',false);
}
JHTML::script('jquery.jcarousel.pack.js','modules/mod_sobi2adslider/jcarousel/lib/',false);
JHTML::script('adslider.helper.js','modules/mod_sobi2adslider/jcarousel/',false);
JHTML::stylesheet('jquery.jcarousel.css', 'modules/mod_sobi2adslider/jcarousel/lib/');
JHTML::stylesheet('skin.css', 'modules/mod_sobi2adslider/jcarousel/skins/'.$params->get('SkinName').'/');


if (!defined("_JQUERY")){
$doc =&JFactory::getDocument();
$doc->addScriptDeclaration('jQuery.noConflict();');
define ("_JQUERY", true);
}

/*/// static content init
$js = 'jQuery(document).ready(function() {
jQuery("#'.$cId.'").jcarousel({';

$js .= 'size:'.$cId.'_itemList.length,';

$js .= 'itemLoadCallback: {onBeforeAnimation:'.$cId.'._itemLoadCallback}';

if ($params->get('vertical')) $js .='vertical: true,';
if ($params->get('UseCustomEffect')) $js .= "easing: '".$params->get('CustomEffectName')."',";
if ($params->get('wrap') !='none') $js .= "wrap: '".$params->get('wrap')."',";
$js .= 'animation:'.$params->get('Animation').',';
$js .= 'auto:'.$params->get('AutoScroll').',';
$js .= 'scroll:'. $params->get('ItemsToScroll');

$js .= ' });
});';
$doc->addScriptDeclaration($js);
*/
return 0;
}

function PrepareAdsDB($limit=0, $how=null, $imgsrc='gallery'){
$database =&JFactory::getDBO();
if($limit>0) {
$limit = "LIMIT $limit";
} else {
$limit = "";
}
// did not use SELECT * for faster query
if ($imgsrc == 'gallery'){

$query = "SELECT ad.itemid, ac.catid, ac.ordering, ad.title, ad.last_update FROM #__sobi2_item AS ad";
$query .="\nJOIN #__sobi2_cat_items_relations AS ac ON ad.itemid=ac.itemid WHERE ad.published = 1";
}
else{
$query = "SELECT ad.itemid, ac.catid, ac.ordering, ad.title, ad.icon FROM #__sobi2_item AS ad";
$query .="\nJOIN #__sobi2_cat_items_relations AS ac ON ad.itemid=ac.itemid WHERE ad.published = 1";
}
switch( $how ) {
case 'random':
$query .= "\n ORDER BY RAND() $limit";
break;
case 'newest':
$query .= "\n ORDER BY ad.publish_up DESC $limit";
break;
case 'popular':
$query .= "\n ORDER BY ad.hits ASC $limit";
break;
default:
$query .= "\n ORDER BY ad.publish_up $limit";
break;
}
$database->setQuery( $query );
$rows = $database->loadObjectList();

if ( $database->getErrorNum() ) {
trigger_error( "DB reports: ".$database->stderr(), E_USER_WARNING );
}


return $rows;

}

function DisplayAdsThumb($row,$imageSource,$noImagePath){

$url = JRoute::_("index.php?option=com_sobi2&amp;sobi2Task=sobi2Details&amp;catid={$row->catid}&amp;sobi2Id={$row->itemid}&amp;Itemid=1"); //{$urltitle}";

if ($imageSource == 'gallery'){

$db=&JFactory::getDBO();
$q="SELECT thumb FROM #__sobi2_plugin_gallery WHERE itemid = {$row->itemid} ORDER BY 1";
$db->SetQuery($q);
$thumb = $db->LoadResult();
if ( $db->getErrorNum() ) {
trigger_error( "DB reports: ".$db->stderr(), E_USER_WARNING );
}
if(! $thumb){
$imgurl = JURI::base().$noImagePath;
}
else{
$imgurl =JURI::base()."images/com_sobi2/gallery/{$row->itemid}/{$thumb}";
}
}
else {
//If no images are in Icon field then...
if ($row->icon == '') {
$imgurl = JURI::base().$noImagePath;
}
else {
$imgurl = JURI::base()."images/com_sobi2/clients/{$row->icon}";
}
}
$result = '{url :"'.$url. '",imgurl :"'.$imgurl .'",title:"'.$row->title .'"}';
return $result;

}

function DisplaySlider($rows,$params){
$result = '';
foreach($rows as $row){
$result .='<li>'. modSobiAdsliderHelper::DisplayAdsThumb($row,$params->get('ImageSource'),$params->get('noImagePath')).'</li>';

}
return $result;

}

function PrepareDynamicList($rows,$params){
$result = '';
foreach($rows as $row){
if($result =='')
$result = modSobiAdsliderHelper::DisplayAdsThumb($row,$params->get('ImageSource'),$params->get('noImagePath'));
else
$result .= ',
'.modSobiAdsliderHelper::DisplayAdsThumb($row,$params->get('ImageSource'),$params->get('noImagePath'));
}
return $result;

}


}
?>

coopster

1:19 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You just need to append that logic to the existing WHERE clause. Have you tried that yet?