Class Web::Layout
In: lib/web/layout.rb
Parent: ActiveRecord::Base

Page layouts. These are individual layouts for items in the navigation bar. Layouts have portlets, these are modeled by parsing (by regexp) the typesettings xml. Layouts belong to a certain LayoutSet.

Methods

Public Class methods

Actions for Permissions.

[Source]

    # File lib/web/layout.rb, line 17
17:     def self.actions
18:       %w{
19:       ADD_DISCUSSION
20:       UPDATE
21:       VIEW
22:       }
23:     end

Creates a new Layout.

This process is engineered by creating a new layout with Liferay‘s (v. 5.1.1) tools and inspecting the database dump diffs.

Mandatory parameters:

 - groupid
 - privatelayout (true or false)

Optional extra parameters:

 - locale

[Source]

     # File lib/web/layout.rb, line 36
 36:     def initialize(params)
 37:       raise 'No groupid given' unless (params[:groupid] or params[:group])
 38:       raise 'No privatelayout given' if params[:privatelayout].nil?
 39:       _name = params.delete(:name) || 'New layout'
 40:       _locale = params[:locale] || 'en_US'
 41: 
 42:       super(params)
 43: 
 44:       # COPY layout (plid, groupid, companyid, privatelayout, layoutid, parentlayoutid, name, title, description, type_, typesettings, hidden_, friendlyurl, iconimage, iconimageid, themeid, colorschemeid, wapthemeid, wapcolorschemeid, css, priority, dlfolderid) FROM stdin;
 45:       # +10301  10166    10109      f    1  0        <?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US" default-locale="en_US"><name language-id="en_US">frontpage</name></root> <root />                portlet       layout-template-id=2_columns_ii\n     f   /1        f      0                                            0     0
 46: 
 47:       self.companyid = self.group.companyid
 48: 
 49:       name = "<?xml version='1.0' encoding='UTF-8'?>"
 50:       name += '<root available-locales="%s" default-locale="%s">' % [_locale, _locale]
 51:       name += '<name language-id="%s">' % _locale
 52:       name += _name
 53:       name += '</name></root>'
 54:       self.name = name
 55: 
 56:       # perhaps layoutid could be sequenced.
 57:       layouts = (self.is_public? ? self.group.public_layouts : self.group.private_layouts)
 58:       _ids = (layouts.any? ? layouts.collect(&:layoutid) : nil)
 59:       self.layoutid = (_ids.nil? ? 1 : _ids.sort.max+1)
 60: 
 61:       # increment pagecount
 62:       _set = self.layoutset
 63:       _set.pagecount += 1
 64:       _set.save
 65: 
 66:       self.friendlyurl    ||= '/'+self.layoutid.to_s
 67:       self.type_          ||= 'portlet'
 68:       self.typesettings   ||= Web::Typesettings.new.to_s # 'bout to change
 69:       self.title          ||= '<root />'
 70:       self.description    ||= ''
 71:       self.parentlayoutid ||= 0
 72:       self.priority       ||= 0
 73:       self.dlfolderid     ||= 0
 74:       self.iconimageid    ||= 0
 75:       self.iconimage = false if self.iconimage.nil?
 76:       self.hidden_ = false if self.hidden_.nil?
 77: 
 78:       self.save
 79: 
 80:       #####
 81:       # Group 10166 is a private group of User 10164.
 82:       # 10129 is the Company's admin. 10111 is Guest.
 83:       #####
 84: 
 85:       # Create a resource with scope=2 for the Group.
 86: 
 87:       # COPY resource_ (resourceid, codeid, primkey) FROM stdin;
 88:       # +201    2  10166
 89:       # +202    3  10301
 90: 
 91:       rc = self.resource_code(2)
 92:       unless rc
 93:         rc = ResourceCode.create(
 94:           :companyid => self.companyid,
 95:           :name => self.liferay_class,
 96:           :scope => 2
 97:         )
 98:       end
 99:       unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.group.id}'")
