diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index acc874752..4ca1c1933 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -157,7 +157,7 @@ class ContestsController < ApplicationController contests = Contest.where('parent_id = ?', @contest.id) @softapplications = [] for contest in contests - @softapplications += contest.softapplications + @softapplications += contest.contesting_softapplications end respond_to do |format| @@ -240,6 +240,7 @@ class ContestsController < ApplicationController # @user = @contest.user @softapplication = Softapplication.all + @contesting_softapplication = @contest.contesting_softapplications # @temp = [] # @softapplicationt.each do |pro| @@ -292,15 +293,15 @@ class ContestsController < ApplicationController def add_softapplication softapplication = Softapplication.find(params[:contest]) contest_message = params[:contest_for_save][:contest_message] - if Softapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0 - if Softapplication.create_contesting(@contest.id, softapplication.id, contest_message) + if ContestingSoftapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0 + if ContestingSoftapplication.create_contesting(@contest.id, softapplication.id, contest_message) flash.now[:notice] = l(:label_bidding_contest_succeed) end else flash.now[:error] = l(:label_bidding_fail) end - @softapplication = @contest.softapplications + @contesting_softapplication = @contest.contesting_softapplications render :text => params.to_json # respond_to do |format| diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index d48342b59..00fb5b77c 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -105,7 +105,7 @@ module ContestsHelper contests = Contest.find(:id) @softapplications = [] for contest in contests - @softapplications += contest.contesting_projects + @softapplications += contest.contesting_softapplications end @projects.count end @@ -122,6 +122,16 @@ module ContestsHelper @users.count end + def count_contest_softapplication_user + contests = Contest.find(:id) + @users = [] + for contest in contests + for project in contest.softapplications + @users += softapplication.users + end + end + @users.count + end def im_watching_student_id? contest people = [] people << contest.author @@ -152,8 +162,8 @@ module ContestsHelper end def select_option_app_helper options tmp = Hash.new - options.each do |project| - tmp[project.name] = project.id + options.each do |option| + tmp[option.name] = option.id end tmp end diff --git a/app/models/contest.rb b/app/models/contest.rb index b3e6c4f77..edc252574 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -5,8 +5,8 @@ class Contest < ActiveRecord::Base belongs_to :author, :class_name => 'User', :foreign_key => :author_id has_many :contesting_projects, :dependent => :destroy has_many :projects, :through => :contesting_projects - has_many :softapplications, :dependent => :destroy - # has_many :softapplications, :through => :softapplications + has_many :contesting_softapplications, :dependent => :destroy + has_many :softapplications, :through => :contesting_softapplications has_many :projects_member, :class_name => 'User', :through => :projects has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy diff --git a/app/models/contesting_project.rb b/app/models/contesting_project.rb index 773c04c68..c0c360548 100644 --- a/app/models/contesting_project.rb +++ b/app/models/contesting_project.rb @@ -19,6 +19,11 @@ class ContestingProject < ActiveRecord::Base :project_id => project_id, :description => description) end + def self.cerate_softapplication_contesting(contest_id, softapplication_id, description = nil) + self.create_softapplication(:user_id => User.current.id, :contest_id => contest_id, + :softapplication_id => softapplication_id, :description => description) + end + def update_reward(which) self.update_attribute(:reward,which) end diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index 4cf76001a..e63eb428d 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -2,6 +2,7 @@ class Softapplication < ActiveRecord::Base attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id acts_as_attachable has_many :journals_for_messages, :as => :jour, :dependent => :destroy + has_many :contesting_softapplications, :dependent => :destroy belongs_to :user belongs_to :contest diff --git a/app/models/user.rb b/app/models/user.rb index 1aa1e0382..0255b0da6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -79,6 +79,7 @@ class User < Principal ## added by xianbo for delete has_many :biding_projects, :dependent => :destroy has_many :contesting_projects, :dependent => :destroy + has_many :contesting_softapplications, :dependent => :destroy belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy ##ended by xianbo diff --git a/app/views/contests/_contest_list.html.erb b/app/views/contests/_contest_list.html.erb index cdc390410..5a8bf6890 100644 --- a/app/views/contests/_contest_list.html.erb +++ b/app/views/contests/_contest_list.html.erb @@ -18,9 +18,10 @@