Conflicts:
	.access_token
dev_pull v20160708_04
cxt 9 years ago
commit 320db4ddd9

1
.gitignore vendored

@ -35,3 +35,4 @@ vendor/cache
1234567 1234567
public/javascripts/wechat/node_modules/ public/javascripts/wechat/node_modules/
.ruby-version .ruby-version
.access_token

@ -6,7 +6,7 @@ unless RUBY_PLATFORM =~ /w32/
if RUBY_PLATFORM =~ /darwin/ if RUBY_PLATFORM =~ /darwin/
gem "rmagick", "= 2.15.4" ## osx must be this version gem "rmagick", "= 2.15.4" ## osx must be this version
else else
gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel #gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel
end end
gem 'certified' gem 'certified'
gem 'net-ssh', '2.9.1' gem 'net-ssh', '2.9.1'

@ -0,0 +1,114 @@
source 'https://ruby.taobao.org/'
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
gem "rmagick", ">= 2.0.0"
gem 'certified'
end
gem 'net-ssh', '2.9.1'
gem 'jenkins_api_client'
gem 'nokogiri'
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
gem 'rest-client'
gem "mysql2", "= 0.3.18"
gem 'redis-rails'
gem 'rubyzip'
gem 'delayed_job_active_record'#, :group => :production
gem 'daemons'
gem 'grape', '~> 0.9.0'
gem 'grape-entity'
gem 'rack-cors', :require => 'rack/cors'
gem 'seems_rateable', '~> 1.0.13'
gem 'rails', '~> 3.2'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem 'coderay', '~> 1.1.0'
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
gem 'binding_of_caller'
gem 'chinese_pinyin'
# gem 'sunspot_rails', '~> 1.3.3'
# gem 'sunspot_solr'
# gem 'sunspot'
# gem 'progress_bar'
gem 'ansi'
gem 'kaminari'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
### profile
#gem 'oneapm_rpm'
group :development do
gem 'grape-swagger'
gem 'better_errors', '~> 1.1.0'
# gem "query_reviewer"
# gem 'rack-mini-profiler', '~> 0.9.3'
if RUBY_PLATFORM =~ /w32/
gem 'win32console'
end
end
group :development, :test do
unless RUBY_PLATFORM =~ /w32/
gem 'pry-rails'
if RUBY_VERSION >= '2.0.0'
gem 'pry-byebug'
end
gem 'pry-stack_explorer'
if RUBY_PLATFORM =~ /darwin/
gem 'puma'
end
end
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
# Optional gem for LDAP authentication
group :ldap do
gem "net-ldap", "~> 0.3.1"
end
# Optional gem for OpenID authentication
group :openid do
gem "ruby-openid", "~> 2.1.4", :require => "openid"
gem "rack-openid"
end
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
else
warn("Please configure your config/database.yml first")
end
# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(file)
end

@ -19,6 +19,7 @@ module Mobile
require_relative 'apis/new_comment' require_relative 'apis/new_comment'
require_relative 'apis/praise' require_relative 'apis/praise'
require_relative 'apis/resources' require_relative 'apis/resources'
require_relative 'apis/syllabuses'
class API < Grape::API class API < Grape::API
version 'v1', using: :path version 'v1', using: :path
@ -73,6 +74,7 @@ module Mobile
mount Apis::NewComment mount Apis::NewComment
mount Apis::Praise mount Apis::Praise
mount Apis::Resources mount Apis::Resources
mount Apis::Syllabuses
add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?

@ -10,30 +10,44 @@ module Mobile
params do params do
requires :page, type: Integer requires :page, type: Integer
requires :token, type: String requires :token, type: String
requires :container_type, type: String
end end
post do post do
authenticate! authenticate!
user = current_user user = current_user
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) container_type = params[:container_type] ? params[:container_type] : "All"
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
if container_type == "All" || container_type == "Project"
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")"
project_types = "('Message','Issue','Project')"
end
if container_type == "All" || container_type == "Course"
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
end
page = params[:page] ? params[:page] : 0 page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','Project')"
principal_types = "JournalsForMessage" principal_types = "JournalsForMessage"
watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(',')) watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(','))
user_ids = "(" + user.id.to_s + watched_user_ids + ")" user_ids = "(" + user.id.to_s + watched_user_ids + ")"
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
blog_ids = "(" + watched_user_blog_ids + ")" blog_ids = "(" + watched_user_blog_ids + ")"
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + if container_type == "Course"
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ activities = UserActivity.where("(container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc')
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + elsif container_type == "Project"
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})").order('updated_at desc')
else
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc')
end
all_count = activities.count all_count = activities.count
activities = activities.limit(10).offset(page * 10) activities = activities.limit(10).offset(page * 10)
count = activities.count count = activities.count
@ -42,6 +56,7 @@ module Mobile
present :count, count present :count, count
present :page, page present :page, page
present :status, 0 present :status, 0
present :container_type, container_type
end end
end end
end end

