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

dev_forum
jingquan huang 5 years ago
commit 35d52b5116

@ -5,8 +5,8 @@ class ChallengesController < ApplicationController
before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up,
:edit_choose_question, :show_choose_question, :destroy_challenge_choose,
:update_choose_question, :destroy, :crud_answer, :answer]
# before_action :allowed, except: [:index, :show, :edit_choose_question, :edit]
# 权限控制
before_action :allowed, except: [:index]
include ShixunsHelper
include ChallengesHelper
@ -299,8 +299,7 @@ class ChallengesController < ApplicationController
end
def allowed
# 实训为发布前,除实训的管理者外,其他人都不人都不允许访问
if !current_user.manager_of_shixun?(@shixun) && (@shixun.status < 1 || @shixun.hidden == 1)
unless current_user.manager_of_shixun?(@shixun)
raise Educoder::TipException.new(403, "..")
end
end

@ -11,7 +11,7 @@ class CoursesController < ApplicationController
render_error(ex.model.errors.full_messages.join(','))
end
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups]
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner]
before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt,
:set_public_or_private, :search_teacher_candidate, :teachers,
:top_banner, :left_banner, :add_teacher_popup, :add_teacher,

@ -518,7 +518,7 @@ class ShixunsController < ApplicationController
ActiveRecord::Base.transaction do
begin
#cloud_bridge = edu_setting('cloud_bridge')
cloud_bridge = edu_setting('cloud_bridge')
myshixun_identifier = generate_identifier Myshixun, 10
myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier,
modify_time: @shixun.modify_time, reset_time: @shixun.reset_time,
@ -622,10 +622,16 @@ class ShixunsController < ApplicationController
end
def add_collaborators
raise("搜索内容不能为空") unless params[:search]
member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")"
condition = "%#{params[:search].strip}%".gsub(" ","")
@users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname, login, mail, nickname)) LIKE '#{condition}'")
user_name = "%#{params[:user_name].strip}%"
school_name = "%#{params[:school_name].strip}%"
if user_name.present? || school_name.present?
@users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND
LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE
'#{school_name}'")
else
@users = User.none
end
end
def shixun_members_added
@ -667,14 +673,14 @@ class ShixunsController < ApplicationController
limit = params[:limit] || 20
if params[:search]
search = "%#{params[:search].to_s.strip.downcase}%"
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9)
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m
WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0
AND c.name like '#{search}' ").map(&:id)
else
course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, members m, member_roles mr
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9)
course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, course_members m
WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id)
end
@ -686,7 +692,7 @@ class ShixunsController < ApplicationController
# 将实训发送到课程
def send_to_course
@course = Course.find(params[:course_id])
homework = HomeworksService.new.create_homework shixun, @course, nil, current_user
homework = HomeworksService.new.create_homework @shixun, @course, nil, current_user
end
# 二维码扫描下载

@ -164,8 +164,8 @@ class SubjectsController < ApplicationController
end
def choose_course
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9)
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m
WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id)
@courses = Course.where(id: course_ids)
@none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id)

@ -508,15 +508,14 @@ module ExercisesHelper
current_user_group_name = course_group.first.name if course_group.present?
end
teacher_review = ex_user.subjective_score < 0.0 ? false : true
if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交
# if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数
ex_object_score = nil
ex_subject_score = nil
score = nil
else
if (user_status == 0 && commit_status == 1) || (user_status == 1 && ex_user_exercise_status == 3 && commit_status == 1) #老师都可以看,学生,需在试卷已提交,且已截止的情况下看
ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s
ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s
score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s
else
ex_object_score = nil
ex_subject_score = nil
score = nil
end
{
@ -639,6 +638,9 @@ module ExercisesHelper
if student_status == 2 #当前为老师,或为学生且已提交
user_score = exercise_answers.score_reviewed.pluck(:score).sum
end
if user_score > q.question_score
user_score = q.question_score
end
if ques_type <= 2
answered_content = exercise_answers.pluck(:exercise_choice_id)
elsif ques_type == 3

@ -3,11 +3,11 @@ class Exercise < ApplicationRecord
belongs_to :exercise_bank, optional: true
belongs_to :user
has_many :exercise_users,:dependent => :destroy
has_many :exercise_questions,:dependent => :destroy
has_many :exercise_group_settings,:dependent => :destroy
has_many :exercise_users, :dependent => :delete_all
has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all
has_many :tidings, as: :container
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
scope :is_exercise_published, -> { where("exercise_status > ? ",1)}
scope :unified_setting, -> { where("unified_setting = ?",true) }

@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord
belongs_to :user
belongs_to :exercise_question
belongs_to :exercise_choice, optional: true
has_many :exercise_answer_comments, :dependent => :destroy
has_many :exercise_answer_comments, :dependent => :delete_all
scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)}
scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)}

