Class: ShelfItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/shelf_item.rb

Class Method Summary collapse

Class Method Details

.missingObject


8
9
10
# File 'app/models/shelf_item.rb', line 8

def self.missing
	return :item_missing
end

.shelf_items_editions_from_shelf_with_platform(game_shelf_id, platform_id) ⇒ Object


12
13
14
15
16
17
# File 'app/models/shelf_item.rb', line 12

def self.shelf_items_editions_from_shelf_with_platform(game_shelf_id, platform_id)
	self.where(game_shelf_id: game_shelf_id)
	.joins("INNER JOIN editions on shelf_items.item_id = editions.id")
	.where(:shelf_items => {item_type: "Edition"})
	.where(:editions => {platform_id: platform_id})
end

.shelf_items_expansions_from_shelf_with_platform(game_shelf_id, platform_id) ⇒ Object


18
19
20
21
22
23
24
# File 'app/models/shelf_item.rb', line 18

def self.shelf_items_expansions_from_shelf_with_platform(game_shelf_id, platform_id)
	self.where(game_shelf_id: game_shelf_id)
	.joins("INNER JOIN expansions on shelf_items.item_id = expansions.id")
	.where(:shelf_items => {item_type: "Expansion"})
	.joins("INNER JOIN editions on expansions.edition_id = editions.id")
	.where(:editions => {platform_id: platform_id})
end

.shelf_items_from_shelf_with_platform(game_shelf_id, platform_id) ⇒ Object


26
27
28
29
# File 'app/models/shelf_item.rb', line 26

def self.shelf_items_from_shelf_with_platform(game_shelf_id, platform_id)
	self.shelf_items_editions_from_shelf_with_platform(game_shelf_id, platform_id).union(
		self.shelf_items_expansions_from_shelf_with_platform(game_shelf_id, platform_id))
end

.shelf_items_per_user_and_game(user_id, game_class, game_id) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/shelf_item.rb', line 31

def self.shelf_items_per_user_and_game(user_id, game_class, game_id)
	shelf_items = ShelfItem.joins(:game_shelf).where("user_id = ? and item_type = ? and item_id = ?", user_id, game_class, game_id)
	if not shelf_items.present?
		return nil, []
	end

	main_shelf_item = nil
	other_shelf_items = {}
	shelf_items.each do |si|
		if not si.game_shelf.is_custom_shelf?
			main_shelf_item = si
		else
			other_shelf_items[si.game_shelf_id] = si
		end
	end

	return main_shelf_item, other_shelf_items
end

.unknownObject


5
6
7
# File 'app/models/shelf_item.rb', line 5

def self.unknown
	return :item_unknown
end