ReportTopicController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\controllers;
  3. use app\models\ReportTopic;
  4. use yii\web\Controller;
  5. use yii\web\NotFoundHttpException;
  6. use yii\data\ActiveDataProvider;
  7. class ReportTopicController extends \yii\web\Controller
  8. {
  9. public function actionIndex()
  10. {
  11. $news_query = ReportTopic::find()->where(['<>', 'title', ''])->where([ 'active'=>1]);
  12. $pages = new \yii\data\Pagination(['totalCount' => $news_query->count(), 'pageSize'=>50]);
  13. $gets = \Yii::$app->request->get();
  14. $valid_get = array_filter($gets, function($k) {
  15. $valid = ['page'=>true, 'per-page'=>false];
  16. return isset( $valid[$k] );
  17. }, ARRAY_FILTER_USE_KEY);
  18. $pages->pageSizeParam = false;
  19. // $pages->params = $valid_get;
  20. $pages->route = \Yii::$app->urlManager->createUrl(['photo']);
  21. $dataProvider = new ActiveDataProvider([
  22. 'query' => $news_query,
  23. 'pagination' => $pages,
  24. 'sort' => [
  25. 'defaultOrder' => [
  26. 'id' => SORT_DESC,
  27. ]
  28. ],
  29. ]);
  30. return $this->render('index', [
  31. 'dataProvider' => $dataProvider,
  32. ]);
  33. }
  34. public function actionView($topic){
  35. if( is_numeric($topic) ){
  36. $model = ReportTopic::findOne(['id'=>$topic]);
  37. if( ( !$model instanceof ReportTopic ) || $model->active == 0 ){
  38. throw new NotFoundHttpException("Стр. не найдена");
  39. }
  40. return $this->render("view",["model"=>$model]);
  41. }
  42. throw new NotFoundHttpException("Стр. не найдена");
  43. }
  44. public function actionWidget($topic){
  45. if( is_numeric($topic) ){
  46. $model = ReportTopic::findOne(['id'=>$topic]);
  47. if( ( !$model instanceof ReportTopic ) ){
  48. throw new NotFoundHttpException("Стр. не найдена");
  49. }
  50. return $this->renderPartial("widget",["model"=>$model]);
  51. }
  52. throw new NotFoundHttpException("Стр. не найдена");
  53. }
  54. }