SnapResource Class Reference
[File Objects]

Wrapper class for Snap2 resources. More...

Inheritance diagram for SnapResource:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 __construct ($id="")
 Constructs a new SnapResource object (do not call directly!).
 countRelevantVersions ($constraint=array(), $limit=array(), $order=array())
 Retrieves count relevant versions of this resource.
 countVersions ($constraint=array(), $limit=array(), $order=array())
 Retrieves number of versions in this resource, using constraints.
 createVersion ($oldVersion=null)
 Creates a new version for this resource.
 listActions ($constraint=array(), $limit=array(), $order=array())
 Lists all actions that have occurred on versions of this resource.
 listRelevantVersions ($constraint=array(), $limit=array(), $order=array())
 Retrieves relevant versions of this resource.
 listVersions ($constraint=array(), $limit=array(), $order=array())
 Retrieves array of objects representing the versions of this resource.
 setValidDate ($validDate)
 Changes the valid date field associated with this resource.
 toCacheDump ()
 INSERT BRIEF DESCRIPTION HERE.

Static Public Member Functions

static _cancelDestroy ()
 INSERT BRIEF DESCRIPTION HERE.
static _destroyCMs ()
static lookup ($path)
 Retrieves a resource by path.
static retrieve ($id)
 Retrieves a resource by ID.

Public Attributes

const TYPE_CSS
 CSS Stylesheets.
const TYPE_HTML
 Plain Old HTML (no external objects).
const TYPE_INTERACTIVATE_INSTRUCTOR
 Interactivate Instructors.
const TYPE_INTERACTIVATE_LESSON
 Interactivate Lessons.
const TYPE_JAVASCRIPT
 Javascript Files.
const TYPE_LESSONPLAN
 Experimental lesson plan XML.
const TYPE_MEDIA_AGENTSHEETS
 Agentsheets Applets.
const TYPE_MEDIA_DOCUMENT
 PDF and MS Word documents.
const TYPE_MEDIA_FILE
 Generic file XML.
const TYPE_MEDIA_IMAGE
 Images.
const TYPE_MEDIA_INTERACTIVATE
 Interactivate Java Applets.
const TYPE_MEDIA_NETLOGO
 Netlogo Applets.
const TYPE_STDXML
 Standard XML 3.0 (no external objects).

Static Public Attributes

static $ATTRIBUTES

Protected Member Functions

 _canCreateVersion ($oldVersion=null)
 _canSetValidDate ($timestamp)
 INSERT BRIEF DESCRIPTION HERE.
 doDestroy ()
 loadActiveVersion ()
 loadDevVersion ()
 loadLiveVersion ()
 loadMaxOrdinal ()

Static Private Attributes

static $DELETED_VERSIONS


Detailed Description

Wrapper class for Snap2 resources.

A resource represents one logical piece of content. It is a field, just like directories (see SnapFile), and thus can be linked, unlinked, deleted, etc. It cannot have its own children, though. Instead of children, it has zero or more versions, which store particular revisions of the content logically contained in the resource. The resource itself does not store content. Two special versions will be considered active and when the content needs to be gathered from the resource, it comes from one of these versions. One version is the "dev" version and the other is the "live" version. If the server is a dev server (such as newdev), then the dev version is used for content, or the live version if there is no dev version. If the server is a production server (such as "www"), then only the live version is consulted. If there is no live version, then there is no active content for the resource.

Resources also have types. The type determines the nature of the content. The basic types are HTML and XML, in which case, the versions simply store raw HTML or XML in their content field. Other types support various types of media, such as images and applets. These types require management of external files and that involves a lot of complexity. Content modules (see SnapContent and its derivates) handle these details and make it as easy as possible to add new content types.

Attributes:
  • id: Resource ID
  • name: Descriptive name of resource
  • description: Description of resource
  • created: Creation date/time of resource
  • modified: Date/time of last modification to resource metadata
  • canonParentId: ID of canonical parent directory
  • refCount: Number of links to this resource, including canonical link
  • contentType: Resource content type; one of the TYPE_* constants
  • approvalDate: Most recent date/time when a version was approved as live for this resource
  • validDate: User-defined date for "validity" of resource
  • liveVersionId: ID of version that is currently live for this resource
  • devVersionId: ID of version that is currently marked as dev for this resource
  • nextOrdinal: Next ordinal to be used when creating versions

Fields:
  • maxOrdinal: Highest ordinal of all the versions for this resource
  • devVersion: SnapVersion object corresponding to the dev version of this resource
  • liveVersion: SnapVersion object corresponding to the live version of this resource
  • activeVersion: SnapVersion object corresponding to the active version of this resource

Definition at line 44 of file SnapResource.php5.


Constructor & Destructor Documentation

SnapResource::__construct ( id = ""  ) 

Constructs a new SnapResource object (do not call directly!).

For internal use only.

