ModelHelper

Type
Class
Namespace
Craft
Inherits
Craft\ModelHelper
Since
1.0

Class ModelHelper

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$attributeTypeDefaultsarray

$attributeTypeDefaults

Signature

public static array $attributeTypeDefaults = [\Craft\AttributeType::Mixed => ['model' => null, 'column' => \Craft\ColumnType::Text], \Craft\AttributeType::Bool => ['maxLength' => 1, 'default' => false, 'required' => true, 'column' => \Craft\ColumnType::TinyInt, 'unsigned' => true], \Craft\AttributeType::ClassName => ['maxLength' => 150, 'column' => \Craft\ColumnType::Varchar], \Craft\AttributeType::DateTime => ['column' => \Craft\ColumnType::DateTime], \Craft\AttributeType::Email => ['minLength' => 5, 'column' => \Craft\ColumnType::Varchar], \Craft\AttributeType::Enum => ['values' => [], 'column' => \Craft\ColumnType::Enum], \Craft\AttributeType::Handle => ['maxLength' => 255, 'reservedWords' => 'id,dateCreated,dateUpdated,uid,title', 'column' => \Craft\ColumnType::Varchar], \Craft\AttributeType::Locale => ['column' => \Craft\ColumnType::Locale], \Craft\AttributeType::Name => ['maxLength' => 255, 'column' => \Craft\ColumnType::Varchar], \Craft\AttributeType::Number => ['min' => null, 'max' => null, 'decimals' => 0], \Craft\AttributeType::SortOrder => ['column' => \Craft\ColumnType::SmallInt, 'unsigned' => true], \Craft\AttributeType::Template => ['maxLength' => 500, 'column' => \Craft\ColumnType::Varchar], \Craft\AttributeType::Url => ['maxLength' => 255, 'column' => \Craft\ColumnType::Varchar], \Craft\AttributeType::UrlFormat => ['column' => \Craft\ColumnType::Text]]

Public Methods

MethodDescription
expandModelsInArray()Searches an array for any flattened models, and expands them back to models.
getAttributeLabels()Returns the attribute labels.
getNumberAttributeConfig()Returns a number attribute config, taking the min, max, and number of decimal points into account.
getRules()Returns the rules array used by CModel.
normalizeAttributeConfig()Normalizes an attribute's config.
packageAttributeValue()Takes an attribute's config and value and "normalizes" them either for saving to db or sending across a web service.
populateAttributeDefaults()Populates any default values that are defined for a model.

expandModelsInArray()

Searches an array for any flattened models, and expands them back to models.

View source

Arguments

Returns

array, Craft\BaseModel

Signature

public static array, Craft\BaseModel expandModelsInArray ( $arr )

getAttributeLabels()

Returns the attribute labels.

View source

Arguments

Returns

array

Signature

public static array getAttributeLabels ( CModel $model )

getNumberAttributeConfig()

Returns a number attribute config, taking the min, max, and number of decimal points into account.

View source

Arguments

Returns

array

Signature

public static array getNumberAttributeConfig ( $min = null, $max = null, $decimals = null )

getRules()

Returns the rules array used by CModel.

View source

Arguments

Returns

array

Signature

public static array getRules ( CModel $model )

normalizeAttributeConfig()

Normalizes an attribute's config. Attributes can be defined in 3 ways:

  1. AttributeType::TypeName
  2. array(AttributeType::TypeName [, 'other' => 'settings' ... ] )
  3. array('type' => AttributeType::TypeName [, 'other' => 'settings' ... ] )

This function normalizes on the 3rd, and merges in the default config settings for the attribute type, merges in the default column settings if 'column' is set, and sets the 'unsigned', 'min', and 'max' values for integers.

View source

Arguments

Returns

array

Signature

public static array normalizeAttributeConfig ( $config )

packageAttributeValue()

Takes an attribute's config and value and "normalizes" them either for saving to db or sending across a web service.

View source

Arguments

  • $value (mixed)
  • $jsonEncodeArrays (boolean)

Returns

Signature

public static integer, mixed, null, string packageAttributeValue ( $value, $jsonEncodeArrays = false )

populateAttributeDefaults()

Populates any default values that are defined for a model.

View source

Arguments

Returns

null

Signature

public static null populateAttributeDefaults ( CModel $model )