Sha256: 6b317fa6e2b50a27bdaab4f7b02ea9ae14388df43e46641096cea8c4d6bbe8b3

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

module EducodeSales
  class Teacher < ApplicationRecord
    has_many :activity_teachers
    has_many :activities, through: :activity_teachers
    has_many :teacher_follows, dependent: :destroy
    has_many :operation_plans, dependent: :destroy
    has_many :course_subjects, dependent: :destroy
    has_many :key_person, dependent: :destroy
    belongs_to :department, optional: true
    belongs_to :staff
    belongs_to :user, optional: true
    # belongs_to :follow_up, counter_cache: true, optional: true
    belongs_to :follow_up, class_name: 'TeacherFollow', optional: true
    validates :user_id, uniqueness: { allow_blank: true, message: '已存在老师列表'}


    def teacher_used_of_department
      if user_id.present?
        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)
        if course_ids.present?
          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) > 30").select("COUNT(*) AS count")
          course_members.present? ? course_members[0]['count'] : 0
        else
          0
        end
      else
        0
      end
    end

    def students_count
      if user_id.present?
        course_ids = CourseMember.where.not(role: "STUDENT").where(user_id: user_id).pluck(:course_id)
        CourseMember.where(course_id: course_ids, role: "STUDENT").count
      else
        0
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
educode_sales-0.2.4 app/models/educode_sales/teacher.rb
educode_sales-0.2.3 app/models/educode_sales/teacher.rb
educode_sales-0.2.2 app/models/educode_sales/teacher.rb
educode_sales-0.2.1 app/models/educode_sales/teacher.rb