The constructor should only be used within the API. If you need to get a resource object, use the retrieve() and lookup() methods instead.

Parameters:
$id [integer]: resource ID

Definition at line 91 of file SnapResource.php5.

References SnapObject::setSave().


Member Function Documentation

static SnapResource::_cancelDestroy (  )  [static]

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

Definition at line 243 of file SnapResource.php5.

Referenced by SnapFile::destroy().

SnapResource::_canCreateVersion ( oldVersion = null  )  [protected]

For internal use only.

Definition at line 254 of file SnapResource.php5.

References SnapObject::convertReference(), SnapFile::getPermission(), and SnapObject::setReason().

SnapResource::_canSetValidDate ( timestamp  )  [protected]

INSERT BRIEF DESCRIPTION HERE.

For internal use only.

INSERT FULL DESCRIPTION HERE

Parameters:
$timestamp [TYPE]: DESCRIPTION
Returns:
[TYPE]: RETURN DESCRIPTION

Definition at line 277 of file SnapResource.php5.

References SnapFile::getPermission(), and SnapObject::setReason().

Referenced by setValidDate().

static SnapResource::_destroyCMs (  )  [static]

For internal use only.

Deletes all versions scheduled for deleted

Definition at line 226 of file SnapResource.php5.

Referenced by SnapFile::destroy().

SnapResource::countRelevantVersions ( constraint = array(),
limit = array(),
order = array() 
)

Retrieves count relevant versions of this resource.

A relevant version is one that is not defunct, or is defunct but is a direct "parent" of a non-defunct version. See listVersions() for more on the constraint parameters.

Parameters:
$constraint [array]: trim down results by conditions
$limit [array]: limit number of results by count and offset
$order [array]: sort results
Returns:
[integer]: number of versions for given constraints

Definition at line 687 of file SnapResource.php5.

SnapResource::countVersions ( constraint = array(),
limit = array(),
order = array() 
)

Retrieves number of versions in this resource, using constraints.

See the documentation for listContents() for more on the parameters to this method

Parameters:
$constraint [array]: trim down results by conditions
$limit [array]: limit number of results by count and offset
$order [array]: sort results
Returns:
[integer]: number of results given constraints

Definition at line 587 of file SnapResource.php5.

SnapResource::createVersion ( oldVersion = null  ) 

Creates a new version for this resource.

The version can be created out of nothing, or it can be created as a copy of an existing version. In the latter case, pass in a SnapVersion object as the sole parameter to this method. The new version will be in the 'In Progress' state and will be owned by the current user. You must have the Edit permission on this resource to create a new version.

Parameters:
$oldVersion [SnapVersion]: version to copy from (if desired)
Returns:
[SnapVersion]: newly created version object, or null on failure

Definition at line 404 of file SnapResource.php5.

References SnapDBI::cancelTransaction().

SnapResource::doDestroy (  )  [protected]

For internal use only.

Schedules all versions to be deleted (puts them in ()$DELETED_VERSIONS array)

Reimplemented from SnapFile.

Definition at line 212 of file SnapResource.php5.

References listVersions().

SnapResource::listActions ( constraint = array(),
limit = array(),
order = array() 
)

Lists all actions that have occurred on versions of this resource.

Actions are things like "Edit", "Submit", etc. That is, changes in state of a version. This is useful for tracking progress. This method will list those actions. The result array consists of subarrays which contain three fields: 'uid', which is the user ID of the user who performed the action; 'action', which is a string naming the action; 'actionTime', which is a MySQL timestamp of when the action occurred; and 'id', which is the ID of the version upon which the action was performed. See listContents() for more on the constraint parameters.

Parameters:
$constraint [array]: trim down results by conditions
$limit [array]: limit number of results by count and offset
$order [array]: sort results
Returns:
[array]: array of action info arrays (see description above), or null on error

Definition at line 730 of file SnapResource.php5.

SnapResource::listRelevantVersions ( constraint = array(),
limit = array(),
order = array() 
)

Retrieves relevant versions of this resource.

A relevant version is one that is not defunct, or is defunct but is a direct "parent" of a non-defunct version. See listVersions() for more on the constraint parameters.

Parameters:
$constraint [array]: trim down results by conditions
$limit [array]: limit number of results by count and offset
$order [array]: sort results
Returns:
[array]: array of SnapVersion objects for given constraints

Definition at line 637 of file SnapResource.php5.

SnapResource::listVersions ( constraint = array(),
limit = array(),
order = array() 
)

Retrieves array of objects representing the versions of this resource.

This method allows you to trim down the result set and sort it, mostly arbitrarily. The first parameter can be an array that specifies constraints that are converted into a WHERE clause on the database query. See [[SWAT_Model2::Simple_Entities]] for more on how to specify a constraint array. The second parameter lets you limit the number of results. As a simple number, a 'LIMIT x' is appended to the query. If an array of two numbers is given, then the first number specifies the offset to start the resultset at and the second specifies the number of records after that. The final parameter specifies how to order the results. If the elements in the array are not associative, then they are passed directly to the ORDER BY clause as is. If they are associative, then the key specifies the column and the value specifies either ASC or DESC.

