Esempio n. 1
0
 public function actionLoadAjax()
 {
     $keyword = trim(yii::app()->request->getParam('q', ''));
     $search_type = $type = trim(yii::app()->request->getParam('type', 'song'));
     $page = intval(yii::app()->request->getParam('page', 1));
     $is_search = Yii::app()->request->getParam('is_search', 1);
     $paging = array('page' => $page, 'recordsPerPage' => !$search_type ? Yii::app()->params['numberPerPage'] : Yii::app()->params['pageSize']);
     switch ($search_type) {
         case 'song':
             $response = SearchHelper::getInstance()->search($keyword, 'song', $paging['recordsPerPage'], $page - 1);
             $results = $this->copyAndCast($response->docs, array('name' => 'name', 'artist_name' => 'artist_name'));
             if ($response->numFound > 0) {
                 $countSong = $response->numFound;
                 $pages = new CPagination($countSong);
                 $pageSize = Yii::app()->params['pageSize'];
                 $pages->params = array('q' => $keyword, 'type' => $type);
                 $pages->setPageSize($pageSize);
                 $topItems = array();
                 $topItemPages = new CPagination(0);
                 $results = $this->getStatistic($results, $type);
             } else {
                 $pages = new CPagination(0);
                 $pageSize = Yii::app()->params['numberPerPage'];
                 $topItemPages = new CPagination($pageSize);
                 $topItemPages->setPageSize($pageSize);
                 $currentPage = $topItemPages->getCurrentPage();
                 $topItems = null;
                 // WapSongModel::model()->getTopSongsWeek($currentPage * $pageSize, $pageSize);;//WapSongModel::getListHot(1,$pageSize,'filter_sync_status');
             }
             $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages);
             break;
         case 'clip':
             $response = SearchHelper::getInstance()->search($keyword, 'video', $paging['recordsPerPage'], $page - 1);
             $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name'));
             if ($response->numFound > 0) {
                 $countClip = $response->numFound;
                 $pages = new CPagination($countClip);
                 $pageSize = Yii::app()->params['pageSize'];
                 $pages->params = array('q' => $keyword, 'type' => $type);
                 $pages->setPageSize($pageSize);
                 $topItems = array();
                 $topItemPages = new CPagination(0);
                 $results = $this->getStatistic($results, $type);
             } else {
                 $pages = new CPagination(0);
                 $pageSize = Yii::app()->params['numberPerPage'];
                 $topItemPages = new CPagination($pageSize);
                 $currentPage = $topItemPages->getCurrentPage();
                 $topItemPages->setPageSize($pageSize);
                 $topItems = null;
                 //WapVideoModel::model()->getTopVideosWeek($currentPage * $pageSize, $pageSize);//WapVideoModel::getListHot(1,$pageSize,'filter_sync_status');
             }
             $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages);
             break;
         case 'album':
             $response = SearchHelper::getInstance()->search($keyword, 'album', $paging['recordsPerPage'], $page - 1);
             $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name'));
             if ($response->numFound > 0) {
                 $countAlbum = $response->numFound;
                 $pages = new CPagination($countAlbum);
                 $pageSize = Yii::app()->params['pageSize'];
                 $pages->params = array('q' => $keyword, 'type' => $type);
                 $pages->setPageSize($pageSize);
                 $topItems = array();
                 $topItemPages = new CPagination(0);
                 $results = $this->getStatistic($results, $type);
             } else {
                 $pages = new CPagination(0);
                 $pageSize = Yii::app()->params['numberPerPage'];
                 $topItemPages = new CPagination($pageSize);
                 $topItemPages->setPageSize($pageSize);
                 $currentPage = $topItemPages->getCurrentPage();
                 $topItems = null;
                 //WapAlbumModel::model()->getTopAlbumsWeek($currentPage * $pageSize, $pageSize);//WapAlbumModel::getListHot(1,$pageSize);
             }
             $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages);
             break;
         case 'artist':
             $response = SearchHelper::getInstance()->search($keyword, 'artist', $paging['recordsPerPage'], $page - 1);
             $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name'));
             if ($response->numFound > 0) {
                 $countArtist = $response->numFound;
                 $pages = new CPagination($countArtist);
                 $pageSize = Yii::app()->params['pageSize'];
                 $pages->params = array('q' => $keyword, 'type' => $type);
                 $pages->setPageSize($pageSize);
                 $topItems = array();
                 $topItemPages = new CPagination(0);
                 $results = $this->getStatistic($results, $type, 'song_count');
             } else {
                 $pages = new CPagination(0);
                 $pageSize = Yii::app()->params['numberPerPage'];
                 $topItemPages = new CPagination($pageSize);
                 $currentPage = $topItemPages->getCurrentPage();
                 $topItemPages->setPageSize($pageSize);
                 $topItems = null;
                 //WapArtistModel::model()->getTopArtists($currentPage * $pageSize, $pageSize);
             }
             $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages);
             break;
         case 'videoplaylist':
             $response = SearchHelper::getInstance()->search($keyword, 'videoplaylist', $paging['recordsPerPage'], $page - 1);
             $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name'));
             if ($response->numFound > 0) {
                 $countArtist = $response->numFound;
                 $pages = new CPagination($countArtist);
                 $pageSize = Yii::app()->params['pageSize'];
                 $pages->params = array('q' => $keyword, 'type' => $type);
                 $pages->setPageSize($pageSize);
                 $topItems = array();
                 $topItemPages = new CPagination(0);
                 $results = $this->getStatistic($results, $type);
             } else {
                 $pages = new CPagination(0);
                 $pageSize = Yii::app()->params['numberPerPage'];
                 $topItemPages = new CPagination($pageSize);
                 $currentPage = $topItemPages->getCurrentPage();
                 $topItemPages->setPageSize($pageSize);
                 $topItems = null;
                 //WapArtistModel::model()->getTopArtists($currentPage * $pageSize, $pageSize);
             }
             $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages);
             break;
     }
     $this->layout = false;
     $this->render("_ajaxList", compact('total_results', 'search_type'));
 }