socialforge/app/helpers/organizations_helper.rb

251 lines
7.8 KiB
Ruby
Raw Normal View History

2015-11-05 17:57:07 +08:00
# encoding: utf-8
module OrganizationsHelper
2015-11-05 17:57:07 +08:00
include ApplicationHelper
2016-03-29 20:09:47 +08:00
include FilesHelper
2015-11-05 17:57:07 +08:00
def find_user_not_in_current_org_by_name org
if params[:q] && params[:q].lstrip.rstrip != ""
scope = Principal.active.sorted.not_member_of_org(org).like(params[:q])
else
scope = []
end
principals = paginateHelper scope,10
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true
}
2015-11-12 19:37:28 +08:00
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" )
2015-11-05 17:57:07 +08:00
end
2015-11-12 09:32:00 +08:00
def get_default_name field
case field.name
when 'activity' then
return '动态'
when 'course' then
return '课程'
when 'project' then
return '项目'
end
end
2015-11-14 14:31:52 +08:00
2016-03-29 13:43:28 +08:00
def get_message_org(org_id, field_id)
2016-03-31 17:06:00 +08:00
OrgDocumentComment.find_by_sql("SELECT * FROM org_document_comments where organization_id = #{org_id} and org_subfield_id = #{field_id} and parent_id is null order by updated_at desc limit 8;")
2016-03-30 17:22:23 +08:00
end
def get_message_reply_org(org_id, ids)
# OrgDocumentComment.find_by_sql("SELECT * FROM org_document_comments where organization_id = #{org_id} and parent_id is not null order by updated_at desc limit 1;")
OrgDocumentComment.find_by_sql("SELECT * FROM org_document_comments where organization_id = #{org_id} and parent_id in (#{ids}) order by updated_at desc limit 1;")
2016-03-29 13:43:28 +08:00
end
2016-03-29 16:45:14 +08:00
def get_attach_org(field_id)
Attachment.find_by_sql("SELECT * FROM `attachments` where container_id =#{field_id} and container_type = 'OrgSubfield' and is_public =1 order by created_on limit 6;")
end
2016-05-31 16:03:48 +08:00
# 获取两种类型的隐藏状态数量大于0说明是可见
def double_field_show org
OrgSubfield.find_by_sql("SELECT * FROM `org_subfields` where organization_id = #{org.id} and (field_type = 'Compstu' or field_type = 'Comptec') and hide = 0;").count
end
2016-03-29 20:09:47 +08:00
def get_attach_org2(field)
org_attachments = field.attachments
2016-05-31 14:41:50 +08:00
attachments = User.current.admin? ? org_attachments.first(5) : visable_attachemnts(org_attachments).first(5)
attachments.sort_by{|x| x.created_on}.reverse
2016-03-29 20:09:47 +08:00
end
2016-03-30 18:35:47 +08:00
# 从内容中获取路径
def get_image_path_from_content content
r = Regexp.new(/src="\/files\/uploads\/image(.+?)"/)
if r.match(content).nil?
image_path = nil
else
image_path = r.match(content)[1]
end
end
2016-06-02 13:17:38 +08:00
def org_user_by_type obj
case obj.act_type
when "Message"
2016-06-02 18:41:00 +08:00
user = obj.act.author
2016-06-02 13:17:38 +08:00
when "News"
2016-06-02 18:41:00 +08:00
user = obj.act.author
2016-06-02 13:17:38 +08:00
when "HomeworkCommon"
2016-06-02 18:41:00 +08:00
user = obj.act.user
2016-06-02 13:17:38 +08:00
when "Issue"
2016-06-02 18:41:00 +08:00
user = obj.act.author
2016-06-02 13:17:38 +08:00
end
2016-06-02 18:41:00 +08:00
end
2016-06-02 13:17:38 +08:00
2016-06-02 18:41:00 +08:00
def org_title_by_type obj
case obj.act_type
when "Message"
user = obj.act.parent_id.nil? ? obj.act.subject : obj.act.parent.subject
when "News"
user = obj.act.title
when "HomeworkCommon"
user = obj.act.name
when "Issue"
user = obj.act.subject
end
end
def org_content_by_type obj
case obj.act_type
when "Message"
user = obj.act.parent_id.nil? ? obj.act.content : obj.act.parent.content
when "News"
user = obj.act.description
when "HomeworkCommon"
user = obj.act.description
when "Issue"
user = obj.act.description
end
2016-06-02 13:17:38 +08:00
end
2016-06-03 12:42:02 +08:00
def org_time_by_type obj
case obj.act_type
when "Message"
time = obj.act.updated_on
when "News"
user = obj.act.created_on
when "HomeworkCommon"
user = obj.act.updated_at
when "Issue"
user = obj.act.updated_on
end
end
#排列下拉框
def subfield_status_option
type = []
2016-05-30 16:24:51 +08:00
option2 = []
option2 << "左二"
option2 << "2"
type << option2
2016-04-25 16:00:52 +08:00
option3 = []
2016-05-30 16:24:51 +08:00
option3 << "左三"
option3 << "2"
2016-04-25 16:00:52 +08:00
type << option3
type
end
# 课程和项目不参与某些模块的排列
def subfield_status_option_default
type = []
option1 = []
2016-05-06 10:39:37 +08:00
option1 << "左一"
option1 << "1"
type << option1
2016-05-30 16:24:51 +08:00
option2 = []
option2 << "左二"
option2 << "2"
type << option2
option3 = []
2016-05-30 16:24:51 +08:00
option3 << "左三"
option3 << "2"
type << option3
option4 = []
2016-05-30 16:24:51 +08:00
option4 << "右一"
option4 << "3"
type << option4
2016-05-30 16:24:51 +08:00
option5 = []
option5 << "右二"
option5 << "5"
type << option5
type
end
2016-04-25 18:54:21 +08:00
def subfield_list_type subfield
case subfield.to_i
when 1
2016-05-06 10:39:37 +08:00
resulet = "左一"
2016-04-25 18:54:21 +08:00
when 2
2016-05-06 10:39:37 +08:00
resulet = "左二"
2016-04-25 18:54:21 +08:00
when 3
2016-05-06 10:39:37 +08:00
resulet = "左二"
2016-04-25 18:54:21 +08:00
when 4
2016-05-06 10:39:37 +08:00
resulet = "右一"
2016-05-30 16:24:51 +08:00
when 5
2016-05-06 10:39:37 +08:00
resulet = "右二"
2016-05-30 16:24:51 +08:00
when 6
2016-05-06 10:39:37 +08:00
resulet = "右三"
2016-04-25 18:54:21 +08:00
end
end
# 系统栏目只有管理员才能看到
def subfield_to_addmin?(org)
if User.current.admin?
@organization.org_subfields.order("priority")
else
@organization.org_subfields.select { |os| (os.field_type != "Comptec" && os.field_type != "Compstu") }.sort_by {|os| os.priority}
end
end
2016-04-26 11:01:12 +08:00
def get_subfield_acts field
org_subfield = OrgSubfield.find(field.id)
org_subfield_ids = org_subfield.org_document_comments.map(&:id) << 0
org_acts = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{org_subfield.id})").order('updated_at desc')
end
2016-05-31 10:31:08 +08:00
def allow_to_create?(org, type)
!org_subfield_had_created?(org, type) && User.current.admin?
end
def org_subfield_had_created?(org, type)
sub_field = org.org_subfields.select{|subfield| subfield.field_type == type}
result = sub_field.length > 0 ? true : false
end
2016-05-09 15:00:50 +08:00
def org_subfield_type(field)
case field.field_type
when "Post"
result = "帖子"
when "Resource"
result = "资源"
when "Compstu"
result = "学生"
when "Comptec"
result = "教师"
when "Complex"
result = "综合"
end
end
# 获取最新动态
2016-06-02 13:17:38 +08:00
# def get_latest_acts
# acts = UserActivity.find_by_sql("SELECT * FROM `user_activities` where act_type in ('HomeworkCommon', 'news', 'message', 'Issue') and (container_type = 'Course' or container_type = 'Project') order by created_at limit 10;")
# end
2016-05-10 10:00:28 +08:00
def org_teacher_resource_count user
2016-05-10 13:41:21 +08:00
results = Attachment.find_by_sql("SELECT * FROM attachments where author_id = #{user.id};").count
2016-05-10 11:33:02 +08:00
end
def org_teacher_course_count user
2016-05-10 13:41:21 +08:00
results = Course.find_by_sql("select * from courses where courses.tea_id = #{user.id}").count
2016-05-10 10:00:28 +08:00
end
2016-05-10 13:41:21 +08:00
def org_student_course_count user
course_ids = user.courses.map { |c| c.is_delete == 0 && c.id}
results = Member.find_by_sql("select id from courses where courses.tea_id = #{user.id}").count
end
2016-05-13 13:39:44 +08:00
def excellent_teachers
2016-05-13 16:54:27 +08:00
User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and u.excellent_teacher =1 order by course_count desc").first(5)
2016-05-13 13:39:44 +08:00
end
2016-05-31 16:03:48 +08:00
def excellent_students
User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
from users u, user_extensions ue where u.id = ue.user_id and ue.identity = 1 and u.excellent_student = 1 order by course_count desc").first(5)
end
def excellent_teachers_hide? org
org.org_subfields.where(:field_type => "Comptec").first.hide
end
def excellent_students_hide? org
org.org_subfields.where(:field_type => "Compstu").first.hide
end
2015-01-30 14:11:35 +08:00
end