← All changes
|
Modules/Course/Http/Controllers/CourseController.php
+16
-4
2.7.7
→
2.10.01
View file →
| @@ -530,9 +530,9 @@ | ||
| 530 | 530 | { |
| 531 | 531 | $user = $this->getUser(); |
| 532 | 532 | $isCourseCreator = $user && $user->hasCourseCreatorAccess(); |
| 533 | 533 | |
| 534 | - $courses = Course::where(function ($q) use ($isCourseCreator, $user) { | |
| 534 | + $coursesQuery = Course::where(function ($q) use ($isCourseCreator, $user) { | |
| 535 | 535 | if ($isCourseCreator) { |
| 536 | 536 | $q->where('status', 'published') |
| 537 | 537 | ->orWhere('created_by', $user->ID); |
| 538 | 538 | } else { |
| @@ -537,11 +537,23 @@ | ||
| 537 | 537 | ->orWhere('created_by', $user->ID); |
| 538 | 538 | } else { |
| 539 | 539 | $q->where('status', 'published'); |
| 540 | 540 | } |
| 541 | - }) | |
| 542 | - ->with(['creator']) | |
| 543 | - ->paginate(); | |
| 541 | + }); | |
| 542 | + | |
| 543 | + if (!($user && $user->isCommunityModerator())) { | |
| 544 | + $userId = get_current_user_id(); | |
| 545 | + $coursesQuery->where(function ($q) use ($userId) { | |
| 546 | + $q->whereIn('privacy', ['public', 'private']) | |
| 547 | + ->orWhereHas('space_pivot', function ($sub) use ($userId) { | |
| 548 | + $sub->where('user_id', $userId) | |
| 549 | + ->where('role', 'student'); | |
| 550 | + }) | |
| 551 | + ->orWhere('created_by', $userId); | |
| 552 | + }); | |
| 553 | + } | |
| 554 | + | |
| 555 | + $courses = $coursesQuery->with(['creator'])->paginate(); | |
| 544 | 556 | |
| 545 | 557 | $formattedCourses = []; |
| 546 | 558 | foreach ($courses as $course) { |
| 547 | 559 | $course->sectionsCount = CourseTopic::where('space_id', $course->id)->count(); |