Class: EducodeSales::Teacher

Inherits:
ApplicationRecord show all
Defined in:
app/models/educode_sales/teacher.rb

Instance Method Summary collapse

Instance Method Details

#cal_courses_countObject



18
19
20
21
22
23
24
# File 'app/models/educode_sales/teacher.rb', line 18

def cal_courses_count
  if self.user_id.present?
    Course.joins(:course_members).where(course_members: {user_id: self.user_id}).where("is_delete = 0 and role != 4  and excellent = 0 and is_hidden = 0").where("start_date is null or start_date <= '#{Date.today}'").distinct(:course_id).count
  else
    0
  end
end

#cal_students_countObject



33
34
35
36
37
38
39
40
# File 'app/models/educode_sales/teacher.rb', line 33

def cal_students_count
  if user_id.present?
    course_ids = Course.joins(:course_members).where(course_members: {user_id: user_id}).where("is_delete = 0 and role != 4  and excellent = 0  and is_hidden = 0").where("start_date is null or start_date <= '#{Date.today}'").distinct("course_id").pluck(:course_id)
    CourseMember.where(course_id: course_ids, role: "STUDENT").count
  else
    0
  end
end

#teacher_used_of_departmentObject



26
27
28
29
30
31
# File 'app/models/educode_sales/teacher.rb', line 26

def teacher_used_of_department
  user_ids = User.joins(:user_extension).where(user_extensions: {department_id: self.department_id, identity: 0}).pluck(:id)
  course_ids = CourseMember.where(role: "CREATOR", user_id: user_ids).pluck(:course_id)
  course_members = CourseMember.joins(course: :practice_homework_shixuns).where(course_id: course_ids).group("course_id").having("COUNT(homework_commons_shixuns.id) > 100 AND COUNT(course_members.user_id) > 20").select("COUNT(case when course_members.role !=4 then 1 END) AS count")
  course_members.present? ? course_members[0]['count'] : 0
end