diff --git a/app/Caches/FeaturedArticleList.php b/app/Caches/FeaturedArticleList.php index bd5fc0f2..61d718e2 100644 --- a/app/Caches/FeaturedArticleList.php +++ b/app/Caches/FeaturedArticleList.php @@ -75,7 +75,7 @@ class FeaturedArticleList extends Cache ->where('featured = 1') ->andWhere('published = 1') ->andWhere('deleted = 0') - ->orderBy('id DESC') + ->orderBy('RAND()') ->limit($limit) ->execute(); } diff --git a/app/Caches/FeaturedCourseList.php b/app/Caches/FeaturedCourseList.php index cb2817a8..8243ce1d 100644 --- a/app/Caches/FeaturedCourseList.php +++ b/app/Caches/FeaturedCourseList.php @@ -77,7 +77,7 @@ class FeaturedCourseList extends Cache ->where('featured = 1') ->andWhere('published = 1') ->andWhere('deleted = 0') - ->orderBy('id DESC') + ->orderBy('RAND()') ->limit($limit) ->execute(); } diff --git a/app/Caches/FeaturedQuestionList.php b/app/Caches/FeaturedQuestionList.php new file mode 100644 index 00000000..bbb599fb --- /dev/null +++ b/app/Caches/FeaturedQuestionList.php @@ -0,0 +1,74 @@ +findQuestions($limit); + + if ($questions->count() == 0) { + return []; + } + + $result = []; + + foreach ($questions as $question) { + + $result[] = [ + 'id' => $question->id, + 'title' => $question->title, + 'cover' => $question->cover, + 'favorite_count' => $question->favorite_count, + 'answer_count' => $question->answer_count, + 'view_count' => $question->view_count, + 'like_count' => $question->like_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|QuestionModel[] + */ + protected function findQuestions($limit = 5) + { + return QuestionModel::query() + ->where('featured = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') + ->orderBy('RAND()') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Http/Admin/Services/Question.php b/app/Http/Admin/Services/Question.php index 9e69c819..e17a687d 100644 --- a/app/Http/Admin/Services/Question.php +++ b/app/Http/Admin/Services/Question.php @@ -170,6 +170,10 @@ class Question extends Service $data['anonymous'] = $validator->checkAnonymousStatus($post['anonymous']); } + if (isset($post['featured'])) { + $data['featured'] = $validator->checkFeatureStatus($post['featured']); + } + if (isset($post['closed'])) { $data['closed'] = $validator->checkCloseStatus($post['closed']); } diff --git a/app/Http/Admin/Views/question/edit_basic.volt b/app/Http/Admin/Views/question/edit_basic.volt index 9df6661f..af731d39 100644 --- a/app/Http/Admin/Views/question/edit_basic.volt +++ b/app/Http/Admin/Views/question/edit_basic.volt @@ -33,10 +33,10 @@