Class Template
In: app/models/template.rb
Parent: ActiveRecord::Base

API for interaction with the database table ‘templates’, and it‘s related data model.

Methods

Public Class methods

Retrieve a template.

[Source]

    # File app/models/template.rb, line 19
19:   def self.get (
20:     project_host_id,
21:     id
22:   )
23:     id = id.to_i
24: 
25:     if (row = template(id))
26:       # A host may access only templates for itself and the 
27:       # default Code Blue project host.
28:       if ((project_host_id         == row.project_host_id) || 
29:           (DEFAULT_PROJECT_HOST_ID == row.project_host_id))
30:         return row.frame
31:       end
32:     end
33: 
34:     FALSE
35:   end

Retrieve a content type‘s template.

[Source]

    # File app/models/template.rb, line 41
41:   def self.get_content_type_template (
42:     project_host_id,
43:     template_id,
44:     content_type
45:   )
46:     # A specific template has been requested.
47:     if (template_id && template_id.to_i > 0)
48:       template = get(project_host_id, template_id.to_i)
49: 
50:     # Otherwise, obtain the default template for this content type.
51:     else
52:       # Retrieve the template.
53:       if (content_type.template_id.to_i > 0)
54:         template = get_content_type_template(project_host_id,
55:                                              content_type.template_id,
56:                                              content_type)
57:       # Base Case.
58:       else
59:         template = get(DEFAULT_PROJECT_HOST_ID, 
60:                       o('content:index:type_template_id').to_i)
61:       end
62:     end
63: 
64:     template
65:   end

Determine the maximum value of the ‘updated_on’ field for this table, comparing the values of all rows for this project host.

[Source]

    # File app/models/template.rb, line 72
72:   def self.last_modified (
73:     project_host_id
74:   )
75:     max = Time.at(0)
76: 
77:     for template in find_all_by_project_host_id_and_active(project_host_id,TRUE)
78:       max = template.updated_on if (template.updated_on > max)
79:     end
80: 
81:     max                                                                           end

Interface for management of the ‘templates’ (hash) instance variable.

If the requested template is in the ‘templates’ hash then return it, else retrieve the template, initialize it in the hash, and return it.

[Source]

     # File app/models/template.rb, line 90
 90:   def self.template (
 91:     id
 92:   )
 93:     id = id.to_i
 94: 
 95:     # Return the cached result.
 96:     if ($templates[id])
 97:       return $templates[id]
 98:     # If the requested template is not cached then retrieve it from the 
 99:     # database. Every template must have a database row.
100:     elsif (row = find_by_id_and_active(id, 'TRUE'))
101:       # Template frames are obtained from the database by default, however if
102:       # the application or this host are configured to retrieve templates from
103:       # the filesystem then attempt to read the requested template from this
104:       # project host's template directory.
105:       if o('template:configuration:read_from_filesystem')
106:         file      = TEMPLATE_FILE.parse_data(row.project_host_id, row.id)
107:         row.frame = file_read(file)
108:       end
109: 
110:       # Wrap this template in BEGIN and END tags.
111:       # 
112:       # The template module may be configured to insert a template's database 
113:       # row id when returning the template, if this option is enabled then 
114:       # HTML comments specifying the row id are inserted at the beginning and 
115:       # end of the template, for example:
116:       #
117:       #   <!-- 85 | BEGIN -->
118:       #        ... HTML for template with id = 85 ...
119:       #   <!-- 85 | END -->
120:       if o('template:parse:insert_id_as_comment')
121:         row.frame = ID_COMMENT_TEMPLATE.parse_data(id, row.frame)
122:       end
123: 
124:       # Cache and return the result.
125:       if (o('application:cache:templates') && o('application:cache:enabled'))
126:         $templates[id] = row 
127:       end
128: 
129:       return row
130:     else
131:       return FALSE
132:     end
133:   end

[Validate]