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
ResourceFactory Class Reference

Factory for Resource objects. More...

Inheritance diagram for ResourceFactory:
[legend]
Collaboration diagram for ResourceFactory:
[legend]

## Public Member Functions
| __construct ($SchemaId=MetadataSchema::SCHEMAID_DEFAULT)
| Class constructor. More...
| Schema ()
| Get metadata schema associated with this resource factory. More...
| DuplicateResource ($ResourceId)
| Duplicate the specified resource and return to caller. More...
| ImportResourcesFromXmlFile ($FileName)
| Import resource records from XML file. More...
| ClearQualifier ($ObjectOrId, $NewObjectOrId=NULL)
| Clear or change specific qualifier for all resources. More...
| GetRatedResourceCount ()
| Return number of resources that have ratings. More...
| GetRatedResourceUserCount ()
| Return number of users who have rated resources. More...
| GetRecentlyReleasedResources ($Count=10, $Offset=0, $MaxDaysToGoBack=90)
| Get resources sorted by descending Date of Record Release, with Date of Record Creation as the secondary sort criteria. More...
| GetResourceIdsSortedBy ($FieldId, $Ascending=TRUE, $Limit=NULL)
| Get resource IDs sorted by specified field. More...
| FilterNonViewableResources ($ResourceIds, $User)
| Filter a list of resources leaving only those viewable by a specified user. More...
| GetPossibleFieldNames ()
| Get possible field names for resources. More...
| GetMatchingResources ($ValuesToMatch, $AllRequired=TRUE, $ReturnObjects=TRUE, $Operator="==")
| Find resources with values that match those specified. More...
| AssociatedVisibleResourceCount ($ValueId, $User, $ForegroundUpdate=FALSE)
| Return the number of resources in this schema that are visible to a specified user and that have a given ControlledName value set. More...
| UpdateAssociatedVisibleResourceCount ($ValueId, $UserId)
| Update the count of resources associated with a ControlledName that are visible to a specified user. More...
| GetVisibleResourceCount (CWUser $User)
| Get the total number of resources visible to a specified user. More...
| ClearVisibleResourceCountForValues ($ValueIds)
| Clear cache of visible resources associated with a ControlledName. More...
| ClearVisibleResourceCount ($Resource)
| Clear database visibility caches for all the CNames referenced by a specified resource. More...
| GetReleasedResourceTotal ()
| Get the total number of released resources in the collection. More...
| GetResourceTotal ()
| Get the total number of resources in the collection, even if they are not released. More...
| ClearCaches ()
| Clear internal caches. More...
Public Member Functions inherited from ItemFactory
| __construct ($ItemClassName, $ItemTableName, $ItemIdColumnName, $ItemNameColumnName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
| Class constructor. More...
| GetItemClassName ()
| Get class name of items manipulated by factory. More...
| CleanOutStaleTempItems ($MinutesUntilStale=10080)
| Clear out (call the Delete() method) for any temp items more than specified number of minutes old. More...
| GetNextItemId ()
| Retrieve next available (non-temp) item ID. More...
| GetHighestItemId ($IgnoreSqlCondition=FALSE)
| Retrieve highest item ID in use. More...
| GetNextTempItemId ()
| Return next available temporary item ID. More...
| GetItemCount ($Condition=NULL, $IncludeTempItems=FALSE)
| Get count of items. More...
| GetItemIds ($Condition=NULL, $IncludeTempItems=FALSE, $SortField=NULL, $SortAscending=TRUE)
| Return array of item IDs. More...
| GetLatestModificationDate ($Condition=NULL)
| Get newest modification date (based on values in "DateLastModified" column in database table). More...
| GetItem ($ItemId)
| Retrieve item by item ID. More...
| ItemExists ($ItemId, $IgnoreSqlCondition=FALSE)
| Check that item exists with specified ID. More...
| GetItemByName ($Name, $IgnoreCase=FALSE)
| Retrieve item by name. More...
| GetItemIdByName ($Name, $IgnoreCase=FALSE)
| Retrieve item ID by name. More...
| GetItemIdsByNames ($Names)
| Look up IDs for specified names. More...
| GetItemNames ($SqlCondition=NULL)
| Retrieve item names. More...
| GetItems ($SqlCondition=NULL)
| Retrieve items. More...
| GetItemsAsOptionList ($OptionListName, $SelectedItemId=NULL, $SqlCondition=NULL, $DisplaySize=1, $SubmitOnChange=FALSE, $Disabled=FALSE)
| Retrieve items of specified type as HTML option list with item names as labels and item IDs as value attributes. More...
| NameIsInUse ($Name, $IgnoreCase=FALSE)
| Check whether item name is currently in use. More...
| SearchForItemNames ($SearchString, $NumberOfResults=100, $IncludeVariants=FALSE, $UseBooleanMode=TRUE, $Offset=0, $IdExclusions=array(), $NameExclusions=array())
| Retrieve items with names matching search string. More...
| GetCountForItemNames ($SearchString, $IncludeVariants=FALSE, $UseBooleanMode=TRUE, $IdExclusions=array(), $NameExclusions=array())
| Retrieve count of items with names matching search string. More...
| ReindexByItemIds ($Array)
| Reindex supplied associative array, by replacing item names with item IDs. More...
| CachingEnabled ($NewValue=NULL)
| Enable/disable caching of item information. More...
| ClearCaches ()
| Clear item information caches. More...
| SetOrderOpsCondition ($Condition)
| Set SQL condition (added to WHERE clause) used to select items for ordering operations. More...
| InsertBefore ($TargetItem, $NewItem)
| Insert item into order before specified item. More...
| InsertAfter ($TargetItem, $NewItem)
| Insert item into order after specified item. More...
| Prepend ($Item)
| Add item to beginning of order. More...
| Append ($Item)
| Add item to end of order. More...
| GetItemIdsInOrder ()
| Retrieve list of item IDs in order. More...
| RemoveItemFromOrder ($ItemId)
| Remove item from existing order. More...

## Static Public Member Functions
static | FlattenMultiSchemaResourceList ($ResourcesPerSchema)
| Take an array keyed by SchemaId with elements giving arrays of ResourceIds and merge it to a flattened list of ResourceIds. More...
static | BuildMultiSchemaResourceList ($ResourceIds)
| Take an array of ResourceIds and split it into an array keyed by SchemaId where the elements are arrays of ResourceIds for that schema. More...
static | ClearViewingPermsCache ()
| Clear the cache of viewable resources. More...

## Protected Attributes
| $Schema
| $SchemaId
Protected Attributes inherited from ItemFactory
| $DB

## Detailed Description

Factory for Resource objects.

Definition at line 13 of file ResourceFactory.php.

## Constructor & Destructor Documentation

ResourceFactory::__construct | ( |  | $SchemaId = `MetadataSchema::SCHEMAID_DEFAULT` | ) |

Class constructor.

Parameters

  int | $SchemaId | ID of schema to load resources for. (OPTIONAL, defaults to SCHEMAID_DEFAULT)

Definition at line 22 of file ResourceFactory.php.

References $SchemaId, and Schema().

## Member Function Documentation

ResourceFactory::AssociatedVisibleResourceCount | ( |  | $ValueId,
|  |  | $User,
|  |  | $ForegroundUpdate = `FALSE`
| ) |  |

Return the number of resources in this schema that are visible to a specified user and that have a given ControlledName value set.

Parameters

  string | $ValueId | Field valueid to look for
  User | $User | User to check
  bool | $ForegroundUpdate | TRUE to wait for value rather than a background update (OPTIONAL, default FALSE)

Returns
  int the number of associated resources or -1 when no count is available

Definition at line 805 of file ResourceFactory.php.

References UpdateAssociatedVisibleResourceCount().

static ResourceFactory::BuildMultiSchemaResourceList | ( |  | $ResourceIds | ) |
| static

Take an array of ResourceIds and split it into an array keyed by SchemaId where the elements are arrays of ResourceIds for that schema.

Parameters

  array | $ResourceIds | Array of ResourceIds.

Returns
  array Two-dimensional array of ResourceIds.

See also
  ResourceFactory::FlattenMultiSchemaResourceList()

Definition at line 987 of file ResourceFactory.php.

References ItemFactory\$DB, and $SchemaId.

Referenced by CWUserFactory\FilterNonViewableResourcesFromPerUserLists().

Here is the caller graph for this function:

ResourceFactory::ClearCaches | ( |  | ) |

Clear internal caches.

This is primarily intended for situations where memory may have run low.

Definition at line 1031 of file ResourceFactory.php.

ResourceFactory::ClearQualifier | ( |  | $ObjectOrId,
|  |  | $NewObjectOrId = `NULL`
| ) |  |

Clear or change specific qualifier for all resources.

Parameters

  mixed | $ObjectOrId | Qualifier ID or object to clear or change.
  mixed | $NewObjectOrId | New Qualifier ID or object. (OPTIONAL, defaults to NULL, which will clear old qualifier)

Definition at line 249 of file ResourceFactory.php.

References Schema().

static ResourceFactory::ClearViewingPermsCache | ( |  | ) |
| static

Clear the cache of viewable resources.

Definition at line 1021 of file ResourceFactory.php.

References ItemFactory\$DB.

ResourceFactory::ClearVisibleResourceCount | ( |  | $Resource | ) |

Clear database visibility caches for all the CNames referenced by a specified resource.

Parameters

  Resource | $Resource | Resource to snag values from.

Definition at line 932 of file ResourceFactory.php.

References ClearVisibleResourceCountForValues(), MetadataSchema\MDFTYPE_CONTROLLEDNAME, MetadataSchema\MDFTYPE_OPTION, and Schema().

ResourceFactory::ClearVisibleResourceCountForValues | ( |  | $ValueIds | ) |

Clear cache of visible resources associated with a ControlledName.

Parameters

  array | $ValueIds | CNIds to clear the cache for.

Definition at line 918 of file ResourceFactory.php.

Referenced by ClearVisibleResourceCount().

Here is the caller graph for this function:

ResourceFactory::DuplicateResource | ( |  | $ResourceId | ) |

Duplicate the specified resource and return to caller.

Parameters

  int | $ResourceId | ID of resource to duplicate.

Returns
  object New Resource object.

Definition at line 47 of file ResourceFactory.php.

References Resource\Create(), Item\ItemExists(), and Schema().

ResourceFactory::FilterNonViewableResources | ( |  | $ResourceIds,
|  |  | $User
| ) |  |

Filter a list of resources leaving only those viewable by a specified user.

Parameters

  array | $ResourceIds | ResourceIds to check
  CWUser | $User | User to use for check

Returns
  array of ResourceIds (subset of $ResourceIds) that $User can view

Definition at line 464 of file ResourceFactory.php.

References Item\ItemExists(), and Schema().

Referenced by GetRecentlyReleasedResources(), GetVisibleResourceCount(), and UpdateAssociatedVisibleResourceCount().

Here is the caller graph for this function:

static ResourceFactory::FlattenMultiSchemaResourceList | ( |  | $ResourcesPerSchema | ) |
| static

Take an array keyed by SchemaId with elements giving arrays of ResourceIds and merge it to a flattened list of ResourceIds.

Parameters

  array | $ResourcesPerSchema | Array of per-schema ResourceIds.

Returns
  array Flattened array of ResourceIds.

See also
  ResourceFactory::BulidMultiSchemaResourceList()

Definition at line 968 of file ResourceFactory.php.

References $SchemaId.

Referenced by CWUserFactory\FilterNonViewableResourcesFromPerUserLists().

Here is the caller graph for this function:

ResourceFactory::GetMatchingResources | ( |  | $ValuesToMatch,
|  |  | $AllRequired = `TRUE`,
|  |  | $ReturnObjects = `TRUE`,
|  |  | $Operator = `"=="`
| ) |  |

Find resources with values that match those specified.

(Only works for Text, Paragraph, Number, Timestamp, Date, Flag, Url, Point, and User fields.)

Parameters

  array | $ValuesToMatch | Array with metadata field IDs (or other values that can be resolved by MetadataSchema::GetCanonicalFieldIdentifier()) for the index and string values to search for for the values.
  bool | $AllRequired | TRUE to AND conditions together, FALSE to OR them (OPTIONAL, default TRUE)
  bool | $ReturnObjects | TRUE to return Resource objects, FALSE for IDs
  string | $Operator | Operator for comparison, (OPTIONAL, default ==)

Returns
  Array of Resource objects with resource IDs for index.

Definition at line 617 of file ResourceFactory.php.

References MetadataSchema\GetCanonicalFieldIdentifier(), MetadataSchema\MDFTYPE_DATE, MetadataSchema\MDFTYPE_FLAG, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_PARAGRAPH, MetadataSchema\MDFTYPE_POINT, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\MDFTYPE_URL, MetadataSchema\MDFTYPE_USER, and Schema().

ResourceFactory::GetPossibleFieldNames | ( |  | ) |

Get possible field names for resources.

Returns
  array Array of metadata field names with metadata field IDs for the index.

Definition at line 590 of file ResourceFactory.php.

References Schema().

ResourceFactory::GetRatedResourceCount | ( |  | ) |

Return number of resources that have ratings.

Returns
  int Resource count.

Definition at line 303 of file ResourceFactory.php.

ResourceFactory::GetRatedResourceUserCount | ( |  | ) |

Return number of users who have rated resources.

Returns
  int User count.

Definition at line 315 of file ResourceFactory.php.

ResourceFactory::GetRecentlyReleasedResources | ( |  | $Count = `10`,
|  |  | $Offset = `0`,
|  |  | $MaxDaysToGoBack = `90`
| ) |  |

Get resources sorted by descending Date of Record Release, with Date of Record Creation as the secondary sort criteria.

Parameters

  int | $Count | Maximum number of resources to return.
  int | $Offset | Starting offset of segment to return (0=beginning).
  int | $MaxDaysToGoBack | Maximum number of days to go back for resources, according to Date of Record Release.

Returns
  array Array of Resource objects.

Definition at line 332 of file ResourceFactory.php.

References FilterNonViewableResources().

ResourceFactory::GetReleasedResourceTotal | ( |  | ) |

Get the total number of released resources in the collection.

Returns
  int The total number of released resources.

Definition at line 955 of file ResourceFactory.php.

References User\GetAnonymousUser(), and GetVisibleResourceCount().

ResourceFactory::GetResourceIdsSortedBy | ( |  | $FieldId,
|  |  | $Ascending = `TRUE`,
|  |  | $Limit = `NULL`
| ) |  |

Get resource IDs sorted by specified field.

Only IDs for resources with non-empty non-null values for the specified field are returned.

Parameters

  mixed | $FieldId | ID or name of field.
  bool | $Ascending | If TRUE, sort is ascending, otherwise sort is descending.
  int | $Limit | Number of IDs to retrieve. (OPTIONAL)

Returns
  array Resource IDs.

Definition at line 376 of file ResourceFactory.php.

References MetadataSchema\MDFTYPE_DATE, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_PARAGRAPH, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\MDFTYPE_URL, and Schema().

ResourceFactory::GetResourceTotal | ( |  | ) |

Get the total number of resources in the collection, even if they are not released.

Returns
  int The total number of resources.

Definition at line 1008 of file ResourceFactory.php.

ResourceFactory::GetVisibleResourceCount | ( | CWUser | $User | ) |

Get the total number of resources visible to a specified user.

Parameters

  CWUser | $User | User to check.

Returns
  int Number of visible resources.

Definition at line 901 of file ResourceFactory.php.

References FilterNonViewableResources().

Referenced by GetReleasedResourceTotal().

Here is the caller graph for this function:

ResourceFactory::ImportResourcesFromXmlFile | ( |  | $FileName | ) |

Import resource records from XML file.

The file should contain a top-level "ResourceCollection" tag, inside of which should be one or more <Resource> tags. Within the <Resource> tag are tags giving metadata field values, with the tag names constructed from the alphanumeric part of the field names (e.g. Title in a <Title> tag, Date Record Checked in a <DateRecordChecked> tag, etc). See install/SampleResource.xml for an example.

Parameters

  string | $FileName | Name of XML file.

Returns
  array IDs of any new resource records.

Exceptions

  Exception | When input file cannot be opened.

Definition at line 95 of file ResourceFactory.php.

References ControlledName\Create(), Classification\Create(), Resource\Create(), 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 Schema().

ResourceFactory::Schema | ( |  | ) |

Get metadata schema associated with this resource factory.

Returns
  object MetadataSchema.

Definition at line 37 of file ResourceFactory.php.

References $Schema.

Referenced by __construct(), ClearQualifier(), ClearVisibleResourceCount(), DuplicateResource(), FilterNonViewableResources(), GetMatchingResources(), GetPossibleFieldNames(), GetResourceIdsSortedBy(), and ImportResourcesFromXmlFile().

Here is the caller graph for this function:

ResourceFactory::UpdateAssociatedVisibleResourceCount | ( |  | $ValueId,
|  |  | $UserId
| ) |  |

Update the count of resources associated with a ControlledName that are visible to a specified user.

Parameters

  int | $ValueId | ControlledNameId to update.
  int | $UserId | UserId to update.

Definition at line 864 of file ResourceFactory.php.

References FilterNonViewableResources().

Referenced by AssociatedVisibleResourceCount().

Here is the caller graph for this function:

## Member Data Documentation

ResourceFactory::$Schema
| protected

Definition at line 1043 of file ResourceFactory.php.

Referenced by Schema().

ResourceFactory::$SchemaId
| protected

Definition at line 1044 of file ResourceFactory.php.

Referenced by __construct(), BuildMultiSchemaResourceList(), and FlattenMultiSchemaResourceList().

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

- objects/ResourceFactory.php