public function actionSearch($ihq = null, $iht = null, $status = null) { $queryLength = mb_strlen($ihq, 'UTF-8'); // search by hash $is_hash = false; if (40 == $queryLength && preg_match('#^[0-9a-f]{40}$#i', $ihq)) { $is_hash = true; if ($torrent = Yii::app()->torrentsService->getTorrentByHash($ihq)) { Yii::app()->request->redirect($torrent->getUrl()); } } $this->checkSearchRequest(); if (!empty($iht)) { if (preg_match('#^\\d$#sui', $iht) && LCategory::getCategoryTag($iht)) { $iht = LCategory::getCategoryTag($iht); } } if (!empty($ihq)) { $this->pageTitle = ucfirst($ihq) . ' Torrents Search Results | ' . Yii::app()->name . ' Torrent Search Engine'; } elseif (!empty($iht)) { $this->pageTitle = mb_convert_case($iht, MB_CASE_TITLE, 'utf-8') . ' Torrents | ' . Yii::app()->name . ' Torrent Search Engine'; } Yii::app()->getRequest()->getQuery('age'); if (Yii::app()->getRequest()->getQuery('ihs', null) === '1') { $_GET['popular'] = '1'; } $searchModel = new SearchForm('simple'); $searchModel->words = $ihq; $searchModel->tags = $iht; $searchModel->age = Yii::app()->getRequest()->getQuery('age', 0); $searchModel->popular = empty($_GET['popular']) ? 0 : 1; $searchModel->status = empty($status) ? 0 : 1; $searchModel->validate(); $torrents = new CArrayDataProvider(array()); $totalCount = 0; if (!$searchModel->getErrors()) { $torrentModel = LTorrent::model(); $torrents = $torrentModel->getSphinxDataProvider($searchModel); $totalCount = $torrents->getTotalItemCount(); if (empty($totalCount)) { $words = explode(' ', $searchModel->words); if (count($words) > 1) { $searchModel->words = $words; $torrents = $torrentModel->getSphinxDataProvider($searchModel); $totalCount = $torrents->getTotalItemCount(); } } } if (isset($_REQUEST['lucky'])) { $t = $torrents->getData(); if (count($t)) { $idx = rand(0, count($t) - 1); Yii::app()->request->redirect($t[$idx]->getUrl()); } } $this->render('list', array('torrents' => $torrents, 'search' => $searchModel->words, 'categoryTag' => $iht, 'categoriesTags' => LCategory::$categoriesTags, 'totalFound' => $totalCount)); }
/** * Поиск результатов по параметрам * @return mixed */ public function actionSearch() { if ($this->_needRegister()) { $this->render('needregister'); return; } if ((isset($_GET['clean']) || isset($_GET['newsearch'])) && Yii::app()->user->getState('searchdata')) { // очистить результаты поиска и в раздел "мне нравятся" Yii::app()->user->setState('searchdata', null, null); if (isset($_GET['clean'])) { $this->redirect(array('anketa/mylike')); } else { //newsearch $this->redirect(array('anketa/search')); } } if (isset(Yii::app()->user->searchdata) && !Yii::app()->user->getState('mainsearch')) { // определить критерии поиска // echo Yii::app()->user->name; if (Yii::app()->user->isGuest) { $model = new Anketa(); //(array('gender'=>'')); } else { $model = Anketa::model()->findbypk(Yii::app()->user->id); } $criteria = $model->getsearchcriteria(Yii::app()->user->searchdata); $count = Anketa::model()->count($criteria); $criteria->limit = 2; $models = Anketa::model()->findAll($criteria); $this->render('2big', array('models' => $models, 'count' => $count)); } else { $model = new SearchForm(); Yii::app()->user->setState('mainsearch', 0); if (Yii::app()->user->hasState('saveddata')) { $model->attributes = Yii::app()->user->getState('saveddata'); } if (isset($_POST['SearchForm'])) { $model->attributes = $_POST['SearchForm']; if ($model->validate()) { if (isset($_POST['savedata'])) { Yii::app()->user->setState('saveddata', $model->attributes); } Yii::app()->user->setState('searchdata', $model->attributes); Yii::app()->user->setState('guestlikes', array()); $this->refresh(); } else { print_r($model->getErrors()); } } $this->render('search', array('model' => $model)); } }