CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Resource Class Reference

Represents a "resource" in CWIS. More...

## Public Member Functions
| __construct ($ResourceId)
| Object constructor for loading an existing resource. More...
| Delete ()
| Remove resource (and accompanying associations) from database and delete any associated files. More...
| Status ()
| Retrieve result of last operation if available. More...
| Id ()
| Retrieve numerical resource ID. More...
| SchemaId ()
| Retrieve ID of schema for resource. More...
| IsTempResource ($NewSetting=NULL)
| Get/set whether resource is a temporary record. More...
| Get ($FieldNameOrObject, $ReturnObject=FALSE, $IncludeVariants=FALSE)
| Retrieve value using field name or field object. More...
| GetByField ($FieldNameOrObject, $ReturnObject=FALSE, $IncludeVariants=FALSE)
| Old method for retrieving values, deprecated in favor of Get(). More...
| GetByFieldId ($FieldId, $ReturnObject=FALSE, $IncludeVariants=FALSE)
| Retrieve value using field ID. More...
| GetAsArray ($IncludeDisabledFields=FALSE, $ReturnObjects=TRUE)
| Retrieve all resource values as an array. More...
| GetMapped ($MappedName, $ReturnObject=FALSE, $IncludeVariants=FALSE)
| Retrieve value using standard (mapped) field name. More...
| GetQualifier ($FieldName, $ReturnObject=TRUE)
| Retrieve qualifier by field name. More...
| GetQualifierByFieldId ($FieldId, $ReturnObject=TRUE)
| Retrieve qualifier by field ID. More...
| GetQualifierByField ($Field, $ReturnObject=TRUE)
| Retrieve qualifier by Field object. More...
| FieldIsSet ($FieldNameOrObject, $IgnorePadding=FALSE)
| Determine if the value for a field is set. More...
| Set ($FieldNameOrObject, $NewValue, $Reset=FALSE)
| Set value using field name or field object. More...
| SetByField ($Field, $NewValue)
| Method replaced by Resource::Set(), preserved for backward compatibility. More...
| SetByFieldId ($FieldId, $NewValue)
| SetQualifier ($FieldName, $NewValue)
| SetQualifierByFieldId ($FieldId, $NewValue)
| SetQualifierByField ($Field, $NewValue)
| ClearByFieldId ($FieldId, $ValueToClear=NULL)
| Clear ($Field, $ValueToClear=NULL)
| ClearByField ($Field, $ValueToClear=NULL)
| Classifications ()
| CumulativeRating ()
| ScaledCumulativeRating ()
| NumberOfRatings ()
| Rating ($NewRating=NULL, $UserId=NULL)
| Comments ()
| NumberOfComments ()
| UserCanView (User $User, $AllowHooksToModify=TRUE)
| Determine if the given user can view the resource, e.g., on the full record page. More...
| UserCanEdit ($User)
| Determine if the given user can edit the resource. More...
| UserCanAuthor ($User)
| Determine if the given user can edit the resource. More...
| UserCanViewField ($User, $FieldOrFieldName)
| Check whether user is allowed to view specified metadata field. More...
| UserCanEditField ($User, $FieldOrFieldName)
| Check whether user is allowed to edit specified metadata field. More...
| UserCanAuthorField ($User, $FieldOrFieldName)
| Check whether user is allowed to author specified metadata field. More...
| UserCanModifyField ($User, $FieldOrFieldName)
| Check whether user is allowed to modify (Edit for perm resources, Author for temp) specified metadata field. More...

## Static Public Member Functions
static | Create ($SchemaId)
| Create a new resource. More...

## Protected Attributes
| $DB

## Detailed Description

Represents a "resource" in CWIS.

Definition at line 13 of file Resource.php.

## Constructor & Destructor Documentation

Resource::__construct | ( |  | $ResourceId | ) |

Object constructor for loading an existing resource.

(To create a new resource, use Resource::Create().)

Parameters

  int | $ResourceId | ID of resource to load.

See also
  Create()

Definition at line 23 of file Resource.php.

References CumulativeRating(), and Id().

## Member Function Documentation

Resource::Classifications | ( |  | ) |

Definition at line 1881 of file Resource.php.

References $DB, and Id().

Referenced by Delete().

Here is the caller graph for this function:

