CourseApi.php 885 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Http\Api;
  3. use App\Models\CourseMember;
  4. class CourseApi
  5. {
  6. public static function getStudentChannels($courseId)
  7. {
  8. $channels = [];
  9. $studentsChannel = CourseMember::where('course_id', $courseId)
  10. ->whereNotNull('channel_id')
  11. ->where('role', 'student')
  12. ->whereIn('status', ['joined', 'accepted', 'agreed'])
  13. ->select('channel_id')
  14. ->orderBy('created_at')
  15. ->get();
  16. foreach ($studentsChannel as $key => $channel) {
  17. $channels[] = $channel->channel_id;
  18. }
  19. return $channels;
  20. }
  21. public static function role($courseId, $userUid)
  22. {
  23. $role = CourseMember::where('course_id', $courseId)
  24. ->where('user_id', $userUid)
  25. ->where('is_current', true)
  26. ->value('role');
  27. return $role;
  28. }
  29. }