/** * Function is responsible for listing the ALL of the products from * the database without querying for any categories. * * @return unknown|string */ function getAllServices() { $db =& $this->getDBO(); $db->resetTree(); $db->setTree('SELECT', '`' . $this->_tbl . '`.*'); $db->setTree('FROM', '`#__rel_serv_cca`'); $db->setTree('INNER JOIN', '`' . $this->_tbl . '` ON `#__rel_serv_cca`.bizid=' . $this->_tbl . '.bizid'); $db->setTree('WHERE', '`#__rel_serv_cca`.catid = ' . $db->Quote('108')); if (BRequest::getCmd('p', false) == 'h' && BRequest::getCmd('s', false) == 'r' && BRequest::getCmd('r', false) == 'o') { $db->setTree('ORDER BY', '`' . $this->_tbl . '`.`price` DESC'); } elseif (BRequest::getCmd('p', false) == 'l' && BRequest::getCmd('s', false) == 'r' && BRequest::getCmd('r', false) == 'o') { $db->setTree('ORDER BY', "`{$this->_tbl}`.`price` ASC"); } elseif (BRequest::getCmd('s', false) == 'l' && BRequest::getCmd('r', false) == 'o') { //@todo doesn't work as expected $db->setTree('SELECT', "sum((`likes`.`like`)) AS `tlikes`"); $db->setTree('LEFT JOIN', "`likes` ON `{$this->_tbl}`.`id` = `likes`.`itemid`"); $db->setTree('ORDER BY', "tlikes ASC"); } elseif (BRequest::getCmd('s', false) == 'r' && BRequest::getCmd('r', false) == 'n') { $db->setTree('ORDER BY', "`{$this->_tbl}`.`dateAdded` DESC"); } elseif (BRequest::getCmd('s', false) == 'r' && BRequest::getCmd('r', false) == 'o') { $db->setTree('ORDER BY', "`{$this->_tbl}`.`dateAdded` ASC"); } elseif (BRequest::getCmd('s', false) == 'r') { //@todo doesn't work as expected $db->setTree('SELECT', "sum((`ratings`.`like`)) AS `ratingsum`"); $db->setTree('LEFT JOIN', "`ratings` ON `{$this->_tbl}`.`id` = `ratings`.`itemid`"); $db->setTree('ORDER BY', "ratingsum ASC"); } //default ordering if (empty($sql['ORDER BY'])) { $db->setTree('ORDER BY', "`{$this->_tbl}`.dateAdded ASC"); } $per_page = config('products.per_page'); $db->setTree('LIMIT', $per_page); if ($offset = (BRequest::getInt('ppage', 1) - 1) * $per_page) { $db->setTree('OFFSET', $offset); } $q = $db->queryTree(); //echo _520($q); if ($results = $db->loadList($this->_tbl_key, $this->_type)) { return $results; } return false; }
$ratings_newest = BRequest::getVar('s') == 'r' && BRequest::getVar('r') == 'n' ? 'active' : ''; $ratings_oldest = BRequest::getVar('s') == 'r' && BRequest::getVar('r') == 'o' && !BRequest::getVar('p', false) ? 'active' : ''; $ratings_rating = BRequest::getVar('s') == 'r' && !BRequest::getVar('r', false) ? 'active' : ''; $ratings_like = BRequest::getVar('s') == 'l' && BRequest::getVar('r') == 'o' ? 'active' : ''; $hight_low = BRequest::getVar('p') == 'h' && BRequest::getVar('s') == 'r' && BRequest::getVar('r') == 'o' ? 'active' : ''; $querystring = array(); $querystring['s'] = BRequest::getVar('s'); $querystring['p'] = BRequest::getVar('p'); $querystring['r'] = BRequest::getVar('r'); $parts = explode('?', $_SERVER['REQUEST_URI']); $uri = $parts[0]; ?> <div class="index_filters"> <div style="width:80px;height:30px;position:relative;float:left;"> </div> <div class="filters_buttons"> <div class="filter_button fbl"><a href="<?php $querystring['ppage'] = BRequest::getInt('ppage') - 1; echo Router::normalize($uri, $querystring); ?> ">Previous</a></div> <div class="filter_button fbr"><a href="<?php $querystring['ppage'] = BRequest::getInt('ppage') + 1; echo Router::normalize($uri, $querystring); ?> ">Next</a></div> </div> </div>
function get_services($nrpp) { // START INIT VARS \\ global $path_site; $return = NULL; $append_url = NULL; $list = NULL; $page = (BRequest::getVar('spage') and preg_match('/^[0-9]{1,999}$/i', BRequest::getVar('spage'))) ? BRequest::getInt('spage') : 1; // $_REQUEST['s'] = sort and value=r is ratings, value=l is likes if (BRequest::getVar('s') == 'r') { $SORT = ", avg(r.`rating`) desc"; $append_url .= '&s=r'; } else { if (BRequest::getVar('s') == 'l') { $SORT = ", sum(l.`like`) desc"; $append_url .= '&s=l'; } else { $SORT = NULL; } } // $_REQUEST['r'] = release and value=n is latest to oldest released, value=o is oldest to newest if (BRequest::getVar('r') == 'n') { $RELEASE = ",b.dateCreated desc"; $append_url .= '&r=n'; } else { if (BRequest::getVar('r') == 'o') { $RELEASE = ",b.dateCreated asc"; $append_url .= '&r=o'; } else { $RELEASE = NULL; } } // RANDOM TRIGGER IF NO SORTING SET $RAND = NULL; if (empty($SORT) && empty($RELEASE)) { $RAND = 'RAND()'; } else { if (!empty($SORT)) { $SORT = substr($SORT, 1); } else { if (!empty($RELEASE)) { $RELEASE = substr($RELEASE, 1); } } } $startof = $page * $nrpp - $nrpp + 1; $endof = $page * $nrpp; $append_url = isset($_SESSION['category']) ? $append_url . '&category=' . urlencode($_SESSION['category']) : $append_url; $append_url = isset($_SESSION['collection']) ? $append_url . '&collection=' . urlencode($_SESSION['collection']) : $append_url; $append_url = isset($_SESSION['asssortment']) ? $append_url . '&asssortment=' . urlencode($_SESSION['asssortment']) : $append_url; $append_url = BRequest::getVar('ppage', false) ? $append_url . '&ppage=' . BRequest::getVar('ppage') : $append_url; // END INIT VARS \\ // GO if (isset($_SESSION['assortment'])) { $catid = 108; $colid = get_colid_from_name(html_entity_decode(urldecode($_SESSION['collection']))); $asstid = get_asstid_from_name(html_entity_decode(urldecode($_SESSION['assortment']))); $cacid = get_cacid($catid, $colid); $ccaid = get_ccaid($cacid, $asstid); $query = "select b.id as id,b.name as name,b.flag_SS as type,b.urlPM as url,b.desc as `desc`, i.filepath as fp, i.file as f, avg(r.`rating`) as rating from rel_serv_cca rscca\n\t\t\t\t\t\tjoin business b on rscca.bizid=b.id\n\t\t\t\t\t\tleft join images i on b.id = i.itemid\n\t\t\t\t\t\tleft join likes l on b.id=l.itemid\n\t\t\t\t\t\tleft join ratings r on b.id=r.itemid\n\t\t\t\t\t\t\twhere i.item='businessicon' and b.status='active' and b.flag_feat='1' and rscca.catid='108' and rscca.cacid='" . $cacid . "' and rscca.ccaid='" . $ccaid . "'\n\t\t\t\t\t\t\t\tgroup by b.id\n\t\t\t\t\t\t\t\torder by " . $RAND . $SORT . $RELEASE; } else { if (isset($_SESSION['collection'])) { $catid = 108; $colid = get_colid_from_name(html_entity_decode(urldecode($_SESSION['collection']))); $cacid = get_cacid($catid, $colid); $query = "select b.id as id,b.name as name,b.flag_SS as type,b.urlPM as url,b.desc as `desc`, i.filepath as fp, i.file as f, avg(r.`rating`) as rating from rel_serv_cca rscca\n\t\t\t\t\t\tjoin business b on rscca.bizid=b.id\n\t\t\t\t\t\tleft join images i on b.id = i.itemid\n\t\t\t\t\t\tleft join likes l on b.id=l.itemid\n\t\t\t\t\t\tleft join ratings r on b.id=r.itemid\n\t\t\t\t\t\t\twhere i.item='businessicon' and b.status='active' and b.flag_feat='1' and rscca.catid='108' and rscca.cacid='" . $cacid . "'\n\t\t\t\t\t\t\t\tgroup by b.id\n\t\t\t\t\t\t\t\torder by " . $RAND . $SORT . $RELEASE; } else { $query = "select b.id as id,b.name as name,b.flag_SS as type,b.urlPM as url,b.desc as `desc`, i.filepath as fp, i.file as f, avg(r.`rating`) as rating from rel_serv_cca rscca\n\t\t\t\t\t\tjoin business b on rscca.bizid=b.id\n\t\t\t\t\t\tleft join images i on b.id = i.itemid\n\t\t\t\t\t\tleft join likes l on b.id=l.itemid\n\t\t\t\t\t\tleft join ratings r on b.id=r.itemid\n\t\t\t\t\t\t\twhere i.item='businessicon' and b.status='active' and b.flag_feat='1' and rscca.catid='108'\n\t\t\t\t\t\t\t\tgroup by b.id\n\t\t\t\t\t\t\t\torder by " . $RAND . $SORT . $RELEASE; } } //CACHING SEARCH RESULTS FOR THE LAST 30 MINUTES OF SESSION if (!isset($_SESSION['indexServData'][$query]) || $_SESSION['indexServData'][$query]['time'] < time() - 30 * 60) { $result = mysql_query($query) or die(mysql_error()); $_SESSION['indexServData'][$query]['time'] = time(); $_SESSION['indexServData'][$query]['count'] = mysql_num_rows($result); $i = 0; if ($_SESSION['indexServData'][$query]['count'] > 0) { while ($row = mysql_fetch_assoc($result)) { $_SESSION['indexServData'][$query]['data'][$i] = $row; $i++; } } else { $_SESSION['indexServData'][$query]['data'] = NULL; } } $data = $_SESSION['indexServData'][$query]['data']; if (!empty($data)) { $count_total = $_SESSION['indexServData'][$query]['count']; $num_pages = ceil($count_total / $nrpp); $prev = $page > 1 ? '<a href="' . SITE_BASEURL . 'index.php?spage=' . ($page - 1) . $append_url . '">« previous</a>' : NULL; $next = $page < $num_pages ? '<a href="' . SITE_BASEURL . 'index.php?spage=' . ($page + 1) . $append_url . '">next »</a>' : NULL; $pn_divide = (!empty($prev) and !empty($next)) ? ' | ' : NULL; if ($page > 1) { $y = ($page - 1) * $nrpp; $z = $page * $nrpp; } else { $y = 0; $z = $nrpp; } while ($y < $z) { if (isset($data[$y]['name'])) { $seoPhrase = preg_replace('/[[:punct:]]*/i', '', stripslashes($data[$y]['name'])); $seoPhrase = preg_replace('/[[:space:]]+/i', '-', $seoPhrase); $seoPhrase = preg_replace('/-{0,1}$/i', '', $seoPhrase); $margin = !(1 & $y) ? '6px' : 0; $rating = round($data[$y]['rating'], 0); $ratings = compile_rating($data[$y]['id'], $rating); $list .= replace_hh('HH-PM-INDEX-SERV1', array('path_site' => SITE_BASEURL, 'alt' => stripslashes($data[$y]['name']), 'title' => truncate_hard(stripslashes($data[$y]['name']), 26), 'desc' => truncate(strip_tags(stripslashes($data[$y]['desc'])), 42), 'image_src' => SITE_BASEURL . $data[$y]['fp'] . $data[$y]['f'], 'margin' => $margin, 'rating' => $ratings, 'serv_href' => SITE_BASEURL . $data[$y]['url'] . '/' . $seoPhrase)); } $y++; } $header_text = BRequest::getVar('category', false, 'session') == 'services' ? 'featured services' : 'services'; $endof = $count_total < $endof ? $count_total : $endof; $return = replace_output(file_get_contents($path_site . 'inc/cb/indexServices.inc'), array('start' => $startof, 'end' => $endof, 'headertxt' => $header_text, 'total' => $count_total, 'prevnext' => $prev . $pn_divide . $next, 'services' => $list)); } else { $return = '<div class="services_box" style="width:320px; padding:20px;">' . ERROR_MS_SERV1 . '</div>'; } return $return; }