Added: branches/snapshots/app/models/pack_version.rb (0 => 3203)
--- branches/snapshots/app/models/pack_version.rb (rev 0)
+++ branches/snapshots/app/models/pack_version.rb 2012-11-26 14:06:02 UTC (rev 3203)
@@ -0,0 +1,50 @@
+# myExperiment: app/models/pack_version.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class PackVersion < ActiveRecord::Base
+
+ validates_presence_of :title
+
+ belongs_to :pack
+ belongs_to :contributor, :polymorphic => true
+
+ format_attribute :description
+
+ has_many :contributable_entries,
+ :class_name => "PackContributableEntry",
+ :dependent => :destroy,
+ :finder_sql =>
+ 'SELECT *
+ FROM pack_contributable_entries
+ WHERE pack_id = #{pack_id} AND version = #{version}
+ ORDER BY created_at DESC'
+
+ has_many :remote_entries,
+ :class_name => "PackRemoteEntry",
+ :dependent => :destroy,
+ :finder_sql =>
+ 'SELECT *
+ FROM pack_remote_entries
+ WHERE pack_id = #{pack_id} AND version = #{version}
+ ORDER BY created_at DESC'
+
+ def items_count
+ contributable_entries.count + remote_entries.count
+ end
+
+ def versioned_resource
+ pack
+ end
+
+ def items_count
+ return contributable_entries.count + remote_entries.count
+ end
+
+ def contributables
+ contributable_entries.map do |e| e.contributable end
+ end
+
+end
+