socialforge/app/models/myshixun.rb

30 lines
985 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Myshixun < ActiveRecord::Base
attr_accessible :description, :name, :parent_id, :user_id, :gpid, :forked_from, :visits, :is_public
has_many :users, :through => :myshixun_members
has_many :myshixun_members
has_one :repository
has_many :games, :dependent => :destroy, :order => "games.id ASC"
# 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录)
# 优先取未完成的任务如果任务都完成则取stage最大的任务有下一步
def current_task
games = self.games
current_game = games.select{|game| game.status != 2}
if undo_agame.blank?
current_game = Game.find_by_sql("SELECT * FROM `games` where myshixun_id=#{self.id} and status = 2 order by stage desc;")
end
end
def parent
Shixun.find(self.parent_id)
rescue ActiveRecord::RecordNotFound
render_404
end
def owner
User.find(self.user_id)
rescue ActiveRecord::RecordNotFound
render_404
end
end