Comments: on this page. Click to read or post your own.

Class DataObject

Description

Implements interfaces:

A single database record & abstract class for the data-access-model.

Object-level access control by Permission. Permission codes are arbitrary strings which can be selected on a group-by-group basis.

  1.  class Article extends DataObject implements PermissionProvider {
  2.      static $api_access true;
  3.  
  4.      public function canView($member false{
  5.          return Permission::check('ARTICLE_VIEW');
  6.      }
  7.      public function canEdit($member false{
  8.          return Permission::check('ARTICLE_EDIT');
  9.      }
  10.      public function canDelete({
  11.          return Permission::check('ARTICLE_DELETE');
  12.      }
  13.      public function canCreate({
  14.          return Permission::check('ARTICLE_CREATE');
  15.      }
  16.      public function providePermissions({
  17.          return array(
  18.              'ARTICLE_VIEW' => 'Read an article object',
  19.              'ARTICLE_EDIT' => 'Edit an article object',
  20.              'ARTICLE_DELETE' => 'Delete an article object',
  21.              'ARTICLE_CREATE' => 'Create an article object',
  22.          );
  23.      }
  24.  }

Object-level access control by Group membership:

  1.  class Article extends DataObject {
  2.      static $api_access true;
  3.  
  4.      public function canView($member false{
  5.          if(!$member$member Member::currentUser();
  6.         return $member->inGroup('Subscribers');
  7.      }
  8.      public function canEdit($member false{
  9.          if(!$member$member Member::currentUser();
  10.         return $member->inGroup('Editors');
  11.      }
  12.  
  13.      // ...
  14.  }

Located in /sapphire/core/model/DataObject.php (line 56)

Object
   |
   --ViewableData
      |
      --DataObject
Direct descendents
Class Description
File This class handles the representation of a File within Sapphire Note: The files are stored in the "/assets/" directory, but sapphire looks at the db object to gather information about a file such as URL
SQLQueryTest_DO A single database record & abstract class for the data-access-model.
CsvBulkLoaderTest_Team A single database record & abstract class for the data-access-model.
CsvBulkLoaderTest_Player A single database record & abstract class for the data-access-model.
CsvBulkLoaderTest_PlayerContract A single database record & abstract class for the data-access-model.
DataObjectDecoratorTest_Member A single database record & abstract class for the data-access-model.
DataObjectDecoratorTest_RelatedObject A single database record & abstract class for the data-access-model.
DataObjectTest_Team A single database record & abstract class for the data-access-model.
DataObjectTest_FunnyFieldNames A single database record & abstract class for the data-access-model.
DataObjectTest_ValidatedObject A single database record & abstract class for the data-access-model.
FormTest_Player A single database record & abstract class for the data-access-model.
FormTest_Team A single database record & abstract class for the data-access-model.
CheckboxSetFieldTest_Article A single database record & abstract class for the data-access-model.
CheckboxSetFieldTest_Tag A single database record & abstract class for the data-access-model.
FormScaffolderTest_Article A single database record & abstract class for the data-access-model.
FormScaffolderTest_Tag A single database record & abstract class for the data-access-model.
TableListFieldTest_Obj A single database record & abstract class for the data-access-model.
TableListFieldTest_CsvExport A single database record & abstract class for the data-access-model.
RestfulServerTest_Comment Everybody can view comments, logged in members in the "users" group can create comments, but only "editors" can edit or delete them.
RestfulServerTest_SecretThing A single database record & abstract class for the data-access-model.
RestfulServerTest_Page A single database record & abstract class for the data-access-model.
RestfulServerTest_Author A single database record & abstract class for the data-access-model.
RestfulServerTest_AuthorRating A single database record & abstract class for the data-access-model.
SoapModelAccessTest_Comment Everybody can view comments, logged in members in the "users" group can create comments, but only "editors" can edit or delete them.
SoapModelAccessTest_Page A single database record & abstract class for the data-access-model.
SearchContextTest_Person A single database record & abstract class for the data-access-model.
SearchContextTest_Book A single database record & abstract class for the data-access-model.
SearchContextTest_Company A single database record & abstract class for the data-access-model.
SearchContextTest_Project A single database record & abstract class for the data-access-model.
SearchContextTest_Deadline A single database record & abstract class for the data-access-model.
SearchContextTest_Action A single database record & abstract class for the data-access-model.
SearchContextTest_AllFilterTypes A single database record & abstract class for the data-access-model.
Permission Represents a permission assigned to a group.
LoginAttempt Record all login attempts through the LoginForm object.
Member The member class which represents the users of the system
Group A security group.
MemberPassword Keep track of users' previous passwords, so that we can check that new passwords aren't changed back to old ones.
SiteTree Basic data-object representing all pages within the site tree.
QueuedEmail Stores a queued email to be sent at the given time
Email_BounceRecord Database record for recording a bounced email
Email_BlackList This class is responsible for ensuring that members who are on it receive NO email communication at all. any correspondance is caught before the email is sent.
Widget Base class for widgets.
WidgetArea Represents a set of widgets shown on a page.
PageComment A single database record & abstract class for the data-access-model.
NewsletterType A single database record & abstract class for the data-access-model.
Newsletter A single database record & abstract class for the data-access-model.
Newsletter_Recipient A single database record & abstract class for the data-access-model.
ProductVariation A single database record & abstract class for the data-access-model.
Order The order class is a databound object for handling Orders within SilverStripe.
OrderStatusLog Class which implement a log object to keep a history of the status changes of an order.
OrderAttribute OrderAttribute is an attribute which makes up an Order.
Payment Payment class.
Variable Summary
static array $ancestry
static mixed $api_access
static array $belongs_many_many
static array $cache_get_one
static array $casting
static array $db
static array $defaults
static array $default_records
static string $default_sort
static mixed $field_labels
static array $has_many
static array $has_one
static array $indexes
static array $many_many
static array $many_many_extraFields
static string $plural_name
static mixed $searchable_fields
static string $singular_name
static mixed $summary_fields
boolean $brokenOnDelete
boolean $brokenOnWrite
array $changed
array $components
boolean $destroyed
array $original
array $record
Method Summary
static void context_obj ()
static void delete_by_id (string $className, int $id)
static void disable_subclass_access ()
static void enable_subclass_access ()
static mixed get (string $callerClass, [string $filter = ""], [string|array $sort = ""], [string $join = ""], [string|array $limit = ""], [string $containerClass = "DataObjectSet"])
static DataObject get_by_id (string $callerClass, int $id)
static SiteTree get_by_url (string $urlSegment)
static DataObject get_one (string $callerClass, [string $filter = ""], [boolean $cache = true], [string $orderby = ""])
static void set_context_obj ( $obj)
DataObject __construct ([array|null $record = null], [boolean $isSingleton = false])
void baseTable ()
mixed buildDataObjectSet (Query|array $records, [string $containerClass = "DataObjectSet"], [ $query = null], [ $baseClass = null])
SQLQuery buildSQL ([string $filter = ""], [string|array $sort = ""], [string|array $limit = ""], [string $join = ""], [ $restrictClasses = true], [string $having = ""], boolean $restictClasses)
boolean can (string $perm, [Member $member = null])
boolean canCreate ([Member $member = null])
boolean canDelete ([Member $member = null])
boolean canEdit ([Member $member = null])
boolean canView ([Member $member = null])
void castedUpdate (array $data)
DataObject createComponent (string $componentName)
array databaseFields ()
void databaseIndexes ()
array db ([ $component = null])
DBField dbObject (string $fieldName)
string debug ()
void defineMethods ()
void delete ()
void destroy ()
DataObject duplicate ([$doWrite $doWrite = true])
boolean exists ()
SQLQuery extendedSQL ([string $filter = ""], [string|array $sort = ""], [string|array $limit = ""], [string $join = ""], [string $having = ""])
string fieldExists (string $field)
string fieldLabel (string $name)
array fieldLabels ()
boolean filledOut ( $args, array|string $args,...)
void flushCache ()
void forceChange ()
array getAllFields ()
array getChangedFields ([boolean $databaseFieldsOnly = false], [int $changeLevel = 1])
array getClassAncestry ()
FieldSet getCMSFields ([array $params = null])
DataObject getComponent (string $componentName)
string getComponentJoinField (string $componentName)
ComponentSet getComponents (string $componentName, [string $filter = ""], [string|array $sort = ""], [string $join = ""], [string|array $limit = ""])
SQLQuery getComponentsQuery (string $componentName, [string $filter = ""], [string|array $sort = ""], [string $join = ""], [string|array $limit = ""])
mixed getField (string $field)
FieldSet getFrontEndFields ([array $params = null])
ComponentSet getManyManyComponents (string $componentName, [ $filter = ""], [ $sort = ""], [ $join = ""], [ $limit = ""])
SQLQuery getManyManyComponentsQuery (string $componentName, [string $filter = ""], [string|array $sort = ""], [string $join = ""], [string|array $limit = ""])
void getManyManyFilter ( $componentName,  $baseTable)
string getManyManyJoin (string $componentName, string $baseTable)
String getReverseAssociation ( $className)
string getTitle ()
boolean hasDatabaseField (string $field)
boolean hasField (string $field)
string hasOwnTableDatabaseField (string $field)
string|array has_many ([string $component = null])
string|array has_one ([string $component = null])
string i18n_plural_name ()
string i18n_singular_name ()
mixed instance_get ([string $filter = ""], [string $sort = ""], [string $join = ""], [string $limit = ""], [string $containerClass = "DataObjectSet"])
DataObject instance_get_one (string $filter, [string $orderby = null])
void isEmpty ()
boolean isInDB ()
string listOfFields ()
array many_many ([string $component = null])
Boolean merge ($obj $rightObj, [$priority $priority = 'right'], [$includeRelations $includeRelations = true], [$overwriteWithEmpty $overwriteWithEmpty = false])
DataObject newClassInstance (string $newClassName)
void onAfterWrite ()
void onBeforeDelete ()
void onBeforeWrite ()
string plural_name ()
DBField relObject ($fieldPath $fieldPath)
void requireTable ()
FieldSet scaffoldFormFields ([array $_params = null])
FieldSet scaffoldSearchFields ([array $_params = null])
array searchableFields ()
void setCastedField (string $fieldName,  $val, mixed $value)
void setClassName (string $className)
void setComponent (string $componentName, DataObject|ComponentSet $componentValue)
void setField (string $fieldName, mixed $val)
string singular_name ()
array summaryFields ()
array toMap ()
void update (array $data)
A validate ()
int write ([boolean $showDebug = false], [boolean $forceInsert = false], [boolean $forceWrite = false], [boolean $writeComponents = false])
void writeComponents ([$recursive $recursive = false])
Variables
static array $ancestry (line 883)

A cache used by getClassAncestry()

  • access: protected
static array $belongs_many_many = null (line 2764)

The inverse side of a many-many relationship.

This is a map from component name to data type.

  • access: public

Redefined in descendants as:
static array $cache_get_one (line 2160)

A cache used by get_one.

  • access: protected
static array $casting = array(
"LastEdited" => "SSDatetime",
"Created" => "SSDatetime",
"Title" => 'Text',
)
(line 2680)

Use a casting object for a field. This is a map from field name to class name of the casting object.

  • access: public

Redefinition of:
ViewableData::$casting
Object-casting information for class methods

Redefined in descendants as:
static array $db = null (line 2673)

Database field definitions.

This is a map from field names to field type. The field type should be a class that extends .

  • access: public

Redefined in descendants as:
static array $defaults = null (line 2704)

Inserts standard column-values when a DataObject is instanciated. Does not insert default records {@see $default_records}.

This is a map from classname to default value.

  • If you would like to change a default value in a sub-class, just specify it.
  • If you would like to disable the default value given by a parent class, set the default value to 0,'',or false in your subclass. Setting it to null won't work.

  • access: public

Redefined in descendants as:
static array $default_records = null (line 2720)

Multidimensional array which inserts default data into the database on a db/build-call as long as the database-table is empty. Please use this only for simple constructs, not for SiteTree-Objects etc. which need special behaviour such as publishing and ParentNodes.

Example: array( array('Title' => "DefaultPage1", 'PageTitle' => 'page1'), array('Title' => "DefaultPage2") ).

  • access: public
static string $default_sort = null (line 2771)

The default sort expression. This will be inserted in the ORDER BY clause of a SQL query if no other sort expression is provided.

  • access: public

Redefined in descendants as:
static mixed $field_labels = null (line 2812)

User defined labels for searchable_fields, used to override default display in the search form.

static array $has_many = null (line 2743)

one-to-many relationship definitions.

This is a map from component name to data type.

Caution: Because this doesn't define any data structure itself, you should specify a $has_one relationship on the other end of the relationship. Also, if the $has_one relationship on the other end has multiple definitions of this class (e.g. two different relationships to the Member object), then you need to write a custom accessor (e.g. overload the function from the key of this array), because sapphire won't know which to access.

  • access: public

Redefined in descendants as:
static array $indexes = null (line 2691)

If a field is in this array, then create a database index on that field. This is a map from fieldname to index type.

  • access: public

Redefined in descendants as:
static array $many_many = null (line 2750)

many-many relationship definitions.

This is a map from component name to data type.

  • access: public

Redefined in descendants as:
static array $many_many_extraFields = null (line 2757)

Extra fields to include on the connecting many-many table.

This is a map from field name to field type.

  • access: public

Redefined in descendants as:
static string $plural_name = null (line 100)

Human-readable pluaral name


Redefined in descendants as:
static mixed $searchable_fields = null (line 2806)

Default list of fields that can be scaffolded by the ModelAdmin search interface.

Overriding the default filter, with a custom defined filter:

  1.      static $searchable_fields array(
  2.         "Name" => "PartialMatchFilter"
  3.   );

Overriding the default form fields, with a custom defined field. The 'filter' parameter will be generated from DBField::$default_search_filter_class. The 'title' parameter will be generated from DataObject->fieldLabels().

  1.      static $searchable_fields array(
  2.         "Name" => array(
  3.              "field" => "TextField"
  4.          )
  5.   );

Overriding the default form field, filter and title:

  1.      static $searchable_fields array(
  2.         "Organisation.ZipCode" => array(
  3.              "field" => "TextField",
  4.              "filter" => "PartialMatchFilter",
  5.              "title" => 'Organisation ZIP'
  6.          )
  7.   );

  • access: public

Redefined in descendants as:
static string $singular_name = null (line 94)

Human-readable singular name.


Redefined in descendants as:
static mixed $summary_fields = null (line 2818)

Provides a default list of fields to be used by a 'summary' view of this object.

  • access: public

Redefined in descendants as:
boolean $brokenOnDelete = false (line 604)

Used by onBeforeDelete() to ensure child classes call parent::onBeforeDelete()

  • access: protected
boolean $brokenOnWrite = false (line 589)

Used by onBeforeWrite() to ensure child classes call parent::onBeforeWrite()

  • access: protected
array $changed (line 68)

An array indexed by fieldname, true if the field has been changed.

  • access: protected
array $componentCache (line 946)

A cache used by component getting classes

  • access: protected
array $components (line 82)

The one-to-one, one-to-many and many-to-one components indexed by component name.

  • access: protected
boolean $destroyed = false (line 88)

True if this DataObject has been destroyed.

  • access: public
array $original (line 75)

The database record (in the same format as $record), before any changes.

  • access: protected
array $record (line 62)

Data stored in this objects database record. An array indexed by fieldname.

  • access: protected

Inherited Variables

Inherited from ViewableData

ViewableData::$castingHelperPair_cache
ViewableData::$customisedObj
ViewableData::$failover
ViewableData::$iteratorPos
ViewableData::$iteratorTotalItems
ViewableData::$namedAs
ViewableData::$parent
ViewableData::$_natural_cache
ViewableData::$_object_cache
ViewableData::$_xml_cache

Inherited from Object

Object::$builtInMethods
Object::$class
Object::$classConstructed
Object::$extensions
Object::$extension_instances
Object::$extraMethods
Object::$extraStatics
Object::$statics
Object::$static_cached
Methods
static method context_obj (line 2641)

Retrieve the current context object.

  • access: public
static void context_obj ()
static method delete_by_id (line 870)

Delete the record with the given ID.

  • access: public
static void delete_by_id (string $className, int $id)
  • string $className: The class name of the record to be deleted
  • int $id: ID of record to be deleted
static method disable_subclass_access (line 2658)

Temporarily disable subclass access in data object qeur

static void disable_subclass_access ()
static method enable_subclass_access (line 2661)
static void enable_subclass_access ()
static method get (line 2105)

Return all objects matching the filter sub-classes are automatically selected and included

  • return: The objects matching the filter, in the class specified by $containerClass
  • access: public
static mixed get (string $callerClass, [string $filter = ""], [string|array $sort = ""], [string $join = ""], [string|array $limit = ""], [string $containerClass = "DataObjectSet"])
  • string $callerClass: The class of objects to be returned
  • string $filter: A filter to be inserted into the WHERE clause.
  • string|array $sort: A sort expression to be inserted into the ORDER BY clause. If omitted, self::$default_sort will be used.
  • string $join: A single join clause. This can be used for filtering, only 1 instance of each DataObject will be returned.
  • string|array $limit: A limit expression to be inserted into the LIMIT clause.
  • string $containerClass: The container class to return the results in.
static method get_by_id (line 2265)

Return the given element, searching by ID

  • return: The element
  • access: public
static DataObject get_by_id (string $callerClass, int $id)
  • string $callerClass: The class of the object to be returned
  • int $id: The id of the element
static method get_by_url (line 2253)

Return the SiteTree object with the given URL segment.

  • return: The object with the given URL segment
  • access: public
static SiteTree get_by_url (string $urlSegment)
  • string $urlSegment: The URL segment, eg 'home'
static method get_one (line 2173)

Return the first item matching the given query.

All calls to get_one() are cached.

  • return: The first item matching the query
  • access: public
static DataObject get_one (string $callerClass, [string $filter = ""], [boolean $cache = true], [string $orderby = ""])
  • string $callerClass: The class of objects to be returned
  • string $filter: A filter to be inserted into the WHERE clause
  • boolean $cache: Use caching
  • string $orderby: A sort expression to be inserted into the ORDER BY clause.
static method set_context_obj (line 2633)

Sets a 'context object' that can be used to provide hints about how to process a particular get / get_one request.

In particular, DataObjectDecorators can use this to amend queries more effectively. Care must be taken to unset the context object after you're done with it, otherwise you will have a stale context, which could cause horrible bugs.

  • access: public
static void set_context_obj ( $obj)
  • $obj
Constructor __construct (line 117)

Construct a new DataObject.

DataObject __construct ([array|null $record = null], [boolean $isSingleton = false])
  • array|null $record: This will be null for a new database record. Alternatively, you can pass an array of field values. Normally this contructor is only