| @@ 33-70 (lines=38) @@ | ||
| 30 | * @return string |
|
| 31 | * @throws \yii\web\NotFoundHttpException |
|
| 32 | */ |
|
| 33 | public function actionIndex($id = null, $slug = null) |
|
| 34 | { |
|
| 35 | $render = 'index'; |
|
| 36 | ||
| 37 | if ($id) { |
|
| 38 | $postType = $this->findPostType($id); |
|
| 39 | } elseif ($slug) { |
|
| 40 | $postType = $this->findPostTypeBySlug($slug); |
|
| 41 | } else { |
|
| 42 | throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); |
|
| 43 | } |
|
| 44 | ||
| 45 | $query = $postType->getPosts() |
|
| 46 | ->andWhere(['status' => 'publish']) |
|
| 47 | ->andWhere(['<=', 'date', date('Y-m-d H:i:s')]) |
|
| 48 | ->orderBy(['id' => SORT_DESC]); |
|
| 49 | $countQuery = clone $query; |
|
| 50 | $pages = new Pagination([ |
|
| 51 | 'totalCount' => $countQuery->count(), |
|
| 52 | 'pageSize' => Option::get('posts_per_page'), |
|
| 53 | ]); |
|
| 54 | $query->offset($pages->offset)->limit($pages->limit); |
|
| 55 | $posts = $query->all(); |
|
| 56 | ||
| 57 | if ($posts) { |
|
| 58 | if (is_file($this->view->theme->basePath . '/post/index-' . $postType->name . '.php')) { |
|
| 59 | $render = 'index-' . $postType->name . '.php'; |
|
| 60 | } |
|
| 61 | ||
| 62 | return $this->render($render, [ |
|
| 63 | 'postType' => $postType, |
|
| 64 | 'posts' => $posts, |
|
| 65 | 'pages' => $pages, |
|
| 66 | ]); |
|
| 67 | } |
|
| 68 | ||
| 69 | throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * Displays a single Post model. |
|
| @@ 33-70 (lines=38) @@ | ||
| 30 | * @return mixed |
|
| 31 | * @throws \yii\web\NotFoundHttpException |
|
| 32 | */ |
|
| 33 | public function actionView($id = null, $user = null) |
|
| 34 | { |
|
| 35 | $render = '/user/view'; |
|
| 36 | ||
| 37 | if ($id) { |
|
| 38 | $model = $this->findModel($id); |
|
| 39 | } elseif ($user) { |
|
| 40 | $model = $this->findModelByUsername($user); |
|
| 41 | } else { |
|
| 42 | throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); |
|
| 43 | } |
|
| 44 | ||
| 45 | $query = $model->getPosts() |
|
| 46 | ->andWhere(['status' => 'publish']) |
|
| 47 | ->andWhere(['<=', 'date', date('Y-m-d H:i:s')]) |
|
| 48 | ->orderBy(['date' => SORT_DESC]); |
|
| 49 | $countQuery = clone $query; |
|
| 50 | $pages = new Pagination([ |
|
| 51 | 'totalCount' => $countQuery->count(), |
|
| 52 | 'pageSize' => Option::get('posts_per_page'), |
|
| 53 | ]); |
|
| 54 | $query->offset($pages->offset)->limit($pages->limit); |
|
| 55 | $posts = $query->all(); |
|
| 56 | ||
| 57 | if ($posts) { |
|
| 58 | if (is_file($this->view->theme->basePath . '/user/view-' . $model->username . '.php')) { |
|
| 59 | $render = 'view-' . $model->username . '.php'; |
|
| 60 | } |
|
| 61 | ||
| 62 | return $this->render($render, [ |
|
| 63 | 'user' => $model, |
|
| 64 | 'posts' => $posts, |
|
| 65 | 'pages' => isset($pages) ? $pages : null, |
|
| 66 | ]); |
|
| 67 | } |
|
| 68 | ||
| 69 | throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * Finds the User model based on its primary key value. |
|