Exemplo n.º 1
0
 function BuildForm()
 {
     Form::Form('BuildForm');
     CGlobal::$website_title = "Xây dựng cấu hình máy tính";
     if (Build::$bcatid) {
         $this->filter_get = Url::get('filter');
         AZLib::getFilters();
         if (isset(CGlobal::$filters[Build::$bcatid])) {
             $this->filter_groups = CGlobal::$filters[Build::$bcatid];
         }
         #############################################################################################################################################
         #Search condition
         CGlobal::$item_condition = "category_id = " . Build::$bcatid . " AND quantity>0 AND status = 1 AND price>0 AND quantity>0";
         //CGlobal::$item_condition .="status = 1 AND filter_ids != ''";
         $filter_str = '';
         if (isset(CGlobal::$filters[Build::$bcatid])) {
             $this->filter_groups = CGlobal::$filters[Build::$bcatid];
             $filter_get = $this->filter_get;
             $this->filter_get = array();
             if ($this->filter_groups) {
                 foreach ($this->filter_groups as $fgid => $gfilter) {
                     if ($filter_get && isset($filter_get[$fgid]) && $filter_get[$fgid]) {
                         $fid = $filter_get[$fgid];
                         if ($gfilter['filters'] && in_array($fid, array_keys($gfilter['filters']))) {
                             CGlobal::$no_paging = true;
                             $this->filter_get[$fgid] = $fid;
                             $filter_str .= ($filter_str == '' ? '+' : ' +') . "g{$fgid}f{$fid}f";
                         }
                     }
                 }
             }
         }
         $price_str = CGlobal::$allCategories[Build::$bcatid]['price_str'];
         if ($price_str) {
             $filter_price = array();
             $arr = explode(',', $price_str);
             $link = AZRewrite::formatUrl(Url::build_all(array('min', 'max', 'filter', 'page_no')));
             if ($this->filter_get) {
                 foreach ($this->filter_get as $get_gid => $get_fid) {
                     $link .= "&filter[{$get_gid}]={$get_fid}";
                 }
             }
             //SELECT 	SUM((price < 2000000 AND currency_id=1) OR ((price* 18000)< 200000 AND currency_id=2)) AS filter,
             //SUM((price >= 2000000 AND price< 5000000  AND currency_id=1) OR ((price* 18000) >= 200000 AND (price* 18000) < 500000 AND currency_id=2)) AS filter
             //FROM products
             $last_price = 0;
             $get_min = (int) Url::get('min', 0);
             $get_max = (int) Url::get('max', 0);
             $i = 1;
             foreach ($arr as $price) {
                 if ($last_price == 0) {
                     $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . " SUM((price < {$price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") < {$price} AND currency_id=2)) AS `0`";
                 } else {
                     $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . " SUM((price >= {$last_price} AND price < {$price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= {$last_price} AND (price * " . CGlobal::$exchange . ") < {$price} AND currency_id=2)) AS `{$last_price}`";
                 }
                 if ($get_min == $last_price && $get_max == $price) {
                     $this->min = $get_min;
                     $this->max = $get_max;
                 }
                 $filter_price[] = array('min' => $last_price, 'max' => $price);
                 $last_price = $price;
                 $i++;
             }
             if ($last_price) {
                 if ($get_min == $last_price && $get_max == 0) {
                     $this->min = $get_min;
                     $this->max = 0;
                 }
                 $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . "SUM((price >= {$last_price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= {$last_price} AND currency_id=2)) AS `{$last_price}`";
                 $filter_price[] = array('min' => $last_price, 'max' => 0);
                 $last_price = $price;
             }
             if ($this->min) {
                 CGlobal::$item_condition .= " AND ((price >= " . $this->min . " AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= " . $this->min . " AND currency_id=2))";
             }
             if ($this->max) {
                 CGlobal::$item_condition .= " AND ((price < " . $this->max . " AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") < " . $this->max . " AND currency_id=2))";
             }
         }
         if ($filter_str) {
             CGlobal::$item_condition .= " AND MATCH(filter_search) AGAINST ('{$filter_str}' IN BOOLEAN MODE)";
         }
         #############################################################################################################################################
         if ($this->price_cout_str) {
             $this->filter_price = array('name' => "Giới hạn theo giá (VNĐ)", 'filters' => array());
             $price_cout_arr = DB::fetch("SELECT " . $this->price_cout_str . " FROM item WHERE " . CGlobal::$item_condition);
             if ($filter_price) {
                 foreach ($filter_price as $fprice) {
                     $min = $fprice['min'];
                     $max = $fprice['max'];
                     if ($price_cout_arr[$min]) {
                         if ($min && $max) {
                             $link2 = "{$link}&min={$min}&max={$max}";
                             $name = AZLib::money($min) . " - " . AZLib::money($max);
                         } elseif (!$max) {
                             $link2 = "{$link}&min={$min}";
                             $name = "Trên " . AZLib::money($min);
                         } elseif (!$min) {
                             $link2 = "{$link}&max={$max}";
                             $name = "Dưới " . AZLib::money($max);
                         }
                         if ($this->min == $min && $this->max == $max) {
                             $this->filter_price['filters'][] = array('link' => $link, 'name' => $name, 'count' => $price_cout_arr[$min], 'remove' => 1);
                         } else {
                             $this->filter_price['filters'][] = array('link' => $link2, 'name' => $name, 'count' => $price_cout_arr[$min], 'remove' => 0);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 function __construct()
 {
     Form::Form('FilterMenuSearchForm');
     $this->filter_get = Url::get('filter');
     $this->search_catid = (int) Url::get('search_catid', -1);
     if ($this->search_catid <= 0 || !isset(CGlobal::$allCategories[$this->search_catid]) || CGlobal::$allCategories[$this->search_catid]['status'] == 'HIDE') {
         $this->search_catid = 0;
     }
     $keywords = AZLib::getParam('keywords');
     if ($this->search_catid && $keywords != '') {
         if (isset(CGlobal::$filters[$this->search_catid])) {
             $this->filter_groups = CGlobal::$filters[$this->search_catid];
         }
         $curCategory = CGlobal::$allCategories[$this->search_catid];
         if ($curCategory['parent_id'] && isset(CGlobal::$allCategories[$curCategory['parent_id']])) {
             $parent_cat = CGlobal::$allCategories[$curCategory['parent_id']];
             $this->search_top_catid = $curCategory['parent_id'];
             $this->search_sec_catid = $this->search_catid;
         } else {
             $this->search_top_catid = $this->search_catid;
         }
         #############################################################################################################################################
         #Search condition
         if ($this->search_sec_catid) {
             CGlobal::$item_condition = "level_2_catid = " . $this->search_sec_catid . " AND ";
         } elseif ($this->search_top_catid) {
             CGlobal::$item_condition = "level_1_catid = " . $this->search_top_catid . " AND ";
         }
         CGlobal::$item_condition .= "status = 1";
         //CGlobal::$item_condition .="status = 1 AND filter_ids != ''";
         $arr = explode(' ', $keywords);
         if ($arr) {
             $keywords = '';
             foreach ($arr as $keyword) {
                 if (trim($keyword) != '') {
                     $keywords .= ($keywords == '' ? '+' : ' +') . trim($keyword);
                 }
             }
         }
         //CGlobal::$item_condition .= ' AND MATCH(name, list_brief, brief, description) AGAINST (\'*'.$keywords.'*\' IN BOOLEAN MODE)  HAVING relevance > 0.2';
         //CGlobal::$item_condition .= " AND MATCH(name) AGAINST ('*$keywords*' IN BOOLEAN MODE)";
         CGlobal::$item_condition .= " AND MATCH(name, list_brief, brief, description) AGAINST ('{$keywords}' IN BOOLEAN MODE)";
         $filter_get = $this->filter_get;
         $this->filter_get = array();
         $filter_str = '';
         if ($this->filter_groups) {
             foreach ($this->filter_groups as $fgid => $gfilter) {
                 if ($filter_get && isset($filter_get[$fgid]) && $filter_get[$fgid]) {
                     $fid = $filter_get[$fgid];
                     if ($gfilter['filters'] && in_array($fid, array_keys($gfilter['filters']))) {
                         CGlobal::$no_paging = true;
                         $this->filter_get[$fgid] = $fid;
                         $filter_str .= ($filter_str == '' ? '+' : ' +') . "g{$fgid}f{$fid}f";
                     }
                 }
             }
         }
         $price_str = CGlobal::$allCategories[$this->search_catid]['price_str'];
         if ($price_str) {
             $filter_price = array();
             $arr = explode(',', $price_str);
             $link = Url::build_all(array('filter', 'max', 'min'));
             if ($this->filter_get) {
                 foreach ($this->filter_get as $get_gid => $get_fid) {
                     $link .= "&filter[{$get_gid}]={$get_fid}";
                 }
             }
             //SELECT 	SUM((price < 2000000 AND currency_id=1) OR ((price* 18000)< 200000 AND currency_id=2)) AS filter,
             //SUM((price >= 2000000 AND price< 5000000  AND currency_id=1) OR ((price* 18000) >= 200000 AND (price* 18000) < 500000 AND currency_id=2)) AS filter
             //FROM products
             $last_price = 0;
             $get_min = (int) Url::get('min', 0);
             $get_max = (int) Url::get('max', 0);
             $i = 1;
             foreach ($arr as $price) {
                 if ($last_price == 0) {
                     $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . " SUM((price < {$price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") < {$price} AND currency_id=2)) AS `0`";
                 } else {
                     $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . " SUM((price >= {$last_price} AND price < {$price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= {$last_price} AND (price * " . CGlobal::$exchange . ") < {$price} AND currency_id=2)) AS `{$last_price}`";
                 }
                 if ($get_min == $last_price && $get_max == $price) {
                     $this->min = $get_min;
                     $this->max = $get_max;
                 }
                 $filter_price[] = array('min' => $last_price, 'max' => $price);
                 $last_price = $price;
                 $i++;
             }
             if ($last_price) {
                 if ($get_min == $last_price && $get_max == 0) {
                     $this->min = $get_min;
                     $this->max = 0;
                 }
                 $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . "SUM((price >= {$last_price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= {$last_price} AND currency_id=2)) AS `{$last_price}`";
                 $filter_price[] = array('min' => $last_price, 'max' => 0);
                 $last_price = $price;
             }
             if ($this->min) {
                 CGlobal::$item_condition .= " AND ((price >= " . $this->min . " AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= " . $this->min . " AND currency_id=2))";
             }
             if ($this->max) {
                 CGlobal::$item_condition .= " AND ((price < " . $this->max . " AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") < " . $this->max . " AND currency_id=2))";
             }
         }
         if ($filter_str) {
             CGlobal::$item_condition .= " AND MATCH(filter_search) AGAINST ('{$filter_str}' IN BOOLEAN MODE)";
         }
         #############################################################################################################################################
         if ($this->price_cout_str) {
             $this->filter_price = array('name' => "Giới hạn theo giá (VNĐ)", 'filters' => array());
             $price_cout_arr = DB::fetch("SELECT " . $this->price_cout_str . " FROM item WHERE " . CGlobal::$item_condition);
             if ($filter_price) {
                 foreach ($filter_price as $fprice) {
                     $min = $fprice['min'];
                     $max = $fprice['max'];
                     if ($price_cout_arr[$min]) {
                         if ($min && $max) {
                             $link2 = "{$link}&min={$min}&max={$max}";
                             $name = AZLib::money($min) . " - " . AZLib::money($max);
                         } elseif (!$max) {
                             $link2 = "{$link}&min={$min}";
                             $name = "Trên " . AZLib::money($min);
                         } elseif (!$min) {
                             $link2 = "{$link}&max={$max}";
                             $name = "Dưới " . AZLib::money($max);
                         }
                         if ($this->min == $min && $this->max == $max) {
                             $this->filter_price['filters'][] = array('link' => $link, 'name' => $name, 'count' => $price_cout_arr[$min], 'remove' => 1);
                         } else {
                             $this->filter_price['filters'][] = array('link' => $link2, 'name' => $name, 'count' => $price_cout_arr[$min], 'remove' => 0);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 function __construct()
 {
     Form::Form('FilterMenuForm');
     $this->filter_get = Url::get('filter');
     if (CGlobal::$curCategory && isset(CGlobal::$filters[CGlobal::$curCategory])) {
         $this->filter_groups = CGlobal::$filters[CGlobal::$curCategory];
     }
     #############################################################################################################################################
     #Search condition
     if (CGlobal::$curLevel2Cat) {
         CGlobal::$item_condition = "level_2_catid = " . CGlobal::$curLevel2Cat['id'] . " AND ";
     } elseif (CGlobal::$curMainCat) {
         CGlobal::$item_condition = "level_1_catid = " . CGlobal::$curMainCat['id'] . " AND ";
     }
     CGlobal::$item_condition .= "status = 1";
     //CGlobal::$item_condition .="status = 1 AND filter_ids != ''";
     $filter_get = $this->filter_get;
     $this->filter_get = array();
     $filter_str = '';
     if ($this->filter_groups) {
         foreach ($this->filter_groups as $fgid => $gfilter) {
             if ($filter_get && isset($filter_get[$fgid]) && $filter_get[$fgid]) {
                 $fid = $filter_get[$fgid];
                 if ($gfilter['filters'] && in_array($fid, array_keys($gfilter['filters']))) {
                     CGlobal::$no_paging = true;
                     $this->filter_get[$fgid] = $fid;
                     $filter_str .= ($filter_str == '' ? '+' : ' +') . "g{$fgid}f{$fid}f";
                 }
             }
         }
     }
     if (CGlobal::$curCategory && isset(CGlobal::$allCategories[CGlobal::$curCategory])) {
         $price_str = CGlobal::$allCategories[CGlobal::$curCategory]['price_str'];
         if ($price_str) {
             $filter_price = array();
             $arr = explode(',', $price_str);
             $link = WEB_DIR . "c" . CGlobal::$curCategory . "/" . Url::get('ebname');
             if ($this->filter_get) {
                 foreach ($this->filter_get as $get_gid => $get_fid) {
                     $link .= "&filter[{$get_gid}]={$get_fid}";
                 }
             }
             //SELECT 	SUM((price < 2000000 AND currency_id=1) OR ((price* 18000)< 200000 AND currency_id=2)) AS filter,
             //SUM((price >= 2000000 AND price< 5000000  AND currency_id=1) OR ((price* 18000) >= 200000 AND (price* 18000) < 500000 AND currency_id=2)) AS filter
             //FROM products
             $last_price = 0;
             $get_min = (int) Url::get('min', 0);
             $get_max = (int) Url::get('max', 0);
             $i = 1;
             foreach ($arr as $price) {
                 if ($last_price == 0) {
                     $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . " SUM((price < {$price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") < {$price} AND currency_id=2)) AS `0`";
                 } else {
                     $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . " SUM((price >= {$last_price} AND price < {$price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= {$last_price} AND (price * " . CGlobal::$exchange . ") < {$price} AND currency_id=2)) AS `{$last_price}`";
                 }
                 if ($get_min == $last_price && $get_max == $price) {
                     $this->min = $get_min;
                     $this->max = $get_max;
                 }
                 $filter_price[] = array('min' => $last_price, 'max' => $price);
                 $last_price = $price;
                 $i++;
             }
             if ($last_price) {
                 if ($get_min == $last_price && $get_max == 0) {
                     $this->min = $get_min;
                     $this->max = 0;
                 }
                 $this->price_cout_str .= ($this->price_cout_str != '' ? ',' : '') . "SUM((price >= {$last_price} AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= {$last_price} AND currency_id=2)) AS `{$last_price}`";
                 $filter_price[] = array('min' => $last_price, 'max' => 0);
                 $last_price = $price;
             }
             if ($this->min) {
                 CGlobal::$item_condition .= " AND ((price >= " . $this->min . " AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") >= " . $this->min . " AND currency_id=2))";
             }
             if ($this->max) {
                 CGlobal::$item_condition .= " AND ((price < " . $this->max . " AND currency_id=1) OR ((price * " . CGlobal::$exchange . ") < " . $this->max . " AND currency_id=2))";
             }
         }
         if ($filter_str) {
             CGlobal::$item_condition .= " AND MATCH(filter_search) AGAINST ('{$filter_str}' IN BOOLEAN MODE)";
         }
         #############################################################################################################################################
         if ($this->price_cout_str) {
             $this->filter_price = array('name' => "Giới hạn theo giá (VNĐ)", 'filters' => array());
             $price_cout_arr = DB::fetch("SELECT " . $this->price_cout_str . " FROM item WHERE " . CGlobal::$item_condition);
             if ($filter_price) {
                 foreach ($filter_price as $fprice) {
                     $min = $fprice['min'];
                     $max = $fprice['max'];
                     if ($price_cout_arr[$min]) {
                         if ($min && $max) {
                             $link2 = "{$link}&min={$min}&max={$max}";
                             $name = AZLib::money($min) . " - " . AZLib::money($max);
                         } elseif (!$max) {
                             $link2 = "{$link}&min={$min}";
                             $name = "Trên " . AZLib::money($min);
                         } elseif (!$min) {
                             $link2 = "{$link}&max={$max}";
                             $name = "Dưới " . AZLib::money($max);
                         }
                         if ($this->min == $min && $this->max == $max) {
                             $this->filter_price['filters'][] = array('link' => $link, 'name' => $name, 'count' => $price_cout_arr[$min], 'remove' => 1);
                         } else {
                             $this->filter_price['filters'][] = array('link' => $link2, 'name' => $name, 'count' => $price_cout_arr[$min], 'remove' => 0);
                         }
                     }
                 }
             }
         }
     }
 }