RedBeanModel Class Reference

Inheritance diagram for RedBeanModel:
BeanModel ObservableComponent A ActiveLanguage AuditEvent BaseCustomField BaseStarredModel ContactState Currency CustomFieldData CustomFieldsModel CustomFieldValue DateDateTime DDD DerivedAttributeMetadata E F FFF FileContent G GameNotification GGG GlobalMetadata H HHH III KanbanItem M MashableInboxForTestModel MessageSource MessageTranslation MixedRelationsModel NoBean OwnedModel P PerUserMetadata Portlet PP PPP PPPP ProjectAuditEvent QueryFromModel SavedCalendarSubscription ShortUrl StuckJob TestAttributeNamedLikeSqlKeywordModel TestBlobModel TestBooleanAttributeModel TestDatabaseBulkInsertModel TestDataUtilModel TestDateTimeModel TestDateTimeUserModel TestDefaultedAttributeModel TestGetAttributeLabelModel TestIdentityModel TestInvalidSpecificLinkType TestManyManyRelationToItemModel TestModelToMessagesModel TestNameModel TestOperatorTypeModel TestPolyOneToManyOneSide TestPolyOneToManyOneSideTwo TestPolyOneToManyPolySide TestPolyOneToManyPolySideOwned TestPrecisionModel TestReadOnlyAttributeModel TestSelfRelatingModel TestSimplestManyRelationModel TestSimplestModel TestTypesModel TestViewMetadataValidatorModel ThingWithCalculatedDates Z ZZ

Public Member Functions

 getIsNewModel ()
 __construct ($setDefaults=true, RedBean_OODBBean $bean=null, $forceTreatAsCreation=false, $runConstruction=true)
 serialize ()
 unserialize ($data)
 getPrimaryBean ()
 getClassId ($modelClassName)
 getClassBean ($modelClassName)
 getModelIdentifier ()
 castDown (array $derivedModelClassNames)
 isSame (RedBeanModel $model)
 __toString ()
 __get ($attributeName)
 __set ($attributeName, $value)
 __isset ($attributeName)
 __unset ($attributeName)
 attributeNames ()
 isAttribute ($attributeName)
 isAttributeReadOnly ($attributeName)
 isAttributeFormattedAsProbability ($attributeName)
 isAllowedToSetReadOnlyAttribute ($attributeName)
 rules ()
 behaviors ()
 attributeLabels ()
 abbreviatedAttributeLabels ()
 validate (array $attributeNames=null, $ignoreRequiredValidator=false)
 onBeforeValidate (CModelEvent $event)
 onAfterValidate ($event)
 getValidatorList ()
 getValidators ($attributeName=null)
 forgetValidators ()
 createValidators ()
 isUniqueAttributeValue ($attributeName, $value)
 save ($runValidation=true, array $attributeNames=null)
 onBeforeSave ($event)
 onAfterSave ($event)
 onRedBeanOneToManyRelatedModelsChange ($event)
 onBeforeDelete ($event)
 onAfterDelete ($event)
 isModified ()
 delete ()
 isDeleted ()
 isDeletable ()
 forget ()
 isAttributeRequired ($attributeName)
 isAttributeSafe ($attributeName)
 getAttributeLabel ($attributeName)
 getAttributeLabelsForAllActiveLanguagesByAttributeName ($attributeName)
 hasErrors ($attributeNameOrNames=null)
 getErrors ($attributeNameOrNames=null)
 getError ($attributeName)
 addError ($attributeName, $errorMessage)
 addErrors (array $errors)
 clearErrors ($attributeName=null)
 generateAttributeLabel ($attributeName)
 getAttributes (array $attributeNames=null)
 setAttributes (array $values, $safeOnly=true)
 unsetAttributes ($attributeNames=null)
 onUnsafeAttribute ($name, $value)
 getScenario ()
 setScenario ($scenarioName)
 getSafeAttributeNames ()
 getIterator ()
 offsetExists ($offset)
 offsetGet ($offset)
 offsetSet ($offset, $item)
 offsetUnset ($offset)
 stringifyOneToManyRelatedModelsValues ($values)
 setIsCopied ()
 isCopied ()
 addValidator ($attribute, $validator, $params=array())

Static Public Member Functions

