dev_aliyun
daiao 5 years ago
commit 659f963519

@ -67,12 +67,12 @@ class CollegesController < ApplicationController
user_extensions.`school_id`=#{@school.id}) and work_status between 1 and 2 and myshixun_id !=0").first.try(:sw_count)
@teachers = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count,
(SELECT count(c.id) FROM courses c, members m, member_roles mr WHERE c.id != 1309 and m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) and c.school_id = #{@school.id} AND m.user_id=users.id AND c.is_delete = 0) as course_count
(SELECT count(c.id) FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) and c.school_id = #{@school.id} AND m.user_id=users.id AND c.is_delete = 0) as course_count
FROM `users`, user_extensions ue where users.id=ue.user_id and ue.identity=0 and ue.school_id=#{@school.id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10")
# ).order("publish_shixun_count desc, experience desc").limit(10)
@teachers =
@teachers.map do |teacher|
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr WHERE c.id != 1309 and m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}")
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}")
course_count = course_ids.size
homeworks = HomeworkCommon.where(:homework_type => 4, :course_id => course_ids.map(&:id))
un_shixun_work_count = homeworks.where("publish_time > '#{Time.now}' or publish_time is null").count

@ -32,9 +32,8 @@ class CompetitionTeamsController < ApplicationController
# todo使用新版course_members
course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01'))
.joins('join members on members.course_id = courses.id')
.joins('join member_roles on member_roles.member_id = members.id and member_roles.role_id in (3,7,9)')
.where(members: { user_id: @team_user_ids }).pluck(:id)
.joins('join course_members on course_members.course_id = courses.id and course_members.role in (1,2,3)')
.where(course_members: { user_id: @team_user_ids }).pluck(:id)
courses = Course.where(id: course_ids).joins(:shixun_homework_commons).where('homework_commons.publish_time < now()')
@courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count')
.group('courses.id').order('shixun_homework_count desc').having('shixun_homework_count > 0')

@ -87,7 +87,7 @@ class CoursesController < ApplicationController
course_ids = course_ids.present? ? course_ids.join(",") : -1
@courses = Course.where("courses.is_delete = 0 and courses.is_hidden = 0 #{course_ids == -1 ? "" : "and courses.id in (#{course_ids})"}").select("courses.id, courses.tea_id, courses.name, courses.is_public, courses.members_count, courses.homework_commons_count,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("courses.id = 1309 desc, a desc")
elsif @order == "mine"
my_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,10) AND m.user_id=#{@user.id} AND c.is_delete = 0")
my_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,4) AND m.user_id=#{@user.id} AND c.is_delete = 0")
course_ids = course_ids.present? ? my_course_ids.map(&:id) & course_ids : my_course_ids.map(&:id)
course_ids = course_ids.size > 0 ? course_ids.join(",") : "-1"
@courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 and c.is_hidden = 0 and c.id in (#{course_ids}) order by c.id = 1309 desc, #{order_str} desc")
@ -894,7 +894,7 @@ class CoursesController < ApplicationController
# @teacher_count = TeacherAndAssistantCount @course
if @course.try(:id) != 1309 || User.current.admin? || User.current.try(:id) == 15582
@teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7,9]).count
@teacher_count = @course.course_members.includes(:roles, :user).where("roles.id" => [3,7,9]).count
else
@teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7]).count
end

@ -2944,20 +2944,20 @@ end
course_group = CourseGroup.where(:course_id => course.id, :name => group_name).first ||
CourseGroup.create(:name => group_name, :course_id => course.id) if group_name
member = course.members.where(:user_id => user.id).first
member = course.course_members.where(:user_id => user.id, :role => 4).first
# 如果已是课堂成员且是学生身份and不在指定的分班则移动到该分班
if member.present? && member.member_roles.pluck(:role_id).include?(10) && member.course_group_id != course_group.try(:id).to_i
if member.present? && member.course_group_id != course_group.try(:id).to_i
member.update_column("course_group_id", course_group.try(:id).to_i)
member_count += 1
elsif !member.present?
member = Member.new(:role_ids => [member_role], :user_id => user.id)
if member_role == 10
StudentsForCourse.create(:student_id => user.id, :course_id => course.id)
end
member = CourseMember.new(:role => 4, :user_id => user.id)
# if member_role == 10
# StudentsForCourse.create(:student_id => user.id, :course_id => course.id)
# end
Tiding.create(:user_id => user.id, :trigger_user_id => course.tea_id, :container_id => course.id, :container_type => 'TeacherJoinCourse',
:belong_container_id => course.id, :belong_container_type => "Course", :tiding_type => "System", :extra => member_role)
member.course_group_id = course_group.try(:id).to_i
course.members << member
course.course_members << member
member_count += 1
end
@ -4262,7 +4262,7 @@ end
teacher_name = course.teacher ? course.teacher.show_real_name : ""
sheet1[count_row,0] = course.id
sheet1[count_row,1] = course.name
sheet1[count_row,2] = course.members.count
sheet1[count_row,2] = course.course_members_count
sheet1[count_row,3] = course.attachments.count
sheet1[count_row,4] = course.homework_commons.where(:homework_type => 1).count
sheet1[count_row,5] = course.homework_commons.where(:homework_type => 4).count

