コード例 #1
0
 /**
  * Loads a row from the database and binds the fields to the object properties
  *
  * @access	public
  * @param	mixed	Optional primary key.  If not specifed, the value of current key is used
  * @return	boolean	True if successful
  */
 function loadByParents($parentCat = null, $parentCol = null)
 {
     $category = FiveTable::getInstance('categories');
     $category->loadByName($parentCat);
     $collection = FiveTable::getInstance('collections');
     $collection->loadByParentAndName($parentCat, $parentCol);
     $cacid = get_cacid($category->id, $collection->id);
     $this->reset();
     $db =& $this->getDBO();
     $query = "select `" . $this->_tbl . "`.* from rel_cac_assts rca \n\t\t\t\t\tjoin rel_cats_cols rcac on rca.cacid=rcac.id \n\t\t\t\t\tleft join categories cat on rcac.catid=cat.id\n\t\t\t\t\tleft join collections col on rcac.colid=col.id\n\n\t\t\t\t\tleft join assortments on rca.asstid = `" . $this->_tbl . "`.id\n\t\t\t\t\t\twhere rca.cacid='" . $cacid . "'\n\t\t\t\t\t\torder by `" . $this->_tbl . "`.sortOrder asc, `" . $this->_tbl . "`.name asc";
     $db->setQuery($query);
     if ($result = $db->loadList($this->_tbl_key, $this->_type)) {
         return $result;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
コード例 #2
0
ファイル: main.php プロジェクト: Jonathonbyrd/5TwentyCMS
 function get_services_main($nrpp)
 {
     // START INIT VARS \\
     global $path_site;
     $return = NULL;
     $append_url = NULL;
     $list = NULL;
     $page = (BRequest::getVar('smpage', false) and preg_match('/^[0-9]{1,999}$/i', BRequest::getVar('smpage'))) ? BRequest::getVar('smpage') : 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('spage', false) ? $append_url . '&spage=' . BRequest::getVar('spage') : $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 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 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 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['indexServmainData'][$query]) || $_SESSION['indexServmainData'][$query]['time'] < time() - 30 * 60) {
         $result = mysql_query($query) or die(mysql_error());
         $_SESSION['indexServmainData'][$query]['time'] = time();
         $_SESSION['indexServmainData'][$query]['count'] = mysql_num_rows($result);
         $i = 0;
         if ($_SESSION['indexServmainData'][$query]['count'] > 0) {
             while ($row = mysql_fetch_assoc($result)) {
                 $_SESSION['indexServmainData'][$query]['data'][$i] = $row;
                 $i++;
             }
         } else {
             $_SESSION['indexServmainData'][$query]['data'] = NULL;
         }
     }
     $data = $_SESSION['indexServmainData'][$query]['data'];
     if (!empty($data)) {
         $count_total = $_SESSION['indexServmainData'][$query]['count'];
         $num_pages = ceil($count_total / $nrpp);
         $prev = $page > 1 ? '<a href="' . SITE_BASEURL . 'index.php?spage=' . ($page - 1) . $append_url . '">&laquo; previous</a>' : NULL;
         $next = $page < $num_pages ? '<a href="' . SITE_BASEURL . 'index.php?spage=' . ($page + 1) . $append_url . '">next &raquo;</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);
                 $rating = round($data[$y]['rating'], 0);
                 $ratings = compile_rating($data[$y]['id'], $rating);
                 $list .= replace_hh('HH-PM-INDEX-SERV2', array('path_site' => SITE_BASEURL, 'alt' => stripslashes($data[$y]['name']), 'title' => truncate_hard(stripslashes($data[$y]['name']), 30), 'desc' => truncate(strip_tags(stripslashes($data[$y]['desc'])), 100), 'image_src' => SITE_BASEURL . $data[$y]['fp'] . $data[$y]['f'], 'serv_href' => SITE_BASEURL . $data[$y]['url'] . '/' . $seoPhrase));
             }
             $y++;
         }
         $endof = $count_total < $endof ? $count_total : $endof;
         $return = replace_output(file_get_contents($path_site . 'inc/cb/indexServicesMain.inc'), array('start' => $startof, 'end' => $endof, 'total' => $count_total, 'prevnext' => $prev . $pn_divide . $next, 'services' => $list));
     } else {
         $return = '<div class="services_box" style="width:440px; padding:20px;">' . ERROR_MS_SERV1 . '</div>';
     }
     return $return;
 }
コード例 #3
0
ファイル: products.php プロジェクト: Jonathonbyrd/5TwentyCMS
 /**
  * get collections products
  * 
  * @param unknown_type $catName
  * @param unknown_type $colName
  * @return unknown|string
  */
 function getCollectionProducts($catName = null, $colName = null)
 {
     $category = FiveTable::getInstance('categories');
     $category->loadByName(urldecode($catName));
     $collection = FiveTable::getInstance('collections');
     $collection->loadByParentAndName(urldecode($catName), urldecode($colName));
     $cacid = get_cacid($category->id, $collection->id);
     //echo _520($collection);
     $db =& $this->getDBO();
     $db->resetTree();
     $db->setTree('SELECT', '`' . $this->_tbl . '`.*');
     $db->setTree('FROM', '`#__rel_prod_cca`');
     $db->setTree('INNER JOIN', '`' . $this->_tbl . '` ON `#__rel_prod_cca`.prodid=' . $this->_tbl . '.id');
     $db->setTree('WHERE', '`' . $this->_tbl . '`.`status`=' . $db->Quote('active'));
     $db->setTree('WHERE', '`#__rel_prod_cca`.cacid = ' . $db->Quote($cacid));
     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', "`prod_name` 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();
     if ($results = $db->loadList($this->_tbl_key, $this->_type)) {
         return $results;
     }
     return false;
 }