function getSEFCatString($id) { $catOb = BidsHelperTools::getCategoryModel(); return $catOb->getCategoryPathString($id); }
function rss() { $database = JFactory::getDBO(); $cfg = BidsHelperTools::getConfig(); ob_end_clean(); $feed = $cfg->bid_opt_RSS_feedtype; $cat = JRequest::getInt('cat', ''); $user = JRequest::getInt('user', ''); $limit = $cfg->bid_opt_RSS_description ? intval($cfg->bid_opt_RSS_nritems) : intval($cfg->bid_opt_nr_items_per_page); if (!$limit) $limit = 10; require_once (JPATH_COMPONENT_SITE.DS.'libraries'.DS.'feedcreator'.DS.'feedcreator.php'); $rss = new UniversalFeedCreator(); $rss->title = $cfg->bid_opt_RSS_title; $rss->description = $cfg->bid_opt_RSS_description; $rss->link = htmlspecialchars(JURI::root()); $rss->syndicationURL = htmlspecialchars(JURI::root()); $rss->cssStyleSheet = null; $rss->encoding = 'UTF-8'; $where = " where a.published=1 and a.close_offer=0 and a.close_by_admin=0 "; if ($cat) { if (!$cfg->bid_opt_inner_categories) { $where .= " and a.cat = '" . $cat . "' "; } else { $catOb = BidsHelperTools::getCategoryModel(); $cTree = $catOb->getCategoryTree($cat,true); $cat_ids = array(); if ($cTree) { foreach ($cTree as $cc) { if (!empty($cc->id)) { $cat_ids[] = $cc->id; } } } if (count($cat_ids)) $cat_ids = implode(",", $cat_ids); $where .= " and ( a.cat IN (" . $cat_ids . ") )"; } } if ($user) { $where .= " AND userid=".$database->quote($user); } $database->setQuery("select a.* from #__bid_auctions a left join #__categories c on c.id=a.cat ".$where." order by id desc", 0, $limit); $rows = $database->loadObjectList(); for ($i = 0; $i < count($rows); $i++) { $auction = $rows[$i]; $item_link = JHtml::_('auctiondetails.auctionDetailsURL',$auction, false); // removes all formating from the intro text for the description text $item_description = $auction->description; $item_description = JFilterOutput::cleanText($item_description); $item_description = html_entity_decode($item_description); // load individual item creator class $item = new FeedItem(); // item info $item->title = $auction->title; $item->link = $item_link; $item->description = $item_description; $item->source = $rss->link; $item->date = date('r', strtotime($auction->start_date)); $database->setQuery( "select title from #__categories where id=".$database->quote($auction->cat) ); $item->category = $database->loadResult(); $rss->addItem($item); } echo $rss->createFeed($feed); }
private function buildQuery() { $user = JFactory::getUser(); $db = JFactory::getDBO(); $cfg = BidsHelperTools::getConfig(); $query = JTheFactoryDatabase::getQuery(); $query->from('#__bid_auctions','a'); //SELECTS $query->select('`a`.*'); $query->select('`a`.id AS auctionId'); //$query->select('`cat`.`id` as cati, `cat`.`catname`, `catsef`.`categories` as catslug'); $query->select('`cat`.`id` as cati, `cat`.`title` AS categoryname'); $query->select('`u`.`username`'); $query->select('GROUP_CONCAT(DISTINCT `t`.`id`) AS tagIds'); $query->select('GROUP_CONCAT(DISTINCT `t`.`tagname`) AS tagNames'); $query->select('GROUP_CONCAT(`pics`.`picture` ORDER BY `pics`.`ordering`) AS pictures'); $query->select('COUNT(DISTINCT bids.userid) AS nr_bidders'); $query->select( 'CASE a.auction_type WHEN '.AUCTION_TYPE_PUBLIC.' THEN MAX(bids.bid_price) WHEN '.AUCTION_TYPE_PRIVATE.' THEN a.initial_price WHEN '.AUCTION_TYPE_BIN_ONLY.' THEN a.bin_price END AS highest_bid' ); //NEXT ONE IS USED FOR PRICE RANGE SEARCHES $query->select( 'CASE a.auction_type WHEN ' . AUCTION_TYPE_PUBLIC . ' THEN IF(MAX(bids.bid_price)>0,MAX(bids.bid_price),a.initial_price) WHEN ' . AUCTION_TYPE_PRIVATE . ' THEN a.initial_price WHEN ' . AUCTION_TYPE_BIN_ONLY . ' THEN a.bin_price END AS current_price' ); $query->select('GROUP_CONCAT(IF(bids.userid='.$user->id.',bids.bid_price,NULL)) AS mybid'); $query->select('AVG(ru.rating) AS rating_overall'); $query->select('IF(ru.rate_type=\'auctioneer\',AVG(ru.rating),0) as rating_auctioneer'); $query->select('IF(ru.rate_type=\'bidder\',AVG(ru.rating),0) as rating_bidder'); if($cfg->bid_opt_quantity_enabled) { $query->select('bids.quantity AS nr_items'); } else { $query->select('1 AS nr_items'); } //JOINS $query->join('left','#__bids','bids','`bids`.`auction_id`=`a`.`id`'); $query->join('left','#__bid_rate','ru','ru.user_rated_id=`a`.`userid`'); $query->join('left','#__categories','cat','`a`.`cat`=`cat`.`id`'); $query->join('left','#__bid_tags','t','`a`.`id`=`t`.`auction_id`'); $query->join('left','#__bid_pictures','pics','`a`.`id`=`pics`.`auction_id`'); //WHERE conditions if ($user->id) { $query->select('IF ( `a`.`userid` = \'' . $user->id . '\', 1, 0 ) AS `isMyAuction`'); $query->select('IF ( `fav_table`.`id`>0, 1, 0 ) AS favorite'); } else { $query->select('0 AS `isMyAuction`'); $query->select('-1 AS `favorite`'); } if($this->getState('behavior')!='mywatchlist') { $query->join('left','#__bid_watchlist','fav_table','`fav_table`.`auction_id`=`a`.`id` AND `fav_table`.`userid`='.$user->id); } switch($this->getState('behavior')) { case 'myauctions': $query->where('`a`.`userid` = \'' . $user->id . '\''); switch ($this->getState('filters.filter_archive')) { case 'active': $query->where('`a`.`close_by_admin`=0'); $query->where('`a`.`close_offer`=0'); $query->where('`a`.`published`=1'); break; case 'unpublished': $query->where('`a`.`close_by_admin`=0'); $query->where('`a`.`close_offer`=0'); $query->where('`a`.`published`=0'); break; case 'archived': $query->where('`a`.`close_offer`=1'); break; case 'unsold': $query->where('`a`.`close_by_admin`=0'); $query->where('`a`.`close_offer`=1'); $query->where('`bids`.`accept`=0 OR `bids`.`accept` IS NULL'); break; case 'sold': $query->where('`a`.`close_by_admin`=0'); //auction_type=3 --> BIN Only with items sold $query->where('(`a`.`close_offer`=1 and `bids`.`accept`=1) OR (`a`.`auction_type`=3 and `a`.`quantity`<`a`.`nr_items`)'); break; case 'banned': $query->where('`a`.`close_by_admin`=1'); break; } $query->where(array('`cat`.`published`=1','`cat`.`published` IS NULL'),'OR'); if ($this->getState('filters.cat')) { if (!$cfg->bid_opt_inner_categories) { $query->where(" a.cat= '" . $db->escape($this->getState('filters.cat')) . "' "); } else { $catModel = BidsHelperTools::getCategoryModel(); $cTree = $catModel->getCategoryTree($this->getState('filters.cat'),false); $cat_ids = array(); if ($cTree) { foreach ($cTree as $cc) { if ($cc->id) $cat_ids[] = $cc->id; } } if (count($cat_ids)) { $cat_ids = implode(',', $cat_ids); } $query->where(' a.cat IN (' . $db->escape($cat_ids) . ') '); } } break; case 'mybids': //need a second join with table #__bids, for filtering purposes $query->join('left','#__bids','bids2','`bids2`.`auction_id`=`a`.`id`'); $query->where('`bids2`.`userid` = \'' . $user->id . '\''); //get my proxy $query->select('proxy.max_proxy_price AS my_proxy_bid'); $query->join('left','#__bid_proxy','proxy','`proxy`.`auction_id`=`a`.`id` AND `proxy`.`user_id`='.$user->id); $query->select('bids2.modified AS mybid_date'); switch ($this->getState('filters.filter_bidtype')) { default: case 0: $query->where('`a`.`close_offer`=0'); $query->where('`a`.`close_by_admin`=0'); break; case 1: $query->where('`a`.`close_by_admin`=0'); $query->where('`a`.`close_offer`=1'); break; } break; case 'mywonbids': $query->where('`bids`.`userid`='.intval($user->id)); $query->where('`bids`.`accept`=1'); break; case 'mywatchlist': $query->join('inner','#__bid_watchlist','fav_table','`fav_table`.`auction_id`=`a`.`id` AND `fav_table`.`userid`='.intval($user->id)); break; case 'listauctions': $query->where('`a`.`close_by_admin`=0'); switch ($this->getState('filters.filter_type')) { default: case 'all': //nothing break; case 'auctions_only': $query->where('a.BIN_price<=0'); break; case 'bin_only': $query->where('a.BIN_price>0'); break; } if (!$this->getState('filters.inarch')) { $query->where('`a`.`published`=1'); $query->where('a.close_offer=0'); } if ($this->getState('filters.keyword')) { $keyword = $db->escape($this->getState('filters.keyword')); $w = array(); $w[] = 'a.title LIKE \'%' . $keyword . '%\''; if ($this->getState('filters.indesc')) { $w[] = 'a.shortdescription LIKE \'%' . $keyword . '%\''; $w[] = 'a.description LIKE \'%' . $keyword . '%\''; } $query->where($w,'OR'); } if ($this->getState('filters.userid')) { $query->where(" a.userid = '" . $db->escape($this->getState('filters.userid')) . "' "); } $users = (array) $this->getState('filters.users'); $users = array_filter($users); foreach ($users as $k => $u) { $users[$k] = intval($u); if (!$users[$k]) { unset($users[$k]); } } if (count($users)) { $query->where(' a.userid IN (' . $db->escape(implode(',', $users)) . ') '); } $username = $this->getState('filters.username'); if( !empty($username) ) { $query->where(' u.username LIKE \'%' . $db->escape($username) . '%\' '); } if ( $this->getState('filters.tagnames') ) { $query->join('left','#__bid_tags','search_tagname2','`a`.`id`=`search_tagname2`.`auction_id`'); $query->where(' search_tagname2.tagname LIKE \'%' . $db->escape($this->getState('filters.keyword')) . '%\' '); } if ($this->getState('filters.tagid')) { $query->join('left','#__bid_tags','search_tagid','`a`.`id`=`search_tagid`.`auction_id`'); $query->join('left','#__bid_tags','search_tagname','`search_tagid`.`tagname`=`search_tagname`.`tagname`'); $query->where(" search_tagname.id='" . $db->escape($this->getState('filters.tagid')) . "'"); } if ($this->getState('filters.auction_nr')) { $query->where(" a.auction_nr ='" . $db->escape($this->getState('filters.auction_nr')) . "' "); } $query->where(array('`cat`.`published`=1','`cat`.`published` IS NULL'),'OR'); if ($this->getState('filters.cat')) { if (!$cfg->bid_opt_inner_categories) { $query->where(" a.cat= '" . $db->escape($this->getState('filters.cat')) . "' "); } else { $catModel = BidsHelperTools::getCategoryModel(); $cTree=$catModel->getCategoryTree($this->getState('filters.cat'),false); $cat_ids = array(); if ($cTree) { foreach ($cTree as $cc) { if ($cc->id) $cat_ids[] = $cc->id; } } if (count($cat_ids)) { $cat_ids = implode(',', $cat_ids); $query->where(' a.cat IN (' . $db->escape($cat_ids) . ') '); } } } if ($this->getState('filters.afterd')) { $query->where(' a.start_date>=\'' . $db->escape($this->getState('filters.afterd')) . '\''); } elseif(!$this->getState('filters.inarch')) { $query->where(' a.start_date<=UTC_TIMESTAMP()'); } if ($this->getState('filters.befored')) { $query->where('a.end_date<=\'' . $db->escape($this->getState('filters.befored')) . '\''); } elseif(!$this->getState('filters.inarch')) { $query->where(' a.end_date>=UTC_TIMESTAMP()'); } if($this->getState('filters.currency')) { $q = $db->getQuery(true); $q->select( '`name`,`convert`' ) ->from( '#__bid_currency' ) ; $db->setQuery($q); $currencies = $db->loadAssocList('name'); if(isset($currencies[$this->getState('filters.currency')])) { $query->select('curr.convert AS auctionCurrencyConversionRate'); $query->join('left','#__bid_currency','curr','a.currency=curr.name'); $this->_searchWithCurrency = true; $searchCurrencyConversionRate = $currencies[$this->getState('filters.currency')]['convert']; if ($this->getState('filters.startprice')) { $query->having( 'current_price>=('.$searchCurrencyConversionRate.'/COALESCE (auctionCurrencyConversionRate,1))*' . $db->escape($this->getState('filters.startprice')) . ' ' ); } if ($this->getState('filters.endprice')) { $query->having( 'current_price<=(' . $searchCurrencyConversionRate . '/COALESCE (auctionCurrencyConversionRate,1))*' . $db->escape($this->getState('filters.endprice')) . ' ' ); } } } if($user->id) { $query->select('1-MIN(msg.wasread) AS nrNewMessages'); $query->join('left','#__bid_messages','msg', 'a.id=msg.auction_id AND msg.userid2='.$user->id); } break; } // Featurings first if($this->getState('behavior')=='mywatchlist') { $query->order('`a`.`end_date` ASC'); } else { $query->order('`a`.`featured`=\'featured\' DESC'); $query->order('`a`.`featured`=\'none\' DESC'); } // Required ordering filter $filter_order = (string) $this->getState('filters.filter_order'); if ($filter_order) { $filter_order_Dir = $this->getState('filters.filter_order_Dir'); $query->order( $db->escape($this->order_fields[$filter_order] . ' ' . $filter_order_Dir ) ); } else { $query->order('`a`.`end_date` ASC'); } $query->group('`a`.`id`'); $profile = BidsHelperTools::getUserProfileObject(); $additionalFields = array('paypalemail'); //this binds to the query object everything that is related to custom fields parent::buildCustomQuery($query,$profile,'`a`.`userid`',$additionalFields); return $query; }