@ -1,9 +1,10 @@
class ExerciseChoice < ApplicationRecord
belongs_to :exercise_question
has_many :exercise_answers, :dependent => :destroy
has_many :exercise_standard_answers, :dependent => :destroy
has_many :exercise_answers, :dependent => :delete_all
has_many :exercise_standard_answers, :dependent => :delete_all
scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
end

@ -4,19 +4,18 @@ class ExerciseQuestion < ApplicationRecord
belongs_to :exercise
belongs_to :shixun, optional: true
has_many :exercise_choices, :dependent => :destroy
has_many :exercise_answers, :dependent => :destroy
has_many :exercise_shixun_challenges,:dependent => :destroy
has_many :exercise_shixun_answers, :dependent => :destroy
has_many :exercise_answer_comments, :dependent => :destroy
has_many :exercise_standard_answers, :dependent => :destroy
has_many :exercise_choices, :dependent => :delete_all
has_many :exercise_answers
has_many :exercise_shixun_challenges, :dependent => :delete_all
has_many :exercise_shixun_answers
has_many :exercise_answer_comments
has_many :exercise_standard_answers
scope :insert_question_ex, lambda {|k| where("question_number > ?",k)}
scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
# scope :next_exercise, lambda {|k| where("question_number > ?",k).first}
# scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
def question_type_name
case self.question_type

@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord
belongs_to :exercise_question
belongs_to :user
belongs_to :exercise_shixun_challenge
has_many :exercise_answer_comments, :dependent => :destroy
has_many :exercise_answer_comments, :dependent => :delete_all
# status 0: 未通过, 1通过
# attr_accessible :answer_text, :score, :status
scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)}

@ -4,13 +4,13 @@ class Poll < ApplicationRecord
belongs_to :exercise_bank, optional: true
# belongs_to :exercise_bank
has_many :poll_questions,dependent: :destroy
has_many :poll_users, :dependent => :destroy
has_many :poll_questions,dependent: :delete_all
has_many :poll_users, :dependent => :delete_all
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
has_many :poll_group_settings, :dependent => :destroy
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :poll_group_settings, :dependent => :delete_all
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all
has_many :tidings, as: :container, dependent: :destroy
has_many :tidings, as: :container, dependent: :delete_all
scope :publish_or_not, -> { where("polls_status > ? ",1)}
scope :only_public, -> {where("is_public = ?",true)}

@ -3,7 +3,7 @@ class PollAnswer < ApplicationRecord
# include Redmine::SafeAttributes
belongs_to :poll_question
has_many :poll_votes, :dependent => :destroy
has_many :poll_votes, :dependent => :delete_all
scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题
scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题

@ -1,9 +1,9 @@
class PollQuestion < ApplicationRecord
belongs_to :poll
has_many :poll_answers, :dependent => :destroy
has_many :poll_answers, :dependent => :delete_all
attr_accessor :question_answers, :question_other_anser
has_many :poll_votes, :dependent => :destroy
has_many :poll_votes
scope :ques_count, lambda {|k| where("question_type = ?",k)}
scope :ques_necessary, -> {where("is_necessary = ?",1)}

@ -6,10 +6,11 @@ json.question_type question.question_type
json.question_score question.question_score.round(1).to_s
if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置
standard_answers_array = question.get_standard_answer_ids
exercise_choices = choices.order("choice_position ASC")
ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱
if ex_choice_random_boolean
exercise_choices = exercise_choices.order("RAND()")
exercise_choices = choices.order("RAND()")
else
exercise_choices = choices.order("choice_position ASC")
end
json.question_choices do
json.array! exercise_choices.each_with_index.to_a do |a,index|

@ -1,4 +1,3 @@
json.status 1
json.message "发送成功"
json.url course_homework_commons_path(@course.id, type: 4)
# json.url "#{Rails::configuration.educoder['old_edu_host']}/homework_common?course=#{@course.id}&homework_type=4"
json.course_id @course.id
Loading…
Cancel
Save