Exemplo n.º 1
0
 function show()
 {
     $idu = isset($_SESSION['idu']) ? $_SESSION['idu'] : 0;
     $this->stat->saveStat($idu, "search/show");
     $model = new Model_Search();
     if ($idu > 0) {
         $p = intval(isset($_GET['p']) ? $_GET['p'] : 1);
         $sex = intval(isset($_POST['sex']) ? $_POST['sex'] : (isset($_SESSION['sex']) ? $_SESSION['sex'] : 0));
         $bage = intval(isset($_POST['bage']) ? $_POST['bage'] : (isset($_SESSION['bage']) ? $_SESSION['bage'] : 0));
         $aage = intval(isset($_POST['aage']) ? $_POST['aage'] : (isset($_SESSION['aage']) ? $_SESSION['aage'] : 0));
         $idcity = intval(isset($_POST['idcity']) ? $_POST['idcity'] : (isset($_SESSION['idcity']) ? $_SESSION['idcity'] : 0));
         $_SESSION['sex'] = $sex;
         $_SESSION['bage'] = $bage;
         $_SESSION['aage'] = $aage;
         $_SESSION['idcity'] = $idcity;
         $userCount = $model->getUsersCount($idu, $sex, $bage, $aage, $idcity);
         $pageCount = $this->getPageCount($userCount, REC_ON_PAGE);
         $p = $this->getPage($p, $pageCount);
         $userList = $model->getUsersList($idu, $sex, $bage, $aage, $idcity, $p);
         $this->template->vars('p', $p);
         $this->template->vars('blockleft', $p <= 1);
         $this->template->vars('blockright', $p >= $pageCount);
         $this->template->vars('userCount', $userCount);
         $this->template->vars('userList', $userList);
         $this->template->view('show', true);
     } else {
         header('Location:' . WEB_APP);
     }
 }