static model ($className=null)
static getAll ($orderBy=null, $sortDescending=false, $modelClassName=null)
static getSubset (RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $modelClassName=null, $selectDistinct=false)
static getSubsetIds (RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $modelClassName=null, $selectDistinct=false)
static makeSubsetOrCountSqlQuery ($tableName, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter, $offset=null, $count=null, $where=null, $orderBy=null, $selectCount=false, $selectDistinct=false, array $quotedExtraSelectColumnNameAndAliases=array())
static getCount (RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static getById ($id, $modelClassName=null)
static deleteAll ()
static mangleTableName ()
static getTableName ()
static getTableNames ($classNames)
static getForeignKeyName ($modelClassName, $relationName)
static getMetadata ()
static canSaveMetadata ()
static setMetadata (array $metadata)
static getDefaultMetadata ()
static isTypeDeletable ()
static forgetAll ()
static getModelLabelByTypeAndLanguage ($type, $language=null)
static getAnAttributeLabel ($attributeName)
static makeModel (RedBean_OODBBean $bean, $modelClassName=null)
static makeModels (array $beans, $modelClassName=null)
static getModuleClassName ()
static getLastClassInBeanHeirarchy ()
static getSortAttributesByAttribute ($attribute)
static isCacheable ()
static getYiiValidatorsToRedBeanValidators ()
static getHasManyOpposingRelationName (RedBeanModel $model, $precedingModelClassName, $precedingRelation)
static relationLinksToPrecedingRelation ($modelClassName, $relation, $precedingModelClassName=null, $precedingRelation=null)

Protected Member Functions

 constructDerived ($bean, $setDefaults)
 constructIncomplete ($bean)
 setNotModified ()
 onCreated ()
 onLoaded ()
 onModified ()
 mapAndCacheMetadataAndSetHints ($modelClassName, RedBean_OODBBean $bean)
 runDefaultValidators ()
 setClassBean ($modelClassName, RedBean_OODBBean $bean)
 unrestrictedGet ($attributeName)
 unrestrictedSet ($attributeName, $value)
 beforeValidate ()
 afterValidate ()
 beforeSave ()
 afterSave ()
 linkBeans ()
 beforeDelete ()
 afterDelete ()
 unrestrictedDelete ()
 deleteOwnedRelatedModels ($modelClassName)
 deleteForeignRelatedModels ($modelClassName)
 deleteManyManyRelations ($modelClassName)

Static Protected Member Functions

static makeCasedLinkName ($relationType, $linkType, $relationLinkName)
static assertMetadataIsValid (array $metadata)
static getByRelatedClassId ($relatedModelClassName, $id, $modelClassName=null)
static getLabel ($language=null)
static getPluralLabel ($language=null)
static getAttributeLabelByLanguage ($attributeName, $language)
static getTranslatedCustomAttributeLabelByLanguage ($attributeName, $languageCode)
static resolveModelClassNameForClassesWithoutBeans (&$modelClassName)

Protected Attributes

 $modified = false
 $deleted = false
 $isInIsModified = false
 $isInHasErrors = false
 $isInGetErrors = false
 $isValidating = false
 $isSaving = false
 $isNewModel = false
 $isCopied = false
 $isSavableFromRelation = true

Static Protected Attributes

static $lastClassInBeanHeirarchy = 'RedBeanModel'

Detailed Description

Abstraction over the top of an application database accessed via RedBean. The base class for an MVC model. Replaces the M part of MVC in Yii. Yii maps from the database scheme to the objects, (good for database guys, not so good for OO guys), this maps from objects to the database schema.

A domain model is created by extending RedBeanModel and supplying a getDefaultMetadata() method.

Static getXxxx() methods can be supplied to query for the given domain models, and instance methods should supply additional behaviour.

getDefaultMetadata() returns an array of the class name mapped to an array containing 'members' mapped to an array of member names, (to be accessed as $model->memberName).

It can then optionally have, 'relations' mapped to an array of relation names, (to be accessed as $model->relationName), mapped to its type, (the extending model class to which it relates).

And it can then optionally have as well, 'rules' mapped to an array of attribute names, (attributes are members and relations), a validator name, and the parameters to the validator, if any, as per the Yii::CModel::rules() method.See http://www.yiiframework.com/wiki/56/reference-model-rules-validation.

These are used to automatically and dynamically create the database schema on the fly as opposed to Yii's getting attributes from an already existing schema.

Definition at line 67 of file RedBeanModel.php.


Constructor & Destructor Documentation

__construct ( setDefaults = true,
RedBean_OODBBean $  bean = null,
forceTreatAsCreation = false,
runConstruction = true 
)

Constructs a new model. Important: Models are only constructed with beans by the RedBeanModel. Beans are never used by the application directly. The application can construct a new model object by constructing a model without specifying a bean. In other words, if Php had overloading a constructor with $setDefaults would be public, and a constructor taking a $bean and $forceTreatAsCreation would be private.

Parameters:
$setDefaults. If false the default validators will not be run on construction. The Yii way is that defaults are filled in after the fact, which is counter the usual for objects.
$bean A bean. Never specified by an application.
$forceTreatAsCreation. Never specified by an application.
$runConstruction. Sometimes a model is needed to hook in events and the construction logic does not necessarily need to be run.
See also:
getById()
makeModel()
makeModels()

Definition at line 404 of file RedBeanModel.php.


Member Function Documentation

static model ( className = null  )  [static]

Returns the static model of the specified AR class. The model returned is a static instance of the AR class. It is provided for invoking class-level methods (something similar to static class methods.)

EVERY derived AR class must override this method as follows,

 public static function model($className=__CLASS__)
 {
     return parent::model($className);
 }
 

This method will make a model that does not run construction

Parameters:
string $className active record class name.
Returns:
CActiveRecord active record model instance.

Definition at line 169 of file RedBeanModel.php.

static getAll ( orderBy = null,
sortDescending = false,
modelClassName = null 
) [static]

Gets all the models from the database of the named model type.

Parameters:
$orderBy TODO
$modelClassName Pass only when getting it at runtime gets the wrong name.
Returns:
An array of models of the type of the extending model.

Definition at line 193 of file RedBeanModel.php.

static getSubset ( RedBeanModelJoinTablesQueryAdapter joinTablesAdapter = null,
offset = null,
count = null,
where = null,
orderBy = null,
modelClassName = null,
selectDistinct = false 
) [static]

Gets a range of models from the database of the named model type.

Parameters:
$modelClassName 
$joinTablesAdapter null or instance of joinTablesAdapter.
$offset The zero based index of the first model to be returned.
$count The number of models to be returned.
$where 
$orderBy - sql string. Example 'a desc' or 'a.b desc'. Currently only supports non-related attributes
$modelClassName Pass only when getting it at runtime gets the wrong name.
Returns:
An array of models of the type of the extending model.

Definition at line 222 of file RedBeanModel.php.

static getSubsetIds ( RedBeanModelJoinTablesQueryAdapter joinTablesAdapter = null,
offset = null,
count = null,
where = null,
orderBy = null,
modelClassName = null,
selectDistinct = false 
) [static]

Gets a range of model ids from the database of the named model type.

Parameters:
$modelClassName 
$joinTablesAdapter null or instance of joinTablesAdapter.
$offset The zero based index of the first model to be returned.
$count The number of models to be returned.
$where 
$orderBy - sql string. Example 'a desc' or 'a.b desc'. Currently only supports non-related attributes
$modelClassName Pass only when getting it at runtime gets the wrong name.
Returns:
An array of models ids

Definition at line 256 of file RedBeanModel.php.

static makeSubsetOrCountSqlQuery ( tableName,
RedBeanModelJoinTablesQueryAdapter joinTablesAdapter,
offset = null,
count = null,
where = null,
orderBy = null,
selectCount = false,
selectDistinct = false,
array $  quotedExtraSelectColumnNameAndAliases = array() 
) [static]
Parameters:
boolean $selectCount If true then make this a count query. If false, select ids from rows.
array $quotedExtraSelectColumnNameAndAliases - extra columns to select.
Returns:
string - sql statement.

Reimplemented in OwnedSecurableItem.

Definition at line 288 of file RedBeanModel.php.

static getCount ( RedBeanModelJoinTablesQueryAdapter joinTablesAdapter = null,
where = null,
modelClassName = null,
selectDistinct = false 
) [static]
Parameters:
$modelClassName 
$joinTablesAdapter null or instance of joinTablesAdapter.
$modelClassName Pass only when getting it at runtime gets the wrong name.

Definition at line 325 of file RedBeanModel.php.

static getById ( id,
modelClassName = null 
) [static]

Gets a model from the database by Id.

Parameters:
$id Integer Id.
$modelClassName Pass only when getting it at runtime gets the wrong name.
Returns:
A model of the type of the extending model.

Reimplemented in Currency, and Group.

Definition at line 356 of file RedBeanModel.php.

static deleteAll (  )  [static]

Delete all models

Reimplemented in E, and Permission.

Definition at line 485 of file RedBeanModel.php.

constructIncomplete ( bean  )  [protected]

Utilized when pieces of information need to be constructed on an existing model, that can potentially be missing. For example, if a model is created, then a custom field is added, it is possible the cached model is missing the custom field customFieldData.

Parameters:
unknown_type $bean

Definition at line 517 of file RedBeanModel.php.

setNotModified (  )  [protected]

Overriding constructors must call this function to ensure that they leave the newly constructed instance not modified since anything modifying the class during constructionm will set it modified automatically.

Definition at line 573 of file RedBeanModel.php.

static mangleTableName (  )  [static]

By default the table name is the lowercased class name. If this conflicts with a database keyword override to return true. RedBean does not quote table names in most cases.

Reimplemented in User, Group, and Right.

Definition at line 585 of file RedBeanModel.php.

static getTableName (  )  [static]

Returns the table name for a class. For use by RedBeanModelDataProvider. It will not be of any use to an application. Applications should not be doing anything table related. Derived classes can refer directly to the table name.

Definition at line 598 of file RedBeanModel.php.

static getTableNames ( classNames  )  [static]

Returns the table names for an array of classes. For use by RedBeanModelDataProvider. It will not be of any use to an application.

Definition at line 616 of file RedBeanModel.php.

static getForeignKeyName ( modelClassName,
relationName 
) [static]

Used by classes such as containers which use sql to optimize getting models from the database.

Definition at line 630 of file RedBeanModel.php.

onCreated (  )  [protected]

Called on construction when a new model is created.

Reimplemented in Activity, Conversation, EmailMessageSendError, GameRewardTransaction, GamePointTransaction, MarketingListMember, Mission, SocialItem, Item, ShortUrl, and ShortUrlForTest.

Definition at line 670 of file RedBeanModel.php.

onLoaded (  )  [protected]

Called on construction when a model is loaded.

Definition at line 682 of file RedBeanModel.php.

onModified (  )  [protected]

Called when a model is modified.

Reimplemented in Item.

Definition at line 694 of file RedBeanModel.php.

mapAndCacheMetadataAndSetHints ( modelClassName,
RedBean_OODBBean $  bean 
) [protected]

Used for mixins.

$this->relationNameToRelationTypeModelClassNameAndOwns[$relationName] = array($relationType, $relationModelClassName, $owns, $linkType, $relationLinkName);

Definition at line 713 of file RedBeanModel.php.

runDefaultValidators (  )  [protected]

Used for mixins.

Definition at line 910 of file RedBeanModel.php.

getPrimaryBean (  ) 

For use only by RedBeanModel and RedBeanModels. Beans are never used by the application directly.

Definition at line 925 of file RedBeanModel.php.

getClassId ( modelClassName  ) 

Used for optimization.

Definition at line 933 of file RedBeanModel.php.

setClassBean ( modelClassName,
RedBean_OODBBean $  bean 
) [protected]

Used for mixins.

Definition at line 951 of file RedBeanModel.php.

static getMetadata (  )  [static]

Returns metadata for the model. Attempts to cache metadata, if it is not already cached.

See also:
getDefaultMetadata()
Returns:
An array of metadata.

Reimplemented from BeanModel.

Reimplemented in User.

Definition at line 970 of file RedBeanModel.php.

static canSaveMetadata (  )  [static]

By default models cannot save their metadata, allowing them to be loaded quickly because the loading of of metadata can be avoided as much as possible. To make a model able to save its metadata override this method to return true. PUT it before the getDefaultMetadata in the derived class.

Reimplemented in KanbanItem, A, AAA, ExtendsNoBean, M, MixedRelationsModel, NoBean, P, PP, PPP, PPPP, TestModelToMessagesModel, TestOperatorTypeModel, TestPolyOneToManyOneSide, TestPolyOneToManyOneSideTwo, TestPolyOneToManyPolySide, TestPolyOneToManyPolySideOwned, AccountAccountAffiliation, AccountContactAffiliation, Account, Activity, Autoresponder, AutoresponderItem, SavedCalendar, Campaign, CampaignItem, Comment, Contact, ContactWebForm, ContactWebFormEntry, Conversation, ConversationParticipant, EmailBox, EmailFolder, EmailMessage, EmailMessageActivity, EmailMessageRecipient, EmailMessageSender, EmailMessageSendError, EmailMessageUrl, EmailTemplate, EmailTemplateModelTestItem, GameReward, GameRewardTransaction, GameBadge, GameCoin, GameCollection, GameLevel, GameNotification, GamePoint, GamePointTransaction, GameScore, Import, MarketingList, MarketingListMember, PersonWhoHaveNotReadLatest, Meeting, Mission, Note, Opportunity, Product, ProductCatalog, ProductCategory, ProductTemplate, SellPriceFormula, Project, SavedReport, ReportModelTestItem11, SocialItem, Task, TaskCheckListItem, User, ByTimeWorkflowInQueue, SavedWorkflow, WorkflowMessageInQueue, Address, Currency, and ExtendsOwnedModel.

Definition at line 1027 of file RedBeanModel.php.

static setMetadata ( array $  metadata  )  [static]

Sets metadata for the model.

See also:
getDefaultMetadata()
Returns:
An array of metadata.

Reimplemented in User.

Definition at line 1037 of file RedBeanModel.php.

static getDefaultMetadata (  )  [static]

Returns the default meta data for the class. It must be appended to the meta data from the parent model, if any.

Reimplemented in KanbanItem, ActiveLanguage, BaseCustomField, CalculatedDerivedAttributeMetadata, CustomField, CustomFieldData, CustomFieldValue, DerivedAttributeMetadata, DropDownDependencyDerivedAttributeMetadata, FileContent, GlobalMetadata, MessageSource, MessageTranslation, MultipleValuesCustomField, PerUserMetadata, Portlet, A, AAA, B, BBB, C, CCC, D, DateDateTime, DDD, E, EEE, ExtendsNoBean, F, FFF, G, GG, GGG, H, HHH, I, II, III, J, K, L, M, MixedRelationsModel, NoBean, P, PP, PPP, PPPP, QQ, QueryFromModel, TestAttributeNamedLikeSqlKeywordModel, TestBlobModel, TestBooleanAttributeModel, TestCustomFieldsModel, TestDatabaseBulkInsertModel, TestDataUtilModel, TestDateTimeModel, TestDateTimeUserModel, TestDefaultedAttributeModel, TestGetAttributeLabelModel, TestIdentityModel, TestInvalidSpecificLinkType, TestModelToMessagesModel, TestNameModel, TestOperatorTypeModel, TestPolyOneToManyOneSide, TestPolyOneToManyOneSideTwo, TestPolyOneToManyPolySide, TestPolyOneToManyPolySideOwned, TestPrecisionModel, TestReadOnlyAttributeModel, TestSelfRelatingModel, TestSimplestManyRelationModel, TestSimplestModel, TestTypesModel, TestViewMetadataValidatorModel, Y, Z, ZZ, ThingWithCalculatedDates, AccountAccountAffiliation, AccountContactAffiliation, Account, AccountStarred, Activity, ApiTestModelItem, ApiTestModelItem2, ApiTestModelItem3, ApiTestModelItem4, Autoresponder, AutoresponderItem, AutoresponderItemActivity, SavedCalendar, SavedCalendarSubscription, Campaign, CampaignItem, CampaignItemActivity, Comment, Contact, ContactStarred, ContactState, ContactWebForm, ContactWebFormEntry, Conversation, ConversationParticipant, ConversationStarred, TestDropDownDependencyModel, EmailAccount, EmailBox, EmailFolder, EmailMessage, EmailMessageActivity, EmailMessageContent, EmailMessageRecipient, EmailMessageSender, EmailMessageSendError, EmailMessageUrl, EmailSignature, EmailTemplate, EmailTemplateModelTestItem, ExportItem, ExportTestModelItem, ExportTestModelItem2, ExportTestModelItem3, ExportTestModelItem4, ExportTestModelItem5, GameReward, GameRewardTransaction, GameBadge, GameCoin, GameCollection, GameLevel, GameNotification, GamePoint, GamePointTransaction, GameScore, Dashboard, Import, ImportDedupeModelTestItem, ImportModelTestItem, ImportModelTestItem2, ImportModelTestItem3, ImportModelTestItem4, ImportModelTestItem5, JobInProcess, JobLog, StuckJob, MarketingList, MarketingListMember, PersonWhoHaveNotReadLatest, Meeting, Mission, Note, Notification, NotificationMessage, NotificationSubscriber, Opportunity, OpportunityStarred, Product, ProductCatalog, ProductCategory, ProductTemplate, SellPriceFormula, Project, ProjectAuditEvent, SavedReport, ReportModelTestItem, ReportModelTestItem10, ReportModelTestItem11, ReportModelTestItem2, ReportModelTestItem3, ReportModelTestItem4, ReportModelTestItem5, ReportModelTestItem6, ReportModelTestItem7, ReportModelTestItem8, ReportModelTestItem9, SocialItem, Task, TaskCheckListItem, TestManyManyRelationToItemModel, User, ByTimeWorkflowInQueue, SavedWorkflow, WorkflowMessageInQueue, ByTimeWorkflowInQueueForTest, WorkflowModelTestItem, WorkflowModelTestItem2, WorkflowModelTestItem3, WorkflowModelTestItem4, WorkflowModelTestItem5, WorkflowModelTestItem6, WorkflowModelTestItem7, WorkflowModelTestItem8, WorkflowModelTestItem9, Address, AuditEvent, BaseStarredModel, Currency, CurrencyValue, Email, FileModel, Group, Item, NamedSecurableItem, OwnedSecurableItem, Permission, Permitable, Person, Policy, Right, Role, SavedSearch, SecurableItem, ShortUrl, AuditTestItem, CurrencyValueTestItem, ExtendsOwnedModel, ModelToArrayAdapterTestItem, ModelToArrayAdapterTestItem2, ModelToArrayAdapterTestItem3, ModelToArrayAdapterTestItem4, ModelWithAttachmentTestItem, OwnedSecurableTestItem, OwnedSecurableTestItem2, TestOwnedCustomFieldsModel, and TestOwnedLinkSpecificModel.

Definition at line 1081 of file RedBeanModel.php.

castDown ( array $  derivedModelClassNames  ) 

Downcasting in general is a bad concept, but when pulling a Person from the database it would require a lot of jumping through hoops to make the RedBeanModel automatically figure out if that person is really a User, Contact, Customer or whatever might be derived from Person. So to avoid that complication and performance hit where it is not necessary this method can be used to convert a model to one of a given set of derivatives. If model is not one of those NotFoundException is thrown.

Definition at line 1144 of file RedBeanModel.php.

isSame ( RedBeanModel model  ) 

Returns whether the given object is of the same type with the same id.

Definition at line 1210 of file RedBeanModel.php.

__get ( attributeName  ) 

Exposes the members and relations of the model as if they were actual attributes of the model. See __set().

Parameters:
$attributeName A non-empty string that is the name of a member or relation.
See also:
attributeNames()
Returns:
A value or model of the type specified as valid for the member or relation by the meta data supplied by the extending class's getMetadata() method.

Reimplemented in Group, NamedSecurableItem, OwnedMultipleValuesCustomField, Permission, and SecurableItem.

Definition at line 1251 of file RedBeanModel.php.

unrestrictedGet ( attributeName  )  [protected]

A protected version of __get() for models to talk to themselves to use their dynamically created members from 'members' and 'relations' in its metadata.

Reimplemented in CustomFieldsModel.

Definition at line 1261 of file RedBeanModel.php.

__set ( attributeName,
value 
)

Sets the members and relations of the model as if they were actual attributes of the model. For example, if Account extends RedBeanModel and its attributeNames() returns that one it has a member 'name' and a relation 'owner' they are simply accessed as:

   $account = new Account();
   $account->name = 'International Corp';
   $account->owner = User::getByUsername('bill');
   $account->save();
Parameters:
$attributeName A non-empty string that is the name of a member or relation of the model.
$value A value or model of the type specified as valid for the member or relation by the meta data supplied by the extending class's getMetadata() method.

Reimplemented in BaseCustomField, EmailTemplate, GamePoint, Group, Item, OwnedCustomField, OwnedModel, OwnedMultipleValuesCustomField, OwnedSecurableItem, Permission, and SecurableItem.

Definition at line 1400 of file RedBeanModel.php.

unrestrictedSet ( attributeName,
value 
) [protected]

A protected version of __set() for models to talk to themselves to use their dynamically created members from 'members' and 'relations' in its metadata.

Definition at line 1422 of file RedBeanModel.php.

__isset ( attributeName  ) 

Allows testing of the members and relations of the model as if they were actual attributes of the model.

Definition at line 1519 of file RedBeanModel.php.

__unset ( attributeName  ) 

Allows unsetting of the members and relations of the model as if they were actual attributes of the model.

Definition at line 1533 of file RedBeanModel.php.

attributeNames (  ) 

Returns the member and relation names defined by the extending class's getMetadata() method.

Definition at line 1544 of file RedBeanModel.php.

isAttribute ( attributeName  ) 

Returns true if the named attribute is one of the member or relation names defined by the extending class's getMetadata() method.

Definition at line 1554 of file RedBeanModel.php.

isAttributeReadOnly ( attributeName  ) 

Returns true if the attribute is read-only.

Definition at line 1562 of file RedBeanModel.php.

isAttributeFormattedAsProbability ( attributeName  ) 

Returns true if the attribute is formattted as probability

Definition at line 1581 of file RedBeanModel.php.

isAllowedToSetReadOnlyAttribute ( attributeName  ) 
Parameters:
boolean $attributeName
Returns:
true/false whether the attributeName specified, it is allowed to be set externally even though it is a read-only attribute.

Reimplemented in AccountContactAffiliation, User, and Item.

Definition at line 1602 of file RedBeanModel.php.

rules (  ) 

See the yii documentation. Not used by RedBeanModel.

See also:
getMetadata()

Definition at line 1611 of file RedBeanModel.php.

behaviors (  ) 

See the yii documentation.

Definition at line 1619 of file RedBeanModel.php.

attributeLabels (  ) 

See the yii documentation. RedBeanModels utilize translatedAttributeLabels to store any attribute information.

Definition at line 1628 of file RedBeanModel.php.

abbreviatedAttributeLabels (  ) 

Public method

Definition at line 1636 of file RedBeanModel.php.

validate ( array $  attributeNames = null,
ignoreRequiredValidator = false 
)

Performs validation using the validators specified in the 'rules' meta data by the extending class's getMetadata() method. Validation occurs on a new model or a modified model, but only proceeds to modified related models. Once validated a model will pass validation without revalidating until it is modified. Related models are only validated if the model validates. Cyclic relationships are prevented from causing problems by the validation either stopping at a non-validating model and only proceeding to non-validated models.

See also:
RedBeanModel
Parameters:
$ignoreRequiredValidator - set to true in scenarios where you want to validate everything but the the required validator. An example is a search form.

Definition at line 1655 of file RedBeanModel.php.

beforeValidate (  )  [protected]

See the yii documentation.

Reimplemented in Campaign, Product, ProductTemplate, User, CurrencyValue, and Role.

Definition at line 1727 of file RedBeanModel.php.

afterValidate (  )  [protected]

See the yii documentation.

Reimplemented in EmailAccount.

Definition at line 1737 of file RedBeanModel.php.

onBeforeValidate ( CModelEvent $  event  ) 

See the yii documentation.

Definition at line 1745 of file RedBeanModel.php.

onAfterValidate ( event  ) 

See the yii documentation.

Definition at line 1753 of file RedBeanModel.php.

getValidatorList (  ) 

See the yii documentation.

Definition at line 1761 of file RedBeanModel.php.

getValidators ( attributeName = null  ) 

See the yii documentation.

Definition at line 1769 of file RedBeanModel.php.

forgetValidators (  ) 

Method to call to clear out validators from memory. Can help with performance. Used by async export for example.

Definition at line 1791 of file RedBeanModel.php.

createValidators (  ) 

See the yii documentation.

Definition at line 1802 of file RedBeanModel.php.

isUniqueAttributeValue ( attributeName,
value 
)

Returns true if the attribute value does not already exist in the database. This is used in the unique validator, but on saving RedBean can still throw because the unique constraint on the column has been violated because it was concurrently updated between the Yii validator being called and the save actually occuring.

Reimplemented in Currency.

Definition at line 1814 of file RedBeanModel.php.

save ( runValidation = true,
array $  attributeNames = null 
)

Saves the model to the database. Models are only saved if they have been modified and related models are saved before this model. If a related model is modified and needs saving the deems the model to be modified and need saving, which ensures that keys are updated. Cyclic relationships are prevented from causing problems by the save only proceeding to non-saved models.

Reimplemented in CustomFieldData, User, Currency, Item, NamedSecurableItem, OwnedCustomField, OwnedModel, and OwnedMultipleValuesCustomField.

Definition at line 1848 of file RedBeanModel.php.

beforeSave (  )  [protected]

This method is invoked before saving a record (after validation, if any). The default implementation raises the onBeforeSave event. You may override this method to do any preparation work for record saving. Use isNewModel to determine whether the saving is for inserting or updating record. Make sure you call the parent implementation so that the event is raised properly.

Returns:
boolean whether the saving should be executed. Defaults to true.

Reimplemented in AutoresponderItem, Conversation, EmailMessageActivity, MarketingListMember, Meeting, Mission, Note, Opportunity, SocialItem, Task, User, Address, FileModel, Group, Item, and Role.

Definition at line 2013 of file RedBeanModel.php.

onBeforeSave ( event  ) 

This event is raised before the record is saved. By setting CModelEvent::isValid to be false, the normal save() process will be stopped.

Parameters:
CModelEvent $event the event parameter
Since:
1.0.2

Definition at line 2039 of file RedBeanModel.php.

onAfterSave ( event  ) 

This event is raised after the record is saved.

Parameters:
CEvent $event the event parameter
Since:
1.0.2

Definition at line 2049 of file RedBeanModel.php.

onRedBeanOneToManyRelatedModelsChange ( event  ) 

This event is raised on a RedBeanOneToManyRelatedModels change

Parameters:
$event 

Definition at line 2058 of file RedBeanModel.php.

onBeforeDelete ( event  ) 

This event is raised before the record is deleted. By setting CModelEvent::isValid to be false, the normal delete() process will be stopped.

Parameters:
CModelEvent $event the event parameter
Since:
1.0.2

Definition at line 2069 of file RedBeanModel.php.

onAfterDelete ( event  ) 

This event is raised after the record is deleted.

Parameters:
CEvent $event the event parameter
Since:
1.0.2

Definition at line 2079 of file RedBeanModel.php.

isModified (  ) 

Returns true if the model has been modified since it was saved or constructed.

Definition at line 2101 of file RedBeanModel.php.

delete (  ) 

Deletes the model from the database.

Reimplemented in Item, and SecurableItem.

Definition at line 2147 of file RedBeanModel.php.

beforeDelete (  )  [protected]

This method is invoked before deleting a record. The default implementation raises the onBeforeDelete event. You may override this method to do any preparation work for record deletion. Make sure you call the parent implementation so that the event is raised properly.

Returns:
boolean whether the record should be deleted. Defaults to true.

Reimplemented in Portlet, EmailFolder, Import, ProductCatalog, ProductCategory, ProductTemplate, Project, User, Group, OwnedSecurableItem, and Role.

Definition at line 2181 of file RedBeanModel.php.

afterDelete (  )  [protected]

This method is invoked after deleting a record. The default implementation raises the onAfterDelete event. You may override this method to do postprocessing after the record is deleted. Make sure you call the parent implementation so that the event is raised properly.

Reimplemented in Contact, Group, and Role.

Definition at line 2201 of file RedBeanModel.php.

static isTypeDeletable (  )  [static]

To be overriden on intermediate derived classes to return false so that deletes are not done on intermediate classes because the object relational mapping will not clean up properly. For example if User is a Person, and Person is a RedBeanModel delete should be called only on User, not on Person. So User must override isDeletable to return false.

Reimplemented in KanbanItem, FileContent, A, ExtendsNoBean, M, MixedRelationsModel, P, PP, PPP, PPPP, TestModelToMessagesModel, TestPolyOneToManyOneSide, TestPolyOneToManyOneSideTwo, TestPolyOneToManyPolySide, TestPolyOneToManyPolySideOwned, AccountAccountAffiliation, AccountContactAffiliation, Account, Activity, ApiTestModelItem, ApiTestModelItem2, ApiTestModelItem3, ApiTestModelItem4, Autoresponder, AutoresponderItem, SavedCalendar, Campaign, CampaignItem, Comment, Contact, ContactWebForm, ContactWebFormEntry, Conversation, ConversationParticipant, EmailAccount, EmailBox, EmailFolder, EmailMessage, EmailMessageActivity, EmailMessageContent, EmailMessageRecipient, EmailMessageSender, EmailMessageSendError, EmailMessageUrl, EmailSignature, EmailTemplate, EmailTemplateModelTestItem, ExportItem, ExportTestModelItem, ExportTestModelItem2, ExportTestModelItem3, ExportTestModelItem4, ExportTestModelItem5, GameReward, GameBadge, GameCoin, GameCollection, GameLevel, GameNotification, GamePoint, GameScore, Dashboard, Import, ImportDedupeModelTestItem, ImportModelTestItem, ImportModelTestItem2, ImportModelTestItem3, ImportModelTestItem4, ImportModelTestItem5, JobInProcess, JobLog, StuckJob, MarketingList, MarketingListMember, PersonWhoHaveNotReadLatest, Meeting, Mission, Note, Notification, NotificationMessage, Opportunity, Product, ProductCatalog, ProductCategory, ProductTemplate, SellPriceFormula, Project, SavedReport, ReportModelTestItem, ReportModelTestItem10, ReportModelTestItem11, ReportModelTestItem2, ReportModelTestItem3, ReportModelTestItem4, ReportModelTestItem5, ReportModelTestItem6, ReportModelTestItem7, ReportModelTestItem8, ReportModelTestItem9, SocialItem, Task, User, ByTimeWorkflowInQueue, SavedWorkflow, WorkflowMessageInQueue, WorkflowModelTestItem, WorkflowModelTestItem2, WorkflowModelTestItem3, WorkflowModelTestItem4, WorkflowModelTestItem5, WorkflowModelTestItem6, WorkflowModelTestItem7, WorkflowModelTestItem8, WorkflowModelTestItem9, Address, BaseStarredModel, Currency, CurrencyValue, Email, FileModel, Group, Item, NamedSecurableItem, OwnedModel, OwnedSecurableItem, Permission, Permitable, Person, Policy, Right, Role, SavedSearch, SecurableItem, ModelToArrayAdapterTestItem, ModelToArrayAdapterTestItem2, ModelToArrayAdapterTestItem3, ModelToArrayAdapterTestItem4, ModelWithAttachmentTestItem, OwnedSecurableTestItem, and TestOwnedLinkSpecificModel.

Definition at line 2335 of file RedBeanModel.php.

isDeletable (  ) 

To be overridden by derived classes to prevent deletion.

Reimplemented in EmailBox, User, and Group.

Definition at line 2344 of file RedBeanModel.php.

static forgetAll (  )  [static]

Forgets about all of the objects so that when they are retrieved again they will be recreated from the database. For use in testing.

Definition at line 2353 of file RedBeanModel.php.

forget (  ) 

Forgets about the object so that if it is retrieved again it will be recreated from the database. For use in testing.

Definition at line 2364 of file RedBeanModel.php.

isAttributeRequired ( attributeName  ) 

See the yii documentation.

Definition at line 2374 of file RedBeanModel.php.

isAttributeSafe ( attributeName  ) 

See the yii documentation.

Definition at line 2390 of file RedBeanModel.php.

static getLabel ( language = null  )  [static, protected]

Returns the display name for the model class. Defaults to the module label. Override if the model label is not the module label. Make sure to return a translated label. Also provides fall back in moduleClassName is null.

Parameters:
null | string $language
Returns:
dynamic label name based on module.

Reimplemented in A, AccountAccountAffiliation, AccountContactAffiliation, AccountStarred, Autoresponder, AutoresponderItem, AutoresponderItemActivity, Campaign, CampaignItem, CampaignItemActivity, Contact, ContactStarred, ContactWebForm, ContactWebFormEntry, ConversationParticipant, ConversationStarred, EmailAccount, EmailBox, EmailFolder, EmailMessage, EmailMessageActivity, EmailMessageContent, EmailMessageRecipient, EmailMessageSender, EmailMessageSendError, EmailMessageUrl, EmailSignature, EmailTemplate, GameRewardTransaction, GameBadge, GameCoin, GameCollection, GameLevel, GameNotification, GamePoint, GamePointTransaction, GameScore, Dashboard, ImportDedupeModelTestItem, ImportModelTestItem2, ImportModelTestItem3, ImportModelTestItem4, ImportModelTestItem5, JobInProcess, JobLog, StuckJob, MarketingList, MarketingListMember, NotificationMessage, OpportunityStarred, ProductCatalog, ProductCategory, ProductTemplate, ReportModelTestItem10, ReportModelTestItem11, ReportModelTestItem2, ReportModelTestItem3, ReportModelTestItem4, ReportModelTestItem5, ReportModelTestItem6, ReportModelTestItem7, ReportModelTestItem8, ReportModelTestItem9, ByTimeWorkflowInQueue, WorkflowMessageInQueue, WorkflowModelTestItem2, WorkflowModelTestItem3, WorkflowModelTestItem4, WorkflowModelTestItem5, WorkflowModelTestItem6, WorkflowModelTestItem7, WorkflowModelTestItem8, WorkflowModelTestItem9, Address, BaseStarredModel, Email, Person, SavedSearch, and TestOwnedLinkSpecificModel.

Definition at line 2424 of file RedBeanModel.php.

static getPluralLabel ( language = null  )  [static, protected]

Returns the display name for plural of the model class. Defaults to the module label. Override if the model label is not the module label. Make sure to return a translated label

Parameters:
null | string $language
Returns:
dynamic label name based on module.

Reimplemented in A, AccountAccountAffiliation, AccountContactAffiliation, AccountStarred, Autoresponder, AutoresponderItem, AutoresponderItemActivity, Campaign, CampaignItem, CampaignItemActivity, Contact, ContactStarred, ContactWebForm, ContactWebFormEntry, ConversationParticipant, ConversationStarred, EmailAccount, EmailBox, EmailFolder, EmailMessage, EmailMessageActivity, EmailMessageContent, EmailMessageRecipient, EmailMessageSender, EmailMessageSendError, EmailMessageUrl, EmailSignature, EmailTemplate, GameRewardTransaction, GameBadge, GameCoin, GameCollection, GameLevel, GameNotification, GamePoint, GamePointTransaction, GameScore, Dashboard, ImportDedupeModelTestItem, ImportModelTestItem2, ImportModelTestItem3, ImportModelTestItem4, ImportModelTestItem5, JobInProcess, JobLog, StuckJob, MarketingList, MarketingListMember, NotificationMessage, OpportunityStarred, ProductCatalog, ProductCategory, ProductTemplate, ReportModelTestItem10, ReportModelTestItem11, ReportModelTestItem2, ReportModelTestItem3, ReportModelTestItem4, ReportModelTestItem5, ReportModelTestItem6, ReportModelTestItem7, ReportModelTestItem8, ReportModelTestItem9, ByTimeWorkflowInQueue, WorkflowMessageInQueue, WorkflowModelTestItem2, WorkflowModelTestItem3, WorkflowModelTestItem4, WorkflowModelTestItem5, WorkflowModelTestItem6, WorkflowModelTestItem7, WorkflowModelTestItem8, WorkflowModelTestItem9, Address, BaseStarredModel, Email, Person, SavedSearch, and TestOwnedLinkSpecificModel.

Definition at line 2439 of file RedBeanModel.php.

getAttributeLabel ( attributeName  ) 

See the yii documentation.

Definition at line 2451 of file RedBeanModel.php.

static getAnAttributeLabel ( attributeName  )  [static]

Static implementation of

See also:
getAttributeLabel

Definition at line 2459 of file RedBeanModel.php.

static getAttributeLabelByLanguage ( attributeName,
language 
) [static, protected]

Given an attributeName and a language, retrieve the translated attribute label. Attempts to find a customized label in the metadata first, before falling back on the standard attribute label for the specified attribute.

Returns:
string - translated attribute label

Definition at line 2469 of file RedBeanModel.php.

static getTranslatedCustomAttributeLabelByLanguage ( attributeName,
languageCode 
) [static, protected]

Given an attributeName, attempt to find in the metadata a custom attribute label for the given language.

Returns:
string - translated attribute label, if not found return null.

Definition at line 2495 of file RedBeanModel.php.

getAttributeLabelsForAllActiveLanguagesByAttributeName ( attributeName  ) 

Given an attributeName, return an array of all attribute labels for each active language.

Returns:
array - attribute labels by language for the given attributeName.

Definition at line 2516 of file RedBeanModel.php.

hasErrors ( attributeNameOrNames = null  ) 

See the yii documentation. The yii hasErrors() takes an optional attribute name. RedBeanModel's hasErrors() takes an optional attribute name or array of attribute names. See getErrors() for an explanation of this difference.

Definition at line 2533 of file RedBeanModel.php.

getErrors ( attributeNameOrNames = null  ) 

See the yii documentation. The yii getErrors() takes an optional attribute name. RedBeanModel's getErrors() takes an optional attribute name or array of attribute names.

Parameters:
@attributeNameOrNames Either null, return all errors on the model and its related models, an attribute name on the model, return errors on that attribute, or an array of relation and attribute names, return errors on a related model's attribute.

Reimplemented in Campaign.

Definition at line 2632 of file RedBeanModel.php.

getError ( attributeName  ) 

See the yii documentation.

Definition at line 2725 of file RedBeanModel.php.

addError ( attributeName,
errorMessage 
)

See the yii documentation.

Definition at line 2734 of file RedBeanModel.php.

addErrors ( array $  errors  ) 

See the yii documentation.

Definition at line 2747 of file RedBeanModel.php.

clearErrors ( attributeName = null  ) 

See the yii documentation.

Definition at line 2772 of file RedBeanModel.php.

generateAttributeLabel ( attributeName  ) 

See the yii documentation.

Definition at line 2788 of file RedBeanModel.php.

getAttributes ( array $  attributeNames = null  ) 

See the yii documentation.

Definition at line 2797 of file RedBeanModel.php.

setAttributes ( array $  values,
safeOnly = true 
)

See the yii documentation.

Definition at line 2826 of file RedBeanModel.php.

unsetAttributes ( attributeNames = null  ) 

See the yii documentation.

Definition at line 2888 of file RedBeanModel.php.

onUnsafeAttribute ( name,
value 
)

See the yii documentation.

Definition at line 2903 of file RedBeanModel.php.

getScenario (  ) 

See the yii documentation.

Definition at line 2915 of file RedBeanModel.php.

setScenario ( scenarioName  ) 

See the yii documentation.

Definition at line 2923 of file RedBeanModel.php.

getSafeAttributeNames (  ) 

See the yii documentation.

Definition at line 2932 of file RedBeanModel.php.

getIterator (  ) 

See the yii documentation.

Definition at line 2963 of file RedBeanModel.php.

offsetExists ( offset  ) 

See the yii documentation.

Definition at line 2971 of file RedBeanModel.php.

offsetGet ( offset  ) 

See the yii documentation.

Definition at line 2979 of file RedBeanModel.php.

offsetSet ( offset,
item 
)

See the yii documentation.

Definition at line 2987 of file RedBeanModel.php.

offsetUnset ( offset  ) 

See the yii documentation.

Definition at line 2995 of file RedBeanModel.php.

static makeModel ( RedBean_OODBBean $  bean,
modelClassName = null 
) [static]

Creates an instance of the extending model wrapping the given bean. For use only by models. Beans are never used by the application directly.

Parameters:
$bean A RedBean bean.
$modelClassName Pass only when getting it at runtime gets the wrong name.
Returns:
An instance of the type of the extending model.

Definition at line 3010 of file RedBeanModel.php.

static makeModels ( array $  beans,
modelClassName = null 
) [static]

Creates an array of instances of the named model type wrapping the given beans. For use only by models. Beans are never used by the application directly.

Parameters:
$beans An array of RedBean beans.
$modelClassName Pass only when getting it at runtime gets the wrong name.
Returns:
An array of instances of the type of the extending model.

Definition at line 3041 of file RedBeanModel.php.

stringifyOneToManyRelatedModelsValues ( values  ) 

Given an array of data, create stringified content.

Parameters:
array $values

Reimplemented in MultipleValuesCustomField.

Definition at line 3071 of file RedBeanModel.php.

static resolveModelClassNameForClassesWithoutBeans ( &$  modelClassName  )  [static, protected]

Resolve and get model class name used for table retrieval factoring in when a class does not have a bean and must use a parent class

Parameters:
string $modelClassName

Definition at line 3082 of file RedBeanModel.php.

static getSortAttributesByAttribute ( attribute  )  [static]

Returns a list of attributes to be added when sorting by the attribute

Parameters:
string $attribute
Returns:
array

Reimplemented in Q, User, and Person.

Definition at line 3108 of file RedBeanModel.php.

setIsCopied (  ) 

Utilized by copy mechanism, helps elements, views, understand the model better before the new model is saved.

Definition at line 3116 of file RedBeanModel.php.

isCopied (  ) 
Returns:
bool

Definition at line 3124 of file RedBeanModel.php.

static isCacheable (  )  [static]
Returns:
bool

Reimplemented in FileContent.

Definition at line 3132 of file RedBeanModel.php.

addValidator ( attribute,
validator,
params = array() 
)

Wrapper for CValidator::createValidator

Parameters:
$attribute 
$validator 
array $params

Definition at line 3148 of file RedBeanModel.php.

static relationLinksToPrecedingRelation ( modelClassName,
relation,
precedingModelClassName = null,
precedingRelation = null 
) [static]
Parameters:
string $modelClassName
string $relation
null|string $precedingModelClassName
null|string $precedingRelation
Returns:
bool

Definition at line 3180 of file RedBeanModel.php.


Field Documentation

$lastClassInBeanHeirarchy = 'RedBeanModel' [static, protected]
See also:
RedBeanModel::$lastClassInBeanHeirarchy

Reimplemented from BeanModel.

Reimplemented in CustomFieldsModel, and OwnedModel.

Definition at line 96 of file RedBeanModel.php.


The documentation for this class was generated from the following file:
 All Data Structures Functions Variables
Generated on Sun Aug 20 07:10:29 2017