@ -2438,14 +2438,14 @@ class UsersController < ApplicationController
case @type
when "a_course"
student_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, students_for_courses sfc WHERE sfc.course_id = c.id AND sfc.student_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}")
manage_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) AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}")
manage_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=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}")
course_ids = student_course_ids.map(&:id) + manage_course_ids.map(&:id)
@objects = Course.where(:id => course_ids.uniq).includes(:attachments, :teacher => [:user_extensions => [:school]]).order("updated_at #{order}")
when "l_course"
student_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, students_for_courses sfc WHERE sfc.course_id = c.id AND sfc.student_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}")
student_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE m.course_id = c.id and m.role = 4 AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}")
@objects = Course.where(:id => student_course_ids.map(&:id)).includes(:attachments, :teacher => [:user_extensions => [:school]]).order("updated_at #{order}")
when "p_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) AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}")
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=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}")
@objects = Course.where(:id => course_ids.map(&:id)).includes(:attachments, :teacher => [:user_extensions => [:school]]).order("id = 1309 desc, updated_at #{order}")
when "a_shixun"
shixun_ids = @user.shixun_members.map(&:shixun_id) + @user.myshixuns.map(&:shixun_id)

@ -33,6 +33,8 @@ class Course < ActiveRecord::Base
belongs_to :syllabus
belongs_to :course_list
# has_many :bid
has_many :course_members, dependent: :destroy
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'
has_many :member_principals, :class_name => 'Member',
@ -290,12 +292,16 @@ class Course < ActiveRecord::Base
# 课堂的老师不包括助教
def course_teachers
self.members.select{|m| m.roles.to_s.include?("Manager") || m.roles.to_s.include?("Teacher")}
self.course_members.where(:role => [1, 2])
end
# 课堂的老师包括助教
def teachers
self.members.includes(:roles).where("roles.id" => [3,7,9])
self.course_members.where(:role => [1, 2, 3])
end
def students
self.course_members.where(:role => [4])
end
def self.visible_condition(user, options={})

@ -1,6 +1,7 @@
class CourseGroup < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :course
has_many :course_members
has_many :members
has_many :memberships, :class_name => 'Member'
has_many :member_principals, :class_name => 'Member',

@ -0,0 +1,7 @@
class CourseMember < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :course, counter_cache: true
belongs_to :user
belongs_to :course_group, counter_cache: true
end

@ -54,6 +54,7 @@ class Message < ActiveRecord::Base
belongs_to :reply, :class_name => 'Message', :foreign_key => 'reply_id'
#has_one :message_detail, :dependent => :destroy
has_one :message_detail, dependent: :destroy
#转发表
has_many :forwards, :as => :from, :dependent => :destroy
@ -102,7 +103,7 @@ class Message < ActiveRecord::Base
}
safe_attributes 'subject', 'content', 'reply_id', 'root_id', 'visits'
safe_attributes 'subject', 'reply_id', 'root_id', 'visits'
safe_attributes 'board_id','locked', 'sticky',
:if => lambda {|message, user|
if message.project
@ -115,7 +116,7 @@ class Message < ActiveRecord::Base
}
def description
self.content
message_detail.try(:content)
end
# def content

@ -0,0 +1,4 @@
class MessageDetail < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :message, :touch => true
end

@ -97,6 +97,8 @@ class User < Principal
has_many :homework_evaluations, :dependent => :destroy
has_many :syllabuses, :dependent => :destroy
has_many :syllabus_members, :dependent => :destroy
has_many :course_members, :dependent => :destroy
#问卷相关关关系
has_many :poll_users, :dependent => :destroy
has_many :poll_votes, :dependent => :destroy
@ -1125,7 +1127,7 @@ class User < Principal
end
def member_of_course?(course)
courses.to_a.include?(course) || User.current.business?
course.course_members.exists?(user_id: self.id) || User.current.business?
end
def member_of_contest?(contest)