100:         Resource.create(
101:           :codeid  => rc.id,
102:           :primkey => self.group.id
103:         )
104:       end
105: 
106:       # Create a resource with scope=4 for this Layout.
107:       rc = self.resource_code(4)
108:       unless rc
109:         rc = ResourceCode.create(
110:           :companyid => self.companyid,
111:           :name => self.liferay_class,
112:           :scope => 4
113:         )
114:       end
115:       resource = Resource.create(
116:         :codeid  => rc.id,
117:         :primkey => self.id
118:       )
119: 
120:       # COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
121:       # +301    10109      ADD_DISCUSSION       202
122:       # +302    10109      UPDATE       202
123:       # +303    10109      VIEW 202
124: 
125:       self.class.actions.each do |actionid|
126:         p = Permission.create(
127:           :companyid  => self.companyid,
128:           :actionid   => actionid,
129:           :resourceid => resource.id
130:         )
131: 
132:         # COPY users_permissions (userid, permissionid) FROM stdin;
133:         # +10129        301
134:         # +10129        302
135:         # +10129        303
136:         # +10111        303
137: 
138:         self.company.administrators.each do |user|
139:           user.user_permissions << p
140:         end
141: 
142:         # COPY groups_permissions (groupid, permissionid) FROM stdin;
143:         # +10166        301
144:         # +10166        303
145:         group = self.group
146:         self.group.permissions << p
147:       end
148:       return self
149:     end

Public Instance methods

[Source]

     # File lib/web/layout.rb, line 219
219:     def contents
220:       Typesettings.new(self.typesettings)
221:     end

Portlet instances on the Layout.

[Source]

     # File lib/web/layout.rb, line 192
192:     def instances
193:       Web::PortletPreferences.find(:all, :conditions => "plid=#{self.plid} AND portletid LIKE '%INSTANCE%'")
194:     end

[Source]

     # File lib/web/layout.rb, line 204
204:     def is_hidden?
205:       self.hidden_
206:     end

[Source]

     # File lib/web/layout.rb, line 200
200:     def is_private?
201:       self.privatelayout
202:     end

[Source]

     # File lib/web/layout.rb, line 196
196:     def is_public?
197:       !self.privatelayout
198:     end

[Source]

     # File lib/web/layout.rb, line 162
162:     def layoutset
163:       Web::LayoutSet.find(:first, :conditions => "groupid=#{self.groupid} AND privatelayout=#{self.privatelayout}" )
164:     end

com.liferay.portal.model.Layout

[Source]

    # File lib/web/layout.rb, line 12
12:     def liferay_class
13:       'com.liferay.portal.model.Layout'
14:     end

the URL path to this Layout

[Source]

     # File lib/web/layout.rb, line 209
209:     def path
210:       self.layoutset.url_prefix + self.group.friendlyurl + self.friendlyurl
211:     end

[Source]

     # File lib/web/layout.rb, line 166
166:     def portletids
167:       begin
168:         ts = self.typesettings
169:         c1= ts[/column-1=(.*)/,1] || ""
170:         c2= ts[/column-2=(.*)/,1] || ""
171:         c3= ts[/column-3=(.*)/,1] || ""
172:         (c1+c2+c3).split(",").uniq
173:       rescue
174:       end
175:     end

[Source]

     # File lib/web/layout.rb, line 182
182:     def portlets
183:       portlets = []
184:       return portlets unless self.portletids
185:       self.portletids.each do |id|
186:         portlets << (Web::Portlet.find_by_portletid(id) or Web::PortletPreferences.find_by_portletid(id))
187:       end
188:       return portlets.compact
189:     end

ResourceCode associated to this instance (and scope)

[Source]

     # File lib/web/layout.rb, line 214
214:     def resource_code(scope=4)
215:       ResourceCode.find(:first,
216:         :conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
217:     end

[Validate]