Resource::Clear | ( |  | $Field,
|  |  | $ValueToClear = `NULL`
| ) |  |

Definition at line 1580 of file Resource.php.

References $DB, Get(), Id(), IsTempResource(), MetadataSchema\MDFTYPE_CONTROLLEDNAME, MetadataSchema\MDFTYPE_DATE, MetadataSchema\MDFTYPE_FILE, MetadataSchema\MDFTYPE_FLAG, MetadataSchema\MDFTYPE_IMAGE, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_OPTION, MetadataSchema\MDFTYPE_PARAGRAPH, MetadataSchema\MDFTYPE_POINT, MetadataSchema\MDFTYPE_REFERENCE, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\MDFTYPE_TREE, MetadataSchema\MDFTYPE_URL, and MetadataSchema\MDFTYPE_USER.

Referenced by ClearByField().

Here is the caller graph for this function:

Resource::ClearByField | ( |  | $Field,
|  |  | $ValueToClear = `NULL`
| ) |  |

Definition at line 1872 of file Resource.php.

References Clear().

Referenced by ClearByFieldId(), and Set().

Here is the caller graph for this function:

Resource::ClearByFieldId | ( |  | $FieldId,
|  |  | $ValueToClear = `NULL`
| ) |  |

Definition at line 1573 of file Resource.php.

References ClearByField().

Resource::Comments | ( |  | ) |

Definition at line 2042 of file Resource.php.

References Id().

static Resource::Create | ( |  | $SchemaId | ) |
| static

Create a new resource.

Parameters

  int | $SchemaId | ID of metadata schema for new resource.

Returns
  object Resource object.

Exceptions

  Exception | if resource creation failed.

Definition at line 60 of file Resource.php.

References $DB, Id(), MetadataSchema\MDFTYPE_FLAG, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_OPTION, MetadataSchema\MDFTYPE_POINT, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\SCHEMAID_DEFAULT, and MetadataField\UPDATEMETHOD_ONRECORDCREATE.

Referenced by CWUserFactory\CreateNewUser(), and ResourceFactory\DuplicateResource().

Here is the caller graph for this function:

Resource::CumulativeRating | ( |  | ) |

Definition at line 1911 of file Resource.php.

Referenced by __construct(), GetAsArray(), NumberOfRatings(), and ScaledCumulativeRating().

Here is the caller graph for this function:

Resource::Delete | ( |  | ) |

Remove resource (and accompanying associations) from database and delete any associated files.

Definition at line 154 of file Resource.php.

References $DB, Classifications(), and Id().

Referenced by CWUser\Delete().

Here is the caller graph for this function:

Resource::FieldIsSet | ( |  | $FieldNameOrObject,
|  |  | $IgnorePadding = `FALSE`
| ) |  |

Determine if the value for a field is set.

Parameters

  mixed | $FieldNameOrObject | Full name of field or a Field object.
  bool | $IgnorePadding | Optional flag for ignoring whitespace padding for text, paragraph, number, and URL fields.

Returns
  Returns TRUE if the value is set or FALSE otherwise.

Definition at line 936 of file Resource.php.

References Get(), MetadataSchema\MDFTYPE_CONTROLLEDNAME, MetadataSchema\MDFTYPE_DATE, MetadataSchema\MDFTYPE_FILE, MetadataSchema\MDFTYPE_FLAG, MetadataSchema\MDFTYPE_IMAGE, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_OPTION, MetadataSchema\MDFTYPE_PARAGRAPH, MetadataSchema\MDFTYPE_POINT, MetadataSchema\MDFTYPE_REFERENCE, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\MDFTYPE_TREE, MetadataSchema\MDFTYPE_URL, and MetadataSchema\MDFTYPE_USER.

Resource::Get | ( |  | $FieldNameOrObject,
|  |  | $ReturnObject = `FALSE`,
|  |  | $IncludeVariants = `FALSE`
| ) |  |

Retrieve value using field name or field object.

Parameters

  mixed | $FieldNameOrObject | Full name of field or a Field object.
  bool | $ReturnObject | For field types that can return multiple values, if TRUE, returns array of objects, else returns array of values. Defaults to FALSE.
  bool | $IncludeVariants | If TRUE, includes variants in return value. Only applicable for ControlledName fields.

Returns
  Requested object(s) or value(s). Returns empty array (for field types that allow multiple values) or NULL (for field types that do not allow multiple values) if no values found. Returns NULL if field does not exist or was otherwise invalid.