Parameters:
$constraint [array]: trim down results by conditions
$limit [array]: limit number of results by count and offset
$order [array]: sort results
Returns:
[array]: array of SnapVersion objects that belong to this directory and satisfy the given constraints; or null if there was an error or invalid parameter

Definition at line 539 of file SnapResource.php5.

Referenced by doDestroy().

SnapResource::loadActiveVersion (  )  [protected]

For internal use only.

Dynamic loader to load the activeVersion field, which contains a SnapVersion object for whichever version is active for this server, if any

Definition at line 183 of file SnapResource.php5.

References SConfig::getDefault(), SnapObject::getId(), SnapObject::getType(), and SnapCache::updateById().

SnapResource::loadDevVersion (  )  [protected]

For internal use only.

Dynamic loader to load the devVersion field, which contains a SnapVersion object for the dev version associated with this resource

Definition at line 150 of file SnapResource.php5.

References SnapObject::getId(), SnapObject::getType(), SnapVersion::retrieve(), and SnapCache::updateById().

SnapResource::loadLiveVersion (  )  [protected]

For internal use only.

Dynamic loader to load the liveVersion field, which contains a SnapVersion object for the live version associated with this resource

Definition at line 167 of file SnapResource.php5.

References SnapObject::getId(), SnapObject::getType(), SnapVersion::retrieve(), and SnapCache::updateById().

SnapResource::loadMaxOrdinal (  )  [protected]

For internal use only.

Dynamic loader to load the maxOrdinal field, which gives the highest ordinal of all the versions belonging to this resource

Definition at line 130 of file SnapResource.php5.

References SnapObject::getId(), SnapObject::getType(), SnapDBI::query(), SObject::setError(), and SnapCache::updateById().

static SnapResource::lookup ( path  )  [static]

Retrieves a resource by path.

Use this method to retrieve a resource if you know its path. You cannot instantiate a resource and have it populate via a path anyways, but don't try, or badder things will happen.

Parameters:
$path [string]: path to resource
Returns:
[SnapResource]: resource object pointed to by $path, or null on failure or invalid path

Reimplemented from SnapFile.

Definition at line 335 of file SnapResource.php5.

References Snap2::checkInit(), and SnapCache::getByPath().

Referenced by SnapFile::addStylesheet(), SnapObject::convertReference(), SnapFile::getStylesheets(), SnapFile::lookup(), Snap2::lookup(), STransHTMLMedia::replaceMediaTag(), TSDBook::setCoverImage(), STransStdXMLHelper::translateContent(), STransStdXML3Helper::translateListPage(), STransStdXMLHelper::translateMedia(), STransStdXML3Helper::translateSectionData(), and TSDBook::uploadCoverImage().

static SnapResource::retrieve ( id  )  [static]

Retrieves a resource by ID.

Use this method to get a SnapREsource object if you know the ID. Do not instantiate a SnapResource object directly, or bad things will happen.

Parameters:
$id [integer]: ID of resource
Returns:
[SnapResource]: resource indicated by ID, or null if ID is invalid

Definition at line 306 of file SnapResource.php5.

References Snap2::checkInit(), SnapCache::getById(), SnapObject::getId(), and SnapCache::putById().

Referenced by SnapObject::convertReference(), TSDBook::delete(), SnapVersion::loadResource(), STransHTMLMedia::replaceMediaTag(), STransStdXML3Helper::translateListPage(), STransStdXMLHelper::translateMedia(), and STransStdXML3Helper::translateSectionData().

SnapResource::setValidDate ( validDate  ) 

Changes the valid date field associated with this resource.

The valid date indicates when the resource is considered to be applicable. It's meaning is user-defined.

Parameters:
$validDate [string]: MySQL-acceptable timestamp for new valid date
Returns:
[boolean]: success or failure

Definition at line 489 of file SnapResource.php5.

References _canSetValidDate(), SnapObject::checkValid(), SObject::setError(), and SnapDBI::startTransaction().

SnapResource::toCacheDump (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

Reimplemented from SnapObject.

Definition at line 113 of file SnapResource.php5.


Member Data Documentation

SnapResource::$ATTRIBUTES [static]

Database attributes for resources

Definition at line 73 of file SnapResource.php5.

Referenced by SnapSearch::execute(), and SnapDirectory::listContents().

SnapResource::$DELETED_VERSIONS [static, private]

For internal use only.

Used to store list of versions to be deleted after a resource (or series of resources) has been destroyed

Definition at line 81 of file SnapResource.php5.


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

Generated on Wed Nov 24 02:06:29 2010 for Common by  doxygen 1.5.6