Class MB::Category
In: lib/mb/category.rb
Parent: ActiveRecord::Base

Methods

actions   liferay_class   new   parent   path   resource_code  

External Aliases

user -> owner

Public Class methods

Actions for Permissions.

[Source]

    # File lib/mb/category.rb, line 15
15:     def self.actions
16:       %w{
17:         ADD_FILE
18:         ADD_MESSAGE
19:         ADD_SUBCATEGORY
20:         DELETE
21:         MOVE_THREAD
22:         PERMISSIONS
23:         REPLY_TO_MESSAGE
24:         SUBSCRIBE
25:         UPDATE
26:         UPDATE_THREAD_PRIORITY
27:         VIEW
28:       }
29:     end

Creates a new Message Board category.

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
 - name

[Source]

     # File lib/mb/category.rb, line 39
 39:     def initialize(params)
 40:       raise 'No groupid given' unless (params[:groupid] or params[:group])
 41:       raise 'No name given' unless params[:name]
 42:       super(params)
 43: 
 44:       # COPY mbcategory (uuid_, categoryid, groupid, companyid, userid, username, createdate, modifieddate, parentcategoryid, name, description, lastpostdate) FROM stdin;
 45:       # +fda18eef-3992-419e-a373-6e2f01a8b6a9   10307     10166       10109 10129   Test Test 2009-01-17 08:06:00.359 2009-01-17 08:06:00.359 0       Teppo Testaaja        message board for user Teppo   \N
 46: 
 47:       unless self.uuid_
 48:         require 'rubygems'
 49:         require 'uuidtools'
 50:         self.uuid_ = UUID.random_create.to_s
 51:       end
 52: 
 53:       self.companyid = self.group.companyid
 54: 
 55:       # owner (if undefined, use admin)
 56:       unless self.userid
 57:         user = Company.first.administrators.first
 58:         self.userid   ||= user.id
 59:       end
 60:       self.username         ||= self.user.fullname
 61:       self.createdate       = Time.now
 62:       self.modifieddate     = Time.now
 63:       self.parentcategoryid ||= 0
 64:       self.description      ||= ''
 65: 
 66:       self.save
 67: 
 68:       # ResourceCode with scope 1 => Resource for Company
 69:       # ResourceCode with scope 2 => Resource for this Group and Guest's Group
 70:       # ResourceCode with scope 4 => Resource for self
 71: 
 72:       # COPY resourcecode (codeid, companyid, name, scope) FROM stdin;
 73:       # +104    10109      com.liferay.portlet.messageboards.model.MBCategory   1
 74:       # +105    10109      com.liferay.portlet.messageboards.model.MBCategory   2
 75:       # +106    10109      com.liferay.portlet.messageboards.model.MBCategory   4
 76: 
 77:       # COPY resource_ (resourceid, codeid, primkey) FROM stdin;
 78:       # +210    104        10109
 79:       # +211    105        10124
 80:       # +212    105        10166
 81:       # +213    106        10307
 82: 
 83:       rc = self.resource_code(1)
 84:       unless rc
 85:         rc = ResourceCode.create(
 86:           :companyid => self.companyid,
 87:           :name => self.liferay_class,
 88:           :scope => 1
 89:         )
 90:       end
 91:       unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.companyid}'")
 92:         Resource.create(
 93:           :codeid  => rc.id,
 94:           :primkey => self.companyid
 95:         )
 96:       end
 97: 
 98:       rc = self.resource_code(2)
 99:       unless rc
100:         rc = ResourceCode.create(
101:           :companyid => self.companyid,
102:           :name => self.liferay_class,
103:           :scope => 2
104:         )
105:       end
106:       unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.group.id}'")
107:         Resource.create(
108:           :codeid  => rc.id,
109:           :primkey => self.group.id
110:         )
111:       end
112: 
113:       # Create a resource with scope=4 for this Layout.
114:       rc = self.resource_code(4)
115:       unless rc
116:         rc = ResourceCode.create(
117:           :companyid => self.companyid,
118:           :name => self.liferay_class,
119:           :scope => 4
120:         )
121:       end
122:       resource = Resource.create(
123:         :codeid  => rc.id,
124:         :primkey => self.id
125:       )
126: 
127:       # Permissions to scope 4
128: 
129:       # COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
130:       # +312    10109      ADD_FILE     213
131:       # +313    10109      ADD_MESSAGE  213
132:       # +314    10109      ADD_SUBCATEGORY      213
133:       # +315    10109      DELETE       213
134:       # +316    10109      MOVE_THREAD  213
135:       # +317    10109      PERMISSIONS  213
136:       # +318    10109      REPLY_TO_MESSAGE     213
137:       # +319    10109      SUBSCRIBE    213
138:       # +320    10109      UPDATE       213
139:       # +321    10109      UPDATE_THREAD_PRIORITY       213
140:       # +322    10109      VIEW 213
141: 
142:       # COPY users_permissions (userid, permissionid) FROM stdin;
143:       # +10129  312
144:       # +10129  313
145:       # +10129  314
146:       # +10129  315
147:       # +10129  316
148:       # +10129  317
149:       # +10129  318
150:       # +10129  319
151:       # +10129  320
152:       # +10129  321
153:       # +10129  322
154: 
155:       self.class.actions.each do |actionid|
156:         self.user.user_permissions << Permission.create(
157:           :companyid  => self.companyid,
158:           :actionid   => actionid,
159:           :resourceid => resource.id
160:         )
161:       end
162:     end

Public Instance methods

com.liferay.portlet.messageboards.model.MBCategory

[Source]

    # File lib/mb/category.rb, line 10
10:     def liferay_class
11:       'com.liferay.portlet.messageboards.model.MBCategory'
12:     end

Parent Category, nil if this is already root.

[Source]

     # File lib/mb/category.rb, line 182
182:     def parent
183:       self.parentcategoryid != 0 ? MB::Category.find(self.parentcategoryid) : nil
184:     end

URL path to this Category. Works on Liferay 5.1.1. Parameters:

 - pl          only check public or private layouts? defaults to both. ( nil | :public | :private )

[Source]

     # File lib/mb/category.rb, line 207
207:     def path(pl=nil)
208:       layouts = self.group.select_layouts_with('message_boards',pl)
209:       return nil unless layouts.any?
210:       '%s/-/message_boards/category/%i' % [layouts.first.path, self.id]
211:     end

ResourceCode associated to this instance (and scope)

[Source]

     # File lib/mb/category.rb, line 199
199:     def resource_code(scope=4)
200:       ResourceCode.find(:first,
201:         :conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
202:     end

[Validate]