| Class | ProjectPage |
| In: |
app/models/project_page.rb
|
| Parent: | ActiveRecord::Base |
API for interaction with the database table ‘project_pages’, and it‘s related data model.
| content_index | [RW] | Accessor methods. |
| content_type_name | [RW] | Accessor methods. |
| host_id | [RW] | Accessor methods. |
| module_options | [RW] | Accessor methods. |
| option_index | [RW] | Accessor methods. |
| path_info | [RW] | Accessor methods. |
| template | [RW] | Accessor methods. |
Wrap an SQL select query for this model‘s database table, managing the field ‘active’ appropriately.
This method simplifies find() calls for this model:
# File app/models/project_page.rb, line 26
26: def self.fetch (
27: conditions
28: )
29: sql = 'SELECT * FROM ' + table_name + ' WHERE'
30: starting_size = sql.length
31:
32:
33: # Process all conditions for this query.
34: for condition in conditions
35: column = condition[0]
36: value = condition[1]
37:
38: # Is this the first condition?
39: (sql.size > starting_size) ? (sql += " and ") : (sql += " ")
40:
41: # Encase string values within quotes.
42: value = "'" + value + "'" if (value.get_variable_class == 'string')
43:
44: # Append this condition to the SQL query.
45: sql += "#{column} = #{value}"
46: end
47:
48:
49: if (page = find_by_sql(sql += ' and active = "TRUE"')[0])
50: # If this page has no name then generate one from it's path.
51: page.name ||= convert_path_to_title(page.path)
52: return page
53: else
54: return FALSE
55: end
56: end
Retrieve the appropriate project page for the requested host and path:
# File app/models/project_page.rb, line 65
65: def self.get (
66: project_id,
67: host_id,
68: path_info
69: )
70: # Remove trailing forward slash characters from URL paths other than '/';
71: # this is required for the proper lookup of URL page paths, and
72: # also to facilitate the correct application of URL content mapping.
73: path_info = path_info.gsub(/[\/]+$/, '') if (path_info != '/')
74: content_type = ''
75:
76:
77: # If the client has been directed to the application's default page
78: # then obtain it's information.
79: if (DEFAULT_PROJECT_PAGE_PATH == path_info)
80: page = find(DEFAULT_PROJECT_PAGE_ID)
81: end
82:
83:
84: # Otherwise search for an active page using the full requested URL path.
85: if (!page)
86: page = fetch({'project_id' => project_id,
87: 'project_host_id' => host_id,
88: 'path' => path_info})
89: end
90:
91:
92: # If there is no result, then determine if the request is a URL content
93: # mapping.
94: if (!page)
95: # Obtain the (potential) content type name.
96: content_type_name = path_info.split(/\//)[1]
97:
98: # If there exists a content type whose name exactly matches the first
99: # segment of this requested URL then define a page object.
100: if (ContentType.exists(project_id, host_id, content_type_name))
101: # Construct a page object, flag this page as a content index,
102: # and record the index's type.
103: page = ProjectPage.new
104: page.content_index = TRUE
105: page.content_type_name = content_type_name
106: end
107: end
108:
109:
110: # If there is no result or the resulting page has to template defined
111: # then display the application's default error page.
112: #
113: # Note that this provides fundamental failure mode functionality, thus the
114: # result must be available at all times, accordingly the 'active' field is
115: # ignored during this query.
116: if (!page || (!page.template_id && !page.content_index))
117: page = find(DEFAULT_ERROR_PAGE_ID)
118: page.path_info = DEFAULT_ERROR_PATH
119: end
120:
121:
122: # Configure all parameters required by the Template and Content models.
123: # If this page has no name then generate one from it's path.
124: page.name ||= convert_path_to_title(path_info)
125: page.http_content_type ||= DEFAULT_HTTP_CONTENT_TYPE
126: page.path_info ||= path_info
127: page.allow_caching ||= TRUE
128: page.host_id = host_id
129: page.project_id = project_id
130: page.option_index = ApplicationModuleOption.get(page.project_id,
131: page.host_id,
132: page.id)
133:
134:
135: page
136: end