See also
  Resource::GetByFieldId()

Definition at line 373 of file Resource.php.

References FileFactory\GetFilesForResource(), Id(), MetadataSchema\MDFTYPE_CONTROLLEDNAME, MetadataSchema\MDFTYPE_DATE, MetadataSchema\MDFTYPE_FILE, MetadataSchema\MDFTYPE_FLAG, MetadataSchema\MDFTYPE_IMAGE, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_OPTION, MetadataSchema\MDFTYPE_PARAGRAPH, MetadataSchema\MDFTYPE_POINT, MetadataSchema\MDFTYPE_REFERENCE, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\MDFTYPE_TREE, MetadataSchema\MDFTYPE_URL, MetadataSchema\MDFTYPE_USER, and Set().

Referenced by Clear(), FieldIsSet(), CWUser\Get(), GetAsArray(), GetByField(), GetByFieldId(), GetQualifierByField(), and Set().

Here is the caller graph for this function:

Resource::GetAsArray | ( |  | $IncludeDisabledFields = `FALSE`,
|  |  | $ReturnObjects = `TRUE`
| ) |  |

Retrieve all resource values as an array.

Parameters

  bool | $IncludeDisabledFields | Include values for disabled fields. (OPTIONAL, defaults to FALSE)
  bool | $ReturnObjects | If TRUE, an object is returned for field types where appropriate, in the same fashion as Resource::Get() (OPTIONAL, defaults to TRUE)

Returns
  Array of values with field names for array indices. Qualifiers (where available) are returned with an index of the field name with " Qualifier" appended.

See also
  Resource::Get()

Definition at line 712 of file Resource.php.

References CumulativeRating(), Get(), GetQualifierByField(), and Id().

Resource::GetByField | ( |  | $FieldNameOrObject,
|  |  | $ReturnObject = `FALSE`,
|  |  | $IncludeVariants = `FALSE`
| ) |  |

Old method for retrieving values, deprecated in favor of Get().

See also
  Get

Definition at line 677 of file Resource.php.

References Get().

Resource::GetByFieldId | ( |  | $FieldId,
|  |  | $ReturnObject = `FALSE`,
|  |  | $IncludeVariants = `FALSE`
| ) |  |

Retrieve value using field ID.

Parameters

  int | $FieldId | ID of field.
  bool | $ReturnObject | For field types that can return multiple values, if TRUE, returns array of objects, else returns array of values. Defaults to FALSE.
  bool | $IncludeVariants | If TRUE, includes variants in return value. Only applicable for ControlledName fields.

Returns
  Requested object(s) or value(s). Returns empty array (for field types that allow multiple values) or NULL (for field types that do not allow multiple values) if no values found.

See also
  Resource::Get()

Definition at line 694 of file Resource.php.

References Get().

Referenced by GetMapped().

Here is the caller graph for this function:

Resource::GetMapped | ( |  | $MappedName,
|  |  | $ReturnObject = `FALSE`,
|  |  | $IncludeVariants = `FALSE`
| ) |  |

Retrieve value using standard (mapped) field name.

Parameters

  string | $MappedName | Standard field name.
  bool | $ReturnObject | For field types that can return multiple values, if TRUE, returns array of objects, else returns array of values. Defaults to FALSE.
  bool | $IncludeVariants | If TRUE, includes variants in return value. Only applicable for ControlledName fields. Defaults to FALSE.

Returns
  Requested object(s) or value(s), or NULL if no mapping found. Returns empty array (for field types that allow multiple values) or NULL (for field types that do not allow multiple values) if no values found.

See also
  Resource::Get()

Definition at line 758 of file Resource.php.

References GetByFieldId().

Resource::GetQualifier | ( |  | $FieldName,
|  |  | $ReturnObject = `TRUE`
| ) |  |

Retrieve qualifier by field name.

Parameters

  string | $FieldName | Full name of field.
  bool | $ReturnObject | If TRUE, return Qualifier objects, else return qualifier IDs. Defaults to TRUE.

Returns
  Array of qualifiers if field supports qualifiers, or NULL if field does not support qualifiers.

Definition at line 774 of file Resource.php.

References GetQualifierByField().

