30 lines
985 B
Ruby
30 lines
985 B
Ruby
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
|