@ -7,7 +7,7 @@ module Mobile
desc "get special topic" desc "get special topic"
get ':id' do get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user user = current_user
blog = BlogComment.find params[:id] blog = BlogComment.find params[:id]
present :data, blog, with: Mobile::Entities::BlogComment,user: user present :data, blog, with: Mobile::Entities::BlogComment,user: user
present :status, 0 present :status, 0

@ -107,7 +107,7 @@ module Mobile
status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user) status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user)
{ {
status: status[:state], status: status[:state],
messsge:CoursesService::JoinCourseError.message(status[:state]) message:CoursesService::JoinCourseError.message(status[:state])
} }
end end
@ -396,6 +396,23 @@ module Mobile
present :status,0 present :status,0
end end
desc '删除课程'
params do
requires :token, type: String
end
post ':course_id/del' do
authenticate!
c = Course.find(params[:course_id])
# if c.members.count > 1
# {status: -1, message: '已经有成员加入,不能删除'}
# else
c.delete!
present :status,0
# end
end
end end
end end
end end

@ -46,9 +46,25 @@ module Mobile
end end
end desc '发送资源'
params do
requires :token, type: String
requires :course_ids, type: Array[Integer]
requires :send_id, type: Integer
end
post 'send' do
authenticate!
rs = ResourcesService.new
ori, flag, save_message = rs.send_resource_to_course(current_user,params)
if flag
present :status, 0
else
{status: -1, message: save_message.first}
end
end
end
end end
end end

@ -0,0 +1,103 @@
#coding=utf-8
module Mobile
module Apis
class Syllabuses < Grape::API
resources :syllabuses do
desc "获取大纲列表"
params do
requires :token, type: String
end
get do
authenticate!
cs = SyllabusesService.new
courses = cs.user_syllabus(current_user)
present :data, courses, with: Mobile::Entities::Syllabus
present :status, 0
end
desc "获取某个大纲"
params do
requires :token, type: String
end
get ':id' do
authenticate!
ss = SyllabusesService.new
sy = ::Syllabus.find(params[:id])
sy.courses = sy.courses.not_deleted
sy = ss.judge_can_setting(sy,current_user)
present :data, sy, with: Mobile::Entities::Syllabus
present :status, 0
end
desc "获取新建大纲的权限"
params do
requires :token, type: String
end
post 'auth' do
authenticate!
auth = 0
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
auth = 1
end
present :auth, auth
end
desc "新建大纲"
params do
requires :token, type: String
requires :title, type: String, desc: '大纲标题'
requires :courses, type: Array[String], desc: '课程名'
end
post do
authenticate!
ss = SyllabusesService.new
sy = ss.create(current_user, params[:title],
params[:courses].map{|c| {name: c} })
if sy.new_record?
{status:-1, message: '创建大纲失败' }
else
present :data, sy, with: Mobile::Entities::Syllabus
present :status, 0
end
end
desc '编辑大纲'
params do
requires :token, type: String
requires :title, type: String, desc: '大纲标题'
# requires :add_courses, type: Array[String], desc: '课程名'
# requires :modify_courses, type: Array[Integer,String], desc: '课程名'
end
post ':id/edit' do
authenticate!
ss = SyllabusesService.new
#修改课程大纲
status = ss.edit(current_user, params)
if status == -1
{status:status, message: '修改课程信息失败' }
else
present :status, status
end
end
end
end
end
end

@ -53,10 +53,20 @@ module Mobile
requires :password, type: String, desc: 'password' requires :password, type: String, desc: 'password'
end end
post do post do
openid = session[:wechat_openid]
logger.debug "openid ============== #{openid}"
raise "无法获取到openid,请在微信中打开本页面" unless openid
us = UsersService.new us = UsersService.new
user = us.register params.merge(:password_confirmation => params[:password], user = us.register params.merge(:password_confirmation => params[:password],
:should_confirmation_password => true) :should_confirmation_password => true)
raise "该邮箱已经被注册过了" if user.new_record? raise user.errors.full_messages.first if user.new_record?
UserWechat.create!(
openid: openid,
user: user
)
present :data, user, with: Mobile::Entities::User present :data, user, with: Mobile::Entities::User
present :status, 0 present :status, 0

