Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_new_shixunsrepository
daiao 5 years ago
commit 82068f1293

@ -983,8 +983,8 @@ class HomeworkCommonsController < ApplicationController
end
homework.homework_detail_manual.update_attributes!(comment_status: 1)
if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
if homework.course_act.blank?
homework.course_act << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
end
# 发消息
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)

@ -6,6 +6,23 @@ class Weapps::CoursesController < Weapps::BaseController
before_action :teacher_allowed, only: [:edit, :update]
before_action :teacher_or_admin_allowed, only: [:change_member_roles, :delete_course_teachers]
def course_activities
@course = current_course
homework_commons = @course.homework_commons.where(homework_type: ["practice", "normal"]).homework_published
member = @course.course_members.find_by(user_id: current_user.id, is_active: 1)
if (@user_course_identity == Course::STUDENT && member.try(:course_group_id).to_i == 0) || @user_course_identity > Course::STUDENT
homework_commons = homework_commons.unified_setting
elsif @user_course_identity == Course::STUDENT
not_homework_ids = @course.homework_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}").pluck(:homework_common_id)
homework_commons = homework_commons.where.not(id: not_homework_ids)
end
homework_ids = homework_commons.blank? ? "(-1)" : "(" + homework_commons.pluck(:id).join(",") + ")"
activities = @course.course_activities.where("course_act_type in ('Course', 'CourseMessage') or
(course_act_type = 'HomeworkCommon' and course_act_id in #{homework_ids})").order("id desc")
@activities = paginate activities.includes(:course_act, user: :user_extension)
end
def create
# return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher?
course = Course.new(tea_id: current_user.id)

@ -70,7 +70,9 @@ class Course < ApplicationRecord
# 课堂动态
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :course_activities
has_many :tidings, as: :container, dependent: :destroy
# 开放课堂
@ -300,7 +302,7 @@ class Course < ApplicationRecord
#课程动态公共表记录
def act_as_course_activity
self.course_acts << CourseActivity.new(user_id: tea_id, course_id: id)
self.course_act << CourseActivity.new(user_id: tea_id, course_id: id)
end
# 当前老师分班下的所有学生

@ -4,9 +4,26 @@ class CourseActivity < ApplicationRecord
belongs_to :user
belongs_to :exercise
belongs_to :poll
belongs_to :course_message
belongs_to :homework_common
# after_create :add_course_lead
def container_name
case course_act_type
when "HomeworkCommon"
course_act&.name
when "Exercise"
course_act&.exercise_name
when "Poll"
course_act&.poll_name
when "Message"
course_act&.subject
else
""
end
end
# 发布新课导语
# 导语要放置在课程创建信息之后
def add_course_lead

@ -2,6 +2,7 @@ class CourseMessage < ApplicationRecord
enum status: { UNHANDLED: 0, PASSED: 1, REJECTED: 2 }
belongs_to :course
belongs_to :user
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
scope :find_by_course, ->(course) { where(course_id: course.id) }
scope :join_course_requests, -> { where(course_message_type: "JoinCourseRequest") }
@ -9,6 +10,8 @@ class CourseMessage < ApplicationRecord
scope :unhandled_join_course_requests_by_course, ->(course) { find_by_course(course).join_course_requests.unhandled }
after_create :act_as_course_activity
def pass!
update!(status: :PASSED)
send_deal_tiding(1)
@ -25,6 +28,11 @@ class CourseMessage < ApplicationRecord
private
#课程动态公共表记录
def act_as_course_activity
self.course_act << CourseActivity.new(user_id: course_message_id, course_id: course_id)
end
def send_deal_tiding deal_status
# 发送申请处理结果消息
Tiding.create!(

@ -28,7 +28,7 @@ class HomeworkCommon < ApplicationRecord
belongs_to :course_second_category, optional: true
# 课堂动态
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :tidings, as: :container, dependent: :destroy
# 实训作业的分班查重记录
has_many :homework_group_reviews, :dependent => :destroy

@ -19,7 +19,7 @@ class OptionalItemQuery < ApplicationQuery
end
if hacks.present?
items = ItemBank.where(container_id: hacks.pluck(:id), container_type: "Hack").or(ItemBank.where(id: items.pluck(:id)))
items = ItemBank.where(container_id: hacks.where(status: 1).pluck(:id), container_type: "Hack").or(ItemBank.where(id: items.pluck(:id)))
end
public = source.present? ? source.to_i : 1

@ -0,0 +1,12 @@
json.activities @activities do |activity|
json.(activity, :course_act_id, :course_act_type)
json.author do
user = activity.user
json.name user.real_name
json.login user.login
json.img url_to_avatar(user)
end
json.created_at activity.created_at.strftime('%m-%d %H:%M:')
json.container_name activity.container_name
json.container_type activity.course_act_type == "HomeworkCommon" ? activity.course_act&.homework_type : ""
end

@ -1040,12 +1040,13 @@ Rails.application.routes.draw do
member do
get :shixun_homework_category
get :teachers
delete :delete_course_teachers
post :change_member_roles
get :students
delete :delete_course_students
get :course_groups
get :basic_info
get :course_activities
post :change_member_roles
delete :delete_course_teachers
delete :delete_course_students
end
collection do

@ -0,0 +1,5 @@
class MigrateCourseMessageAct < ActiveRecord::Migration[5.2]
def change
CourseActivity.where(course_act_type: "JoinCourse").update_all(course_act_type: "CourseMessage")
end
end

@ -45,7 +45,7 @@ namespace :homework_publishtime do
end
end
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if !homework.course_acts.exists?
homework.course_act << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if !homework.course_act.present?
end
# 分组设置发布时间的作业

Loading…
Cancel
Save