where('course_id', $course_id)->count(); return $total_lesson; } } } if (!function_exists('section_count')) { function section_count($course_id = "") { if ($course_id != '') { $total_section = DB::table('sections')->where('course_id', $course_id)->count(); return $total_section; } } } if (!function_exists('count_blogs_by_category')) { function count_blogs_by_category($category_id = "") { if ($category_id != '') { $total_blog = DB::table('blogs')->where('status', 1)->where('category_id', $category_id)->count(); return $total_blog; } } } if (!function_exists('get_blog_category_name')) { function get_blog_category_name($id = "") { if ($id != '') { $category_title = DB::table('blog_categories')->where('id', $id)->value('title'); return $category_title; } } } if (!function_exists('get_user_info')) { function get_user_info($user_id = "") { $user_info = App\Models\User::where('id', $user_id)->firstOrNew(); return $user_info; } } if (!function_exists('get_image_by_id')) { function get_image_by_id($user_id = "") { $image_path = DB::table('users')->where('id', $user_id)->value('photo'); return get_image($image_path); } } if (!function_exists('timeAgo')) { function timeAgo($time_ago) { $time_ago = strtotime($time_ago); $cur_time = time(); $time_elapsed = $cur_time - $time_ago; $seconds = $time_elapsed; $minutes = round($time_elapsed / 60); $hours = round($time_elapsed / 3600); $days = round($time_elapsed / 86400); $weeks = round($time_elapsed / 604800); $months = round($time_elapsed / 2600640); $years = round($time_elapsed / 31207680); // Seconds if ($seconds <= 60) { return "just now"; } //Minutes else if ($minutes <= 60) { if ($minutes == 1) { return "1 minute ago"; } else { return "$minutes minutes ago"; } } //Hours else if ($hours <= 24) { if ($hours == 1) { return "1 hour ago"; } else { return "$hours hours ago"; } } //Days else if ($days <= 7) { if ($days == 1) { return "Yesterday"; } else { return "$days days ago"; } } //Weeks else if ($weeks <= 4.3) { if ($weeks == 1) { return "1 week ago"; } else { return "$weeks weeks ago"; } } //Months else if ($months <= 12) { if ($months == 1) { return "1 month ago"; } else { return "$months months ago"; } } //Years else { if ($years == 1) { return "1 year ago"; } else { return "$years years ago"; } } } } if (!function_exists('course_enrolled')) { function course_enrolled($user_id = "") { if ($user_id != '') { $enrolled = DB::table('enrollments')->where('user_id', $user_id)->exists(); return $enrolled; } } } if (!function_exists('course_enrollments')) { function course_enrollments($course_id = "") { if ($course_id != '') { $enrolled = DB::table('enrollments')->where('course_id', $course_id)->count(); return $enrolled; } } } if (!function_exists('course_by_instructor')) { function course_by_instructor($course_id = "") { if ($course_id != '') { $user_id = App\Models\Course::where('id', $course_id)->firstOrNew(); $byInstructor = App\Models\User::where('id', $user_id->user_id)->firstOrNew(); return $byInstructor; } } } if (!function_exists('course_instructor_image')) { function course_instructor_image($course_id = "") { if ($course_id != '') { $user_id = DB::table('courses')->where('id', $course_id)->value('user_id'); $user_image = DB::table('users')->where('id', $user_id)->value('photo'); } $img_path = isset($user_image) ? $user_image : $course_id; return get_image($img_path); } } if (!function_exists('get_course_info')) { function get_course_info($course_id) { $course = App\Models\Course::where('id', $course_id)->firstOrNew(); return $course; } } if (!function_exists('count_unread_message_of_thread')) { function count_unread_message_of_thread($message_thread_code = "") { $unread_message_counter = 0; $current_user = auth()->user()->id; $messages = DB::table('messages')->where('message_thread_code', $message_thread_code)->get(); foreach ($messages as $row) { if ($row->sender != $current_user && $row->read_status == '0') { $unread_message_counter++; } } return $unread_message_counter; } } if (!function_exists('get_enroll_info')) { function get_enroll_info($course_id = "", $user_id = "") { if ($course_id != '' && $user_id != "") { $enrolled = App\Models\Enrollment::where('course_id', $course_id)->where('user_id', $user_id)->firstOrNew(); return $enrolled; } } } if (!function_exists('total_enrolled')) { function total_enrolled() { $total_enrolled = DB::table('enrollments')->count(); return $total_enrolled; } } if (!function_exists('total_enroll')) { function total_enroll($course_id = "") { if ($course_id != '') { $count = DB::table('enrollments')->where('course_id', $course_id)->count(); return $count; } } } if (!function_exists('is_course_instructor')) { function is_course_instructor($course_id = "", $user_id = "") { if ($user_id == '') { $user_id = auth()->user()->id; } $course = App\Models\Course::where('id', $course_id)->firstOrNew(); if ($course) { if ($course->instructors()->where('id', $user_id)->count() > 0 || $course->user_id == $user_id) { return true; } } return false; } } // Get Home page Settings Data if (!function_exists('get_homepage_settings')) { function get_homepage_settings($type = "", $return_type = false) { $value = DB::table('home_page_settings')->where('key', $type); if ($value->count() > 0) { if ($return_type === true) { return json_decode($value->value('value'), true); } elseif ($return_type === "object") { return json_decode($value->value('value')); } else { return $value->value('value'); } } else { return false; } } } if (!function_exists('count_student_by_instructor')) { function count_student_by_instructor($user_id = "") { if ($user_id != '') { $course_ids = App\Models\Course::where('user_id', $user_id)->pluck('id')->toArray(); $total_student = 0; $total_student = App\Models\Enrollment::whereIn('course_id', $course_ids)->distinct('user_id')->count(); return ($total_student > 1) ? "{$total_student} " . get_phrase('Students') : "{$total_student} " . get_phrase('Student'); } } } if (!function_exists('count_course_by_instructor')) { function count_course_by_instructor($user_id = "") { if ($user_id != '') { $count_course = DB::table('courses')->where('status', 'active')->where('user_id', $user_id)->count(); return ($count_course > 1) ? "{$count_course} " . get_phrase('Courses') : "{$count_course} " . get_phrase('Course'); } } } if (!function_exists('progress_bar')) { function progress_bar($course_id = "") { if ($course_id != '') { $lesson_history = App\Models\Watch_history::where('course_id', $course_id) ->where('student_id', auth()->user()->id) ->firstOrNew(); $total_lesson = lesson_count($course_id); $progress_result = 0; if ($lesson_history && $lesson_history->completed_lesson != '') { $complete_lesson_ids = json_decode($lesson_history->completed_lesson, true) ?? [0]; $count_incomplete_lesson = App\Models\Lesson::where('course_id', $course_id)->whereNotIn('id', $complete_lesson_ids)->count(); $count_complete_lesson = $total_lesson - $count_incomplete_lesson; if (count($complete_lesson_ids) != $count_complete_lesson) { check_lesson_was_deleted($complete_lesson_ids, $lesson_history->id); } $progress_result = $total_lesson ? (count($complete_lesson_ids) * 100) / $total_lesson : 0; } if ($progress_result <= 100) { return number_format($progress_result, 2); } else { return 100; } } } } if (!function_exists('check_lesson_was_deleted')) { function check_lesson_was_deleted($complete_lesson_ids = [], $lesson_history_id = "") { $updated_completed_lesson_ids = []; foreach ($complete_lesson_ids as $complete_lesson_id) { if (App\Models\Lesson::where('id', $complete_lesson_id)->count() > 0) { $updated_completed_lesson_ids[] = $complete_lesson_id; } } App\Models\Watch_history::where('id', $lesson_history_id)->update(['completed_lesson' => json_encode($updated_completed_lesson_ids)]); } } if (!function_exists('course_creator')) { function course_creator($user_id = "") { if ($user_id != '') { $creator = DB::table('courses')->where('user_id', $user_id)->exists(); return $creator; } } } if (!function_exists('get_course_creator_id')) { function get_course_creator_id($course_id = "") { if ($course_id != '') { $course = DB::table('courses')->where('id', $course_id)->get(); foreach ($course as $value) { $creator = App\Models\User::where('id', $value->user_id)->firstOrNew(); } return $creator; } } } if (!function_exists('user_count')) { function user_count($role = "") { if ($role != '') { $user_count = DB::table('users')->where('role', $role)->count(); return $user_count; } } } if (!function_exists('blog_user')) { function blog_user($user_id = "") { if ($user_id != '') { $user = App\Models\User::where('id', $user_id)->firstOrNew(); return $user; } } } if (!function_exists('category_course_count')) { function category_course_count($slug = "") { if ($slug != '') { $slug_category = App\Models\Category::where('slug', $slug)->firstOrNew(); $all_category = DB::table('categories')->where('id', $slug_category->id)->get(); foreach ($all_category as $row) { $sub_category = DB::table('categories')->where('parent_id', $row->id)->get(); } foreach ($sub_category as $sub_categories) { $category_by_course = DB::table('courses')->where('category_id', $sub_categories->id)->count(); } return $category_by_course; } } } if (!function_exists('category_by_course')) { function category_by_course($category_id = "") { $category_by_courses = App\Models\Category::where('id', $category_id)->firstOrNew(); return $category_by_courses; } } if (!function_exists('check_course_admin')) { function check_course_admin($user_id = "") { if ($user_id != '') { $creator = DB::table('users')->where('id', $user_id)->value('role'); return $creator; } } } if (!function_exists('duration_to_seconds')) { function duration_to_seconds($duration = "00:00:00:") { if($duration == '') { $duration = "00:00:00:"; } $time_array = explode(':', $duration); $hour_to_seconds = $time_array[0] * 60 * 60; $minute_to_seconds = $time_array[1] * 60; $seconds = $time_array[2]; $total_seconds = $hour_to_seconds + $minute_to_seconds + $seconds; return $total_seconds; } } if (!function_exists('total_durations')) { function total_durations($course_id = '') { $total_duration = 0; $lessons = DB::table('lessons')->where('course_id', $course_id)->get(); foreach ($lessons as $lesson) { if ($lesson->duration != '') { $time_array = explode(':', $lesson->duration); $hour_to_seconds = $time_array[0] * 60 * 60; $minute_to_seconds = $time_array[1] * 60; $seconds = $time_array[2]; $total_duration += $hour_to_seconds + $minute_to_seconds + $seconds; } } $hours = floor($total_duration / 3600); $minutes = floor(($total_duration - ($hours * 3600)) / 60); $seconds = floor($total_duration - ($hours * 3600) - ($minutes * 60)); return sprintf("%02dh %02dm", $hours, $minutes); } } if (!function_exists('total_durations_by')) { function total_durations_by($course_id = '') { $total_duration = 0; $lessons = DB::table('lessons')->where('course_id', $course_id)->get(); foreach ($lessons as $lesson) { if ($lesson->duration != '') { $time_array = explode(':', $lesson->duration); $hour_to_seconds = $time_array[0] * 60 * 60; $minute_to_seconds = $time_array[1] * 60; $seconds = $time_array[2]; $total_duration += $hour_to_seconds + $minute_to_seconds + $seconds; } } $hours = floor($total_duration / 3600); $minutes = floor(($total_duration - ($hours * 3600)) / 60); $seconds = floor($total_duration - ($hours * 3600) - ($minutes * 60)); return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds); } } if (!function_exists('lesson_durations')) { function lesson_durations($lesson_id = '') { $total_duration = 0; $lessons = App\Models\Lesson::where('id', $lesson_id)->firstOrNew(); if ($lessons->duration != '') { $time_array = explode(':', $lessons->duration); $hour_to_seconds = $time_array[0] * 60 * 60; $minute_to_seconds = $time_array[1] * 60; $seconds = $time_array[2]; $total_duration += $hour_to_seconds + $minute_to_seconds + $seconds; } $hours = floor($total_duration / 3600); $minutes = floor(($total_duration - ($hours * 3600)) / 60); $seconds = floor($total_duration - ($hours * 3600) - ($minutes * 60)); return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds); } } if (!function_exists('is_root_admin')) { function is_root_admin($admin_id = '') { // GET THE LOGGEDIN IN ADMIN ID if (empty($admin_id)) { $admin_id = auth()->user()->id; } $root_admin_id = App\Models\User::limit(1)->orderBy('id', 'asc')->firstOrNew()->id; if ($root_admin_id == $admin_id) { return true; } else { return false; } } } if (!function_exists('removeScripts')) { function removeScripts($text) { if(!$text) return; // Remove