webCOMAND

cObject Model

  • Class Name: cObject
  • Namespace: io_comand_repo\models
  • Extends: nothing (the only model that extends nothing)
  • Implements: authorized, content_item, persistence, meta_template, validation

A COMAND Object represents an instance of a Content Type, including its field values and methods. It can be accessed like a standard PHP object. All COMAND Objects will use or extend comand\models\cObject. Custom PHP classes that extend comand\models\cObject can be mapped to content types and are created automatically when a COMAND object of the mapped content type is created or loaded through the repo class.

Properties

  • ID - Auto-generated ID unique across all local objects of the same content type.
  • OID - Auto-generated ID unique across all local objects of all content types.
  • DOID - Auto-generated ID unique across all objects and dimensions of all content types.  Dimension variants of an object will share the same ID, OID and UUID, but have different DOIDs.
  • UUID - Auto-generated ID unique across all objects in all repositories.  Unlike ID, OID and DOID, the UUID is maintained across export and import operations, so they can be relied on across repositories and within a repository after export, delete and re-import.  For more information, see UUID.
  • Type - Reference to the Content Type that defines this objects fields.
  • Folders - Reference to a list of folders that contain this object.
  • DIndex - Dimension Index, which determines the position of this object relative to other dimension variants of the same object.  The variant with the lowest DIndex is considered the "default".
  • _Meta - An object with the following object metadata properties.
    • LastModified - A timestamp indicating when the object was last updated, in 'YYYY-MM-DD HH:MM:SSmmm' format.
    • ContentTypeID - ID of the object's Content Type.
    • ContentID - ID of the object, which is more readily accessible as $object->ID.

Usage

To access a COMAND object like a standard PHP object, use:

  • Fields - Accessed like PHP object properties: $object->field
  • Methods - Accessed like PHP object methods: $object->method(param1, param2)
$contact = $repo->get_first('FROM Contact');
$contact->email('Hello ' . $contact->FirstName);

Object Relational Mapping (ORM)

Objects may be mapped to and from a relational database, such as MySQL, when a relational database is used for the repository storage engine.  In these cases, objects will be created automatically from the various tables for a single unified PHP object.  When the PHP object is saved, it is mapped back to the various tables and rows in the relational database. This process is known as object relational mapping (ORM).

Currently COMAND will only map to and from relational databases that store content in the COMAND database schema. Future versions will also support mapping to and from more traditional and custom schemas.

General Purpose cObject Model

By default, objects retrieved from the repository will be an instance of the COMAND object model, which is a PHP class that provides access to the fields and methods defined in the repository, as if a PHP class was defined with the same fields and methods. This is convenient because no PHP class (or model class) is needed to load and work with objects of any content type in the repository.  This is also critical because in many cases content types are not known when the application is programmed.

Content Type Models

While the general purpose object model works well in many situations, it is often useful to define your own models to represent objects of a certain content type when loaded from the repository, providing PHP variables and methods. For more information, see content type models.

Metadata cObject Methods

A set of metadata methods can be used to set and access information about objects that is automatically stored/cached in the repository for all objects when they are stored, saved and approved.

cObject Summary

When a Object is referenced as a string, it will automatically produce a string representation of the object based on the content type. The summary is determined according to the following rules.

  • Content Type Model __toString() Method - If the object has a model with a __toString() method, it will be called and the return value will be used.
  • Content Type Model Summary() Method - If the object has a model with a method__summary() method, it will be called and the return value will be used.
  • Content Type Summary - If the object's content type defines a Summary method, it will be processed and the resulting output will be used. The result is also automatically cached to avoid unnecessary script processing when the object is referenced multiple times.
  • Content Type Display Fields - If the object's content type defines one or more fields with Display enabled, the values of all display fields will be separated by a space, dash, space (" - ") and used for the string.
  • Object Type Identifier and ID - As a last resort, the object's content type Identifier and ID will be used in the form of "(TypeIdentifier) ID".

cObject Key

Each object maintains a string that uniquely identifies it from other object's of the same content type in the same parent collection (field/container). It is useful to reference a specific object by a name in cPath and cQL queries, rather than ID, OID or UUID. In the example queries below, "System", "ContentType" and "Template" are keys used to identify folder and content type objects.

/System/[:ContentType]Template
FROM ContentType IN /System WHERE .Key() = 'Template'

An object's key is determined according to the following rules.

  • Key Method - If the object has a model with a method__key() method, it will be processed and the resulting output will be used. The result is also automatically cached to avoid unnecessary script processing when the object is referenced multiple times.
  • First Unique Field - If the object's content type defines one or more fields with Unique/Key (Uniqueness) set, the values of the first unique field will be used.
  • Object ID - As a last resort, the object's ID will be used.

cObject Description

A short description of each object is maintained in the repository.  It is displayed under the title of an object in List View and accessible using the .Description() cObject method in a cPath or cQL expression.

For example:

/System/[:ContentType][.Description()='Image']
FROM ContentType IN /System WHERE .Description()<'Image'

An object's description is determined according to the following rules.

  • Description Method - If the object has a model with a method__description() method, it will be processed and the resulting output will be used. The result is also automatically cached to avoid unnecessary script processing when the object is referenced multiple times.
  • Field named Description or Summary - If the object's content type defines a field named Description or Summary, it will be used for the description automatically.
  • Object Content Type Title - As a last resort, the object's Content Type Title will be used.

cObject Keywords

A space-separated list of searchable keywords is maintained in the repository.  These keywords are used by the search feature in the Collection Bar in List, Grid and other collection views.  Keywords are also accessible using the .Keywords() cObject method and MATCHES() function in a cPath or cQL expression.

For example:

[:ContentType][MATCHES(.Keywords(),'Image')]
SELECT OID, Title FROM ContentType WHERE MATCHES(.Keywords(),'Image')

An object's keywords can also be accessed from the cObject::Keyword() method.

An object's keywords are determined according to the following rules.

  • Keywords Method - If the object has a model that defines a method__keywords() method, it will be processed and the resulting output will be used. The result is also automatically cached to avoid unnecessary processing.
  • Object Text Fields - If no Keywords method is defined, the text from all text-based fields will be combined to form the keywords.

cObject Icon

An icon for each object is maintained in the repository.  The icon is used by in the webCOMAND user interface and other places to represent the object visually.  Icons are also accessible using the .Icon() object method in a cQL expression.

For example:

SELECT OID, Title, .Icon() AS Icon FROM ContentType

An object's keywords can also be accessed from the cObject::Keyword() method.

An object's keywords are determined according to the following rules.

  • Keywords Method - If the object has a model that defines a method__keywords() method, it will be processed and the resulting output will be used. The result is also automatically cached to avoid unnecessary processing.
  • Object Text Fields - If no Keywords method is defined, the text from all text-based fields will be combined to form the keywords.

cObject Last Modified Timestamp

Each object maintains a last modified timestamp, which indicates the last time it was changed.  The last modified timestamp can be selected or used to filter queries through the META() function in a cPath or cQL expression.

For example:

/System/[:ContentType][META(LastModified)<'2016-01-01 00:00:00']
FROM ContentType IN /System WHERE META(LastModified)<'2016-01-01 00:00:00'