@ -15,6 +15,8 @@ module Mobile
#f.img_url if f.respond_to?(:img_url) #f.img_url if f.respond_to?(:img_url)
elsif field == :created_at || field == :updated_at elsif field == :created_at || field == :updated_at
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field)) (format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field))
elsif field == :member_count
::Course===c ? c.members.count : 0
else else
(c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field)) (c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field))
end end
@ -49,6 +51,8 @@ module Mobile
course_expose :qrcode course_expose :qrcode
course_expose :updated_at course_expose :updated_at
course_expose :course_student_num course_expose :course_student_num
course_expose :member_count
course_expose :can_setting
expose :teacher, using: Mobile::Entities::User do |c, opt| expose :teacher, using: Mobile::Entities::User do |c, opt|
if c.is_a? ::Course if c.is_a? ::Course
c.teacher c.teacher

@ -0,0 +1,13 @@
module Mobile
module Entities
class Syllabus < Grape::Entity
include ApplicationHelper
expose :title
expose :id
expose :can_setting
expose :courses, using: Mobile::Entities::Course
end
end
end

@ -1090,7 +1090,7 @@ class CoursesController < ApplicationController
#删除课程 #删除课程
#删除课程只是将课程的is_deleted状态改为falseis_deleted为false状态的课程只有管理员可以看到 #删除课程只是将课程的is_deleted状态改为falseis_deleted为false状态的课程只有管理员可以看到
def destroy def destroy
@course.update_attributes(:is_delete => true) @course.delete!
@course = nil @course = nil
redirect_to user_url(User.current) redirect_to user_url(User.current)
end end

@ -2022,44 +2022,8 @@ class UsersController < ApplicationController
def add_exist_file_to_course def add_exist_file_to_course
@flag = true @flag = true
if params[:send_id].present? if params[:send_id].present?
send_id = params[:send_id] rs = ResourcesService.new
@ori = Attachment.find_by_id(send_id) @ori, @flag, @save_message = rs.send_resource_to_course(params)
course_ids = params[:course_ids]
if course_ids.nil?
@flag = false
end
unless course_ids.nil?
course_ids.each do |id|
next if @ori.blank?
@exist = false
Course.find(id).attachments.each do |att| #如果课程中包含该资源
if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from
att.created_on = Time.now
att.save
@exist = true
break
end
end
next if @exist
attach_copied_obj = @ori.copy
attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联
attach_copied_obj.container = Course.find(id)
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.is_public = 0
attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
if attach_copied_obj.save
# 更新引用次数
quotes = @ori.quotes.to_i + 1
@ori.update_attribute(:quotes, quotes) unless @ori.nil?
@ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
end
@save_message = attach_copied_obj.errors.full_messages
end
end
elsif params[:send_ids].present? elsif params[:send_ids].present?
send_ids = params[:send_ids].split(",") send_ids = params[:send_ids].split(",")
course_ids = params[:course_ids] course_ids = params[:course_ids]

@ -388,6 +388,21 @@ module UsersHelper
return result return result
end end
#获取指定用户的课程大纲
def user_syllabus(user)
results = []
courses = user_courses_list(user)
other = Syllabus.new(title: '未命名课程')
courses.each do |c|
other << c unless c.syllabus
end
user.syllabuses.to_a << other
end
#获取用户参与的公开的课程列表 #获取用户参与的公开的课程列表
def user_public_course_list user def user_public_course_list user
membership = user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current)) membership = user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current))