Resource::GetQualifierByField | ( |  | $Field,
|  |  | $ReturnObject = `TRUE`
| ) |  |

Retrieve qualifier by Field object.

Parameters

  MetadataField | $Field | Field object.
  bool | $ReturnObject | If TRUE, return Qualifier objects, else return qualifier IDs. Defaults to TRUE.

Returns
  Array of qualifiers if field supports qualifiers, or NULL if field does not support qualifiers or field is invalid.

Definition at line 802 of file Resource.php.

References $Items, Get(), MetadataSchema\MDFTYPE_CONTROLLEDNAME, MetadataSchema\MDFTYPE_OPTION, and MetadataSchema\MDFTYPE_TREE.

Referenced by GetAsArray(), GetQualifier(), and GetQualifierByFieldId().

Here is the caller graph for this function:

Resource::GetQualifierByFieldId | ( |  | $FieldId,
|  |  | $ReturnObject = `TRUE`
| ) |  |

Retrieve qualifier by field ID.

Parameters

  int | $FieldId | ID of field.
  int | $ReturnObject | If TRUE, return Qualifier objects, else return qualifier IDs. Defaults to TRUE.

Returns
  Array of qualifiers if field supports qualifiers, or NULL if field does not support qualifiers or field is invalid.

Definition at line 788 of file Resource.php.

References GetQualifierByField().

Resource::Id | ( |  | ) |

Retrieve numerical resource ID.

Returns
  Resource ID.

Definition at line 275 of file Resource.php.

Referenced by __construct(), Classifications(), Clear(), Comments(), Create(), Delete(), Get(), GetAsArray(), IsTempResource(), NumberOfComments(), NumberOfRatings(), Rating(), CWUser\ResourceId(), and Set().

Here is the caller graph for this function:

Resource::IsTempResource | ( |  | $NewSetting = `NULL` | ) |

Get/set whether resource is a temporary record.

Parameters

  bool | $NewSetting | TRUE/FALSE setting for whether resource is temporary. (OPTIONAL)

Returns
  TRUE if resource is temporary record, or FALSE otherwise.

Definition at line 295 of file Resource.php.

References $DB, Id(), and SchemaId().

Referenced by Clear(), and Set().

Here is the caller graph for this function:

Resource::NumberOfComments | ( |  | ) |

Definition at line 2062 of file Resource.php.

References Id().

Resource::NumberOfRatings | ( |  | ) |

Definition at line 1930 of file Resource.php.

References CumulativeRating(), and Id().

Resource::Rating | ( |  | $NewRating = `NULL`,
|  |  | $UserId = `NULL`
| ) |  |

Definition at line 1955 of file Resource.php.

References $DB, and Id().

Resource::ScaledCumulativeRating | ( |  | ) |

Definition at line 1917 of file Resource.php.

References CumulativeRating().

Resource::SchemaId | ( |  | ) |

Retrieve ID of schema for resource.

Returns
  int Schema ID.

Definition at line 284 of file Resource.php.

Referenced by IsTempResource().

Here is the caller graph for this function:

Resource::Set | ( |  | $FieldNameOrObject,
|  |  | $NewValue,
|  |  | $Reset = `FALSE`
| ) |  |

Set value using field name or field object.

Parameters

  mixed | $FieldNameOrObject | Field name or MetadataField object.
  mixed | $NewValue | New value for field.
  bool | $Reset | When TRUE Controlled Names, Classifications, and Options will be set to contain ONLY the contents of NewValue, rather than appending $NewValue to the current value.

Definition at line 1008 of file Resource.php.

References $DB, Classification\CLASSSTAT_OK, ClearByField(), FileFactory\Copy(), Get(), Id(), IsTempResource(), MetadataSchema\MDFTYPE_CONTROLLEDNAME, MetadataSchema\MDFTYPE_DATE, MetadataSchema\MDFTYPE_FILE, MetadataSchema\MDFTYPE_FLAG, MetadataSchema\MDFTYPE_IMAGE, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_OPTION, MetadataSchema\MDFTYPE_PARAGRAPH, MetadataSchema\MDFTYPE_POINT, MetadataSchema\MDFTYPE_REFERENCE, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\MDFTYPE_TREE, MetadataSchema\MDFTYPE_URL, and MetadataSchema\MDFTYPE_USER.

Referenced by Get(), CWUser\Set(), SetByField(), and SetByFieldId().

