CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

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

Public Member Functions | 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...
| 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...
| ClearViewingPermsCache ()
| Clear the cache of viewable resources. 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...
| 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...
| 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(), $ValueExclusions=array())
| Retrieve items with names matching search string. More...
| GetCountForItemNames ($SearchString, $IncludeVariants=FALSE, $UseBooleanMode=TRUE, $IdExclusions=array(), $ValueExclusions=array())
| Retrieve count of items with names matching search string. 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...

## Additional Inherited Members
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.

## 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 817 of file ResourceFactory.php.

References UpdateAssociatedVisibleResourceCount().

ResourceFactory::ClearCaches | ( |  | ) |

Clear internal caches.

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

Definition at line 963 of file ResourceFactory.php.

References ItemFactory\$DB.

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 241 of file ResourceFactory.php.

ResourceFactory::ClearViewingPermsCache | ( |  | ) |

Clear the cache of viewable resources.

Definition at line 580 of file ResourceFactory.php.

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 38 of file ResourceFactory.php.

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

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 456 of file ResourceFactory.php.

References Item\ItemExists().

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

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 618 of file ResourceFactory.php.

References MetadataSchema\MDFTYPE_DATE, MetadataSchema\MDFTYPE_FLAG, MetadataSchema\MDFTYPE_NUMBER, MetadataSchema\MDFTYPE_PARAGRAPH, MetadataSchema\MDFTYPE_POINT, MetadataSchema\MDFTYPE_TEXT, MetadataSchema\MDFTYPE_TIMESTAMP, MetadataSchema\MDFTYPE_URL, and MetadataSchema\MDFTYPE_USER.

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 591 of file ResourceFactory.php.

ResourceFactory::GetRatedResourceCount | ( |  | ) |

Return number of resources that have ratings.

Returns
  int Resource count.

Definition at line 295 of file ResourceFactory.php.

ResourceFactory::GetRatedResourceUserCount | ( |  | ) |

Return number of users who have rated resources.

Returns
  int User count.

Definition at line 307 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 324 of file ResourceFactory.php.

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

ResourceFactory::GetReleasedResourceTotal | ( |  | ) |

Get the total number of released resources in the collection.

Returns
  int The total number of released resources.

Definition at line 938 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 368 of file ResourceFactory.php.

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

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 949 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 920 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 86 of file ResourceFactory.php.

References 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, and MetadataSchema\MDFTYPE_USER.

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 883 of file ResourceFactory.php.

References FilterNonViewableResources().

Referenced by AssociatedVisibleResourceCount().

Here is the caller graph for this function:

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

- objects/ResourceFactory.php