コード例 #1
0
ファイル: SurverySearch.php プロジェクト: smilehaha/bag-test
 public function getMyTest($uid, $where, $page, $page_size)
 {
     if ($uid < 0) {
         return [];
     }
     $queryParams['SurverySearch']['is_publish'] = 1;
     $searchModel = new SurverySearch();
     $query = $searchModel->query($queryParams);
     $query->join('inner join', 'answer_user', 'answer_user.sid=survey.id');
     $query->where('answer_user.uid=' . $uid);
     $query->andWhere('is_publish=1');
     $query2 = clone $query;
     //         $query2->groupBy= [
     //             'survey.id'
     //         ];
     $query->select('survey.*');
     $query = $query->orderBy(['au_id' => SORT_DESC]);
     $sql = $query->createCommand()->getRawSql();
     $query3 = (new Query())->from(" ({$sql}) as tt ");
     $query3->groupBy(['id']);
     //查询总条数
     $query_count = clone $query3;
     $sql_count = $query_count->createCommand()->getRawSql();
     $count = (new Query())->from(" ({$sql_count}) as tt_count ")->count();
     //      echo $count,'<br/>',$sql_count;
     //         exit;
     //分页
     $pagination = new Pagination();
     isset($page) && intval($page) > 0 ? $pagination->page = $page : null;
     //每页现实数量
     $pagination->pageSize = $page_size;
     //总数量
     $pagination->totalCount = $count;
     $offset = $pagination->getOffset();
     $limit = $pagination->getLimit();
     $query3->offset($offset);
     $query3->limit($limit);
     //          echo $pagination->page,$pagination->pageCount;
     //查询所有
     $models = (new SurverySearch())->findBySql($query3->createCommand()->getRawSql())->all();
     isset($models[0]) ? null : ($models = []);
     if (isset($_GET[$pagination->pageParam]) && $pagination->pageCount < $_GET[$pagination->pageParam]) {
         $models = [];
     }
     //         echo $pagination->page,'-',$pagination->page ;
     $temp_data['models'] = $models;
     $temp_data['pagination'] = $pagination;
     //         echo '<pre>';
     //         echo $query3->createCommand()->getRawSql();
     //         print_r($models);
     //         exit;
     return $temp_data;
 }
コード例 #2
0
 /**
  * 随机显示测试
  * @return Ambigous <multitype:, mixed>
  */
 public function getRandSurvey()
 {
     $queryParams['SurverySearch']['is_publish'] = 1;
     $searchModel = new \common\models\SurverySearch();
     $query = $searchModel->query($queryParams);
     $query->offset(0);
     $query->limit(20);
     $a_models = $query->all();
     $len = count($a_models);
     $len < 1 ? $a_models = [] : null;
     $rand_arr = [];
     if ($len > 4) {
         $rand_arr = array_rand($a_models, 4);
     }
     $temp = [];
     foreach ($rand_arr as $key => $value) {
         $temp[$value] = $a_models[$value];
     }
     return $temp;
 }
コード例 #3
0
ファイル: MyController.php プロジェクト: smilehaha/bag-test
 /**
  * 他人主页,无权限
  */
 public function actionPersonalPage($uid = 0)
 {
     $this->getView()->title = User::getTaUidShowName($uid) . '个人主页';
     $this->layout = false;
     $uid = intval($uid);
     $uid = $uid > 0 ? $uid : 0;
     // $this->render('my2');
     $searchModel = new SurverySearch();
     $queryParams = Yii::$app->request->queryParams;
     $queryParams['SurverySearch']['uid'] = $uid;
     $queryParams['SurverySearch']['is_publish'] = 1;
     $query = $searchModel->query($queryParams);
     $count = $query->count();
     // echo $count;
     // 分页
     $pagination = new Pagination();
     // 每页现实数量
     $pagination->pageSize = $this->pageSize;
     // 总数量
     $pagination->totalCount = $count;
     $old_page = $pagination->page;
     $offset = $pagination->getOffset();
     $limit = $pagination->getLimit();
     $query->offset($offset);
     $query->limit($limit);
     $query->orderBy(['id' => SORT_DESC]);
     $a_models = $query->all();
     if (isset($_GET['ajax'])) {
         if (isset($_GET[$pagination->pageParam]) && $pagination->pageCount < $_GET[$pagination->pageParam]) {
             $a_models = [];
         }
         // echo $pagination->pageCount,'-',$pagination->page,'$old_page',$_GET[$pagination->pageParam] ;
         // exit;
         return $this->render('my-test-list', ['a_models' => $a_models, 'pagination' => $pagination]);
     }
     // isset($a_models[0]) ? null : $a_models=[];
     return $this->render('my2', ['searchModel' => $searchModel, 'a_models' => $a_models, 'pagination' => $pagination, 'self' => 1, 'ajax_url' => Yii::$app->urlManager->createUrl(['my/personal-page', 'page' => '#page#', 'sort' => 1, 'self' => 1, 'ajax' => 1, 'uid' => $uid]), 'uid' => $uid]);
 }
コード例 #4
0
 /**
  * 我的测试
  */
 public function actionMy()
 {
     $this->layout = false;
     if (ZCommonSessionFun::get_user_id() < 1) {
         $url = Yii::$app->urlManager->createUrl([ZCommonSessionFun::urlLoginUserStr]);
         return $this->redirect($url);
     }
     $searchModel = new SurverySearch();
     $queryParams = Yii::$app->request->queryParams;
     $queryParams['SurverySearch']['uid'] = ZCommonSessionFun::get_user_id();
     $query = $searchModel->query($queryParams);
     $count = $query->count();
     // echo $count;
     // 分页
     $pagination = new Pagination();
     // 每页现实数量
     $pagination->pageSize = $this->pageSize;
     // 总数量
     $pagination->totalCount = $count;
     $offset = $pagination->getOffset();
     $limit = $pagination->getLimit();
     $query->offset($offset);
     $query->limit($limit);
     $query->orderBy(['id' => SORT_DESC]);
     $a_models = $query->all();
     if (isset($_GET['is_ajax'])) {
         $this->layout = false;
         if (!isset($a_models[0])) {
             $html['data'] = '';
         } else {
             $html['data'] = $this->render('my-ajax', ['searchModel' => $searchModel, 'a_models' => $a_models, 'pagination' => $pagination, 'self' => 1]);
         }
         ZCommonFun::output_json($html['data'], 0, '');
     }
     return $this->render('my3', ['searchModel' => $searchModel, 'a_models' => $a_models, 'pagination' => $pagination, 'self' => 1]);
 }