Exemplo n.º 2
0
 public function attributesAction()
 {
     $request = $this->getRequest();
     $this->setViewChange('../search/index');
     $this->getLayout()->meta_title = $this->translate('Search');
     $this->getLayout()->meta_description = $this->translate('Search');
     $attributes = array();
     $attributes[0] = $request->getRequest('attributes');
     $attributes[1] = $request->getRequest($attributes[0]);
     /* CRUMBS */
     $this->view->crumbs = array(array('name' => $this->view->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->translate('Search')));
     if (count($attributes) == 2) {
         $page = (int) $request->getRequest('page', 1);
         if ($page < 1) {
             $page = 1;
         }
         $limit = JO_Registry::get('front_limit');
         $order = $request->getRequest('order');
         if (is_null($order)) {
             $order = 'desc';
         }
         $sort = $request->getRequest('sort');
         if (is_null($sort)) {
             $sort = 'relevance';
         }
         if ($sort == 'price') {
             $sort = 'rprice';
         }
         if ($sort == 'username') {
             $prefix = 'users.';
         } else {
             $prefix = 'items.';
         }
         $this->view->searchText = implode(' - ', $attributes);
         $all_cats_link = $link = $request->getBaseUrl() . '?controller=search&action=attributes/' . urlencode($attributes[0] . '/' . urlencode($attributes[1]));
         $category = $request->getRequest('category');
         if ($category) {
             $link .= '&category=' . $category;
         }
         $this->view->sort_by = array(array('name' => $this->view->translate('relevance'), 'href' => WM_Router::create($link . '&sort=relevance'), 'is_selected' => $sort == 'relevance' ? true : false), array('name' => $this->view->translate('date'), 'href' => WM_Router::create($link . '&sort=datetime'), 'is_selected' => $sort == 'datetime' ? true : false), array('name' => $this->view->translate('title'), 'href' => WM_Router::create($link . '&sort=name'), 'is_selected' => $sort == 'name' ? true : false), array('name' => $this->view->translate('rating'), 'href' => WM_Router::create($link . '&sort=rating'), 'is_selected' => $sort == 'rating' ? true : false), array('name' => $this->view->translate('sales'), 'href' => WM_Router::create($link . '&sort=sales'), 'is_selected' => $sort == 'sales' ? true : false), array('name' => $this->view->translate('price'), 'href' => WM_Router::create($link . '&sort=price'), 'is_selected' => $sort == 'price' ? true : false), array('name' => $this->view->translate('author name'), 'href' => WM_Router::create($link . '&sort=username'), 'is_selected' => $sort == 'username' ? true : false));
         /* ORDER */
         $link .= '&sort=' . $sort;
         $all_cats_link .= '&sort=' . $sort;
         $this->view->orders = array(array('name' => '&raquo;', 'href' => WM_Router::create($link . '&order=desc'), 'is_selected' => $order == 'desc' ? true : false), array('name' => '&laquo;', 'href' => WM_Router::create($link . '&order=asc'), 'is_selected' => $order == 'asc' ? true : false));
         $link .= '&order=' . $order;
         $all_cats_link .= '&order=' . $order;
         $total_records = Model_Search::getAllSearchItemsByAttr($attributes, $sort . ' ' . $order, $category);
         if ($total_records) {
             $this->view->total_result = $cnt_total_records = count($total_records);
             $this->view->categories = array();
             $categories = Model_Search::getCategoriesByAttr($attributes, $category);
             if ($categories) {
                 if ($category) {
                     $this->view->all_cats_link = WM_Router::create($all_cats_link);
                     $exists = array();
                     foreach ($categories as $cat) {
                         if (substr_count($cat['categories'], '|||') > 1) {
                             continue;
                         }
                         $cat_parts = explode('|||', $cat['categories']);
                         foreach ($cat_parts as $part) {
                             $sub_parts = explode('@@@', $part);
                             if (in_array($sub_parts[0], $exists)) {
                                 continue;
                             }
                             $exists[] = $sub_parts[0];
                             $this->view->categories[] = array('name' => $sub_parts[1], 'href' => WM_Router::create($link . '&category=' . $sub_parts[0]));
                         }
                     }
                     $this->view->categories[0] = array('name' => $this->view->categories[0]['name']);
                     $this->view->cnt_categories = count($this->view->categories) - 1;
                     $this->view->subcategories = $this->view->cnt_categories == 1 ? $this->translate('Subcategory') : $this->translate('Subcategories');
                 } else {
                     foreach ($categories as $cat) {
                         if (strpos($cat['categories'], '|||')) {
                             continue;
                         }
                         $cat_parts = explode('@@@', $cat['categories']);
                         $this->view->categories[] = array('name' => $cat_parts[1], 'href' => WM_Router::create($link . '&category=' . $cat_parts[0]));
                     }
                     $this->view->cnt_categories = count($this->view->categories);
                     $this->view->subcategories = $this->view->cnt_categories == 1 ? $this->translate('Category') : $this->translate('Categories');
                 }
             }
             $start = $page * $limit - $limit;
             if ($start > $cnt_total_records) {
                 $page = max(ceil($cnt_total_records / $limit), 1);
                 $start = $page * $limit - $limit;
             } elseif ($start < 0) {
                 $start = 0;
             }
             $items = array_slice($total_records, $start, $limit);
             $this->view->items = array();
             foreach ($items as $n => $item) {
                 $item['demo_url'] = WM_Router::create($request->getBaseUrl() . '?module=' . $item['module'] . '&controller=items&action=preview&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
                 $item['categories'] = trim($item['categories'], ',');
                 $item['categories'] = explode(',', $item['categories']);
                 $item['categories'] = JO_Array::multi_array_to_single_uniq($item['categories']);
                 $item['categories'] = array_filter($item['categories'], create_function('$a', 'return $a!="";'));
                 $this->view->items[] = Helper_Items::returnViewIndex($item, 'category');
             }
             $pagination = new Model_Pagination();
             $pagination->setLimit($limit);
             $pagination->setPage($page);
             $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next')));
             $pagination->setTotal($cnt_total_records);
             $pagination->setUrl(WM_Router::create($link . '&page={page}'));
             $this->view->pagination = $pagination->render();
             if (!empty($this->view->pagination)) {
                 $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination);
             }
         }
     }
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
Exemplo n.º 3
0
 public function getFullMaterials2($gid, $limit = 0, $offset = 0, $search_string = NULL, $params = array(), $time = 0)
 {
     if (empty($params)) {
         $for_order = ' a.rating DESC,';
     } else {
         $for_order = '';
     }
     $sort = Arr::get($params, 'sort', 'price_down');
     $data = array();
     $vData = $params;
     //        $vData['date_start'] = $params['date_start'];
     $vData['gid'] = $gid;
     $vData['search_string'] = $search_string;
     $vData['sort'] = $sort;
     $vData['offset'] = $offset;
     $validation = Validation::factory($vData);
     $validation->rule('gid', 'not_empty');
     $validation->rule('gid', 'digit');
     //        $validation->rule('csrf', 'not_empty');
     //        $validation->rule('csrf', 'Security::check');
     $validation->rule('price_from', 'digit');
     $validation->rule('price_to', 'digit');
     if (!$validation->check()) {
         $data['errors'] = $validation->errors('filterErrors');
         return FALSE;
     }
     if ($sort && $sort != '') {
         $srt = explode('_', $sort);
         if (isset($srt[1]) && $srt[1] == 'down') {
             $svariant = 'DESC';
         } else {
             $svariant = 'ASC';
         }
         switch ($srt[0]) {
             case 'views':
                 $material_sort = 'views';
             default:
                 $sfield = 'price';
                 break;
         }
         $srtData = $this->getField($sfield, $gid);
         if (isset($material_sort)) {
             $query = "SELECT DISTINCT a.*\n\t\t\t\t\tFROM materials a\n\t\t\t\t\tWHERE a.sleep = 0 ";
         } else {
             if ($gid != 0) {
                 $query = "SELECT DISTINCT a.*, b1.value\n\t\t\t\t\t\tFROM materials a, " . $srtData['type'] . " b1, group_param_values c1\n\t\t\t\t\t\tWHERE a.sleep = 0 ";
             } else {
                 $query = "SELECT DISTINCT a.*\n\t\t\t\t\tFROM materials a\n\t\t\t\t\tWHERE a.sleep = 0 ";
             }
         }
     } else {
         $query = "SELECT DISTINCT a.*\n\t\t\t\t\tFROM materials a\n\t\t\t\t\tWHERE a.sleep = 0 ";
     }
     if ($gid != 0) {
         $query .= "AND EXISTS (SELECT * FROM group_materials_rel g where a.id = g.mid AND g.gid = " . $gid . ") ";
     }
     if ($search_string) {
         //                //сначала получаем id лист вхождений по тексту
         $searcher = new Model_Search();
         $words = $searcher->getSearchString($search_string);
         if (!empty($words)) {
             if ($gid != 0) {
                 $for_order = 'CASE WHEN ';
             }
             $query .= 'AND (';
             $i = 0;
             foreach ($words as $word) {
                 if ($i != 0) {
                     $query .= ' AND ';
                 }
                 $query .= 'UPPER(a.name) LIKE \'%' . $word . '%\'';
                 if ($i != 0) {
                     $for_order .= ' AND ';
                 }
                 $for_order .= 'UPPER(a.name) LIKE \'%' . $word . '%\'';
                 ++$i;
             }
             if ($gid != 0) {
                 $for_order .= '  THEN 0 ELSE 1 END, ';
             }
             if ($gid == 0) {
                 $query .= ' OR EXISTS (SELECT * FROM groups g, group_materials_rel r WHERE a.id = r.mid AND g.id = r.gid ';
                 foreach ($words as $word) {
                     $query .= 'AND UPPER(g.name) LIKE \'%' . $word . '%\' ';
                 }
                 $query .= ' ) ';
             }
             if ($gid != 0) {
                 $query .= ' OR EXISTS (SELECT * FROM chars b, group_param_values c where a.id = c.mid AND b.id = c.`value` ';
             } else {
                 $query .= ' OR EXISTS (SELECT * FROM chars b, group_param_values c, group_params d where a.id = c.mid AND b.id = c.`value` AND d.type = "chars" AND d.id = c.pid ';
             }
             foreach ($words as $word) {
                 $query .= 'AND UPPER(b.value) LIKE \'%' . $word . '%\'';
             }
             $query .= ' ) ';
             if ($gid != 0) {
                 $query .= ' OR EXISTS (SELECT * FROM `select` s, group_param_values c where a.id = c.mid AND s.id = c.`value` ';
             } else {
                 $query .= ' OR EXISTS (SELECT * FROM `select` s, group_param_values c, group_params d where a.id = c.mid AND s.id = c.`value` AND d.type = "select" AND d.id = c.pid ';
             }
             foreach ($words as $word) {
                 $query .= 'AND UPPER(s.value) LIKE \'%' . $word . '%\'';
             }
             $query .= ' ) ';
             if ($gid != 0) {
                 $query .= ' OR EXISTS (SELECT * FROM `texts` t, group_param_values c where a.id = c.mid AND t.id = c.`value` ';
             } else {
                 $query .= ' OR EXISTS (SELECT * FROM `texts` t, group_param_values c, group_params d where a.id = c.mid AND t.id = c.`value` AND d.type = "texts" AND d.id = c.pid ';
             }
             foreach ($words as $word) {
                 $query .= 'AND UPPER(t.value) LIKE \'%' . $word . '%\'';
             }
             $query .= ' )) ';
         }
     }
     if (count($params) > 0) {
         foreach ($params as $key => $value) {
             if ($value != '') {
                 $key = addslashes($key);
                 $paramTitle = explode('_', $key);
                 $paramData = $this->getField($paramTitle[0], $gid);
                 //формируем параметры запроса к базе данных
                 switch ($key) {
                     case 'price_from':
                         $query .= 'AND EXISTS (SELECT * FROM price b, group_param_values c where a.id = c.mid AND b.id = c.`value` AND c.pid = ' . $paramData['id'] . ' AND b.`value` >= ' . $value * 100 . ') ';
                         break;
                     case 'price_to':
                         $query .= 'AND EXISTS (SELECT * FROM price b, group_param_values c where a.id = c.mid AND b.id = c.`value` AND c.pid = ' . $paramData['id'] . ' AND b.`value` <= ' . $value * 100 . ') ';
                         break;
                     case 'meh-shuby':
                         $query .= 'AND EXISTS (SELECT * FROM `select` b, group_param_values c where a.id = c.mid AND b.id = c.`value` AND c.pid = ' . $paramData['id'] . ' AND b.`value` in (';
                         for ($i = 0; $i < count($value); ++$i) {
                             if ($i != 0) {
                                 $query .= ', ';
                             }
                             $query .= '\'' . addslashes(trim($value[$i])) . '\'';
                         }
                         $query .= ')) ';
                         break;
                     case 'type':
                         $query .= 'AND EXISTS (SELECT * FROM `select` b, group_param_values c where a.id = c.mid AND b.id = c.`value` AND c.pid = ' . $paramData['id'] . ' AND b.`value` in (';
                         for ($i = 0; $i < count($value); ++$i) {
                             if ($i != 0) {
                                 $query .= ', ';
                             }
                             $query .= '\'' . addslashes(trim($value[$i])) . '\'';
                         }
                         $query .= ')) ';
                         break;
                     case 'material':
                         $query .= 'AND EXISTS (SELECT * FROM `select` b, group_param_values c where a.id = c.mid AND b.id = c.`value` AND c.pid = ' . $paramData['id'] . ' AND b.`value` in (';
                         for ($i = 0; $i < count($value); ++$i) {
                             if ($i != 0) {
                                 $query .= ', ';
                             }
                             $query .= '\'' . addslashes(trim($value[$i])) . '\'';
                         }
                         $query .= ')) ';
                         break;
                     case 'razmer':
                         foreach ($value as $itm) {
                             $query .= 'AND EXISTS (SELECT * FROM `select` b, group_param_values c where a.id = c.mid AND b.id = c.`value` AND c.pid = ' . $paramData['id'] . ' AND b.`value` = \'' . mysql_real_escape_string(trim($itm)) . '\') ';
                         }
                         break;
                     case 'color':
                         $query .= 'AND EXISTS (SELECT * FROM `select` b, group_param_values c where a.id = c.mid AND b.id = c.`value` AND c.pid = ' . $paramData['id'] . ' AND b.`value` in (';
                         for ($i = 0; $i < count($value); ++$i) {
                             if ($i != 0) {
                                 $query .= ', ';
                             }
                             $query .= '\'' . addslashes(trim($value[$i])) . '\'';
                         }
                         $query .= ')) ';
                         break;
                 }
             }
         }
     }
     if ($sort && $sort != '') {
         if (isset($material_sort)) {
             $query .= 'ORDER BY a.' . $material_sort . ' ' . $svariant;
         } else {
             if ($gid != 0) {
                 $query .= 'AND a.id = c1.mid AND b1.id = c1.`value` AND c1.pid = ' . $srtData['id'] . ' ORDER BY ' . $for_order . ' CAST(b1.value AS UNSIGNED) ' . $svariant;
             }
         }
     } else {
         $query .= 'ORDER BY a.rating DESC ';
     }
     $query .= ' LIMIT ' . $offset . ', ' . $limit;
     //        if($gid==0)
     //            echo $query;
     try {
         $result = DB::query(Database::SELECT, $query)->execute();
     } catch (Exception $e) {
         throw new HTTP_Exception_500();
     }
     $fieldtypes = array('chars', 'photoalbum', 'select', 'price');
     $chars = new Model_Params_Chars();
     $photoalbum = new Model_Params_Photoalbum('');
     $select = new Model_Params_Selects();
     $price = new Model_Params_Prices();
     $files = new Model_Params_Files('');
     $images = new Model_Params_Images();
     $dates = new Model_Params_Dates();
     $texts = new Model_Params_Texts();
     $catalog = new Model_Category('tree');
     $parents = $catalog->getParents(Arr::get($GLOBALS, 'categoryId'));
     $node = '';
     foreach ($parents as $key => $parent) {
         if ($parent["url"] == "glavnaya") {
             $node .= $parents[$key + 1]["url"] . "/";
             break;
         }
     }
     /*foreach($parents as $parent)
     		{
     			var_dump($parent);
     			if($parent['level']>1 && $parent['url']!='glavnaya')
     			{
     				$node .= $parent['url'].'/';
     			}
     		}*/
     if ($result) {
         foreach ($result as $item) {
             $mid = $item['id'];
             unset($item['id']);
             $gid = $this->getGroupFromMid($mid);
             //var_dump($gid.'-'.$item['name']);
             $charfileds = $chars->getTypeParams($mid, $gid);
             $new = array_merge($item, $charfileds);
             $photos = $photoalbum->getTypeParams($mid, $gid);
             $new = array_merge($new, $photos);
             $filesfield = $files->getTypeParams($mid, $gid);
             $new = array_merge($new, $filesfield);
             $textfields = $texts->getTypeParams($mid, $gid);
             $new = array_merge($new, $textfields);
             $datesfields = $dates->getTypeParams($mid, $gid);
             $new = array_merge($new, $datesfields);
             $imagefields = $images->getTypeParams($mid, $gid);
             $new = array_merge($new, $imagefields);
             $seletfields = $select->getTypeParams($mid, $gid);
             $new = array_merge($new, $seletfields);
             $prices = $price->getTypeParams($mid, $gid);
             $new = array_merge($new, $prices);
             //получаем ноду
             $new['node'] = $node;
             $data[$mid] = $new;
         }
         return $data;
     }
 }