@ -313,8 +313,8 @@ class UsersService
limit = params[:limit]||5
page = params[:page].to_i
offset = (page-1) * limit
courses = Course.find_by_sql("SELECT c.* 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,10) AND
courses = Course.find_by_sql("SELECT c.* FROM courses c, course_members m WHERE m.course_id = c.id AND
m.role in (1,2,3,4) AND
m.user_id=#{current_user.id} AND c.is_delete = 0 order by id desc limit #{limit} offset #{offset} ")
# 如果还没有课程则显示示例课堂
courses = Course.where(:id => 1309) if courses.count == 0

@ -24,7 +24,7 @@
<td><%= (@page-1)*@limit + index + 1 %></td>
<td><%= course.id %></td>
<td class="edu-txt-left"><%= link_to course.name, course_path(course.id) ,:target => '_blank'%></td>
<td><%= course.members.count %></td>
<td><%= course.course_members_count %></td>
<td><%= course.attachments.count %></td>
<td><%= course.homework_commons.where(:homework_type => 1).count %></td>
<td><%= course.homework_commons.where(:homework_type => 4).count %></td>

@ -16,7 +16,7 @@
<td class="edu-txt-left"><%= link_to message.board.course.name, course_path(message.board.course_id), target: '_blank'%></td>
<td><%= message.board.course.teacher.show_real_name %></td>
<td><%= format_time(message.created_on) %></td>
<td class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"><%= link_to message_content(message.content), board_message_path(message.board_id, message), target: '_blank'%></td>
<td class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"><%= link_to message_content(message.description), board_message_path(message.board_id, message), target: '_blank'%></td>
<td>
<%= Message.where(:parent_id => message.id).count %>
</td>

@ -25,7 +25,7 @@
<td width="15%" class="edu-txt-left"><%= link_to shixun_task.name,course_path(shixun_task),:target => '_blank' %></td>
<td width="8%"><%= shixun_task.teacher ? link_to(shixun_task.teacher.show_real_name, user_path(shixun_task.teacher)) : "" %></td>
<td width="10%" class="edu-txt-left"><%= shixun_task.teacher.try(:user_extensions).try(:school).try(:name).blank? ? "--" : shixun_task.teacher.try(:user_extensions).try(:school) %></td>
<td width="5%"><%= shixun_task.student.count %></td>
<td width="5%"><%= shixun_task.students.count %></td>
<% homework_commons = shixun_task.homework_commons.where(:homework_type => 4).order("IF(ISNULL(publish_time),1,0),publish_time asc,created_at asc") %>
<td width="7%"><%= homework_commons.size %></td>
<td># 1</td>

@ -49,37 +49,37 @@
<div class="educontent mt10 clearfix edu-txt-center">
<div class="inline">
<span class="mypost fl mr10"><%= current_user ? @user.identity : (@user.identity == "学生" ? "" : @user.identity) %></span>
<% if current_user %>
<a href="<%= authentication_account_path %>" target="_blank" class="ringauto fl">
<% if @user.authentication %>
<img src="/images/educoder/icon/auto-identityed.svg" class="mt2" data-tip-down="已实名认证"><!--实名认证-->
<% else %>
<% apply_auth = ApplyUserAuthentication.where(:user_id => @user.id, :auth_type => 1).last %>
<img src="/images/educoder/icon/auto-identity.svg" class="mt2" data-tip-down="<%= apply_auth && apply_auth.status == 0 ? '实名认证中' : '未实名认证' %>">
<% end %>
</a>
<a href="<%= professional_certification_account_path %>" target="_blank" class="ringauto fl">
<% if @user.professional_certification %>
<img src="/images/educoder/icon/auto-posted.svg" class="mt2" data-tip-down="已职业认证">
<% else %>
<% apply_auth = ApplyUserAuthentication.where(:user_id => @user.id, :auth_type => 2).last %>
<img src="/images/educoder/icon/auto-post.svg" class="mt2" data-tip-down="<%= apply_auth && apply_auth.status == 0 ? '职业认证中' : '未职业认证' %>">
<% end %>
</a>
<% if @user.try(:phone).blank? %>
<a href="<%= change_or_bind_path(:type => 'phone') %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-phone.svg" class="mt2" data-tip-down="未绑定手机"></a><!--手机认证-->
<% else %>
<a href="<%= my_account_path %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-phoneed.svg" class="mt2" data-tip-down="已绑定手机"></a><!--手机认证-->
<% end %>
<% if @user.try(:mail).blank? %>
<a href="<%= change_or_bind_path(:type => 'mail') %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-email.svg" class="mt2" data-tip-down="未绑定邮箱"></a><!--邮箱认证-->
<% else %>
<a href="<%= my_account_path %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-emailed.svg" class="mt2" data-tip-down="已绑定邮箱"></a><!--邮箱认证-->
<% end %>
<% if @user.department_members.count > 0 %>
<a href="<%= statistics_college_path(@user.department_members.first.try(:department)) %>" target="_blank" class="ringauto fl"><i class="iconfont icon-chengyuanguanli font-12 color-blue" data-tip-down="学院管理员"></i></a><!--学院管理员身份-->
<% end %>
<% else %>
<%# if current_user %>
<!-- <a href="<%#= authentication_account_path %>" target="_blank" class="ringauto fl">-->
<%# if @user.authentication %>
<!-- <img src="/images/educoder/icon/auto-identityed.svg" class="mt2" data-tip-down="已实名认证">-->
<%# else %>
<%# apply_auth = ApplyUserAuthentication.where(:user_id => @user.id, :auth_type => 1).last %>
<!-- <img src="/images/educoder/icon/auto-identity.svg" class="mt2" data-tip-down="<%#= apply_auth && apply_auth.status == 0 ? '实名认证中' : '未实名认证' %>">-->
<%# end %>
<!-- </a>-->
<!-- <a href="<%#= professional_certification_account_path %>" target="_blank" class="ringauto fl">-->
<%# if @user.professional_certification %>
<!-- <img src="/images/educoder/icon/auto-posted.svg" class="mt2" data-tip-down="已职业认证">-->
<%# else %>
<%# apply_auth = ApplyUserAuthentication.where(:user_id => @user.id, :auth_type => 2).last %>
<!-- <img src="/images/educoder/icon/auto-post.svg" class="mt2" data-tip-down="<%#= apply_auth && apply_auth.status == 0 ? '职业认证中' : '未职业认证' %>">-->
<%# end %>
<!-- </a>-->
<%# if @user.try(:phone).blank? %>
<!-- <a href="<%#= change_or_bind_path(:type => 'phone') %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-phone.svg" class="mt2" data-tip-down="未绑定手机"></a>-->
<%# else %>
<!-- <a href="<%#= my_account_path %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-phoneed.svg" class="mt2" data-tip-down="已绑定手机"></a>-->
<%# end %>
<%# if @user.try(:mail).blank? %>
<!-- <a href="<%#= change_or_bind_path(:type => 'mail') %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-email.svg" class="mt2" data-tip-down="未绑定邮箱"></a>-->
<%# else %>
<!-- <a href="<%#= my_account_path %>" target="_blank" class="ringauto fl"><img src="/images/educoder/icon/auto-emailed.svg" class="mt2" data-tip-down="已绑定邮箱"></a><-->
<%# end %>
<%# if @user.department_members.count > 0 %>
<!-- <a href="<%#= statistics_college_path(@user.department_members.first.try(:department)) %>" target="_blank" class="ringauto fl"><i class="iconfont icon-chengyuanguanli font-12 color-blue" data-tip-down="学院管理员"></i></a>-->
<%# end %>
<%# else %>
<span class="ringauto fl">
<% if @user.authentication %>
<img src="/images/educoder/icon/auto-identityed.svg" class="mt2" data-tip-down="已实名认证"><!--实名认证-->
@ -106,10 +106,12 @@
<% else %>
<span class="ringauto fl"><img src="/images/educoder/icon/auto-emailed.svg" class="mt2" data-tip-down="已绑定邮箱"></span><!--邮箱认证-->
<% end %>
<% if @user.department_members.count > 0 %> <!--访问他人主页无连接 -->
<% if @user.department_members.count > 0 && current_user %> <!--访问他人主页无连接 -->
<a href="<%= statistics_college_path(@user.department_members.first.try(:department)) %>" target="_blank" class="ringauto fl"><i class="iconfont icon-chengyuanguanli font-12 color-blue" data-tip-down="学院管理员"></i></a>
<% elsif @user.department_members.count > 0 %>
<a href="javascript:void(0)" class="ringauto fl"><i class="iconfont icon-chengyuanguanli font-12 color-blue" data-tip-down="学院管理员"></i></a><!--学院管理员身份-->
<% end %>
<% end %>
<%# end %>
</div>
</div>
<div class="mt15 educontent clearfix edu-txt-center">

@ -0,0 +1,5 @@
FactoryGirl.define do
factory :course_member do
end
end

@ -0,0 +1,5 @@
FactoryGirl.define do
factory :message_detail do
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe CourseMember, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe MessageDetail, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save