| Class | ContentCallback |
| In: |
app/models/content_callback.rb
|
| Parent: | ActiveRecord::Base |
API for interaction with the database table ‘content_callbacks’, and it‘s related data model.
Callback modules are specific to a project host, because each content type is defined for a project host.
All project specific callback libraries use the same file name, as specified by the constant CONTENT_CALLBACK_LIB. These libraries are stored within a project‘s library directory:
Callback fields map to callback methods using their content type database id and content callback database id:
For example, the content callback method with content type id = 47 and content callback id = 2 would be named:
This naming convention increases portability, stability, and maintainability; a content type‘s name and content callback field‘s name may be changed without impacting the callback method.
Retrieve all callback fields defined for a content type, process their corresponding methods, and return their values.
# File app/models/content_callback.rb, line 36
36: def self.get (
37: project_id,
38: project_host_id,
39: content_type_id,
40: content_item
41: )
42: # Values of all callback fields for this content item, indexed by field
43: # name.
44: fields = {}
45:
46:
47: # If this project's callback library is available then process callbacks.
48: if (load_project_library(project_host_id, CONTENT_CALLBACK_LIB))
49: # Retrieve and process all callbacks.
50: for callback in find_all_by_project_id_and_content_type_id_and_active(
51: project_id,
52: content_type_id,
53: 'TRUE')
54: # Construct the name of this callback field's method.
55: method_name = "callback_#{content_type_id}_#{callback.id}"
56:
57: # Obtain the value for this callback field, by processing the current
58: # content item using this field's callback method.
59: begin
60: value = FALSE
61: eval "value = #{method_name}(project_host_id,
62: content_type_id,
63: content_item)"
64: if (value)
65: fields[callback.field] = value.to_s
66: else
67: fields[callback.field] = FALSE
68: end
69: rescue
70: l(m(3, method_name, callback.field))
71: end
72: end
73: end
74:
75:
76: # Return all fields and values.
77: fields
78: end
Determine the maximum value of the ‘updated_on’ field for this table, comparing the values of all rows for this project host.
# File app/models/content_callback.rb, line 85
85: def self.last_modified (
86: content_type_ids
87: )
88: max = Time.at(0)
89:
90: for content_type_id in content_type_ids
91: for callback in find_all_by_content_type_id_and_active(content_type_id,
92: TRUE)
93: max = callback.updated_on if (callback.updated_on > max)
94: end
95: end
96:
97: max
98: end