| Class | ContentController |
| In: |
app/controllers/content_controller.rb
|
| Parent: | ApplicationController |
Controller for interaction with the content data model.
| content_types | [RW] | Accessor methods. |
| index | [RW] | Accessor methods. |
| type_names | [RW] | Accessor methods. |
Ersatz constructor.
# File app/controllers/content_controller.rb, line 243
243: def self.create
244: # Create an instance of this class.
245: content = self.new
246:
247: # Global hash variable for the mapping of content type names to their
248: # database row ids.
249: content.type_names = {}
250:
251: # Hash variable containing content type entities (not unaltered database
252: # row objects), indexed by database row id.
253: content.content_types = {}
254:
255: # This instance variable stores all URL content mapping data.
256: content.index = {}
257:
258: # Date information from this URL content reference, in YYYYMMDD format.
259: content.index['date'] = ''
260:
261: # All segments of this URL reference, as partitioned by the '/' character.
262: content.index['parts'] = []
263:
264: # Sorted information about all content items that are scheduled for display
265: # in this content index.
266: content.index['map'] = []
267:
268: # Flag signalling that all items should be displayed on a single page.
269: content.index['all'] = FALSE
270:
271: content
272: end
Process a content item download request.
# File app/controllers/content_controller.rb, line 278
278: def self.get_download_file (
279: project,
280: params
281: )
282: # Construct a content object.
283: content = create
284:
285: # Proceed iff this item's content type information is available.
286: if (content_type = content.types(project.id, project.host.id,
287: params['content_type_name']))
288: # Obtain the requested item.
289: content_item = content.item(project.id, project.host.id,
290: content_type.id, params['content_item_id'])
291:
292: # Return this item's data, if the item is downloadable.
293: if (content_item && content_item[:available_for_download])
294: return content_item.file_name
295: end
296: end
297:
298:
299: # If this method has not yet returned then the request or content data
300: # were invalid.
301: return FALSE
302: end
Interface to: @content_types{}.groups{}
This method manages the ‘groups’ (hash) attribute of the variable @content_types: if the requested content group is in the ‘groups’ hash then return it, else retrieve the group, initialize it within the hash, and return it.
# File app/controllers/content_controller.rb, line 21
21: def group (
22: project_id,
23: project_host_id,
24: content_type_id,
25: id
26: )
27: return FALSE if (!project_id || !content_type_id || !id)
28:
29:
30: # Force all input to be of type Fixnum, to ensure consistency within this
31: # data model.
32: id = id.to_i
33: host_id = project_host_id.to_i
34: type_id = content_type_id.to_i
35: project_id = project_id.to_i
36:
37:
38: # Populate this content type if it is not yet available.
39: types(project_id, host_id, type_id) if (!@content_types[type_id])
40:
41:
42: # If the group exists then return it.
43: if (@content_types[type_id].groups[id])
44: content_group = @content_types[type_id].groups[id]
45: # Retrieve and initialize groups that are not in the groups hash.
46: elsif (!@content_types[type_id].groups[id] &&
47: (@content_types[type_id].groups[id] =
48: ContentGroup.get(project_id, id)))
49: # Obtain the ids of all content items in this group. Note that this
50: # does not retrieve full content item database rows, only their id field.
51: @content_types[type_id].groups[id].item_ids = ContentGroup.get_item_ids(
52: project_id,
53: id,
54: type_id)
55: # Return this group.
56: content_group = @content_types[type_id].groups[id]
57: end
58:
59:
60: # Ticket #589 | Begin
61: if (@content_types[type_id] && @content_types[type_id].groups &&
62: @content_types[type_id].groups[id])
63: @content_types[type_id].groups[id] = nil
64: end
65: # Ticket #589 | End
66:
67:
68: (content_group) ? (content_group) : (FALSE)
69: end
Interface to: @content_types{}.items{}
This method manages the ‘items’ (hash) attribute of the variable @content_types: if the requested content item is in the ‘items’ hash then return it, else retrieve the item, initialize it in the hash, and return it.
# File app/controllers/content_controller.rb, line 80
80: def item (
81: project_id,
82: project_host_id,
83: content_type_id,
84: id
85: )
86: return FALSE if (!project_id || !content_type_id || !id)
87:
88:
89: # Force all input to be of type Fixnum, to ensure consistency within this
90: # data model.
91: id = id.to_i
92: host_id = project_host_id.to_i
93: type_id = content_type_id.to_i
94: project_id = project_id.to_i
95:
96:
97: # Populate this content type if it is not yet available.
98: types(project_id, host_id, type_id) if (!@content_types[type_id])
99:
100:
101: # Proceed iff the type exists.
102: if (@content_types[type_id])
103: # If the item exists then return it.
104: if (@content_types[type_id].items[id])
105: content_item = @content_types[type_id].items[id]
106: # Retrieve and initialize items that are not in the items hash.
107: elsif (@content_types[type_id].items[id] = ContentItem.get(project_id,
108: host_id,
109: type_id,
110: id))
111: content_item = @content_types[type_id].items[id]
112: end
113: else
114: content_item = nil
115: end
116:
117:
118: # Ticket #589 | Begin
119: if (@content_types[type_id] && @content_types[type_id].items &&
120: @content_types[type_id].items[id])
121: @content_types[type_id].items[id] = nil
122: end
123: # Ticket #589 | End
124:
125:
126: (content_item) ? (content_item) : (FALSE)
127: end
Interface to: @content_types
This method manages the instance variable @content_types, retrieving and/or initializing content type data that is not in the @content_types hash: if the requested content type is in the hash then return it, else retrieve it, initialize it in the hash, and then return it.
This method accepts two arguments:
# File app/controllers/content_controller.rb, line 142
142: def types (
143: project_id,
144: project_host_id,
145: id
146: )
147: # Force all input to be of type Fixnum to ensure consistency within this
148: # data structure, 'id' is handled below.
149: project_id = project_id.to_i
150: host_id = project_host_id.to_i
151:
152:
153: # Ensure that the class of the id is Fixnum if the identifier is a
154: # content type id.
155: if (id.to_s =~ /#{ID}/)
156: id = id.to_i
157: # If the identifier is a content type name and it's integer id is cached
158: # then set the identifier to it's integer id.
159: elsif (id.to_s =~ /#{CONTENT_TYPE_NAME}/)
160: id = @type_names["#{id}"] if (@type_names["#{id}"])
161: # This id is invalid.
162: else
163: return FALSE
164: end
165:
166:
167: # If the type exists then return it.
168: if ((id.to_s =~ /#{ID}/) && @content_types[id])
169: content_type = @content_types[id]
170: # Retrieve and initialize the data for this type and it's attributes.
171: elsif ((row = ContentType.get(project_id, host_id, id)) &&
172: !@content_types[row.id])
173: content_type = row
174: @type_names[row.name] = row.id
175: @content_types[row.id] = row
176: @content_types[row.id].items = {}
177: @content_types[row.id].groups = {}
178:
179:
180: # The attribute 'item_fields' contains a list of all fields that may
181: # be used to view a content item via the URL. This list must be
182: # generated by excluding all prohibited fields.
183: #
184: # Create an array containing all fields that are explicitly prohibited
185: # for URL access by this content type, and append all application level
186: # exclusions.
187: exclude = []
188:
189: if e(row.index_prohibited_fields)
190: exclude << row.index_prohibited_fields.split(' ')
191: end
192:
193: exclude << INDEX_PROHIBITED_FIELDS if e(INDEX_PROHIBITED_FIELDS)
194:
195: @content_types[row.id].item_fields = url_get_available_fields(row.id,
196: exclude)
197:
198:
199: # The attribute 'index_fields' contains a list of all fields that will
200: # be listed in a content index. This list must be generated by excluding
201: # all hidden and prohibited fields.
202: #
203: # Update the array containing all prohibited fields to include all
204: # hidden fields.
205: if e(row.index_hidden_fields)
206: exclude << row.index_hidden_fields.split(' ')
207: end
208:
209: exclude << INDEX_HIDDEN_FIELDS if e(INDEX_HIDDEN_FIELDS)
210:
211: @content_types[row.id].index_fields = url_get_available_fields(row.id,
212: exclude)
213: end
214:
215:
216: (content_type) ? (content_type) : (FALSE)
217: end
Convert an ActiveRecord datetime timestamp to the URL safe search string format used by Code Blue.
For example:
Steps:
# File app/controllers/content_controller.rb, line 231
231: def url_encode_date (
232: date
233: )
234: date.to_mysql_datetime.gsub('[-:\.]{1,}', '-')
235: end