© 2015 X2Engine Inc.

Difference between revisions of "X2Model and Dynamic Fields"

From X2Engine
Jump to: navigation, search
(Field Types)
(Field Types)
Line 40: Line 40:
 
: (<tt>INT</tt>) Date, as a Unix timestamp. Using this type for an integer field ensures it will effectively be treated as a Unix timestamps and converted to a full date when rendered.
 
: (<tt>INT</tt>) Date, as a Unix timestamp. Using this type for an integer field ensures it will effectively be treated as a Unix timestamps and converted to a full date when rendered.
 
;dropdown
 
;dropdown
: (<tt>VARCHAR</tt>) Specifies the ID of a list of items stored in <tt>x2_dropdowns</tt> to use as the permissible values for the field (stored as a JSON object).
+
: (<tt>VARCHAR</tt>) Specifies the ID of a list of items stored in <tt>x2_dropdowns</tt> to use as the permissible values for the field.
 
;email
 
;email
 
: (<tt>VARCHAR</tt>) Specifies that the contents are formatted like (and correspond to an actual) email address.
 
: (<tt>VARCHAR</tt>) Specifies that the contents are formatted like (and correspond to an actual) email address.
Line 46: Line 46:
 
: (<tt>INT</tt>) Self-explanatory
 
: (<tt>INT</tt>) Self-explanatory
 
;link
 
;link
: (<tt>VARCHAR</tt>) In the case that the record is associated with another record, a field of this type specifies the text to be used as the text of the link to that other record. In such cases, the linkType field is used to distinguish the linked-to model (or other destination).
+
: (<tt>VARCHAR</tt>) If the field content is an integer, this field specifies another record that it is linked to / associated with (and the model is specified by <tt>linkType</tt>), and thus the rendered field will be a link to the view of that record. If it is text, it is treated as a URL and simply rendered.
 
;phone
 
;phone
 
: (<tt>VARCHAR</tt>) Field is a phone number and should be treated/formatted as such when formatting for output.
 
: (<tt>VARCHAR</tt>) Field is a phone number and should be treated/formatted as such when formatting for output.

Revision as of 17:07, 17 September 2012


Introduction

Typically in Yii, when a model (see: CActiveRecord) is used to retrieve data from a table in the database, the model's attributes are simply inherited from the schema for that table. However, in order to provide the means to add and remove fields from models (and thus from database tables), in addition to providing more advanced options for setting behaviors of attributes, most of the model classes in X2EngineCRM (the ones that are associated with database tables) are extended from a class X2Model. The attributes of all such models are not derived from the database itself but from an attribute registry stored in the x2_fields table. The following columns in the fields table are of particular importance:

modelName
The exact name of the model class to which the field belongs, with only one exception (fields with modelName="Quotes" belong to class Quote)
fieldName
The name of the database column
attributeLabel
The attribute label (the name of the field as displayed in the UI)
modified
Whether the field has been modified by the user.
custom
Whether the field has been created by the user.
type
The type of the column. This does not merely specify the canonical MySQL type, but is used for specifying advanced behaviors for the field.
required
Specifies that the model attribute cannot be null or empty, if set to 1.
readOnly
Signifies that the model attribute cannot be modified through user input, if set to 1.
linkType
In the case that the field is being used as a link, keywords set in this field signify what type of link should be generated in output.
searchable
If set to 1, the field's contents are included in global searches through records.
relevance
An integer value used for sorting search results.
isVirtual
If set to 1, the field does not actually correspond to a database column; rather, it is an ephemeral attribute of the model that is used for passing data from the view to the controller and vice-versa. For instance, it would be used in the case of input that needs to be collected as part of the model (initially) so that it can be put through input validation.

Field Types

assignment
The attribute is rendered as a link using User::getUserLinks. The input field for it is a dropdown list of users and groups.
boolean
(TINYINT) Self-explanatory; true or false.
currency
(FLOAT) A currency value. Setting a field to this type enables printing currency symbols by values.
date
(INT) Date, as a Unix timestamp. Using this type for an integer field ensures it will effectively be treated as a Unix timestamps and converted to a full date when rendered.
dropdown
(VARCHAR) Specifies the ID of a list of items stored in x2_dropdowns to use as the permissible values for the field.
email
(VARCHAR) Specifies that the contents are formatted like (and correspond to an actual) email address.
int
(INT) Self-explanatory
link
(VARCHAR) If the field content is an integer, this field specifies another record that it is linked to / associated with (and the model is specified by linkType), and thus the rendered field will be a link to the view of that record. If it is text, it is treated as a URL and simply rendered.
phone
(VARCHAR) Field is a phone number and should be treated/formatted as such when formatting for output.
rating
(varies) The CStarRating widget should be used to format this field in output.
text
(TEXT or VARCHAR) Distinct from VARCHAR in that links within the field's data are automatically transformed using x2base::convertUrls.
url
(VARCHAR) Field is a URL
varchar
(VARCHAR) Self-explanatory.
visibility
(INT) If 1, the record's contents are public. If 0, it is private. If 2, the record is visible only to the user's groups.