@ -4,6 +4,8 @@ require 'elasticsearch/model'
class Course < ActiveRecord::Base class Course < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
include CoursesHelper
STATUS_ACTIVE = 1 STATUS_ACTIVE = 1
STATUS_CLOSED = 5 STATUS_CLOSED = 5
STATUS_ARCHIVED = 9 STATUS_ARCHIVED = 9
@ -22,7 +24,7 @@ class Course < ActiveRecord::Base
end end
end end
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete, :syllabus_id
#belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表 belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
@ -69,8 +71,10 @@ class Course < ActiveRecord::Base
validates_presence_of :term,:name validates_presence_of :term,:name
validates_format_of :class_period, :with =>/^[1-9]\d*$/ validates_format_of :class_period, :with =>/^[1-9]\d*$/
validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]+$/ validates_format_of :time, :with => /^\d{4}$/
validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]*$/
validates_length_of :description, :maximum => 10000 validates_length_of :description, :maximum => 10000
before_save :self_validate before_save :self_validate
# 公开课程变成私有课程,所有资源都变成私有 # 公开课程变成私有课程,所有资源都变成私有
after_update :update_files_public,:update_course_ealasticsearch_index after_update :update_files_public,:update_course_ealasticsearch_index
@ -169,6 +173,10 @@ class Course < ActiveRecord::Base
) )
end end
def delete!
update_attribute(:is_delete, true)
end
def visible?(user=User.current) def visible?(user=User.current)
user.allowed_to?(:view_course, self) user.allowed_to?(:view_course, self)
end end
@ -296,6 +304,13 @@ class Course < ActiveRecord::Base
end end
end end
def update_default_value
self.time = Time.now.year unless time
self.term = cur_course_term unless term
self.class_period = 10 unless class_period
end
# 创建课程讨论区 # 创建课程讨论区
def create_board_sync def create_board_sync
@board = self.boards.build @board = self.boards.build
@ -480,7 +495,7 @@ class Course < ActiveRecord::Base
def generate_qrcode def generate_qrcode
ticket = self.qrcode ticket = self.qrcode
if !ticket || ticket.size < 10 if !ticket || ticket.size < 10
response = Wechat.api.qrcode_create_scene(invite_code) response = Wechat.api.qrcode_create_scene(invite_code, 2592000)
logger.debug "response = #{response}" logger.debug "response = #{response}"
self.qrcode = response['ticket'] self.qrcode = response['ticket']
save! && reload save! && reload

