Class: SakaiInfo::Group

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/group.rb

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiObject

#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ Group

Returns a new instance of Group.



21
22
23
24
25
26
27
# File 'lib/sakai-info/group.rb', line 21

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:group_id]
  @site_id = dbrow[:site_id]
  @title = dbrow[:title]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



14
15
16
# File 'lib/sakai-info/group.rb', line 14

def dbrow
  @dbrow
end

#site_idObject (readonly)

Returns the value of attribute site_id.



14
15
16
# File 'lib/sakai-info/group.rb', line 14

def site_id
  @site_id
end

#titleObject (readonly)

Returns the value of attribute title.



14
15
16
# File 'lib/sakai-info/group.rb', line 14

def title
  @title
end

Class Method Details

.all_serializationsObject



109
110
111
# File 'lib/sakai-info/group.rb', line 109

def self.all_serializations
  [:default, :users, :realm]
end

.clear_cacheObject



16
17
18
# File 'lib/sakai-info/group.rb', line 16

def self.clear_cache
  @@cache = {}
end

.count_by_site_id(site_id) ⇒ Object



53
54
55
# File 'lib/sakai-info/group.rb', line 53

def self.count_by_site_id(site_id)
  Group.query_by_site_id(site_id).count
end

.find(id) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/sakai-info/group.rb', line 33

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:sakai_site_group].filter(:group_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(Group, id)
    end
    @@cache[id] = Group.new(row)
  end
  @@cache[id]
end

.find_by_site_id(site_id) ⇒ Object



48
49
50
51
# File 'lib/sakai-info/group.rb', line 48

def self.find_by_site_id(site_id)
  Group.query_by_site_id(site_id).all.
    collect { |row| @@cache[row[:group_id]] = Group.new(row) }
end

.query_by_site_id(site_id) ⇒ Object



44
45
46
# File 'lib/sakai-info/group.rb', line 44

def self.query_by_site_id(site_id)
  DB.connect[:sakai_site_group].where(:site_id => site_id)
end

Instance Method Details

#default_serializationObject

serialization



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/sakai-info/group.rb', line 74

def default_serialization
  result = {
    "id" => self.id,
    "title" => self.title,
    "site" => self.site.serialize(:summary),
    "user_count" => self.realm.user_count,
    "providers" => self.providers,
    "properties" => self.properties
  }
  if result["properties"] == {}
    result.delete("properties")
  end
  result
end

#propertiesObject



57
58
59
# File 'lib/sakai-info/group.rb', line 57

def properties
  @properties ||= GroupProperty.find_by_group_id(self.id)
end

#providersObject



65
66
67
# File 'lib/sakai-info/group.rb', line 65

def providers
  @providers ||= self.realm.providers
end

#realmObject



61
62
63
# File 'lib/sakai-info/group.rb', line 61

def realm
  @authz_realm ||= AuthzRealm.find_by_site_id_and_group_id(self.site_id, self.id)
end

#realm_serializationObject



103
104
105
106
107
# File 'lib/sakai-info/group.rb', line 103

def realm_serialization
  {
    "realm" => self.realm.name
  }
end

#siteObject



29
30
31
# File 'lib/sakai-info/group.rb', line 29

def site
  @site ||= Site.find(@site_id)
end

#summary_serializationObject



89
90
91
92
93
94
95
# File 'lib/sakai-info/group.rb', line 89

def summary_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "user_count" => self.realm.user_count
  }
end

#usersObject



69
70
71
# File 'lib/sakai-info/group.rb', line 69

def users
  @users ||= AuthzRealmMembership.find_by_realm_id(self.realm.id).collect{|arm|arm.user}
end

#users_serializationObject



97
98
99
100
101
# File 'lib/sakai-info/group.rb', line 97

def users_serialization
  {
    "users" => self.users.collect { |u| u.serialize(:summary) }
  }
end