From 680089e06f30b698872b069229643b5fa7d9e709 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Tue, 7 Jul 2020 20:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9C=A8php7.3=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E7=BB=A7=E6=89=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Builders/CourseTopicList.php | 78 +++++++++++++++++++ app/Http/Web/Controllers/CourseController.php | 15 +--- app/Http/Web/Controllers/HelpController.php | 38 +++++++++ app/Http/Web/Controllers/PageController.php | 2 +- .../Web/Controllers/TeacherController.php | 15 +++- app/Http/Web/Controllers/TopicController.php | 19 ++++- app/Http/Web/Controllers/UserController.php | 12 +-- app/Http/Web/Controllers/VipController.php | 8 +- app/Http/Web/Services/CourseQuery.php | 36 ++++----- app/Http/Web/Views/account/login.volt | 2 +- app/Http/Web/Views/course/list.volt | 2 + app/Http/Web/Views/help/index.volt | 14 ++++ app/Http/Web/Views/page/show.volt | 9 +++ app/Http/Web/Views/teacher/list.volt | 32 +++----- app/Http/Web/Views/teacher/list_pager.volt | 23 ++++++ app/Http/Web/Views/topic/courses.volt | 14 ++++ app/Http/Web/Views/topic/show.volt | 19 +++++ app/Library/Cache/Backend/Redis.php | 34 ++++---- app/Library/Http/Request.php | 4 +- app/Library/Http/Response.php | 6 +- app/Library/Mvc/View.php | 12 +-- .../Paginator/Adapter/QueryBuilder.php | 3 +- app/Models/AccessToken.php | 2 +- app/Models/Account.php | 2 +- app/Models/Audit.php | 2 +- app/Models/Category.php | 2 +- app/Models/Chapter.php | 2 +- app/Models/ChapterLive.php | 2 +- app/Models/ChapterRead.php | 2 +- app/Models/ChapterUser.php | 2 +- app/Models/ChapterVod.php | 2 +- app/Models/ChapterVote.php | 2 +- app/Models/Comment.php | 2 +- app/Models/CommentVote.php | 2 +- app/Models/Consult.php | 2 +- app/Models/ConsultVote.php | 2 +- app/Models/ContentImage.php | 2 +- app/Models/Course.php | 2 +- app/Models/CourseCategory.php | 2 +- app/Models/CourseFavorite.php | 2 +- app/Models/CoursePackage.php | 2 +- app/Models/CourseRelated.php | 2 +- app/Models/CourseTopic.php | 2 +- app/Models/CourseUser.php | 2 +- app/Models/Help.php | 2 +- app/Models/ImFriendGroup.php | 2 +- app/Models/ImFriendMessage.php | 2 +- app/Models/ImFriendUser.php | 2 +- app/Models/ImGroup.php | 2 +- app/Models/ImGroupMessage.php | 2 +- app/Models/ImGroupUser.php | 2 +- app/Models/ImSystemMessage.php | 2 +- app/Models/ImUser.php | 2 +- app/Models/Learning.php | 2 +- app/Models/Nav.php | 2 +- app/Models/Order.php | 2 +- app/Models/OrderStatus.php | 2 +- app/Models/Package.php | 2 +- app/Models/Page.php | 2 +- app/Models/RefreshToken.php | 2 +- app/Models/Refund.php | 2 +- app/Models/RefundStatus.php | 2 +- app/Models/Review.php | 2 +- app/Models/ReviewVote.php | 2 +- app/Models/Reward.php | 2 +- app/Models/Role.php | 2 +- app/Models/Setting.php | 2 +- app/Models/Slide.php | 2 +- app/Models/Task.php | 2 +- app/Models/Topic.php | 2 +- app/Models/Trade.php | 2 +- app/Models/TradeStatus.php | 2 +- app/Models/User.php | 2 +- app/Models/Vip.php | 2 +- app/Repos/CourseTopic.php | 35 +++++++++ app/Repos/Help.php | 38 +++++++++ app/Repos/Page.php | 4 + app/Repos/Topic.php | 4 +- app/Services/Frontend/Help/HelpInfo.php | 30 +++++++ app/Services/Frontend/Help/HelpList.php | 45 +++++++++++ app/Services/Frontend/HelpTrait.php | 24 ++++++ app/Services/Frontend/Topic/CourseList.php | 33 +++++++- app/Services/Frontend/Topic/TopicInfo.php | 3 +- public/static/web/css/common.css | 36 +++++++-- public/static/web/js/teacher.list.js | 10 +++ public/static/web/js/topic.show.js | 9 +++ 86 files changed, 605 insertions(+), 167 deletions(-) create mode 100644 app/Builders/CourseTopicList.php create mode 100644 app/Http/Web/Controllers/HelpController.php create mode 100644 app/Http/Web/Views/help/index.volt create mode 100644 app/Http/Web/Views/page/show.volt create mode 100644 app/Http/Web/Views/teacher/list_pager.volt create mode 100644 app/Http/Web/Views/topic/courses.volt create mode 100644 app/Http/Web/Views/topic/show.volt create mode 100644 app/Services/Frontend/Help/HelpInfo.php create mode 100644 app/Services/Frontend/Help/HelpList.php create mode 100644 app/Services/Frontend/HelpTrait.php create mode 100644 public/static/web/js/teacher.list.js create mode 100644 public/static/web/js/topic.show.js diff --git a/app/Builders/CourseTopicList.php b/app/Builders/CourseTopicList.php new file mode 100644 index 00000000..8ae453d8 --- /dev/null +++ b/app/Builders/CourseTopicList.php @@ -0,0 +1,78 @@ +getCourses($relations); + + foreach ($relations as $key => $value) { + $relations[$key]['course'] = $courses[$value['course_id']] ?? new \stdClass(); + } + + return $relations; + } + + public function handleTopics($relations) + { + $topics = $this->getTopics($relations); + + foreach ($relations as $key => $value) { + $relations[$key]['topic'] = $topics[$value['topic_id']] ?? new \stdClass(); + } + + return $relations; + } + + public function getCourses($relations) + { + $ids = kg_array_column($relations, 'course_id'); + + $courseRepo = new CourseRepo(); + + $columns = [ + 'id', 'title', 'cover', + 'market_price', 'vip_price', + 'rating', 'model', 'level', 'attrs', + 'user_count', 'lesson_count', + ]; + + $courses = $courseRepo->findByIds($ids, $columns); + + $baseUrl = kg_ci_base_url(); + + $result = []; + + foreach ($courses->toArray() as $course) { + $course['cover'] = $baseUrl . $course['cover']; + $course['attrs'] = json_decode($course['attrs'], true); + $result[$course['id']] = $course; + } + + return $result; + } + + public function getTopics($relations) + { + $ids = kg_array_column($relations, 'topic_id'); + + $topicRepo = new TopicRepo(); + + $topics = $topicRepo->findByIds($ids, ['id', 'title', 'summary']); + + $result = []; + + foreach ($topics->toArray() as $topic) { + $result[$topic['id']] = $topic; + } + + return $result; + } + +} diff --git a/app/Http/Web/Controllers/CourseController.php b/app/Http/Web/Controllers/CourseController.php index 4507c78e..af8c94ba 100644 --- a/app/Http/Web/Controllers/CourseController.php +++ b/app/Http/Web/Controllers/CourseController.php @@ -30,23 +30,20 @@ class CourseController extends Controller { $service = new CourseQueryService(); - $params = $service->getQueryParams(); - - $pagerUrl = $this->url->get(['for' => 'web.course.pager'], $params); - $topCategories = $service->handleTopCategories(); $subCategories = $service->handleSubCategories(); $models = $service->handleModels(); $levels = $service->handleLevels(); $sorts = $service->handleSorts(); + $params = $service->getParams(); - $this->view->setVar('pager_url', $pagerUrl); $this->view->setVar('top_categories', $topCategories); $this->view->setVar('sub_categories', $subCategories); $this->view->setVar('models', $models); $this->view->setVar('levels', $levels); $this->view->setVar('sorts', $sorts); + $this->view->setVar('params', $params); } /** @@ -114,13 +111,11 @@ class CourseController extends Controller */ public function consultsAction($id) { - $target = $this->request->get('target', 'trim', 'tab-consults'); - $service = new CourseConsultListService(); $pager = $service->handle($id); $pager->items = kg_array_object($pager->items); - $pager->target = $target; + $pager->target = 'tab-consults'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('pager', $pager); @@ -131,13 +126,11 @@ class CourseController extends Controller */ public function reviewsAction($id) { - $target = $this->request->get('target', 'trim', 'tab-reviews'); - $service = new CourseReviewListService(); $pager = $service->handle($id); $pager->items = kg_array_object($pager->items); - $pager->target = $target; + $pager->target = 'tab-reviews'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('pager', $pager); diff --git a/app/Http/Web/Controllers/HelpController.php b/app/Http/Web/Controllers/HelpController.php new file mode 100644 index 00000000..ba5bd3e9 --- /dev/null +++ b/app/Http/Web/Controllers/HelpController.php @@ -0,0 +1,38 @@ +handle(); + + $this->view->setVar('helps', $helps); + } + + /** + * @Get("/{id:[0-9]+}", name="web.help.show") + */ + public function showAction($id) + { + $service = new HelpInfoService(); + + $help = $service->handle($id); + + $this->view->setVar('help', $help); + } + +} diff --git a/app/Http/Web/Controllers/PageController.php b/app/Http/Web/Controllers/PageController.php index 09289115..57070d65 100644 --- a/app/Http/Web/Controllers/PageController.php +++ b/app/Http/Web/Controllers/PageController.php @@ -2,7 +2,7 @@ namespace App\Http\Web\Controllers; -use App\Services\Frontend\Page\PageInfo as PageInfoService; +use App\Services\Frontend\Page\HelpInfo as PageInfoService; /** * @RoutePrefix("/page") diff --git a/app/Http/Web/Controllers/TeacherController.php b/app/Http/Web/Controllers/TeacherController.php index 18382713..bb008d6e 100644 --- a/app/Http/Web/Controllers/TeacherController.php +++ b/app/Http/Web/Controllers/TeacherController.php @@ -3,6 +3,7 @@ namespace App\Http\Web\Controllers; use App\Services\Frontend\Teacher\TeacherList as TeacherListService; +use Phalcon\Mvc\View; /** * @RoutePrefix("/teacher") @@ -11,18 +12,26 @@ class TeacherController extends Controller { /** - * @Get("/list", name="web.teacher") + * @Get("/list", name="web.teacher.list") */ public function listAction() { - $_REQUEST['limit'] = 12; + } + + /** + * @Get("/pager", name="web.teacher.pager") + */ + public function pagerAction() + { $service = new TeacherListService(); $pager = $service->handle(); - $pager->items = kg_array_object($pager->items); + $pager->target = 'teacher-list'; + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('teacher/list_pager'); $this->view->setVar('pager', $pager); } diff --git a/app/Http/Web/Controllers/TopicController.php b/app/Http/Web/Controllers/TopicController.php index 17c6da33..5555ec71 100644 --- a/app/Http/Web/Controllers/TopicController.php +++ b/app/Http/Web/Controllers/TopicController.php @@ -4,6 +4,7 @@ namespace App\Http\Web\Controllers; use App\Services\Frontend\Topic\CourseList as TopicCourseListService; use App\Services\Frontend\Topic\TopicInfo as TopicInfoService; +use Phalcon\Mvc\View; /** * @RoutePrefix("/topic") @@ -20,12 +21,24 @@ class TopicController extends Controller $topic = $service->handle($id); + $this->view->setVar('topic', $topic); + } + + /** + * @Get("/{id:[0-9]+}/courses", name="web.topic.courses") + */ + public function coursesAction($id) + { + $target = $this->request->get('target', 'trim', 'course-list'); + $service = new TopicCourseListService(); - $courses = $service->handle($id); + $pager = $service->handle($id); + $pager->items = kg_array_object($pager->items); + $pager->target = $target; - $this->view->setVar('topic', $topic); - $this->view->setVar('courses', $courses); + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->setVar('pager', $pager); } } diff --git a/app/Http/Web/Controllers/UserController.php b/app/Http/Web/Controllers/UserController.php index de780983..b7ed5300 100644 --- a/app/Http/Web/Controllers/UserController.php +++ b/app/Http/Web/Controllers/UserController.php @@ -31,13 +31,11 @@ class UserController extends Controller */ public function coursesAction($id) { - $target = $this->request->get('target', 'trim', 'tab-courses'); - $service = new UserCourseListService(); $pager = $service->handle($id); $pager->items = kg_array_object($pager->items); - $pager->target = $target; + $pager->target = 'tab-courses'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('pager', $pager); @@ -48,13 +46,11 @@ class UserController extends Controller */ public function favoritesAction($id) { - $target = $this->request->get('target', 'trim', 'tab-favorites'); - $service = new UserFavoriteListService(); $pager = $service->handle($id); $pager->items = kg_array_object($pager->items); - $pager->target = $target; + $pager->target = 'tab-favorites'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('pager', $pager); @@ -65,13 +61,11 @@ class UserController extends Controller */ public function friendsAction($id) { - $target = $this->request->get('target', 'trim', 'tab-friends'); - $service = new UserFriendListService(); $pager = $service->handle($id); $pager->items = kg_array_object($pager->items); - $pager->target = $target; + $pager->target = 'tab-friends'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('pager', $pager); diff --git a/app/Http/Web/Controllers/VipController.php b/app/Http/Web/Controllers/VipController.php index 5a67306e..8f5dd2d4 100644 --- a/app/Http/Web/Controllers/VipController.php +++ b/app/Http/Web/Controllers/VipController.php @@ -30,13 +30,11 @@ class VipController extends Controller */ public function coursesAction() { - $target = $this->request->get('target', 'trim', 'tab-courses'); - $service = new VipCourseListService(); $pager = $service->handle(); $pager->items = kg_array_object($pager->items); - $pager->target = $target; + $pager->target = 'tab-courses'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('pager', $pager); @@ -47,13 +45,11 @@ class VipController extends Controller */ public function usersAction() { - $target = $this->request->get('target', 'trim', 'tab-users'); - $service = new VipUserListService(); $pager = $service->handle(); $pager->items = kg_array_object($pager->items); - $pager->target = $target; + $pager->target = 'tab-users'; $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('pager', $pager); diff --git a/app/Http/Web/Services/CourseQuery.php b/app/Http/Web/Services/CourseQuery.php index b0b4e34f..2cd729af 100644 --- a/app/Http/Web/Services/CourseQuery.php +++ b/app/Http/Web/Services/CourseQuery.php @@ -18,7 +18,7 @@ class CourseQuery extends Service public function handleTopCategories() { - $params = $this->getQueryParams(); + $params = $this->getParams(); if (isset($params['tc'])) { unset($params['tc']); @@ -33,7 +33,7 @@ class CourseQuery extends Service $defaultItem = [ 'id' => 'all', 'name' => '全部', - 'url' => $baseUrl . $this->buildQueryParams($params), + 'url' => $baseUrl . $this->buildParams($params), ]; $result = []; @@ -49,7 +49,7 @@ class CourseQuery extends Service $result[] = [ 'id' => $category['id'], 'name' => $category['name'], - 'url' => $baseUrl . $this->buildQueryParams($params), + 'url' => $baseUrl . $this->buildParams($params), ]; } @@ -58,7 +58,7 @@ class CourseQuery extends Service public function handleSubCategories() { - $params = $this->getQueryParams(); + $params = $this->getParams(); if (empty($params['tc'])) { return []; @@ -81,7 +81,7 @@ class CourseQuery extends Service $defaultItem = [ 'id' => 'all', 'name' => '全部', - 'url' => $baseUrl . $this->buildQueryParams($params), + 'url' => $baseUrl . $this->buildParams($params), ]; $result = []; @@ -93,7 +93,7 @@ class CourseQuery extends Service $result[] = [ 'id' => $category['id'], 'name' => $category['name'], - 'url' => $baseUrl . $this->buildQueryParams($params), + 'url' => $baseUrl . $this->buildParams($params), ]; } @@ -102,7 +102,7 @@ class CourseQuery extends Service public function handleModels() { - $params = $this->getQueryParams(); + $params = $this->getParams(); if (isset($params['model'])) { unset($params['model']); @@ -111,7 +111,7 @@ class CourseQuery extends Service $defaultItem = [ 'id' => 'all', 'name' => '全部', - 'url' => $this->baseUrl . $this->buildQueryParams($params), + 'url' => $this->baseUrl . $this->buildParams($params), ]; $result = []; @@ -125,7 +125,7 @@ class CourseQuery extends Service $result[] = [ 'id' => $key, 'name' => $value, - 'url' => $this->baseUrl . $this->buildQueryParams($params), + 'url' => $this->baseUrl . $this->buildParams($params), ]; } @@ -134,7 +134,7 @@ class CourseQuery extends Service public function handleLevels() { - $params = $this->getQueryParams(); + $params = $this->getParams(); if (isset($params['level'])) { unset($params['level']); @@ -143,7 +143,7 @@ class CourseQuery extends Service $defaultItem = [ 'id' => 'all', 'name' => '全部', - 'url' => $this->baseUrl . $this->buildQueryParams($params), + 'url' => $this->baseUrl . $this->buildParams($params), ]; $result = []; @@ -157,7 +157,7 @@ class CourseQuery extends Service $result[] = [ 'id' => $key, 'name' => $value, - 'url' => $this->baseUrl . $this->buildQueryParams($params), + 'url' => $this->baseUrl . $this->buildParams($params), ]; } @@ -166,7 +166,7 @@ class CourseQuery extends Service public function handleSorts() { - $params = $this->getQueryParams(); + $params = $this->getParams(); $result = []; @@ -177,7 +177,7 @@ class CourseQuery extends Service $result[] = [ 'id' => $key, 'name' => $value, - 'url' => $this->baseUrl . $this->buildQueryParams($params), + 'url' => $this->baseUrl . $this->buildParams($params), ]; } @@ -197,20 +197,20 @@ class CourseQuery extends Service $result['top'] = [ 'name' => $topCategory->name, - 'url' => $this->baseUrl . $this->buildQueryParams($topParams), + 'url' => $this->baseUrl . $this->buildParams($topParams), ]; $subParams = ['tc' => $topCategory->id, 'sc' => $subCategory->id]; $result['sub'] = [ 'name' => $subCategory->name, - 'url' => $this->baseUrl . $this->buildQueryParams($subParams), + 'url' => $this->baseUrl . $this->buildParams($subParams), ]; return $result; } - public function getQueryParams() + public function getParams() { $query = $this->request->getQuery(); @@ -246,7 +246,7 @@ class CourseQuery extends Service return $params; } - protected function buildQueryParams($params) + protected function buildParams($params) { return $params ? '?' . http_build_query($params) : ''; } diff --git a/app/Http/Web/Views/account/login.volt b/app/Http/Web/Views/account/login.volt index d81f8df8..a9022a1b 100644 --- a/app/Http/Web/Views/account/login.volt +++ b/app/Http/Web/Views/account/login.volt @@ -11,7 +11,7 @@
diff --git a/app/Http/Web/Views/course/list.volt b/app/Http/Web/Views/course/list.volt index 25ad59e0..52aed001 100644 --- a/app/Http/Web/Views/course/list.volt +++ b/app/Http/Web/Views/course/list.volt @@ -4,6 +4,8 @@ {{ partial('course/list_filter') }} + {% set pager_url = url({'for':'web.course.pager'}, params) %} +
{% endblock %} diff --git a/app/Http/Web/Views/help/index.volt b/app/Http/Web/Views/help/index.volt new file mode 100644 index 00000000..eec8c6c6 --- /dev/null +++ b/app/Http/Web/Views/help/index.volt @@ -0,0 +1,14 @@ +{% extends 'templates/full.volt' %} + +{% block content %} + +
+ {% for help in helps %} +
+

{{ help.title }}

+
{{ help.content }}
+
+ {% endfor %} +
+ +{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/page/show.volt b/app/Http/Web/Views/page/show.volt new file mode 100644 index 00000000..cbee24d8 --- /dev/null +++ b/app/Http/Web/Views/page/show.volt @@ -0,0 +1,9 @@ +{% extends 'templates/full.volt' %} + +{% block content %} + +

{{ page.title }}

+ +
{{ page.content }}
+ +{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/teacher/list.volt b/app/Http/Web/Views/teacher/list.volt index 01a9334a..2f581f08 100644 --- a/app/Http/Web/Views/teacher/list.volt +++ b/app/Http/Web/Views/teacher/list.volt @@ -2,33 +2,19 @@ {% block content %} + {% set pager_url = url({'for':'web.teacher.pager'}) %} + - {% if pager.total_pages > 0 %} -
-
- {% for item in pager.items %} - {% set user_title = item.title ? item.title : '小小教书匠' %} - {% set user_about = item.about ? item.about|e : '这个人很懒,什么都没留下' %} - {% set user_url = url({'for':'web.teacher.show','id':item.id}) %} -
-
-
- {{ item.name }} -
- -
{{ user_title }}
-
-
- {% endfor %} -
-
- {{ partial('partials/pager') }} - {% endif %} +
+ +{% endblock %} + +{% block include_js %} + + {{ js_include('web/js/teacher.list.js') }} {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/teacher/list_pager.volt b/app/Http/Web/Views/teacher/list_pager.volt new file mode 100644 index 00000000..6cb4e625 --- /dev/null +++ b/app/Http/Web/Views/teacher/list_pager.volt @@ -0,0 +1,23 @@ +{% if pager.total_pages > 0 %} +
+
+ {% for item in pager.items %} + {% set user_title = item.title ? item.title : '小小教书匠' %} + {% set user_about = item.about ? item.about|e : '这个人很懒,什么都没留下' %} + {% set user_url = url({'for':'web.teacher.show','id':item.id}) %} +
+
+
+ {{ item.name }} +
+ +
{{ user_title }}
+
+
+ {% endfor %} +
+
+ {{ partial('partials/pager_ajax') }} +{% endif %} diff --git a/app/Http/Web/Views/topic/courses.volt b/app/Http/Web/Views/topic/courses.volt new file mode 100644 index 00000000..5bd3e409 --- /dev/null +++ b/app/Http/Web/Views/topic/courses.volt @@ -0,0 +1,14 @@ +{{ partial('partials/macro_course') }} + +{% if pager.total_pages > 0 %} +
+
+ {% for item in pager.items %} +
+ {{ course_card(item) }} +
+ {% endfor %} +
+
+ {{ partial('partials/pager_ajax') }} +{% endif %} \ No newline at end of file diff --git a/app/Http/Web/Views/topic/show.volt b/app/Http/Web/Views/topic/show.volt new file mode 100644 index 00000000..11c2f8e6 --- /dev/null +++ b/app/Http/Web/Views/topic/show.volt @@ -0,0 +1,19 @@ +{% extends 'templates/full.volt' %} + +{% block content %} + + {% set courses_url = url({'for':'web.topic.courses','id':topic.id}) %} + +
+

{{ topic.title }}

+
+ +
+ +{% endblock %} + +{% block include_js %} + + {{ js_include('web/js/topic.show.js') }} + +{% endblock %} \ No newline at end of file diff --git a/app/Library/Cache/Backend/Redis.php b/app/Library/Cache/Backend/Redis.php index aec875cf..c78ad6f2 100644 --- a/app/Library/Cache/Backend/Redis.php +++ b/app/Library/Cache/Backend/Redis.php @@ -16,8 +16,8 @@ class Redis extends \Phalcon\Cache\Backend\Redis /** * {@inheritdoc} * - * @param string $keyName - * @param int $lifetime + * @param string $keyName + * @param int $lifetime * @return mixed|null */ public function get($keyName, $lifetime = null) @@ -49,15 +49,15 @@ class Redis extends \Phalcon\Cache\Backend\Redis /** * {@inheritdoc} * - * @param string $keyName - * @param string $content - * @param int $lifetime - * @param bool $stopBuffer + * @param string $keyName + * @param string $content + * @param int $lifetime + * @param bool $stopBuffer * @return bool * * @throws Exception */ - public function save($keyName = null, $content = null, $lifetime = null, $stopBuffer = true) + public function save($keyName = null, $content = null, $lifetime = null, bool $stopBuffer = true): bool { if ($keyName === null) { $lastKey = $this->_lastKey; @@ -127,10 +127,10 @@ class Redis extends \Phalcon\Cache\Backend\Redis /** * {@inheritdoc} * - * @param string $keyName + * @param string $keyName * @return bool */ - public function delete($keyName) + public function delete($keyName): bool { $redis = $this->getRedis(); @@ -142,10 +142,10 @@ class Redis extends \Phalcon\Cache\Backend\Redis /** * {@inheritdoc} * - * @param string $prefix + * @param string $prefix * @return array */ - public function queryKeys($prefix = null) + public function queryKeys($prefix = null): array { $result = []; @@ -167,11 +167,11 @@ class Redis extends \Phalcon\Cache\Backend\Redis /** * {@inheritdoc} * - * @param string $keyName - * @param string $lifetime + * @param string $keyName + * @param string $lifetime * @return bool */ - public function exists($keyName = null, $lifetime = null) + public function exists($keyName = null, $lifetime = null): bool { $redis = $this->getRedis(); @@ -191,7 +191,7 @@ class Redis extends \Phalcon\Cache\Backend\Redis * @param int $value * @return int */ - public function increment($keyName = null, $value = 1) + public function increment($keyName = null, $value = 1): int { $redis = $this->getRedis(); @@ -211,7 +211,7 @@ class Redis extends \Phalcon\Cache\Backend\Redis * @param int $value * @return int */ - public function decrement($keyName = null, $value = 1) + public function decrement($keyName = null, $value = 1): int { $redis = $this->getRedis(); @@ -229,7 +229,7 @@ class Redis extends \Phalcon\Cache\Backend\Redis * * @return bool */ - public function flush() + public function flush(): bool { } diff --git a/app/Library/Http/Request.php b/app/Library/Http/Request.php index 6bc88c92..d88e43ef 100644 --- a/app/Library/Http/Request.php +++ b/app/Library/Http/Request.php @@ -8,7 +8,7 @@ class Request extends \Phalcon\Http\Request /** * @return bool */ - public function isAjax() + public function isAjax(): bool { if (parent::isAjax()) { return true; @@ -26,7 +26,7 @@ class Request extends \Phalcon\Http\Request /** * @return bool */ - public function isApi() + public function isApi(): bool { $url = $this->get('_url'); diff --git a/app/Library/Http/Response.php b/app/Library/Http/Response.php index 3281b841..b7fdc7c5 100644 --- a/app/Library/Http/Response.php +++ b/app/Library/Http/Response.php @@ -2,14 +2,16 @@ namespace App\Library\Http; +use Phalcon\Http\ResponseInterface; + class Response extends \Phalcon\Http\Response { - public function setJsonContent($content, $jsonOptions = 0, $depth = 512) + public function setJsonContent($content, $jsonOptions = 0, $depth = 512): ResponseInterface { $jsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION; - parent::setJsonContent($content, $jsonOptions, $depth); + return parent::setJsonContent($content, $jsonOptions, $depth); } } \ No newline at end of file diff --git a/app/Library/Mvc/View.php b/app/Library/Mvc/View.php index e32fbcb4..77ef13c6 100644 --- a/app/Library/Mvc/View.php +++ b/app/Library/Mvc/View.php @@ -2,10 +2,12 @@ namespace App\Library\Mvc; -class View extends \Phalcon\Mvc\View +use Phalcon\Mvc\View as PhView; + +class View extends PhView { - public function setVars(array $params, $merge = true) + public function setVars(array $params, bool $merge = true): PhView { foreach ($params as $key => $param) { if (is_array($param)) { @@ -13,16 +15,16 @@ class View extends \Phalcon\Mvc\View } } - parent::setVars($params, $merge); + return parent::setVars($params, $merge); } - public function setVar($key, $value) + public function setVar(string $key, $value): PhView { if (is_array($value)) { $value = kg_array_object($value); } - parent::setVar($key, $value); + return parent::setVar($key, $value); } } \ No newline at end of file diff --git a/app/Library/Paginator/Adapter/QueryBuilder.php b/app/Library/Paginator/Adapter/QueryBuilder.php index f23fc4ce..c826866b 100644 --- a/app/Library/Paginator/Adapter/QueryBuilder.php +++ b/app/Library/Paginator/Adapter/QueryBuilder.php @@ -4,6 +4,7 @@ namespace App\Library\Paginator\Adapter; use App\Library\Paginator\Query; use Phalcon\Paginator\Adapter\QueryBuilder as BaseQueryBuilder; +use stdClass; class QueryBuilder extends BaseQueryBuilder { @@ -12,7 +13,7 @@ class QueryBuilder extends BaseQueryBuilder protected $params = []; - public function paginate() + public function paginate(): stdClass { $pager = parent::paginate(); diff --git a/app/Models/AccessToken.php b/app/Models/AccessToken.php index eadd87f6..f3ff5b05 100644 --- a/app/Models/AccessToken.php +++ b/app/Models/AccessToken.php @@ -47,7 +47,7 @@ class AccessToken extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_access_token'; } diff --git a/app/Models/Account.php b/app/Models/Account.php index 1aff0846..1461a6dc 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -63,7 +63,7 @@ class Account extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_account'; } diff --git a/app/Models/Audit.php b/app/Models/Audit.php index 91a48c87..afe748b0 100644 --- a/app/Models/Audit.php +++ b/app/Models/Audit.php @@ -61,7 +61,7 @@ class Audit extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_audit'; } diff --git a/app/Models/Category.php b/app/Models/Category.php index 4402e719..1e48b380 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -92,7 +92,7 @@ class Category extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_category'; } diff --git a/app/Models/Chapter.php b/app/Models/Chapter.php index c147d91f..82a4af1b 100644 --- a/app/Models/Chapter.php +++ b/app/Models/Chapter.php @@ -174,7 +174,7 @@ class Chapter extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_chapter'; } diff --git a/app/Models/ChapterLive.php b/app/Models/ChapterLive.php index be9c8faa..75def952 100644 --- a/app/Models/ChapterLive.php +++ b/app/Models/ChapterLive.php @@ -61,7 +61,7 @@ class ChapterLive extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_chapter_live'; } diff --git a/app/Models/ChapterRead.php b/app/Models/ChapterRead.php index 446e8791..ec3a6d7c 100644 --- a/app/Models/ChapterRead.php +++ b/app/Models/ChapterRead.php @@ -60,7 +60,7 @@ class ChapterRead extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_chapter_read'; } diff --git a/app/Models/ChapterUser.php b/app/Models/ChapterUser.php index 5ade5b66..cde7c085 100644 --- a/app/Models/ChapterUser.php +++ b/app/Models/ChapterUser.php @@ -91,7 +91,7 @@ class ChapterUser extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_chapter_user'; } diff --git a/app/Models/ChapterVod.php b/app/Models/ChapterVod.php index 6c40e18b..52cbe08d 100644 --- a/app/Models/ChapterVod.php +++ b/app/Models/ChapterVod.php @@ -56,7 +56,7 @@ class ChapterVod extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_chapter_vod'; } diff --git a/app/Models/ChapterVote.php b/app/Models/ChapterVote.php index 6365932a..6f284619 100644 --- a/app/Models/ChapterVote.php +++ b/app/Models/ChapterVote.php @@ -63,7 +63,7 @@ class ChapterVote extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_chapter_vote'; } diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 693bba9c..65ee4da5 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -107,7 +107,7 @@ class Comment extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_comment'; } diff --git a/app/Models/CommentVote.php b/app/Models/CommentVote.php index 635c57e9..b8df55c5 100644 --- a/app/Models/CommentVote.php +++ b/app/Models/CommentVote.php @@ -63,7 +63,7 @@ class CommentVote extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_comment_vote'; } diff --git a/app/Models/Consult.php b/app/Models/Consult.php index ab980a5f..943e4f8f 100644 --- a/app/Models/Consult.php +++ b/app/Models/Consult.php @@ -91,7 +91,7 @@ class Consult extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_consult'; } diff --git a/app/Models/ConsultVote.php b/app/Models/ConsultVote.php index 2d32cc6a..3bf0ca77 100644 --- a/app/Models/ConsultVote.php +++ b/app/Models/ConsultVote.php @@ -56,7 +56,7 @@ class ConsultVote extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_consult_vote'; } diff --git a/app/Models/ContentImage.php b/app/Models/ContentImage.php index 50598c60..f15c73a2 100644 --- a/app/Models/ContentImage.php +++ b/app/Models/ContentImage.php @@ -42,7 +42,7 @@ class ContentImage extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_content_image'; } diff --git a/app/Models/Course.php b/app/Models/Course.php index ec082c64..71b2df3f 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -241,7 +241,7 @@ class Course extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_course'; } diff --git a/app/Models/CourseCategory.php b/app/Models/CourseCategory.php index 4d821002..32eec7c6 100644 --- a/app/Models/CourseCategory.php +++ b/app/Models/CourseCategory.php @@ -33,7 +33,7 @@ class CourseCategory extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_course_category'; } diff --git a/app/Models/CourseFavorite.php b/app/Models/CourseFavorite.php index e1a87301..eda06128 100644 --- a/app/Models/CourseFavorite.php +++ b/app/Models/CourseFavorite.php @@ -49,7 +49,7 @@ class CourseFavorite extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_course_favorite'; } diff --git a/app/Models/CoursePackage.php b/app/Models/CoursePackage.php index 4bdb81ef..1ea23a98 100644 --- a/app/Models/CoursePackage.php +++ b/app/Models/CoursePackage.php @@ -33,7 +33,7 @@ class CoursePackage extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_course_package'; } diff --git a/app/Models/CourseRelated.php b/app/Models/CourseRelated.php index 8a06806c..4c593320 100644 --- a/app/Models/CourseRelated.php +++ b/app/Models/CourseRelated.php @@ -33,7 +33,7 @@ class CourseRelated extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_course_related'; } diff --git a/app/Models/CourseTopic.php b/app/Models/CourseTopic.php index 4bd72f62..083c1aef 100644 --- a/app/Models/CourseTopic.php +++ b/app/Models/CourseTopic.php @@ -33,7 +33,7 @@ class CourseTopic extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_course_topic'; } diff --git a/app/Models/CourseUser.php b/app/Models/CourseUser.php index 4405b957..a925bc9c 100644 --- a/app/Models/CourseUser.php +++ b/app/Models/CourseUser.php @@ -111,7 +111,7 @@ class CourseUser extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_course_user'; } diff --git a/app/Models/Help.php b/app/Models/Help.php index b535b8cd..6ee09917 100644 --- a/app/Models/Help.php +++ b/app/Models/Help.php @@ -64,7 +64,7 @@ class Help extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_help'; } diff --git a/app/Models/ImFriendGroup.php b/app/Models/ImFriendGroup.php index 9878dbce..7c29d685 100644 --- a/app/Models/ImFriendGroup.php +++ b/app/Models/ImFriendGroup.php @@ -56,7 +56,7 @@ class ImFriendGroup extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_friend_group'; } diff --git a/app/Models/ImFriendMessage.php b/app/Models/ImFriendMessage.php index 6aa00e6d..e5292659 100644 --- a/app/Models/ImFriendMessage.php +++ b/app/Models/ImFriendMessage.php @@ -70,7 +70,7 @@ class ImFriendMessage extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_friend_message'; } diff --git a/app/Models/ImFriendUser.php b/app/Models/ImFriendUser.php index 1d3e28fb..5f8609b3 100644 --- a/app/Models/ImFriendUser.php +++ b/app/Models/ImFriendUser.php @@ -61,7 +61,7 @@ class ImFriendUser extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_friend_user'; } diff --git a/app/Models/ImGroup.php b/app/Models/ImGroup.php index 91863d4b..0d5b4005 100644 --- a/app/Models/ImGroup.php +++ b/app/Models/ImGroup.php @@ -78,7 +78,7 @@ class ImGroup extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_group'; } diff --git a/app/Models/ImGroupMessage.php b/app/Models/ImGroupMessage.php index 080105a8..b4ac4a7c 100644 --- a/app/Models/ImGroupMessage.php +++ b/app/Models/ImGroupMessage.php @@ -56,7 +56,7 @@ class ImGroupMessage extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_group_message'; } diff --git a/app/Models/ImGroupUser.php b/app/Models/ImGroupUser.php index e3652d73..6f086020 100644 --- a/app/Models/ImGroupUser.php +++ b/app/Models/ImGroupUser.php @@ -54,7 +54,7 @@ class ImGroupUser extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_group_user'; } diff --git a/app/Models/ImSystemMessage.php b/app/Models/ImSystemMessage.php index 0e0c9b55..eb6931f2 100644 --- a/app/Models/ImSystemMessage.php +++ b/app/Models/ImSystemMessage.php @@ -94,7 +94,7 @@ class ImSystemMessage extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_system_message'; } diff --git a/app/Models/ImUser.php b/app/Models/ImUser.php index e1b25a39..53cfe426 100644 --- a/app/Models/ImUser.php +++ b/app/Models/ImUser.php @@ -79,7 +79,7 @@ class ImUser extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_im_user'; } diff --git a/app/Models/Learning.php b/app/Models/Learning.php index 4d7c2b55..6197defe 100644 --- a/app/Models/Learning.php +++ b/app/Models/Learning.php @@ -111,7 +111,7 @@ class Learning extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_learning'; } diff --git a/app/Models/Nav.php b/app/Models/Nav.php index dbe9bd6c..293d9607 100644 --- a/app/Models/Nav.php +++ b/app/Models/Nav.php @@ -117,7 +117,7 @@ class Nav extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_nav'; } diff --git a/app/Models/Order.php b/app/Models/Order.php index 1a18daae..01eb8e46 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -137,7 +137,7 @@ class Order extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_order'; } diff --git a/app/Models/OrderStatus.php b/app/Models/OrderStatus.php index 7e5b9660..7b33ee6d 100644 --- a/app/Models/OrderStatus.php +++ b/app/Models/OrderStatus.php @@ -33,7 +33,7 @@ class OrderStatus extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_order_status'; } diff --git a/app/Models/Package.php b/app/Models/Package.php index 62a7824e..eaf5919b 100644 --- a/app/Models/Package.php +++ b/app/Models/Package.php @@ -78,7 +78,7 @@ class Package extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_package'; } diff --git a/app/Models/Page.php b/app/Models/Page.php index 9bf00e1b..a5390a87 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -50,7 +50,7 @@ class Page extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_page'; } diff --git a/app/Models/RefreshToken.php b/app/Models/RefreshToken.php index 56340449..a7929abc 100644 --- a/app/Models/RefreshToken.php +++ b/app/Models/RefreshToken.php @@ -47,7 +47,7 @@ class RefreshToken extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_refresh_token'; } diff --git a/app/Models/Refund.php b/app/Models/Refund.php index 757928bb..595b254e 100644 --- a/app/Models/Refund.php +++ b/app/Models/Refund.php @@ -108,7 +108,7 @@ class Refund extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_refund'; } diff --git a/app/Models/RefundStatus.php b/app/Models/RefundStatus.php index 15524878..c8b1b55f 100644 --- a/app/Models/RefundStatus.php +++ b/app/Models/RefundStatus.php @@ -33,7 +33,7 @@ class RefundStatus extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_refund_status'; } diff --git a/app/Models/Review.php b/app/Models/Review.php index e17bddf4..11a18e1e 100644 --- a/app/Models/Review.php +++ b/app/Models/Review.php @@ -91,7 +91,7 @@ class Review extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_review'; } diff --git a/app/Models/ReviewVote.php b/app/Models/ReviewVote.php index 0ece47f5..e709d55e 100644 --- a/app/Models/ReviewVote.php +++ b/app/Models/ReviewVote.php @@ -56,7 +56,7 @@ class ReviewVote extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_review_vote'; } diff --git a/app/Models/Reward.php b/app/Models/Reward.php index 099168e8..017a0258 100644 --- a/app/Models/Reward.php +++ b/app/Models/Reward.php @@ -49,7 +49,7 @@ class Reward extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_reward'; } diff --git a/app/Models/Role.php b/app/Models/Role.php index 780c579e..5ab46137 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -84,7 +84,7 @@ class Role extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_role'; } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 327ce3e9..a4bd5f01 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -33,7 +33,7 @@ class Setting extends Model */ public $item_value; - public function getSource() + public function getSource(): string { return 'kg_setting'; } diff --git a/app/Models/Slide.php b/app/Models/Slide.php index 095f4d52..88dd82eb 100644 --- a/app/Models/Slide.php +++ b/app/Models/Slide.php @@ -99,7 +99,7 @@ class Slide extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_slide'; } diff --git a/app/Models/Task.php b/app/Models/Task.php index f38c7306..80d68642 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -89,7 +89,7 @@ class Task extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_task'; } diff --git a/app/Models/Topic.php b/app/Models/Topic.php index b5ea5077..9294fef0 100644 --- a/app/Models/Topic.php +++ b/app/Models/Topic.php @@ -64,7 +64,7 @@ class Topic extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_topic'; } diff --git a/app/Models/Trade.php b/app/Models/Trade.php index 05a767e7..cd5e345b 100644 --- a/app/Models/Trade.php +++ b/app/Models/Trade.php @@ -105,7 +105,7 @@ class Trade extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_trade'; } diff --git a/app/Models/TradeStatus.php b/app/Models/TradeStatus.php index 723d02ab..002d9742 100644 --- a/app/Models/TradeStatus.php +++ b/app/Models/TradeStatus.php @@ -33,7 +33,7 @@ class TradeStatus extends Model */ public $create_time; - public function getSource() + public function getSource(): string { return 'kg_trade_status'; } diff --git a/app/Models/User.php b/app/Models/User.php index dbc3b996..f1cb233f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -141,7 +141,7 @@ class User extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_user'; } diff --git a/app/Models/Vip.php b/app/Models/Vip.php index 63555cae..26453113 100644 --- a/app/Models/Vip.php +++ b/app/Models/Vip.php @@ -56,7 +56,7 @@ class Vip extends Model */ public $update_time; - public function getSource() + public function getSource(): string { return 'kg_vip'; } diff --git a/app/Repos/CourseTopic.php b/app/Repos/CourseTopic.php index 5ae55624..d1d66e76 100644 --- a/app/Repos/CourseTopic.php +++ b/app/Repos/CourseTopic.php @@ -2,6 +2,7 @@ namespace App\Repos; +use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder; use App\Models\CourseTopic as CourseTopicModel; use Phalcon\Mvc\Model; use Phalcon\Mvc\Model\Resultset; @@ -10,6 +11,40 @@ use Phalcon\Mvc\Model\ResultsetInterface; class CourseTopic extends Repository { + public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15) + { + $builder = $this->modelsManager->createBuilder(); + + + $builder->from(CourseTopicModel::class); + + $builder->where('1 = 1'); + + if (!empty($where['course_id'])) { + $builder->andWhere('course_id = :course_id:', ['course_id' => $where['course_id']]); + } + + if (!empty($where['topic_id'])) { + $builder->andWhere('topic_id = :topic_id:', ['topic_id' => $where['topic_id']]); + } + + switch ($sort) { + default: + $orderBy = 'id DESC'; + break; + } + + $builder->orderBy($orderBy); + + $pager = new PagerQueryBuilder([ + 'builder' => $builder, + 'page' => $page, + 'limit' => $limit, + ]); + + return $pager->paginate(); + } + /** * @param int $courseId * @param int $topicId diff --git a/app/Repos/Help.php b/app/Repos/Help.php index 4b406669..30f95968 100644 --- a/app/Repos/Help.php +++ b/app/Repos/Help.php @@ -2,6 +2,7 @@ namespace App\Repos; +use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder; use App\Models\Help as HelpModel; use Phalcon\Mvc\Model; use Phalcon\Mvc\Model\Resultset; @@ -10,6 +11,43 @@ use Phalcon\Mvc\Model\ResultsetInterface; class Help extends Repository { + public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15) + { + $builder = $this->modelsManager->createBuilder(); + + $builder->from(HelpModel::class); + + $builder->where('1 = 1'); + + if (!empty($where['title'])) { + $builder->andWhere('title LIKE :title:', ['title' => "%{$where['title']}%"]); + } + + if (isset($where['published'])) { + $builder->andWhere('published = :published:', ['published' => $where['published']]); + } + + if (isset($where['deleted'])) { + $builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); + } + + switch ($sort) { + default: + $orderBy = 'id DESC'; + break; + } + + $builder->orderBy($orderBy); + + $pager = new PagerQueryBuilder([ + 'builder' => $builder, + 'page' => $page, + 'limit' => $limit, + ]); + + return $pager->paginate(); + } + /** * @param int $id * @return HelpModel|Model|bool diff --git a/app/Repos/Page.php b/app/Repos/Page.php index a2f81017..e7acb1fe 100644 --- a/app/Repos/Page.php +++ b/app/Repos/Page.php @@ -19,6 +19,10 @@ class Page extends Repository $builder->where('1 = 1'); + if (!empty($where['title'])) { + $builder->andWhere('title LIKE :title:', ['title' => "%{$where['title']}%"]); + } + if (isset($where['published'])) { $builder->andWhere('published = :published:', ['published' => $where['published']]); } diff --git a/app/Repos/Topic.php b/app/Repos/Topic.php index 6081b976..b76f0394 100644 --- a/app/Repos/Topic.php +++ b/app/Repos/Topic.php @@ -21,8 +21,8 @@ class Topic extends Repository $builder->where('1 = 1'); - if (!empty($where['user_id'])) { - $builder->andWhere('user_id = :user_id:', ['user_id' => $where['user_id']]); + if (!empty($where['title'])) { + $builder->andWhere('title LIKE :title:', ['title' => "%{$where['title']}%"]); } if (isset($where['published'])) { diff --git a/app/Services/Frontend/Help/HelpInfo.php b/app/Services/Frontend/Help/HelpInfo.php new file mode 100644 index 00000000..2b6619b9 --- /dev/null +++ b/app/Services/Frontend/Help/HelpInfo.php @@ -0,0 +1,30 @@ +checkHelpCache($id); + + return $this->handleHelp($help); + } + + protected function handleHelp(HelpModel $help) + { + return [ + 'id' => $help->id, + 'title' => $help->title, + 'content' => $help->content, + ]; + } + +} diff --git a/app/Services/Frontend/Help/HelpList.php b/app/Services/Frontend/Help/HelpList.php new file mode 100644 index 00000000..8531189a --- /dev/null +++ b/app/Services/Frontend/Help/HelpList.php @@ -0,0 +1,45 @@ + 1]; + + $helps = $helpRepo->findAll($params); + + if ($helps->count() > 0) { + return $this->handleHelps($helps); + } + } + + /** + * @param HelpModel[] $helps + * @return array + */ + protected function handleHelps($helps) + { + $items = []; + + foreach ($helps as $help) { + + $items[] = [ + 'id' => $help->id, + 'title' => $help->title, + 'content' => $help->content, + ]; + } + + return $items; + } + +} diff --git a/app/Services/Frontend/HelpTrait.php b/app/Services/Frontend/HelpTrait.php new file mode 100644 index 00000000..1be74743 --- /dev/null +++ b/app/Services/Frontend/HelpTrait.php @@ -0,0 +1,24 @@ +checkHelp($id); + } + + public function checkHelpCache($id) + { + $validator = new HelpValidator(); + + return $validator->checkHelpCache($id); + } + +} diff --git a/app/Services/Frontend/Topic/CourseList.php b/app/Services/Frontend/Topic/CourseList.php index 8ade19cd..ad6aa2c2 100644 --- a/app/Services/Frontend/Topic/CourseList.php +++ b/app/Services/Frontend/Topic/CourseList.php @@ -2,7 +2,9 @@ namespace App\Services\Frontend\Topic; -use App\Caches\TopicCourseList as TopicCourseListCache; +use App\Builders\CourseTopicList as CourseTopicListBuilder; +use App\Library\Paginator\Query as PagerQuery; +use App\Repos\CourseTopic as CourseTopicRepo; use App\Services\Frontend\Service as FrontendService; use App\Services\Frontend\TopicTrait; @@ -15,11 +17,34 @@ class CourseList extends FrontendService { $topic = $this->checkTopicCache($id); - $cache = new TopicCourseListCache(); + $pagerQuery = new PagerQuery(); - $result = $cache->get($topic->id); + $sort = $pagerQuery->getSort(); + $page = $pagerQuery->getPage(); + $limit = $pagerQuery->getLimit(); - return $result ?: []; + $params = ['topic_id' => $topic->id]; + + $courseTopicRepo = new CourseTopicRepo(); + + $pager = $courseTopicRepo->paginate($params, $sort, $page, $limit); + + return $this->handleCourses($pager); + } + + protected function handleCourses($pager) + { + if ($pager->total_items == 0) { + return $pager; + } + + $builder = new CourseTopicListBuilder(); + + $relations = $pager->items->toArray(); + + $pager->items = $builder->getCourses($relations); + + return $pager; } } diff --git a/app/Services/Frontend/Topic/TopicInfo.php b/app/Services/Frontend/Topic/TopicInfo.php index a6595d76..70250ec7 100644 --- a/app/Services/Frontend/Topic/TopicInfo.php +++ b/app/Services/Frontend/Topic/TopicInfo.php @@ -23,8 +23,7 @@ class TopicInfo extends FrontendService return [ 'id' => $topic->id, 'title' => $topic->title, - 'summary' => $topic->about, - 'course_count' => $topic->course_count, + 'summary' => $topic->summary, ]; } diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css index b058d74a..847c7c16 100644 --- a/public/static/web/css/common.css +++ b/public/static/web/css/common.css @@ -54,7 +54,7 @@ .container { padding: 20px; - margin-bottom: 15px; + margin-bottom: 20px; background-color: #fff; border-radius: 2px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); @@ -284,6 +284,36 @@ margin-bottom: 5px; } +.page-title { + padding-bottom: 10px; + margin-bottom: 20px; + border-bottom: 1px solid #d3d3d3; + text-align: center; + color: #666; +} + +.page-content { + min-height: 450px; + color: #666; +} + +.topic-info { + margin-bottom: 20px; +} + +.topic-info .title { + text-align: center; +} + +.topic-info .summary { + padding: 15px 0; + color: #666; +} + +.course-list { + margin-bottom: 20px; +} + .course-card { float: left; width: 100%; @@ -376,10 +406,6 @@ margin-right: 20px; } -.course-list { - margin-bottom: 20px; -} - .course-meta .cover { float: left; margin-right: 10px; diff --git a/public/static/web/js/teacher.list.js b/public/static/web/js/teacher.list.js new file mode 100644 index 00000000..28cbe43c --- /dev/null +++ b/public/static/web/js/teacher.list.js @@ -0,0 +1,10 @@ +layui.use(['jquery', 'helper'], function () { + + var $ = layui.jquery; + var helper = layui.helper; + + var $teacherList = $('#teacher-list'); + + helper.ajaxLoadHtml($teacherList.data('url'), $teacherList.attr('id')); + +}); \ No newline at end of file diff --git a/public/static/web/js/topic.show.js b/public/static/web/js/topic.show.js new file mode 100644 index 00000000..c66e7726 --- /dev/null +++ b/public/static/web/js/topic.show.js @@ -0,0 +1,9 @@ +layui.use(['jquery', 'helper'], function () { + + var $ = layui.jquery; + var helper = layui.helper; + var $courseList = $('#course-list'); + + helper.ajaxLoadHtml($courseList.data('url'), $courseList.attr('id')); + +}); \ No newline at end of file