@ -9,8 +9,10 @@ class Syllabus < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :courses has_many :courses
has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy
attr_accessible :user_id, :description, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course
safe_attributes 'title', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course'
validates :title, :user_id, presence: true
scope :like, lambda {|arg| scope :like, lambda {|arg|
if arg.blank? if arg.blank?

@ -44,6 +44,8 @@ class CoursesService
} }
end end
#搜索课程 #搜索课程
def search_course params,current_user def search_course params,current_user
courses_all = Course.all_course courses_all = Course.all_course
@ -324,9 +326,9 @@ class CoursesService
define_error [ define_error [
0, '加入成功', 0, '加入成功',
1, '密码错误', 1, '密码错误',
2, '班级已过期 请联系班级管理员重启班级。', 2, '课程已过期 请联系课程管理员重启课程。',
3, '您已经加入了班级', 3, '您已经加入了课程',
4, '您加入的班级不存在', 4, '您的邀请码不正确',
5, '您还未登录', 5, '您还未登录',
6, '申请成功,请等待审核完毕', 6, '申请成功,请等待审核完毕',
7, '您已经发送过申请了,请耐心等待', 7, '您已经发送过申请了,请耐心等待',

@ -0,0 +1,53 @@
#coding=utf-8
class ResourcesService
#发送资源到课程
def send_resource_to_course user,params
send_id = params[:send_id]
@ori = Attachment.find_by_id(send_id)
course_ids = params[:course_ids]
@flag = false
unless course_ids.nil?
course_ids.each do |id|
next if @ori.blank?
@exist = false
Course.find(id).attachments.each do |att| #如果课程中包含该资源
if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from
att.created_on = Time.now
att.save
@exist = true
@flag = true
break
end
end
next if @exist
attach_copied_obj = @ori.copy
attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联
attach_copied_obj.container = Course.find(id)
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = user.id
attach_copied_obj.is_public = 0
attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
if attach_copied_obj.save
# 更新引用次数
quotes = @ori.quotes.to_i + 1
@ori.update_attribute(:quotes, quotes) unless @ori.nil?
@ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
@flag = true
else
@flag = false
@save_message = attach_copied_obj.errors.full_messages
break
end
end
end
[@ori, @flag, @save_message]
end
end

@ -0,0 +1,143 @@
#coding=utf-8
class SyllabusesService
include ApplicationHelper
include CoursesHelper
def judge_can_setting(sy,user)
sy[:can_setting] = sy[:user_id] == user.id ? true : false
sy[:can_setting] = false if sy[:id].nil?
sy.courses.each do |c|
c[:can_setting] = false
member = c.members.where("user_id=#{user.id} and course_id=#{c.id}")[0]
roleName = member.roles[0].name if member
if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" )
c[:can_setting] = true
end
if c.tea_id == user.id
c[:can_setting] = true
end
end
sy
end
#获取指定用户的课程大纲
def user_syllabus(user)
courses = CoursesService.new.user_courses_list(user)
other = Syllabus.new(title: '未命名课程',user_id: user.id)
courses.each do |c|
other.courses << c[:course] unless c[:course].syllabus
end
# user.syllabuses.each do |syllabus|
# syllabus.courses = syllabus.courses.not_deleted
# end
#
# user.syllabuses.to_a << other
courses = user.courses.not_deleted
syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
syllabuses = Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc")
syllabuses.each do |syllabus|
syllabus.courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc")
end
syllabuses.to_a << other
#管理权限 can_setting
syllabuses.each do |s|
s = judge_can_setting(s,user)
end
syllabuses
end
def after_create_course(course, user)
#unless User.current.admin?
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => user, :roles => [r])
m.project_id = -1
course_info = CourseInfos.new(:user_id => user.id, :course_id => course.id)
#user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
course.members << m
course.course_infos << course_info
end
#创建大纲
# params {title: '大纲名称', [{course}, {course}]}
def create(user, title, courses = [])
sy = Syllabus.new(title: title, user_id: user.id)
ActiveRecord::Base.transaction() do
sy.save!
courses.each do |course|
if ::Course === course
course.syllabus_id = sy.id
course.save!
elsif Hash === course
c = ::Course.new(course)
c.tea_id = user.id
c.syllabus_id = sy.id
c.update_default_value
c.is_public = 0
c.save!
after_create_course(c, user)
end
end
end
sy[:can_setting] = true
sy
end
#修改课程大纲的名称、班级名称、新增班级
def edit(user, option)
courses = []
status = -1
syllabus_id = option[:id]
sy = Syllabus.where("id=?",option[:id]).first
if sy && sy.user_id == user.id
syllabus_title = option[:title]
sy.title = syllabus_title
sy.save!
#修改班级名称
modify_courses = option[:modify_courses]
modify_courses.each do |c|
course = Course.where("id=?",c.id).first
if course && course.tea_id == user.id
course.name = c.name
!course.save
end
end
#新增班级
add_courses = option[:add_courses]
add_courses.each do |c|
course = Course.new()
course.name = c
course.tea_id = user.id
course.syllabus_id = sy.id
course.update_default_value
course.is_public = 0
course.save!
after_create_course(course, user)
end
status = 0
end
status
end
end

@ -319,4 +319,8 @@ class UsersService
my_jours_arr my_jours_arr
end end
end end

@ -27,30 +27,32 @@
</div> </div>
<script src="https://dn-demotest.qbox.me/angular.all.min.js"></script> <script src="https://dn-demotest.qbox.me/angular.all.min.js"></script>
<!--<script src="/javascripts/wechat/build/angular.all.min.js"></script>--> <!-- <script src="/javascripts/wechat/build/angular.all.min.js"></script> -->
<script src="/javascripts/wechat/build/app.min.js"></script> <!-- <script src="/javascripts/wechat/build/app.min.js"></script> -->
<!--<script src="/javascripts/wechat/app.js"></script>--> <script src="/javascripts/wechat/app.js"></script>
<!--<script src="/javascripts/wechat/others/factory.js"></script>--> <script src="/javascripts/wechat/others/factory.js"></script>
<!--<script src="/javascripts/wechat/others/filter.js"></script>--> <script src="/javascripts/wechat/others/filter.js"></script>
<!--<script src="/javascripts/wechat/directives/alert.js"></script>--> <script src="/javascripts/wechat/directives/alert.js"></script>
<!--<script src="/javascripts/wechat/directives/form_validate.js"></script>--> <script src="/javascripts/wechat/directives/form_validate.js"></script>
<!--<script src="/javascripts/wechat/directives/input_auto.js"></script>--> <script src="/javascripts/wechat/directives/input_auto.js"></script>
<!--<script src="/javascripts/wechat/directives/loading_spinner.js"></script>--> <script src="/javascripts/wechat/directives/loading_spinner.js"></script>
<!--<script src="/javascripts/wechat/controllers/reg.js"></script>--> <script src="/javascripts/wechat/controllers/reg.js"></script>
<!--<script src="/javascripts/wechat/controllers/invite_code.js"></script>--> <script src="/javascripts/wechat/controllers/invite_code.js"></script>
<!--<script src="/javascripts/wechat/controllers/login.js"></script>--> <script src="/javascripts/wechat/controllers/login.js"></script>
<!--<script src="/javascripts/wechat/controllers/activity.js"></script>--> <script src="/javascripts/wechat/controllers/activity.js"></script>
<!--<script src="/javascripts/wechat/controllers/new_class.js"></script>--> <script src="/javascripts/wechat/controllers/new_class.js"></script>
<!--<script src="/javascripts/wechat/controllers/blog.js"></script>--> <script src="/javascripts/wechat/controllers/edit_class.js"></script>
<!--<script src="/javascripts/wechat/controllers/course_notice.js"></script>--> <script src="/javascripts/wechat/controllers/blog.js"></script>
<!--<script src="/javascripts/wechat/controllers/discussion.js"></script>--> <script src="/javascripts/wechat/controllers/course_notice.js"></script>
<!--<script src="/javascripts/wechat/controllers/homework.js"></script>--> <script src="/javascripts/wechat/controllers/discussion.js"></script>
<!--<script src="/javascripts/wechat/controllers/issue.js"></script>--> <script src="/javascripts/wechat/controllers/homework.js"></script>
<!--<script src="/javascripts/wechat/controllers/journals.js"></script>--> <script src="/javascripts/wechat/controllers/issue.js"></script>
<!--<script src="/javascripts/wechat/controllers/class.js"></script>--> <script src="/javascripts/wechat/controllers/journals.js"></script>
<!--<script src="/javascripts/wechat/controllers/class_list.js"></script>--> <script src="/javascripts/wechat/controllers/class.js"></script>
<!--<script src="/javascripts/wechat/controllers/myresource.js"></script>--> <script src="/javascripts/wechat/controllers/class_list.js"></script>
<!--<script src="/javascripts/wechat/others/routes.js"></script>--> <script src="/javascripts/wechat/controllers/myresource.js"></script>
<script src="/javascripts/wechat/controllers/send_class_list.js"></script>
<script src="/javascripts/wechat/others/routes.js"></script>
</body> </body>
</html> </html>

@ -0,0 +1,33 @@
default: &default
# corpid: "corpid"
# corpsecret: "corpsecret"
# agentid: 1
# Or if using public account, only need above two line
# guange test
#appid: "wxf694495398c7d470"
#secret: "743e038392f1d89540e95f8f7645849a"
appid: "wx8e1ab05163a28e37"
secret: "beb4d3bc4b32b3557811680835357841"
token: "123456"
access_token: ".access_token"
encrypt_mode: false # if true must fill encoding_aes_key
encoding_aes_key: "QGfP13YP4BbQGkkrlYuxpn4ZIDXpBJww4fxl8CObvNw"
jsapi_ticket: "tmp/wechat_jsapi_ticket"
#template
binding_succ_notice: "jjpDrgFErnmkrE9tf2M3o0t31ZrJ7mr0YtuE_wyLaMc"
journal_notice: "uC1zAw4F2q6HTA3Pcj8VUO6wKKKiYFwnPJB4iXxpdoM"
homework_message_notice: "tCf7teCVqc2vl2LZ_hppIdWmpg8yLcrI8XifxYePjps"
class_notice: "MQ_mFupbXP-9jWbeHT3C5xqNBvPo8EIlNv4ULakSpJA"
production:
<<: *default
development:
<<: *default
test:
<<: *default

@ -0,0 +1,8 @@
class RenewQrcode < ActiveRecord::Migration
def up
Course.update_all(:qrcode => '')
end
def down
end
end

@ -11,8 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160708005533) do ActiveRecord::Schema.define(:version => 20160708091258) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
t.string "act_type", :null => false t.string "act_type", :null => false
@ -562,9 +561,9 @@ ActiveRecord::Schema.define(:version => 20160708005533) do
t.integer "excellent_option", :default => 0 t.integer "excellent_option", :default => 0
t.integer "is_copy", :default => 0 t.integer "is_copy", :default => 0
t.integer "visits", :default => 0 t.integer "visits", :default => 0
t.integer "syllabus_id"
t.string "invite_code" t.string "invite_code"
t.string "qrcode" t.string "qrcode"
t.integer "syllabus_id"
end end
add_index "courses", ["invite_code"], :name => "index_courses_on_invite_code", :unique => true add_index "courses", ["invite_code"], :name => "index_courses_on_invite_code", :unique => true

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save