Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
61167e55c9
|
@ -1,9 +1,15 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class CourseDynamic < Grape::Entity
|
||||
include Redmine::I18n
|
||||
def self.course_dynamic_expose(field)
|
||||
expose field do |c,opt|
|
||||
c[field] if (c.is_a?(Hash) && c.key?(field))
|
||||
if field == :update_time
|
||||
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field)))
|
||||
else
|
||||
c[field] if (c.is_a?(Hash) && c.key?(field))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
course_dynamic_expose :type
|
||||
|
@ -11,6 +17,8 @@ module Mobile
|
|||
course_dynamic_expose :course_name
|
||||
course_dynamic_expose :course_id
|
||||
course_dynamic_expose :course_img_url
|
||||
course_dynamic_expose :message
|
||||
course_dynamic_expose :update_time
|
||||
end
|
||||
end
|
||||
end
|
|
@ -177,6 +177,22 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def logged_user_by_apptoken
|
||||
#从手机端传来apptoken则将当前登陆用户变为对应的用户
|
||||
if params[:apptoken]
|
||||
token = ApiKey.where(access_token: params[:apptoken]).first
|
||||
if token && !token.expired?
|
||||
@current_user = User.find(token.user_id)
|
||||
end
|
||||
unless @current_user.nil?
|
||||
self.logged_user = @current_user
|
||||
if @current_user
|
||||
@current_user.update_column(:last_login_on, Time.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Logs out current user
|
||||
def logout_user
|
||||
if User.current.logged?
|
||||
|
|
|
@ -17,6 +17,7 @@ class CoursesController < ApplicationController
|
|||
menu_item l(:label_sort_by_influence), :only => :index
|
||||
|
||||
before_filter :can_show_course, :except => []
|
||||
before_filter :logged_user_by_apptoken,:only => [:show,:new_homework,:feedback]
|
||||
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_private_courses]
|
||||
before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
|
||||
before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create]
|
||||
|
|
|
@ -6,7 +6,7 @@ class HomeworkAttachController < ApplicationController
|
|||
###############################
|
||||
before_filter :can_show_course,except: []
|
||||
#判断当前角色权限时需先找到当前操作的project
|
||||
before_filter :find_course_by_bid_id, :only => [:new]
|
||||
before_filter :logged_user_by_apptoken,:find_course_by_bid_id, :only => [:new]
|
||||
before_filter :find_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours, :get_student_batch_homework, :get_my_homework]
|
||||
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users, :praise_homework]
|
||||
#判断当前角色是否有操作权限
|
||||
|
|
|
@ -19,6 +19,7 @@ class UsersController < ApplicationController
|
|||
layout :setting_layout
|
||||
#Added by young
|
||||
before_filter :auth_login1, :only => [:show, :user_activities, :user_newfeedback]
|
||||
before_filter :logged_user_by_apptoken, :only => [:show,:user_newfeedback]
|
||||
menu_item :activity
|
||||
menu_item :user_information, :only => :info
|
||||
menu_item :user_course, :only => :user_courses
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#coding=utf-8
|
||||
class CoursesService
|
||||
include ApplicationHelper
|
||||
include CoursesHelper
|
||||
|
@ -344,27 +345,67 @@ class CoursesService
|
|||
else
|
||||
membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user))
|
||||
end
|
||||
if membership.nil? || membership.count == 0
|
||||
raise l(:label_no_courses,:locale => current_user.language.nil? ? 'zh':current_user.language)
|
||||
end
|
||||
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||
result = []
|
||||
membership.each do |mp|
|
||||
course = mp.course
|
||||
unless current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course)))
|
||||
count,is_teacher = get_course_anonymous_evaluation current_user,course
|
||||
if is_teacher
|
||||
student_commit_number = count
|
||||
else
|
||||
need_anonymous_comments_count = count
|
||||
latest_course_dynamics = []
|
||||
latest_news = course.news.order("created_on desc").first
|
||||
unless latest_news.nil?
|
||||
latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => '最近更新了通知' }#l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_message = course.journals_for_messages.order("created_on desc").first
|
||||
unless latest_message.nil?
|
||||
latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => '最近更新了留言'}#l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_attachment = course.attachments.order("created_on desc").first
|
||||
unless latest_attachment.nil?
|
||||
latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => '最近更新了课件'}#l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_bid = course.homeworks.order('updated_on DESC').first
|
||||
unless latest_bid.nil?
|
||||
latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => '最近更新了作业'}#l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
#每个作业中的最新留言
|
||||
messages = []
|
||||
course.homeworks.each do |bid|
|
||||
jour = bid.journals_for_messages.order("created_on desc").first
|
||||
unless jour.nil?
|
||||
messages << jour
|
||||
end
|
||||
news_count = course.news.count
|
||||
message_count = course.journals_for_messages.count
|
||||
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count}
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count}
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number}
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count}
|
||||
#{:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count}
|
||||
end
|
||||
unless messages.count == 0
|
||||
messages.sort!{|order,newer| newer.created_on <=> order.created_on}
|
||||
end
|
||||
latest_bid_message = messages.first
|
||||
unless latest_bid_message.nil?
|
||||
latest_course_dynamics << {:type => 2,:time => latest_bid_message.created_on,:message => '最近更新了留言'}#l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
#每个作业中学生最后提交的作业
|
||||
homeworks = []
|
||||
course.homeworks.each do |bid|
|
||||
homework_attach = bid.homeworks.order('updated_at DESC').first
|
||||
unless homework_attach.nil?
|
||||
homeworks << homework_attach
|
||||
end
|
||||
end
|
||||
unless homeworks.count == 0
|
||||
homeworks.sort!{|order,newer| newer.updated_at <=> order.updated_at}
|
||||
end
|
||||
latest_homework_attach = homeworks.first
|
||||
unless latest_homework_attach.nil?
|
||||
latest_course_dynamics << {:type => 4,:time => latest_homework_attach.updated_at,:message => '最近更新了作业'}#l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_course_dynamics.sort!{|order,newer| newer[:time] <=> order[:time]}
|
||||
latest_course_dynamic = latest_course_dynamics.first
|
||||
unless latest_course_dynamic.nil?
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => latest_course_dynamic[:type],:update_time => latest_course_dynamic[:time],:message => latest_course_dynamic[:message],:count => nil}
|
||||
end
|
||||
end
|
||||
result.sort!{|order,newer| newer[:update_time] <=> order[:update_time]}
|
||||
result
|
||||
end
|
||||
|
||||
|
|
|
@ -1878,3 +1878,10 @@ en:
|
|||
label_enterprise_page_made: enterprise_page
|
||||
|
||||
label_add_tag: Add Tag
|
||||
|
||||
#api
|
||||
label_recently_updated_notification: Recently updated notification
|
||||
label_recently_updated_homework: Recently updated the homework
|
||||
label_recently_updated_message: Recently updated the message
|
||||
label_recently_updated_courseware: Recently updated the courseware
|
||||
label_no_courses: You do not participate in any course, please search the curriculum, course, or create a course!
|
||||
|
|
|
@ -2589,3 +2589,10 @@ zh:
|
|||
label_attachment_sharer: 共享者
|
||||
label_attachment_upload_time: 上传时间
|
||||
|
||||
|
||||
#api
|
||||
label_recently_updated_notification: 最近更新了通知
|
||||
label_recently_updated_homework: 最近更新了作业
|
||||
label_recently_updated_message: 最近更新了留言
|
||||
label_recently_updated_courseware: 最近更新了课件
|
||||
label_no_courses: 您没有参与任何课程,请搜索课程、加入课程,或者创建课程吧!
|
||||
|
|
Loading…
Reference in New Issue