Here is the caller graph for this function:

Resource::SetByField | ( |  | $Field,
|  |  | $NewValue
| ) |  |

Method replaced by Resource::Set(), preserved for backward compatibility.

See also
  Resource::Set()

Definition at line 1517 of file Resource.php.

References Set().

Resource::SetByFieldId | ( |  | $FieldId,
|  |  | $NewValue
| ) |  |

Definition at line 1523 of file Resource.php.

References Set().

Resource::SetQualifier | ( |  | $FieldName,
|  |  | $NewValue
| ) |  |

Definition at line 1530 of file Resource.php.

References SetQualifierByField().

Resource::SetQualifierByField | ( |  | $Field,
|  |  | $NewValue
| ) |  |

Definition at line 1544 of file Resource.php.

Referenced by SetQualifier(), and SetQualifierByFieldId().

Here is the caller graph for this function:

Resource::SetQualifierByFieldId | ( |  | $FieldId,
|  |  | $NewValue
| ) |  |

Definition at line 1537 of file Resource.php.

References SetQualifierByField().

Resource::Status | ( |  | ) |

Retrieve result of last operation if available.

Returns
  Result of last operation (if available).

Definition at line 266 of file Resource.php.

Resource::UserCanAuthor | ( |  | $User | ) |

Determine if the given user can edit the resource.

The result of this method can be modified via the EVENT_RESOURCE_EDIT_PERMISSION_CHECK event.

Parameters

  User | $User | user

Returns
  bool TRUE if the user can edit the resource and FALSE otherwise

Definition at line 2114 of file Resource.php.

Resource::UserCanAuthorField | ( |  | $User,
|  |  | $FieldOrFieldName
| ) |  |

Check whether user is allowed to author specified metadata field.

Parameters

  User | $User | User to check.
  mixed | $FieldOrFieldName | Field name or object.

Returns
  TRUE if user can author field, otherwise FALSE.

Definition at line 2147 of file Resource.php.

Resource::UserCanEdit | ( |  | $User | ) |

Determine if the given user can edit the resource.

The result of this method can be modified via the EVENT_RESOURCE_EDIT_PERMISSION_CHECK event.

Parameters

  User | $User | user

Returns
  bool TRUE if the user can edit the resource and FALSE otherwise

Definition at line 2103 of file Resource.php.

Resource::UserCanEditField | ( |  | $User,
|  |  | $FieldOrFieldName
| ) |  |

Check whether user is allowed to edit specified metadata field.

Parameters

  User | $User | User to check.
  mixed | $FieldOrFieldName | Field name or object.

Returns
  TRUE if user can edit field, otherwise FALSE.

Definition at line 2136 of file Resource.php.

Resource::UserCanModifyField | ( |  | $User,
|  |  | $FieldOrFieldName
| ) |  |

Check whether user is allowed to modify (Edit for perm resources, Author for temp) specified metadata field.

Parameters

  User | $User | User to check.
  mixed | $FieldOrFieldName | Field name or object.

Returns
  TRUE if user can modify field, otherwise FALSE.

Definition at line 2159 of file Resource.php.

Resource::UserCanView | ( | User | $User,
|  |  | $AllowHooksToModify = `TRUE`
| ) |  |

Determine if the given user can view the resource, e.g., on the full record page.

The result of this method can be modified via the EVENT_RESOURCE_VIEW_PERMISSION_CHECK event.

Parameters

  User | $User | user
  bool | $AllowHooksToModify | TRUE if hook functions should be allowed to modify the return value (OPTIONAL default TRUE).

Returns
  bool TRUE if the user can view the resource and FALSE otherwise

Definition at line 2092 of file Resource.php.

Resource::UserCanViewField | ( |  | $User,
|  |  | $FieldOrFieldName
| ) |  |

Check whether user is allowed to view specified metadata field.

Parameters

  User | $User | User to check.
  mixed | $FieldOrFieldName | Field name or object.

Returns
  TRUE if user can view field, otherwise FALSE.

Definition at line 2125 of file Resource.php.

## Member Data Documentation

Resource::$DB
| protected

Definition at line 2168 of file Resource.php.

Referenced by Classifications(), Clear(), Create(), Delete(), IsTempResource(), Rating(), and Set().

The documentation for this class was generated from the following file:

- objects/Resource.php