socialForge#324

This commit is contained in:
yanxd 2014-03-28 18:12:12 +08:00
parent ad23ba646e
commit c38a8e4f6a
2 changed files with 12 additions and 7 deletions

View File

@ -57,11 +57,16 @@ module WelcomeHelper
#
# Returns project&courses array
def find_miracle_course(sum=10, max_rate=7)
max = sum*(max_rate.to_f/10)
c1 = find_new_course(sum).to_a.dup
c2 = find_all_hot_course(sum).to_a.dup
c2 = c2 - c1
(c1.take(max)+c2).take(sum)
Project.active.visible.course_entities.
joins(:course_extra).
joins(:memberships).
group('members.project_id').
reorder("courses.time DESC, COUNT(members.project_id) DESC").take sum
# max = sum*(max_rate.to_f/10)
# c1 = find_new_course(sum).to_a.dup
# c2 = find_all_hot_course(sum).to_a.dup
# c2 = c2 - c1
# (c1.take(max)+c2).take(sum)
end
def find_miracle_project(sum, max_rate)

View File

@ -152,8 +152,8 @@ class Project < ActiveRecord::Base
where("LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p ", :p => pattern)
end
}
scope :project_entities, -> { where(project_type: 0) }
scope :course_entities, -> { where(project_type: 1) }
scope :project_entities, -> { where(project_type: ProjectType_project) }
scope :course_entities, -> { where(project_type: ProjectType_course) }
def new_course
self.where('project_type = ?', 1)